test_dyndns.c revision 5a4239490c7fb7d732180a9d40f27f0247c56631
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 */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozekvoid __wrap_execv(const char *path, char *const argv[])
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek DEBUG(SSSDBG_FUNC_DATA, ("nsupdate success test case\n"));
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek DEBUG(SSSDBG_FUNC_DATA, ("nsupdate error test case\n"));
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek DEBUG(SSSDBG_FUNC_DATA, ("nsupdate timeout test case\n"));
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, ("unknown test case\n"));
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek 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 */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ifap->ifa_addr = (struct sockaddr *) talloc(ifap, struct sockaddr_in);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ((struct sockaddr_in *) ifap->ifa_addr)->sin_family = AF_INET;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek /* convert straddr into ifa_addr */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek &(((struct sockaddr_in *) ifap->ifa_addr)->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 */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ("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) */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ("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) */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ("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,
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek /* Wait until the timer hits */
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek ("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;
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek dyndns_test_ctx->be_ctx->conf_path = talloc_asprintf(dyndns_test_ctx,
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek assert_non_null(dyndns_test_ctx->be_ctx->conf_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);