99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek Copyright (C) 2015 Red Hat
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek This program is free software; you can redistribute it and/or modify
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek it under the terms of the GNU General Public License as published by
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek (at your option) any later version.
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek This program is distributed in the hope that it will be useful,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek GNU General Public License for more details.
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek You should have received a copy of the GNU General Public License
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozekstruct tevent_timer *__real__tevent_add_timer(struct tevent_context *ev,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek const char *location);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozekstruct tevent_timer *__wrap__tevent_add_timer(struct tevent_context *ev,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek return __real__tevent_add_timer(ev, mem_ctx, next_event,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek { "offline_timeout", AS_STR(OFFLINE_TIMEOUT) },
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek global_mock_context = talloc_new(global_talloc_context);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_ctx = talloc_zero(global_talloc_context, struct test_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_ctx->be_ctx = mock_be_ctx(test_ctx, test_ctx->tctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_ctx->be_ctx->domain->subdomains = named_domain(test_ctx,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek "subdomains",
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_non_null(test_ctx->be_ctx->domain->subdomains);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozekstatic void assert_domain_state(struct sss_domain_info *dom,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozekstatic void test_mark_subdom_offline_check(struct tevent_context *ev,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek struct test_ctx *test_ctx = talloc_get_type(pvt, struct test_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_domain_state(test_ctx->be_ctx->domain->subdomains,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_domain_state(test_ctx->be_ctx->domain, DOM_ACTIVE);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek be_mark_dom_offline(test_ctx->be_ctx->domain, test_ctx->be_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_domain_state(test_ctx->be_ctx->domain, DOM_ACTIVE);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozekstatic void test_mark_subdom_offline(void **state)
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_domain_state(test_ctx->be_ctx->domain->subdomains,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek be_mark_dom_offline(test_ctx->be_ctx->domain->subdomains, test_ctx->be_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_domain_state(test_ctx->be_ctx->domain->subdomains,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek /* A timer must be added that resets the state back */
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek /* Global offline state must not change */
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek /* Make sure we don't add a second timer */
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek be_mark_dom_offline(test_ctx->be_ctx->domain->subdomains, test_ctx->be_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_domain_state(test_ctx->be_ctx->domain->subdomains,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek /* Wait for the internal timer to reset our subdomain back */
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek tv = tevent_timeval_current_ofs(OFFLINE_TIMEOUT + 1, 0);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek check_ev = tevent_add_timer(test_ctx->tctx->ev, test_ctx, tv,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Cannot create timer\n");
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozekstatic void test_mark_subdom_offline_disabled(void **state)
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek sss_domain_set_state(test_ctx->be_ctx->domain->subdomains, DOM_DISABLED);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_domain_state(test_ctx->be_ctx->domain->subdomains,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek be_mark_dom_offline(test_ctx->be_ctx->domain->subdomains, test_ctx->be_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_domain_state(test_ctx->be_ctx->domain->subdomains,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek _("Do not delete the test database after a test run"), NULL },
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek cmocka_unit_test_setup_teardown(test_mark_dom_offline,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek cmocka_unit_test_setup_teardown(test_mark_subdom_offline,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek cmocka_unit_test_setup_teardown(test_mark_subdom_offline_disabled,
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub 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 */
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek rv = cmocka_run_group_tests(tests, NULL, NULL);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);