f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose/*
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose Authors:
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose Sumit Bose <sbose@redhat.com>
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose Copyright (C) 2017 Red Hat
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose SSSD tests - sdap certmap
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose This program is free software; you can redistribute it and/or modify
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose it under the terms of the GNU General Public License as published by
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose the Free Software Foundation; either version 3 of the License, or
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose (at your option) any later version.
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose This program is distributed in the hope that it will be useful,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose GNU General Public License for more details.
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose You should have received a copy of the GNU General Public License
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose*/
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose#include <stdarg.h>
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose#include <stdbool.h>
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose#include <setjmp.h>
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose#include <unistd.h>
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose#include <cmocka.h>
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose#include <popt.h>
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose#include "providers/ldap/ldap_common.h"
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose#include "tests/common.h"
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose#include "db/sysdb.h"
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose#define TESTS_PATH "certmap_" BASE_FILE_STEM
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose#define TEST_CONF_DB "test_sysdb_certmap.ldb"
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose#define TEST_ID_PROVIDER "ldap"
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose#define TEST_DOM_NAME "certmap_test"
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bosestruct certmap_info map_a = { discard_const("map_a"), 11,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose NULL, discard_const("(abc=def)"),
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose NULL };
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bosestruct certmap_info map_b = { discard_const("map_b"), UINT_MAX,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose NULL, NULL, NULL };
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bosestruct certmap_info *certmap[] = { &map_a, &map_b, NULL };
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bosestruct certmap_test_ctx {
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct sss_test_ctx *tctx;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct sdap_id_ctx *id_ctx;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose};
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bosestatic int test_sysdb_setup(void **state)
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose{
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose int ret;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct certmap_test_ctx *test_ctx;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct sss_test_conf_param params[] = {
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose { NULL, NULL }, /* Sentinel */
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose };
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_true(leak_check_setup());
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_ctx = talloc_zero(global_talloc_context,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct certmap_test_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_non_null(test_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose check_leaks_push(test_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_dom_suite_setup(TESTS_PATH);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose TEST_CONF_DB, TEST_DOM_NAME,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose TEST_ID_PROVIDER, params);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_non_null(test_ctx->tctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose ret = sysdb_update_certmap(test_ctx->tctx->sysdb, certmap, false);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_int_equal(ret, EOK);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_ctx->id_ctx = talloc_zero(test_ctx->tctx, struct sdap_id_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_non_null(test_ctx->id_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_ctx->id_ctx->opts = talloc_zero(test_ctx->tctx, struct sdap_options);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_non_null(test_ctx->id_ctx->opts);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_ctx->id_ctx->be = talloc_zero(test_ctx->tctx, struct be_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_non_null(test_ctx->id_ctx->be);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_ctx->id_ctx->be->domain = test_ctx->tctx->dom;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose *state = test_ctx;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose return 0;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose}
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bosestatic int test_sysdb_teardown(void **state)
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose{
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct certmap_test_ctx *test_ctx =
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose talloc_get_type(*state, struct certmap_test_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose talloc_free(test_ctx->tctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_true(check_leaks_pop(test_ctx));
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose talloc_free(test_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_true(leak_check_teardown());
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose return 0;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose}
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bosestatic void test_sdap_certmap_init(void **state)
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose{
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose int ret;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct certmap_test_ctx *test_ctx = talloc_get_type(*state,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct certmap_test_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose ret = sdap_init_certmap(test_ctx, test_ctx->id_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_int_equal(ret, EOK);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose talloc_free(test_ctx->id_ctx->opts->sdap_certmap_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose}
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bosestatic void test_sdap_get_sss_certmap(void **state)
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose{
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose int ret;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct certmap_test_ctx *test_ctx = talloc_get_type(*state,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct certmap_test_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct sss_certmap_ctx *sss_certmap_ctx;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose sss_certmap_ctx = sdap_get_sss_certmap(NULL);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_null(sss_certmap_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose ret = sdap_init_certmap(test_ctx, test_ctx->id_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_int_equal(ret, EOK);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose sss_certmap_ctx = sdap_get_sss_certmap(
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_ctx->id_ctx->opts->sdap_certmap_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_non_null(sss_certmap_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose talloc_free(test_ctx->id_ctx->opts->sdap_certmap_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose}
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bosestatic void test_sdap_certmap_init_twice(void **state)
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose{
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose int ret;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct certmap_test_ctx *test_ctx = talloc_get_type(*state,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct certmap_test_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct sdap_certmap_ctx *sdap_certmap_ref;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct sss_certmap_ctx *sss_certmap_ref;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose ret = sdap_init_certmap(test_ctx, test_ctx->id_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_int_equal(ret, EOK);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose sdap_certmap_ref = test_ctx->id_ctx->opts->sdap_certmap_ctx;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose sss_certmap_ref = sdap_get_sss_certmap(sdap_certmap_ref);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose ret = sdap_init_certmap(test_ctx, test_ctx->id_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_int_equal(ret, EOK);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_ptr_equal(sdap_certmap_ref,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_ctx->id_ctx->opts->sdap_certmap_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_ptr_not_equal(sss_certmap_ref,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose sdap_get_sss_certmap(sdap_certmap_ref));
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose talloc_free(test_ctx->id_ctx->opts->sdap_certmap_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose}
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bosestatic void test_sdap_setup_certmap(void **state)
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose{
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose int ret;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct certmap_test_ctx *test_ctx = talloc_get_type(*state,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct certmap_test_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct sdap_certmap_ctx *sdap_certmap_ref;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct sss_certmap_ctx *sss_certmap_ref;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose ret = sdap_init_certmap(test_ctx, test_ctx->id_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_int_equal(ret, EOK);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose sdap_certmap_ref = test_ctx->id_ctx->opts->sdap_certmap_ctx;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose sss_certmap_ref = sdap_get_sss_certmap(sdap_certmap_ref);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose ret = sdap_setup_certmap(NULL, NULL);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_int_equal(ret, EINVAL);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_ptr_equal(sdap_certmap_ref,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_ctx->id_ctx->opts->sdap_certmap_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_ptr_equal(sss_certmap_ref, sdap_get_sss_certmap(sdap_certmap_ref));
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose ret = sdap_setup_certmap(NULL, certmap);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_int_equal(ret, EINVAL);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_ptr_equal(sdap_certmap_ref,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_ctx->id_ctx->opts->sdap_certmap_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_ptr_equal(sss_certmap_ref, sdap_get_sss_certmap(sdap_certmap_ref));
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose ret = sdap_setup_certmap(sdap_certmap_ref, certmap);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_int_equal(ret, EOK);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_ptr_equal(sdap_certmap_ref,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_ctx->id_ctx->opts->sdap_certmap_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose assert_ptr_not_equal(sss_certmap_ref,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose sdap_get_sss_certmap(sdap_certmap_ref));
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose talloc_free(test_ctx->id_ctx->opts->sdap_certmap_ctx);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose}
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Boseint main(int argc, const char *argv[])
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose{
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose int rv;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose poptContext pc;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose int opt;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose struct poptOption long_options[] = {
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose POPT_AUTOHELP
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose SSSD_DEBUG_OPTS
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose POPT_TABLEEND
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose };
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose const struct CMUnitTest tests[] = {
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose cmocka_unit_test_setup_teardown(test_sdap_certmap_init,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_sysdb_setup,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_sysdb_teardown),
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose cmocka_unit_test_setup_teardown(test_sdap_get_sss_certmap,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_sysdb_setup,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_sysdb_teardown),
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose cmocka_unit_test_setup_teardown(test_sdap_certmap_init_twice,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_sysdb_setup,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_sysdb_teardown),
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose cmocka_unit_test_setup_teardown(test_sdap_setup_certmap,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_sysdb_setup,
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose test_sysdb_teardown),
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose };
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose debug_level = SSSDBG_INVALID;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose pc = poptGetContext(argv[0], argc, argv, long_options, 0);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose while((opt = poptGetNextOpt(pc)) != -1) {
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose switch(opt) {
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose default:
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose fprintf(stderr, "\nInvalid option %s: %s\n\n",
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose poptBadOption(pc, 0), poptStrerror(opt));
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose poptPrintUsage(pc, stderr, 0);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose return 1;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose }
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose }
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose poptFreeContext(pc);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose DEBUG_CLI_INIT(debug_level);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose tests_set_cwd();
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose rv = cmocka_run_group_tests(tests, NULL, NULL);
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose return rv;
f2e70ec742cd7aab82b74d7e4b424ba3258da7aaSumit Bose}