7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek Copyright (C) 2014 Red Hat
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek SSSD tests: Common responder code tests
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek This program is free software; you can redistribute it and/or modify
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek it under the terms of the GNU General Public License as published by
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek (at your option) any later version.
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek This program is distributed in the hope that it will be useful,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek GNU General Public License for more details.
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek You should have received a copy of the GNU General Public License
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
56c9f8731173eae841a05f31bb03d311076a8485Petr Cech/* register_cli_protocol_version is required in test since it links with
56c9f8731173eae841a05f31bb03d311076a8485Petr Cechstruct cli_protocol_version *register_cli_protocol_version(void)
56c9f8731173eae841a05f31bb03d311076a8485Petr Cech static struct cli_protocol_version responder_test_cli_protocol_version[] = {
56c9f8731173eae841a05f31bb03d311076a8485Petr Cech__wrap_sss_dp_issue_request(TALLOC_CTX *mem_ctx, struct resp_ctx *rctx,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek tevent_schedule_immediate(imm, rctx->ev, mock_sss_dp_done, nreq);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek parse_inp_ctx = talloc_zero(global_talloc_context, struct parse_inp_test_ctx);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek parse_inp_ctx->tctx = create_dom_test_ctx(parse_inp_ctx, TESTS_PATH,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek /* Testing the request race condition should be a special case */
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek gettimeofday(&parse_inp_ctx->rctx->get_domains_last_call, NULL);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose /* sysdb_master_domain_update sets the view name, if we do not call it
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose * here we get a leak check warning when sysdb_master_domain_update is
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose * called later while processing the tests. */
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = sysdb_master_domain_update(parse_inp_ctx->tctx->dom);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int parse_inp_test_teardown(void **state)
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek struct parse_inp_test_ctx *parse_inp_ctx = talloc_get_type(*state,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek assert_true(check_leaks_pop(parse_inp_ctx) == true);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozekint __real_sss_parse_name_for_domains(TALLOC_CTX *memctx,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozekint __wrap_sss_parse_name_for_domains(TALLOC_CTX *memctx,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek enum sss_test_wrapper_call wtype = sss_mock_type(enum sss_test_wrapper_call);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek return __real_sss_parse_name_for_domains(memctx, domains,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozekvoid parse_inp_simple_done(struct tevent_req *req)
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek tevent_req_callback_data(req, struct parse_inp_test_ctx);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek ret = sss_parse_inp_recv(req, parse_inp_ctx, &name, &domname);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek struct parse_inp_test_ctx *parse_inp_ctx = talloc_get_type(*state,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek will_return(__wrap_sss_parse_name_for_domains, WRAP_CALL_REAL);
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina req = sss_parse_inp_send(parse_inp_ctx, parse_inp_ctx->rctx,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek tevent_req_set_callback(req, parse_inp_simple_done, parse_inp_ctx);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek struct parse_inp_test_ctx *parse_inp_ctx = talloc_get_type(*state,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek /* First call will indicate we need to go to DP */
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek will_return(__wrap_sss_parse_name_for_domains, WRAP_CALL_WRAPPER);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek will_return(__wrap_sss_parse_name_for_domains, EAGAIN);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek /* The second one will succeed as the domains are up-to-date */
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek will_return(__wrap_sss_parse_name_for_domains, WRAP_CALL_REAL);
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina req = sss_parse_inp_send(parse_inp_ctx, parse_inp_ctx->rctx,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek tevent_req_set_callback(req, parse_inp_simple_done, parse_inp_ctx);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek struct parse_inp_test_ctx *parse_inp_ctx = talloc_get_type(*state,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek /* simulate responder startup */
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek parse_inp_ctx->rctx->get_domains_last_call.tv_sec = 0;
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek /* The first parse wouldn't be called, the second one will succeed
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek * as the domains are up-to-date */
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek will_return(__wrap_sss_parse_name_for_domains, WRAP_CALL_REAL);
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina req = sss_parse_inp_send(parse_inp_ctx, parse_inp_ctx->rctx,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek tevent_req_set_callback(req, parse_inp_simple_done, parse_inp_ctx);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek tevent_req_callback_data(req, struct parse_inp_test_ctx);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek ret = sss_parse_inp_recv(req, parse_inp_ctx, &name, &domname);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek struct parse_inp_test_ctx *parse_inp_ctx = talloc_get_type(*state,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek /* Simulate an error */
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek will_return(__wrap_sss_parse_name_for_domains, WRAP_CALL_WRAPPER);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek will_return(__wrap_sss_parse_name_for_domains, EINVAL);
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina req = sss_parse_inp_send(parse_inp_ctx, parse_inp_ctx->rctx,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek tevent_req_set_callback(req, parse_inp_neg_done, parse_inp_ctx);
56c9f8731173eae841a05f31bb03d311076a8485Petr Cecherrno_t __wrap_sss_ncache_reset_repopulate_permanent(struct resp_ctx *rctx,
eca74a9559ce1b0f123c14906ad8394fc303f468Jakub Hrozek test_ev_done(dummy_ncache_ptr->pctx->tctx, EOK);
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozekvoid test_schedule_get_domains_task(void **state)
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek struct parse_inp_test_ctx *parse_inp_ctx = talloc_get_type(*state,
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek dummy_ncache_ptr = talloc(parse_inp_ctx, struct sss_nc_ctx);
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek ret = schedule_get_domains_task(dummy_ncache_ptr,
051e0fc7cc86fb4e4b3a9323a61684ad3a6fa589Lukas Slebodnik struct parse_inp_test_ctx *parse_inp_ctx = talloc_get_type(*state,
051e0fc7cc86fb4e4b3a9323a61684ad3a6fa589Lukas Slebodnik ret = sized_output_name(parse_inp_ctx, parse_inp_ctx->rctx, "dummy",
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek _("Do not delete the test database after a test run"), NULL },
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(parse_inp_simple,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(parse_inp_call_dp,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(parse_inp_call_attach,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(parse_inp_call_neg,
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek cmocka_unit_test_setup_teardown(test_schedule_get_domains_task,
051e0fc7cc86fb4e4b3a9323a61684ad3a6fa589Lukas Slebodnik cmocka_unit_test_setup_teardown(test_sss_output_fqname,
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub 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);