167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose krb5_common - Test for some krb5 utility functions
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose Sumit Bose <sbose@redhat.com>
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose Copyright (C) 2016 Red Hat
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose This program is free software; you can redistribute it and/or modify
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose it under the terms of the GNU General Public License as published by
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose the Free Software Foundation; either version 3 of the License, or
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose (at your option) any later version.
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose This program is distributed in the hope that it will be useful,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose GNU General Public License for more details.
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose You should have received a copy of the GNU General Public License
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose test_ctx = talloc_zero(global_talloc_context, struct test_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH, TEST_CONF_DB,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose krb5_ctx = talloc_zero(global_talloc_context, struct krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose uid_opt = talloc_asprintf(krb5_ctx, "--fast-ccache-uid=%"SPRIuid, getuid());
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose gid_opt = talloc_asprintf(krb5_ctx, "--fast-ccache-gid=%"SPRIgid, getgid());
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = set_extra_args(global_talloc_context, krb5_ctx,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[0], uid_opt);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[1], gid_opt);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = set_extra_args(global_talloc_context, krb5_ctx,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[0], uid_opt);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[1], gid_opt);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[2], "--canonicalize");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = set_extra_args(global_talloc_context, krb5_ctx,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[0], uid_opt);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[1], gid_opt);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[2], "--realm=" TEST_REALM);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[3], "--canonicalize");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose /* --fast-principal will be only set if FAST is used */
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose krb5_ctx->fast_principal = discard_const(TEST_FAST_PRINC);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = set_extra_args(global_talloc_context, krb5_ctx,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[0], uid_opt);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[1], gid_opt);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[2], "--realm=" TEST_REALM);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[3], "--canonicalize");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose krb5_ctx->use_fast_str = discard_const(TEST_FAST_STR);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = set_extra_args(global_talloc_context, krb5_ctx,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[0], uid_opt);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[1], gid_opt);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[2], "--realm=" TEST_REALM);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[3], "--use-fast=" TEST_FAST_STR);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[5], "--canonicalize");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose krb5_ctx->lifetime_str = discard_const(TEST_LIFE_STR);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose krb5_ctx->rlife_str = discard_const(TEST_RLIFE_STR);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = set_extra_args(global_talloc_context, krb5_ctx,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[0], uid_opt);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[1], gid_opt);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[2], "--realm=" TEST_REALM);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[3], "--lifetime=" TEST_LIFE_STR);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[5], "--use-fast=" TEST_FAST_STR);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[7], "--canonicalize");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = sss_krb5_get_options(test_ctx, test_ctx->tctx->confdb,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose krb5_ctx = talloc_zero(test_ctx, struct krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = sss_krb5_check_options(opts, test_ctx->tctx->dom, krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_ctx->realm, TEST_DOM_NAME);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose /* check check_lifetime() indirectly */
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = dp_opt_set_string(opts, KRB5_LIFETIME, "123");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = sss_krb5_check_options(opts, test_ctx->tctx->dom, krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_ctx->lifetime_str, "123s");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = dp_opt_set_string(opts, KRB5_LIFETIME, "abc");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = sss_krb5_check_options(opts, test_ctx->tctx->dom, krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = dp_opt_set_string(opts, KRB5_LIFETIME, "s");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = sss_krb5_check_options(opts, test_ctx->tctx->dom, krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = dp_opt_set_string(opts, KRB5_LIFETIME, "1d");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = sss_krb5_check_options(opts, test_ctx->tctx->dom, krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_ctx->lifetime_str, "1d");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = dp_opt_set_string(opts, KRB5_LIFETIME, "7d 0h 0m 0s");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = sss_krb5_check_options(opts, test_ctx->tctx->dom, krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_ctx->lifetime_str, "7d 0h 0m 0s");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose /* check canonicalize */
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = dp_opt_set_bool(opts, KRB5_USE_ENTERPRISE_PRINCIPAL, true);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = sss_krb5_check_options(opts, test_ctx->tctx->dom, krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = dp_opt_set_bool(opts, KRB5_USE_ENTERPRISE_PRINCIPAL, false);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = dp_opt_set_bool(opts, KRB5_CANONICALIZE, true);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = sss_krb5_check_options(opts, test_ctx->tctx->dom, krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose _("Do not delete the test database after a test run"), NULL },
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose cmocka_unit_test_setup_teardown(test_set_extra_args,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose cmocka_unit_test_setup_teardown(test_sss_krb5_check_options,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose /* Set debug level to invalid value so we can deside if -d 0 was used. */
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose pc = poptGetContext(argv[0], argc, argv, long_options, 0);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);