01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek Copyright (C) 2015 Red Hat
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek SSSD tests: Kerberos wait queue tests
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek This program is free software; you can redistribute it and/or modify
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek it under the terms of the GNU General Public License as published by
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek (at your option) any later version.
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek This program is distributed in the hope that it will be useful,
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek GNU General Public License for more details.
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek You should have received a copy of the GNU General Public License
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozekstatic void krb5_mocked_auth_done(struct tevent_context *ev,
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozekstruct tevent_req *krb5_auth_send(TALLOC_CTX *mem_ctx,
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek req = tevent_req_create(mem_ctx, &state, struct krb5_mocked_auth_state);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create failed.\n");
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek tv = tevent_timeval_current_ofs(0, state->us_delay);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek tt = tevent_add_timer(ev, req, tv, krb5_mocked_auth_done, req);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozekstatic void krb5_mocked_auth_done(struct tevent_context *ev,
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek state = tevent_req_data(req, struct krb5_mocked_auth_state);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "Finished auth request of %s\n", state->user);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek state = tevent_req_data(req, struct krb5_mocked_auth_state);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozekstatic int test_krb5_wait_queue_setup(void **state)
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek test_ctx->be_ctx = mock_be_ctx(test_ctx, test_ctx->tctx);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek test_ctx->pd = talloc_zero(test_ctx, struct pam_data);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek test_ctx->krb5_ctx = talloc_zero(test_ctx, struct krb5_ctx);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozekstatic int test_krb5_wait_queue_teardown(void **state)
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek talloc_get_type(*state, struct test_krb5_wait_queue);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozekstatic void test_krb5_wait_mock(struct test_krb5_wait_queue *test_ctx,
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozekstatic void test_krb5_wait_mock_success(struct test_krb5_wait_queue *test_ctx,
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek return test_krb5_wait_mock(test_ctx, username, 200, 0, 0, 0);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozekstatic void test_krb5_wait_queue_single_done(struct tevent_req *req);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozekstatic void test_krb5_wait_queue_single(void **state)
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek talloc_get_type(*state, struct test_krb5_wait_queue);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek test_krb5_wait_mock_success(test_ctx, "krb5_user");
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek tevent_req_set_callback(req, test_krb5_wait_queue_single_done, test_ctx);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozekstatic void test_krb5_wait_queue_single_done(struct tevent_req *req)
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek tevent_req_callback_data(req, struct test_krb5_wait_queue);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek ret = krb5_auth_queue_recv(req, &pam_status, &dp_err);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozekstatic void test_krb5_wait_queue_multi_done(struct tevent_req *req);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozekstatic void test_krb5_wait_queue_multi(void **state)
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek talloc_get_type(*state, struct test_krb5_wait_queue);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek test_krb5_wait_mock_success(test_ctx, "krb5_user");
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek tevent_req_set_callback(req, test_krb5_wait_queue_multi_done, test_ctx);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozekstatic void test_krb5_wait_queue_multi_done(struct tevent_req *req)
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek tevent_req_callback_data(req, struct test_krb5_wait_queue);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek ret = krb5_auth_queue_recv(req, &pam_status, &dp_err);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek if (test_ctx->num_finished_auths == test_ctx->num_auths) {
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozekstatic void test_krb5_wait_queue_fail_odd_done(struct tevent_req *req);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozekstatic void test_krb5_wait_queue_fail_odd(void **state)
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek talloc_get_type(*state, struct test_krb5_wait_queue);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek test_krb5_wait_mock(test_ctx, "krb5_user", 0, i+1 % 2, PAM_SUCCESS, 0);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek tevent_req_set_callback(req, test_krb5_wait_queue_fail_odd_done, test_ctx);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozekstatic void test_krb5_wait_queue_fail_odd_done(struct tevent_req *req)
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek tevent_req_callback_data(req, struct test_krb5_wait_queue);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek ret = krb5_auth_queue_recv(req, &pam_status, &dp_err);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek assert_int_equal(ret, test_ctx->num_finished_auths+1 % 2);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek if (test_ctx->num_finished_auths == test_ctx->num_auths) {
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek /* Run a single auth request */
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek cmocka_unit_test_setup_teardown(test_krb5_wait_queue_single,
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek /* Run multiple auth requests */
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek cmocka_unit_test_setup_teardown(test_krb5_wait_queue_multi,
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek /* Make sure that all requests in queue run even if some fail */
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek cmocka_unit_test_setup_teardown(test_krb5_wait_queue_fail_odd,
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub 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 */