9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek Copyright (C) 2013 Red Hat
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek SSSD tests: Dynamic DNS tests
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek This program is free software; you can redistribute it and/or modify
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek it under the terms of the GNU General Public License as published by
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek (at your option) any later version.
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek This program is distributed in the hope that it will be useful,
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek GNU General Public License for more details.
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek You should have received a copy of the GNU General Public License
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek/* In order to access opaque types */
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnikstatic TALLOC_CTX *global_mock_context = NULL;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozekvoid __wrap_execv(const char *path, char *const argv[])
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FUNC_DATA, "nsupdate success test case\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FUNC_DATA, "nsupdate error test case\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FUNC_DATA, "nsupdate timeout test case\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "unknown test case\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS, "Child exiting with status %d\n", err);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek while ((name = sss_mock_ptr_type(char *)) != NULL) {
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik ifap = talloc_zero(global_mock_context, struct ifaddrs);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek errno = ENOMEM; /* getifaddrs sets errno, too */
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Do not allocate directly on ifap->ifa_addr to
4cae8609b513c267af11c0409bfe1d17d3a5da2fMichal Zidek * avoid alignment warnings */
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl sa = (struct sockaddr_in *) talloc(ifap, struct sockaddr_in6);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek /* convert straddr into ifa_addr */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozekstatic void dyndns_test_done(struct tevent_req *req)
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek tevent_req_callback_data(req, struct dyndns_test_ctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ctx->tctx->error = be_nsupdate_recv(req, &ctx->child_status);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichlvoid will_return_getifaddrs(const char *ifname, const char *straddr,
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichlvoid dyndns_test_sss_iface_addr_get_misc(void **state)
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl assert_ptr_equal(sss_iface_addr_get_address(NULL), NULL);
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl assert_ptr_equal(sss_iface_addr_get_address(&addrs[0]), &ss[0]);
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl assert_ptr_equal(sss_iface_addr_get_address(&addrs[1]), &ss[1]);
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl assert_ptr_equal(sss_iface_addr_get_address(&addrs[2]), &ss[2]);
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl assert_ptr_equal(sss_iface_addr_get_next(NULL), NULL);
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl assert_ptr_equal(sss_iface_addr_get_next(&addrs[0]), &addrs[1]);
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl assert_ptr_equal(sss_iface_addr_get_next(&addrs[1]), &addrs[2]);
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl assert_ptr_equal(sss_iface_addr_get_next(&addrs[2]), NULL);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl will_return_getifaddrs("eth0", "192.168.0.1", AF_INET);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl will_return_getifaddrs("eth1", "192.168.0.2", AF_INET);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ret = sss_iface_addr_list_get(dyndns_test_ctx, "eth0", &addrlist);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek /* There must be only one address with the correct value */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek &((struct sockaddr_in *) addrlist->addr)->sin_addr,
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_true(check_leaks_pop(dyndns_test_ctx) == true);
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnikvoid dyndns_test_get_multi_ifaddr(void **state)
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl will_return_getifaddrs("eth0", "192.168.0.2", AF_INET);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl will_return_getifaddrs("eth0", "192.168.0.1", AF_INET);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik ret = sss_iface_addr_list_get(dyndns_test_ctx, "eth0", &addrlist);
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik &((struct sockaddr_in *) sss_if_addr->addr)->sin_addr,
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik /* ip addresses are returned in different order */
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik assert_string_equal(straddr, "192.168.0.1");
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik &((struct sockaddr_in *) sss_if_addr->addr)->sin_addr,
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik /* ip addresses are returned in different order */
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik assert_string_equal(straddr, "192.168.0.2");
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik assert_true(check_leaks_pop(dyndns_test_ctx) == true);
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichlvoid dyndns_test_get_ifaddr_enoent(void **state)
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl will_return_getifaddrs("eth0", "192.168.0.1", AF_INET);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl will_return_getifaddrs("eth1", "192.168.0.2", AF_INET);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichl ret = sss_iface_addr_list_get(dyndns_test_ctx, "non_existing_interface",
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichl assert_true(check_leaks_pop(dyndns_test_ctx) == true);
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichlvoid dyndns_test_addr_list_as_str_list(void **state)
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl for (i = 0; i < size; i++) {
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl will_return_getifaddrs("eth0", input[i].addr, input[i].af);
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl ret = sss_iface_addr_list_get(dyndns_test_ctx, "eth0", &addrlist);
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl ret = sss_iface_addr_list_as_str_list(dyndns_test_ctx, addrlist, &output);
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl for (i = 0; i < size; i++) {
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl /* addresses are returned in reversed order */
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl assert_int_equal(strcmp(input[i].addr, output[size - 1 - i]), 0);
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl assert_true(check_leaks_pop(dyndns_test_ctx) == true);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* getifaddrs is called twice in sss_get_dualstack_addresses() */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl for (i = 0; i < 2; i++) {
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "192.168.0.2", AF_INET);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth1", "192.168.0.1", AF_INET);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "2001:cdba::555", AF_INET6);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth1", "2001:cdba::444", AF_INET6);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl sin.sin_addr.s_addr = inet_addr ("192.168.0.2");
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = sss_get_dualstack_addresses(dyndns_test_ctx,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = be_nsupdate_create_fwd_msg(dyndns_test_ctx, NULL, NULL, "bran_stark",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "\nupdate delete bran_stark. in A\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in A 192.168.0.2\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in AAAA\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* fallback case realm and server */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = be_nsupdate_create_fwd_msg(dyndns_test_ctx, "North", "Winterfell",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "bran_stark",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "server Winterfell\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "realm North\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in A\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in A 192.168.0.2\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in AAAA\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* just realm */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = be_nsupdate_create_fwd_msg(dyndns_test_ctx, "North", NULL,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "bran_stark",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "realm North\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in A\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in A 192.168.0.2\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in AAAA\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* just server */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = be_nsupdate_create_fwd_msg(dyndns_test_ctx, NULL, "Winterfell",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "bran_stark",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "server Winterfell\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in A\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in A 192.168.0.2\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in AAAA\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* remove just A */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = be_nsupdate_create_fwd_msg(dyndns_test_ctx, NULL, NULL, "bran_stark",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "\nupdate delete bran_stark. in A\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in A 192.168.0.2\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* remove just AAAA */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = be_nsupdate_create_fwd_msg(dyndns_test_ctx, NULL, NULL, "bran_stark",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "\nupdate add bran_stark. 1234 in A 192.168.0.2\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in AAAA\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_true(check_leaks_pop(dyndns_test_ctx) == true);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichlvoid dyndns_test_create_fwd_msg_mult(void **state)
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* getifaddrs is called twice in sss_get_dualstack_addresses() */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl for (i = 0; i < 2; i++) {
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "192.168.0.2", AF_INET);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "192.168.0.1", AF_INET);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "2001:cdba::555", AF_INET6);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "2001:cdba::444", AF_INET6);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl sin.sin_addr.s_addr = inet_addr ("192.168.0.2");
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = sss_get_dualstack_addresses(dyndns_test_ctx,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = be_nsupdate_create_fwd_msg(dyndns_test_ctx, NULL, NULL, "bran_stark",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "\nupdate delete bran_stark. in A\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in A 192.168.0.1\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in A 192.168.0.2\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in AAAA\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::444\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_true(check_leaks_pop(dyndns_test_ctx) == true);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* getifaddrs is called twice in sss_get_dualstack_addresses() */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl for (i = 0; i < 2; i++) {
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "192.168.0.2", AF_INET);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "192.168.0.1", AF_INET);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl sin.sin_addr.s_addr = inet_addr ("192.168.0.2");
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = sss_get_dualstack_addresses(dyndns_test_ctx,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = be_nsupdate_create_fwd_msg(dyndns_test_ctx, NULL, NULL, "bran_stark",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "\nupdate delete bran_stark. in A\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in A 192.168.0.1\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in A 192.168.0.2\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in AAAA\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_true(check_leaks_pop(dyndns_test_ctx) == true);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichlvoid dyndns_test_create_fwd_msg_AAAA(void **state)
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* getifaddrs is called twice in sss_get_dualstack_addresses() */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl for (i = 0; i < 2; i++) {
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "2001:cdba::555", AF_INET6);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "2001:cdba::444", AF_INET6);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = inet_pton(AF_INET6, "2001:cdba::555", &sin.sin6_addr.s6_addr);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = sss_get_dualstack_addresses(dyndns_test_ctx,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = be_nsupdate_create_fwd_msg(dyndns_test_ctx, NULL, NULL, "bran_stark",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "\nupdate delete bran_stark. in A\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in AAAA\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::444\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_true(check_leaks_pop(dyndns_test_ctx) == true);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl /* getifaddrs is called twice in sss_get_dualstack_addresses() */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl for (i = 0; i < 2; i++) {
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "192.168.0.2", AF_INET);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth1", "192.168.0.1", AF_INET);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "2001:cdba::555", AF_INET6);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth1", "2001:cdba::444", AF_INET6);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl sin.sin_addr.s_addr = inet_addr ("192.168.0.2");
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl ret = sss_get_dualstack_addresses(dyndns_test_ctx,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl &((struct sockaddr_in6 *) sss_if_addrs->addr)->sin6_addr,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl /* ip addresses are returned in different order */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_string_equal(straddr, "2001:cdba::555");
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl &((struct sockaddr_in *) sss_if_addrs->addr)->sin_addr,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl /* ip addresses are returned in different order */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_true(check_leaks_pop(dyndns_test_ctx) == true);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichlvoid dyndns_test_dualstack_multiple_addresses(void **state)
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl /* getifaddrs is called twice in sss_get_dualstack_addresses() */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl for (i = 0; i < 2; i++) {
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "192.168.0.2", AF_INET);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "192.168.0.1", AF_INET);
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* loopback - invalid for DNS (should be skipped) */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "::1", AF_INET6);
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* linklocal - invalid for DNS (should be skipped) */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "fe80::5054:ff:fe4a:65ae", AF_INET6);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "2001:cdba::555", AF_INET6);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "2001:cdba::444", AF_INET6);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl sin.sin_addr.s_addr = inet_addr ("192.168.0.2");
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl ret = sss_get_dualstack_addresses(dyndns_test_ctx,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl &((struct sockaddr_in6 *) sss_if_addrs->addr)->sin6_addr,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl /* ip addresses are returned in different order */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_string_equal(straddr, "2001:cdba::444");
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl &((struct sockaddr_in6 *) sss_if_addrs->addr)->sin6_addr,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl /* ip addresses are returned in different order */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_string_equal(straddr, "2001:cdba::555");
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl &((struct sockaddr_in *) sss_if_addrs->addr)->sin_addr,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl /* ip addresses are returned in different order */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl &((struct sockaddr_in *) sss_if_addrs->addr)->sin_addr,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl /* ip addresses are returned in different order */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_true(check_leaks_pop(dyndns_test_ctx) == true);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichlvoid dyndns_test_dualstack_no_iface(void **state)
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "192.168.0.2", AF_INET);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth1", "192.168.0.1", AF_INET);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "2001:cdba::555", AF_INET6);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth1", "2001:cdba::444", AF_INET6);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl sin.sin_addr.s_addr = inet_addr ("192.168.0.3");
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl ret = sss_get_dualstack_addresses(dyndns_test_ctx,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_true(check_leaks_pop(dyndns_test_ctx) == true);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek req = be_nsupdate_send(tmp_ctx, dyndns_test_ctx->tctx->ev,
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek tevent_req_set_callback(req, dyndns_test_done, dyndns_test_ctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek /* Wait until the test finishes with EOK */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Child request returned [%d]: %s\n", ret, strerror(ret));
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_true(WIFEXITED(dyndns_test_ctx->child_status));
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_int_equal(WEXITSTATUS(dyndns_test_ctx->child_status), 0);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek req = be_nsupdate_send(tmp_ctx, dyndns_test_ctx->tctx->ev,
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek tevent_req_set_callback(req, dyndns_test_done, dyndns_test_ctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek /* Wait until the test finishes with EIO (child error) */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Child request returned [%d]: %s\n", ret, strerror(ret));
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_true(WIFEXITED(dyndns_test_ctx->child_status));
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_int_equal(WEXITSTATUS(dyndns_test_ctx->child_status), 1);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek dyndns_test_ctx->state = MOCK_NSUPDATE_TIMEOUT;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek req = be_nsupdate_send(tmp_ctx, dyndns_test_ctx->tctx->ev,
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek tevent_req_set_callback(req, dyndns_test_done, dyndns_test_ctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek /* Wait until the test finishes with EIO (child error) */
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina /* The event queue may not be empty. We need to make sure that all events
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina * are processed. Unfortunately, tevent_loop_wait() contains a bug that
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina * prevents exiting the loop even if there are no remaining events, thus
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina * we have to use tevent_loop_once().
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina * FIXME: use tevent_loop_wait() when the bug is fixed
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina * https://bugzilla.samba.org/show_bug.cgi?id=10012
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina tevent_loop_once(dyndns_test_ctx->tctx->ev); /* SIGCHLD handler */
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina tevent_loop_once(dyndns_test_ctx->tctx->ev); /* nsupdate_child_handler */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Child request returned [%d]: %s\n", ret, strerror(ret));
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek struct dyndns_test_ctx *ctx = talloc_get_type(pvt, struct dyndns_test_ctx);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek be_nsupdate_timer_schedule(ctx->tctx->ev, ctx->update_ctx);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek ret = be_nsupdate_init(tmp_ctx, dyndns_test_ctx->be_ctx, NULL,
3bd78eb2faf09635b8d307e4440ccb1420f80716Jakub Hrozek ret = be_nsupdate_init_timer(dyndns_test_ctx->update_ctx,
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek /* Wait until the timer hits */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Child request returned [%d]: %s\n", ret, strerror(ret));
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek/* Testsuite setup and teardown */
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik global_mock_context = talloc_new(global_talloc_context);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek dyndns_test_ctx = talloc_zero(global_talloc_context, struct dyndns_test_ctx);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek dyndns_test_ctx->tctx = create_dom_test_ctx(dyndns_test_ctx, TESTS_PATH,
d43c9d18fb263b1ea4071b20e93ce4994583f62fJakub Hrozek dyndns_test_ctx->be_ctx = mock_be_ctx(dyndns_test_ctx, dyndns_test_ctx->tctx);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int dyndns_test_simple_setup(void **state)
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik global_mock_context = talloc_new(global_talloc_context);
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik dyndns_test_ctx = talloc_zero(global_talloc_context, struct dyndns_test_ctx);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek _("Do not delete the test database after a test run"), NULL },
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek /* Utility functions unit test */
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_sss_iface_addr_get_misc,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(dyndns_test_get_ifaddr,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(dyndns_test_get_multi_ifaddr,
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_get_ifaddr_enoent,
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_addr_list_as_str_list,
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek /* Dynamic DNS update unit tests*/
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(dyndns_test_ok,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(dyndns_test_error,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(dyndns_test_timeout,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(dyndns_test_interval,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl /* Dynamic DNS dualstack unit tests*/
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_dualstack,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_dualstack_multiple_addresses,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_dualstack_no_iface,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* Messages for nsupdate */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_create_fwd_msg,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_create_fwd_msg_mult,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_create_fwd_msg_A,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_create_fwd_msg_AAAA,
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek /* Even though normally the tests should clean up after themselves
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz * they might not after a failed run. Remove the old DB to be sure */
cb4742876508a08ba90c82466c9dba708e4bf999Pavel Březina test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek rv = cmocka_run_group_tests(tests, NULL, NULL);