167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose/*
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose SSSD
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose krb5_common - Test for some krb5 utility functions
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose Authors:
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose Sumit Bose <sbose@redhat.com>
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose Copyright (C) 2016 Red Hat
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
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
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
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*/
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose#include <stdarg.h>
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose#include <stddef.h>
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose#include <setjmp.h>
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose#include <cmocka.h>
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose#include <popt.h>
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose#include <stdbool.h>
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose#include "tests/cmocka/common_mock.h"
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose#include "tests/common.h"
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose#include "src/providers/krb5/krb5_common.h"
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose#define TEST_REALM "MY.REALM"
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose#define TEST_FAST_PRINC "fast_princ@" TEST_REALM
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose#define TEST_FAST_STR "dummy"
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose#define TEST_LIFE_STR "dummy-life"
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose#define TEST_RLIFE_STR "dummy-rlife"
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose#define TESTS_PATH "tp_" BASE_FILE_STEM
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose#define TEST_CONF_DB "test_krb5_common_conf.ldb"
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose#define TEST_DOM_NAME "test.krb5.common"
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose#define TEST_ID_PROVIDER "ldap"
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bosestruct test_ctx {
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose struct sss_test_ctx *tctx;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose};
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bosestatic int test_setup(void **state)
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose{
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose struct test_ctx *test_ctx;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_true(leak_check_setup());
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose test_ctx = talloc_zero(global_talloc_context, struct test_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_non_null(test_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH, TEST_CONF_DB,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose TEST_DOM_NAME,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose TEST_ID_PROVIDER, NULL);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_non_null(test_ctx->tctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose check_leaks_push(test_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose *state = test_ctx;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose return 0;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose}
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bosestatic int test_teardown(void **state)
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose{
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_true(check_leaks_pop(test_ctx));
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose talloc_free(test_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_true(leak_check_teardown());
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose return 0;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose}
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bosevoid test_set_extra_args(void **state)
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose{
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose int ret;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose struct krb5_ctx *krb5_ctx;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose char *uid_opt;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose char *gid_opt;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose const char **krb5_child_extra_args;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = set_extra_args(NULL, NULL, NULL);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EINVAL);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose krb5_ctx = talloc_zero(global_talloc_context, struct krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_non_null(krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose uid_opt = talloc_asprintf(krb5_ctx, "--fast-ccache-uid=%"SPRIuid, getuid());
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_non_null(uid_opt);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose gid_opt = talloc_asprintf(krb5_ctx, "--fast-ccache-gid=%"SPRIgid, getgid());
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_non_null(gid_opt);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = set_extra_args(global_talloc_context, krb5_ctx,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose &krb5_child_extra_args);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
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_null(krb5_child_extra_args[2]);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose talloc_free(krb5_child_extra_args);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose krb5_ctx->canonicalize = true;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = set_extra_args(global_talloc_context, krb5_ctx,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose &krb5_child_extra_args);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
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 assert_null(krb5_child_extra_args[3]);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose talloc_free(krb5_child_extra_args);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose krb5_ctx->realm = discard_const(TEST_REALM);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = set_extra_args(global_talloc_context, krb5_ctx,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose &krb5_child_extra_args);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
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 assert_null(krb5_child_extra_args[4]);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose talloc_free(krb5_child_extra_args);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
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 &krb5_child_extra_args);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
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 assert_null(krb5_child_extra_args[4]);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose talloc_free(krb5_child_extra_args);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
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 &krb5_child_extra_args);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
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[4],
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose "--fast-principal=" TEST_FAST_PRINC);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[5], "--canonicalize");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_null(krb5_child_extra_args[6]);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose talloc_free(krb5_child_extra_args);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
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 &krb5_child_extra_args);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
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[4],
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose "--renewable-lifetime=" TEST_RLIFE_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[6],
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose "--fast-principal=" TEST_FAST_PRINC);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_child_extra_args[7], "--canonicalize");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_null(krb5_child_extra_args[8]);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose talloc_free(krb5_child_extra_args);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose talloc_free(krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose}
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bosevoid test_sss_krb5_check_options(void **state)
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose{
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose int ret;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose struct dp_option *opts;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose struct krb5_ctx *krb5_ctx;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = sss_krb5_check_options(NULL, NULL, NULL);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EINVAL);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = sss_krb5_get_options(test_ctx, test_ctx->tctx->confdb,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose "[domain/" TEST_DOM_NAME "]", &opts);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_non_null(opts);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose krb5_ctx = talloc_zero(test_ctx, struct krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_non_null(krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = sss_krb5_check_options(opts, test_ctx->tctx->dom, krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_ctx->realm, TEST_DOM_NAME);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose /* check check_lifetime() indirectly */
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = dp_opt_set_string(opts, KRB5_LIFETIME, "123");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = sss_krb5_check_options(opts, test_ctx->tctx->dom, krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_ctx->lifetime_str, "123s");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = dp_opt_set_string(opts, KRB5_LIFETIME, "abc");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = sss_krb5_check_options(opts, test_ctx->tctx->dom, krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EINVAL);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = dp_opt_set_string(opts, KRB5_LIFETIME, "s");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = sss_krb5_check_options(opts, test_ctx->tctx->dom, krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EINVAL);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = dp_opt_set_string(opts, KRB5_LIFETIME, "1d");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = sss_krb5_check_options(opts, test_ctx->tctx->dom, krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_ctx->lifetime_str, "1d");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = dp_opt_set_string(opts, KRB5_LIFETIME, "7d 0h 0m 0s");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = sss_krb5_check_options(opts, test_ctx->tctx->dom, krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_string_equal(krb5_ctx->lifetime_str, "7d 0h 0m 0s");
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose /* check canonicalize */
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_false(krb5_ctx->canonicalize);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = dp_opt_set_bool(opts, KRB5_USE_ENTERPRISE_PRINCIPAL, true);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = sss_krb5_check_options(opts, test_ctx->tctx->dom, krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_true(krb5_ctx->canonicalize);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = dp_opt_set_bool(opts, KRB5_USE_ENTERPRISE_PRINCIPAL, false);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = dp_opt_set_bool(opts, KRB5_CANONICALIZE, true);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose ret = sss_krb5_check_options(opts, test_ctx->tctx->dom, krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_int_equal(ret, EOK);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose assert_true(krb5_ctx->canonicalize);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose talloc_free(krb5_ctx);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose talloc_free(opts);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose}
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Boseint main(int argc, const char *argv[])
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose{
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose int rv;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose int no_cleanup = 0;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose poptContext pc;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose int opt;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose struct poptOption long_options[] = {
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose POPT_AUTOHELP
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose SSSD_DEBUG_OPTS
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 POPT_TABLEEND
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose };
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose const struct CMUnitTest tests[] = {
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose cmocka_unit_test_setup_teardown(test_set_extra_args,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose test_setup, test_teardown),
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose cmocka_unit_test_setup_teardown(test_sss_krb5_check_options,
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose test_setup, test_teardown),
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose };
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose /* Set debug level to invalid value so we can deside if -d 0 was used. */
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose debug_level = SSSDBG_INVALID;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose pc = poptGetContext(argv[0], argc, argv, long_options, 0);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose while ((opt = poptGetNextOpt(pc)) != -1) {
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose switch (opt) {
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose default:
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose fprintf(stderr, "\nInvalid option %s: %s\n\n",
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose poptBadOption(pc, 0), poptStrerror(opt));
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose poptPrintUsage(pc, stderr, 0);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose return 1;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose }
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose }
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose poptFreeContext(pc);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose DEBUG_CLI_INIT(debug_level);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose tests_set_cwd();
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose test_dom_suite_setup(TESTS_PATH);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose rv = cmocka_run_group_tests(tests, NULL, NULL);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose if (rv == 0 && !no_cleanup) {
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose }
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose return rv;
167b05b28d6b969230973646bee2f1c1f49205d2Sumit Bose}