test_dyndns.c revision e210ed5da220acebb6751db4466fe352de08eaeb
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 */
a95c006f748fa9df0dd81509b51974133d2786afLukas Slebodnik#define TEST_SYSDB_FILE "cache_"TEST_DOM_NAME".ldb"
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) {
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ifap = talloc_zero(global_talloc_context, struct ifaddrs);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek errno = ENOMEM; /* getifaddrs sets errno, too */
4cae8609b513c267af11c0409bfe1d17d3a5da2fMichal Zidek /* Do not alocate directly on ifap->ifa_addr to
4cae8609b513c267af11c0409bfe1d17d3a5da2fMichal Zidek * avoid alignment warnings */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek /* convert straddr into ifa_addr */
4cae8609b513c267af11c0409bfe1d17d3a5da2fMichal Zidek if (inet_pton(AF_INET, straddr, &sa->sin_addr) != 1) {
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);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozekvoid will_return_getifaddrs(const char *ifname, const char *straddr)
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek will_return_getifaddrs(NULL, NULL); /* 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);
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 static int ncalls = 0;
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 */
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,
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek dyndns_test_ctx->be_ctx = talloc_zero(dyndns_test_ctx, struct be_ctx);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek dyndns_test_ctx->be_ctx->cdb = dyndns_test_ctx->tctx->confdb;
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek dyndns_test_ctx->be_ctx->ev = dyndns_test_ctx->tctx->ev;
919cfb623e9b725eaa654c6e1b513d1305057314Jakub Hrozek dyndns_test_ctx->be_ctx->conf_path = dyndns_test_ctx->tctx->conf_dom_path;
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 */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek /* Dynamic DNS update unit tests*/
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek /* Set debug level to invalid value so we can deside 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
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek * they might not after a failed run. Remove the old db to be sure */
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_SYSDB_FILE);