test_dyndns.c revision 6fd5306145d98ea3bab7f32aa66475f610f388ce
d53747c386354ff7db8629dfdf20f44a7c4d715dEugen Kuksa Jakub Hrozek <jhrozek@redhat.com>
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu Copyright (C) 2013 Red Hat
cacbb5e3100fb85d23d1614cace3a8662801f2e6Eugen Kuksa SSSD tests: Dynamic DNS tests
6d81916b9004f8d9b6032113c5987ab07da47015Karl Luc This program is free software; you can redistribute it and/or modify
b062631d2f72f0b2b2b6140bc5b0fccb66d1802bChristian Maeder it under the terms of the GNU General Public License as published by
d53747c386354ff7db8629dfdf20f44a7c4d715dEugen Kuksa the Free Software Foundation; either version 3 of the License, or
b062631d2f72f0b2b2b6140bc5b0fccb66d1802bChristian Maeder (at your option) any later version.
b062631d2f72f0b2b2b6140bc5b0fccb66d1802bChristian Maeder This program is distributed in the hope that it will be useful,
823ce7a568b0f653ebe83af7ab6ac9ec70f2cf8eKarl Luc but WITHOUT ANY WARRANTY; without even the implied warranty of
b062631d2f72f0b2b2b6140bc5b0fccb66d1802bChristian Maeder MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b062631d2f72f0b2b2b6140bc5b0fccb66d1802bChristian Maeder GNU General Public License for more details.
b062631d2f72f0b2b2b6140bc5b0fccb66d1802bChristian Maeder You should have received a copy of the GNU General Public License
c51d1f5ff88cce030fe543e271ca6b85625b70d8Karl Luc along with this program. If not, see <http://www.gnu.org/licenses/>.
1ea7fb6b0f66210bc0d3cb995f1b655277b33884Eugen Kuksa/* In order to access opaque types */
07f731e693fe433a238b5cc0aab6c5c99c1da798Karl Lucvoid __wrap_execv(const char *path, char *const argv[])
07f731e693fe433a238b5cc0aab6c5c99c1da798Karl Luc DEBUG(SSSDBG_FUNC_DATA, "nsupdate success test case\n");
8b42604fc9e948093bde658f32b8446e9c6a3576Eugen Kuksa DEBUG(SSSDBG_FUNC_DATA, "nsupdate error test case\n");
ead7fb0fe5492f65c8e47eaa9d5105bffde163f2Eugen Kuksa DEBUG(SSSDBG_FUNC_DATA, "nsupdate timeout test case\n");
8b42604fc9e948093bde658f32b8446e9c6a3576Eugen Kuksa DEBUG(SSSDBG_TRACE_LIBS, "Child exiting with status %d\n", err);
8b42604fc9e948093bde658f32b8446e9c6a3576Eugen Kuksa while ((name = sss_mock_ptr_type(char *)) != NULL) {
ead7fb0fe5492f65c8e47eaa9d5105bffde163f2Eugen Kuksa ifap = talloc_zero(global_mock_context, struct ifaddrs);
18741eef977546e24fce1fde1b8a8f817aedc6d0Christian Maeder errno = ENOMEM; /* getifaddrs sets errno, too */
07f731e693fe433a238b5cc0aab6c5c99c1da798Karl Luc /* Do not alocate directly on ifap->ifa_addr to
07f731e693fe433a238b5cc0aab6c5c99c1da798Karl Luc * avoid alignment warnings */
8b42604fc9e948093bde658f32b8446e9c6a3576Eugen Kuksa sa = (struct sockaddr_in *) talloc(ifap, struct sockaddr_in6);
07f731e693fe433a238b5cc0aab6c5c99c1da798Karl Luc /* convert straddr into ifa_addr */
b062631d2f72f0b2b2b6140bc5b0fccb66d1802bChristian Maedervoid __wrap_freeifaddrs(struct ifaddrs *ifap)
dabf0263008e0b55440c4e3fa0b61261af8c28ceEugen Kuksastatic void dyndns_test_done(struct tevent_req *req)
dabf0263008e0b55440c4e3fa0b61261af8c28ceEugen Kuksa tevent_req_callback_data(req, struct dyndns_test_ctx);
dabf0263008e0b55440c4e3fa0b61261af8c28ceEugen Kuksa ctx->tctx->error = be_nsupdate_recv(req, &ctx->child_status);
ff41d94839a36ce86291af5d83abe2bd39cce1d0Eugen Kuksavoid will_return_getifaddrs(const char *ifname, const char *straddr,
ff41d94839a36ce86291af5d83abe2bd39cce1d0Eugen Kuksa will_return_getifaddrs("eth0", "192.168.0.1", AF_INET);
ff41d94839a36ce86291af5d83abe2bd39cce1d0Eugen Kuksa will_return_getifaddrs("eth1", "192.168.0.2", AF_INET);
ff41d94839a36ce86291af5d83abe2bd39cce1d0Eugen Kuksa will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
ff41d94839a36ce86291af5d83abe2bd39cce1d0Eugen Kuksa ret = sss_iface_addr_list_get(dyndns_test_ctx, "eth0", &addrlist);
ff41d94839a36ce86291af5d83abe2bd39cce1d0Eugen Kuksa /* There must be only one address with the correct value */
ff41d94839a36ce86291af5d83abe2bd39cce1d0Eugen Kuksa &((struct sockaddr_in *) addrlist->addr)->sin_addr,
ff41d94839a36ce86291af5d83abe2bd39cce1d0Eugen Kuksa assert_true(check_leaks_pop(dyndns_test_ctx) == true);
07f731e693fe433a238b5cc0aab6c5c99c1da798Karl Luc will_return_getifaddrs("eth0", "192.168.0.2", AF_INET);
07f731e693fe433a238b5cc0aab6c5c99c1da798Karl Luc will_return_getifaddrs("eth0", "192.168.0.1", AF_INET);
07f731e693fe433a238b5cc0aab6c5c99c1da798Karl Luc will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
07f731e693fe433a238b5cc0aab6c5c99c1da798Karl Luc ret = sss_iface_addr_list_get(dyndns_test_ctx, "eth0", &addrlist);
8b42604fc9e948093bde658f32b8446e9c6a3576Eugen Kuksa &((struct sockaddr_in *) sss_if_addr->addr)->sin_addr,
8b42604fc9e948093bde658f32b8446e9c6a3576Eugen Kuksa /* ip addresses are returned in different order */
8b42604fc9e948093bde658f32b8446e9c6a3576Eugen Kuksa &((struct sockaddr_in *) sss_if_addr->addr)->sin_addr,
8b42604fc9e948093bde658f32b8446e9c6a3576Eugen Kuksa /* ip addresses are returned in different order */
8b42604fc9e948093bde658f32b8446e9c6a3576Eugen Kuksa assert_true(check_leaks_pop(dyndns_test_ctx) == true);
c51d1f5ff88cce030fe543e271ca6b85625b70d8Karl Luc will_return_getifaddrs("eth0", "192.168.0.1", AF_INET);
d5c6ddb570942f686319dcaf6c4b513a033e00ceEugen Kuksa will_return_getifaddrs("eth1", "192.168.0.2", AF_INET);
d5c6ddb570942f686319dcaf6c4b513a033e00ceEugen Kuksa will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
d5c6ddb570942f686319dcaf6c4b513a033e00ceEugen Kuksa ret = sss_iface_addr_list_get(dyndns_test_ctx, "non_existing_interface",
d5c6ddb570942f686319dcaf6c4b513a033e00ceEugen Kuksa assert_true(check_leaks_pop(dyndns_test_ctx) == true);
d5c6ddb570942f686319dcaf6c4b513a033e00ceEugen Kuksavoid dyndns_test_addr_list_as_str_list(void **state)
d5c6ddb570942f686319dcaf6c4b513a033e00ceEugen Kuksa const char* addr;
d5c6ddb570942f686319dcaf6c4b513a033e00ceEugen Kuksa for (i = 0; i < size; i++) {
d5c6ddb570942f686319dcaf6c4b513a033e00ceEugen Kuksa will_return_getifaddrs("eth0", input[i].addr, input[i].af);
d5c6ddb570942f686319dcaf6c4b513a033e00ceEugen Kuksa will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
d5c6ddb570942f686319dcaf6c4b513a033e00ceEugen Kuksa ret = sss_iface_addr_list_get(dyndns_test_ctx, "eth0", &addrlist);
c51d1f5ff88cce030fe543e271ca6b85625b70d8Karl Luc ret = sss_iface_addr_list_as_str_list(dyndns_test_ctx, addrlist, &output);
f2bb6f4c9f075b94e7f83a6589f457bc8b7fb30cEugen Kuksa for (i = 0; i < size; i++) {
08e520eb8e9947de926d733c48a13249c857f570Eugen Kuksa /* addresses are returned in reversed order */
08e520eb8e9947de926d733c48a13249c857f570Eugen Kuksa assert_int_equal(strcmp(input[i].addr, output[size - 1 - i]), 0);
c51d1f5ff88cce030fe543e271ca6b85625b70d8Karl Luc assert_true(check_leaks_pop(dyndns_test_ctx) == true);
823ce7a568b0f653ebe83af7ab6ac9ec70f2cf8eKarl Luc /* getifaddrs is called twice in sss_get_dualstack_addresses() */
07f731e693fe433a238b5cc0aab6c5c99c1da798Karl Luc for (i = 0; i < 2; i++) {
823ce7a568b0f653ebe83af7ab6ac9ec70f2cf8eKarl Luc will_return_getifaddrs("eth0", "192.168.0.2", AF_INET);
18741eef977546e24fce1fde1b8a8f817aedc6d0Christian Maeder will_return_getifaddrs("eth1", "192.168.0.1", AF_INET);
07f731e693fe433a238b5cc0aab6c5c99c1da798Karl Luc will_return_getifaddrs("eth0", "2001:cdba::555", AF_INET6);
cba0aeea95db26960d4d2e5a1dd571f17a5b7ae4Eugen Kuksa will_return_getifaddrs("eth1", "2001:cdba::444", AF_INET6);
07f731e693fe433a238b5cc0aab6c5c99c1da798Karl Luc will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
c51d1f5ff88cce030fe543e271ca6b85625b70d8Karl Luc &((struct sockaddr_in6 *) sss_if_addrs->addr)->sin6_addr,
1ea7fb6b0f66210bc0d3cb995f1b655277b33884Eugen Kuksa /* ip addresses are returned in different order */
&addrlist);
&addrlist);
static int ncalls = 0;
ncalls++;
int rv;
int no_cleanup = 0;
int opt;
switch(opt) {
return rv;