49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose/*
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose SSSD
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz sysdb_certmap - Tests for sysdb certmap related calls
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose Authors:
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose Jakub Hrozek <jhrozek@redhat.com>
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose Copyright (C) 2017 Red Hat
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose This program is free software; you can redistribute it and/or modify
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose it under the terms of the GNU General Public License as published by
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose the Free Software Foundation; either version 3 of the License, or
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose (at your option) any later version.
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose This program is distributed in the hope that it will be useful,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose GNU General Public License for more details.
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose You should have received a copy of the GNU General Public License
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose*/
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose#include <stdarg.h>
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose#include <stddef.h>
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose#include <setjmp.h>
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose#include <cmocka.h>
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose#include <popt.h>
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose#include "tests/cmocka/common_mock.h"
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose#include "tests/common.h"
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose#define TESTS_PATH "certmap_" BASE_FILE_STEM
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose#define TEST_CONF_DB "test_sysdb_certmap.ldb"
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose#define TEST_ID_PROVIDER "ldap"
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose#define TEST_DOM_NAME "certmap_test"
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bosestruct certmap_test_ctx {
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose struct sss_test_ctx *tctx;
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose};
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bosestatic int test_sysdb_setup(void **state)
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose{
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose struct certmap_test_ctx *test_ctx;
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose struct sss_test_conf_param params[] = {
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose { NULL, NULL }, /* Sentinel */
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose };
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_true(leak_check_setup());
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose test_ctx = talloc_zero(global_talloc_context,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose struct certmap_test_ctx);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_non_null(test_ctx);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose check_leaks_push(test_ctx);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose test_dom_suite_setup(TESTS_PATH);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose TEST_CONF_DB, TEST_DOM_NAME,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose TEST_ID_PROVIDER, params);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_non_null(test_ctx->tctx);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose *state = test_ctx;
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose return 0;
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose}
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bosestatic int test_sysdb_teardown(void **state)
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose{
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose struct certmap_test_ctx *test_ctx =
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose talloc_get_type(*state, struct certmap_test_ctx);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose talloc_free(test_ctx->tctx);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_true(check_leaks_pop(test_ctx));
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose talloc_free(test_ctx);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_true(leak_check_teardown());
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose return 0;
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose}
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bosestatic void test_sysdb_get_certmap_not_exists(void **state)
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose{
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose int ret;
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose struct certmap_info **certmap;
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose bool user_name_hint;
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose struct certmap_test_ctx *ctctx = talloc_get_type(*state,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose struct certmap_test_ctx);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_get_certmap(ctctx, ctctx->tctx->sysdb, &certmap,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose &user_name_hint);
ee7e72a65d323636600ffda271d5b5c4ddbc78b1Sumit Bose assert_int_equal(ret, EOK);
ee7e72a65d323636600ffda271d5b5c4ddbc78b1Sumit Bose assert_null(certmap);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose}
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bosestatic void check_certmap(struct certmap_info *m, struct certmap_info *r,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose size_t exp_domains)
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose{
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose size_t d;
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_non_null(r);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_non_null(m);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_string_equal(m->name, r->name);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose if (r->map_rule == NULL) {
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_null(m->map_rule);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose } else {
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_string_equal(m->map_rule, r->map_rule);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose }
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose if (r->match_rule == NULL) {
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_null(m->match_rule);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose } else {
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_string_equal(m->match_rule, r->match_rule);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose }
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_int_equal(m->priority, r->priority);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_non_null(m->domains);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose if (r->domains == NULL) {
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_null(m->domains[0]);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose } else {
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose for (d = 0; r->domains[d]; d++) {
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_non_null(m->domains[d]);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_true(string_in_list(m->domains[d], discard_const(r->domains),
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose true));
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose }
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_int_equal(d, exp_domains);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose }
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose}
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bosestatic void test_sysdb_update_certmap(void **state)
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose{
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose int ret;
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose const char *domains[] = { "dom1.test", "dom2.test", "dom3.test", NULL };
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose struct certmap_info map_a = { discard_const("map_a"), 11, discard_const("abc"), discard_const("def"), NULL };
ee7e72a65d323636600ffda271d5b5c4ddbc78b1Sumit Bose struct certmap_info map_b = { discard_const("map_b"), UINT_MAX, discard_const("abc"), NULL, domains };
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose struct certmap_info *certmap_empty[] = { NULL };
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose struct certmap_info *certmap_a[] = { &map_a, NULL };
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose struct certmap_info *certmap_b[] = { &map_b, NULL };
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose struct certmap_info *certmap_ab[] = { &map_a, &map_b, NULL };
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose struct certmap_info **certmap;
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose struct certmap_test_ctx *ctctx = talloc_get_type(*state,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose struct certmap_test_ctx);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose bool user_name_hint;
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_update_certmap(ctctx->tctx->sysdb, NULL, false);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_int_equal(ret, EINVAL);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_update_certmap(ctctx->tctx->sysdb, certmap_empty, false);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_int_equal(ret, EOK);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_get_certmap(ctctx, ctctx->tctx->sysdb, &certmap,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose &user_name_hint);
ee7e72a65d323636600ffda271d5b5c4ddbc78b1Sumit Bose assert_int_equal(ret, EOK);
ee7e72a65d323636600ffda271d5b5c4ddbc78b1Sumit Bose assert_null(certmap);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_update_certmap(ctctx->tctx->sysdb, certmap_a, false);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_int_equal(ret, EOK);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_get_certmap(ctctx, ctctx->tctx->sysdb, &certmap,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose &user_name_hint);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_int_equal(ret, EOK);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_false(user_name_hint);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_non_null(certmap);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_non_null(certmap[0]);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_string_equal(certmap[0]->name, map_a.name);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_string_equal(certmap[0]->map_rule, map_a.map_rule);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_string_equal(certmap[0]->match_rule, map_a.match_rule);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_int_equal(certmap[0]->priority, map_a.priority);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_non_null(certmap[0]->domains);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_null(certmap[0]->domains[0]);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_null(certmap[1]);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose check_certmap(certmap[0], &map_a, 0);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose talloc_free(certmap);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_update_certmap(ctctx->tctx->sysdb, certmap_b, true);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_int_equal(ret, EOK);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_get_certmap(ctctx, ctctx->tctx->sysdb, &certmap,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose &user_name_hint);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_int_equal(ret, EOK);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_true(user_name_hint);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_non_null(certmap);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_non_null(certmap[0]);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose check_certmap(certmap[0], &map_b, 3);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_null(certmap[1]);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose talloc_free(certmap);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_update_certmap(ctctx->tctx->sysdb, certmap_ab, false);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_int_equal(ret, EOK);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_get_certmap(ctctx, ctctx->tctx->sysdb, &certmap,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose &user_name_hint);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_int_equal(ret, EOK);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_false(user_name_hint);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_non_null(certmap);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_non_null(certmap[0]);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_non_null(certmap[1]);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_null(certmap[2]);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose if (strcmp(certmap[0]->name, "map_a") == 0) {
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose check_certmap(certmap[0], &map_a, 0);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose check_certmap(certmap[1], &map_b, 3);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose } else {
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose check_certmap(certmap[0], &map_b, 3);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose check_certmap(certmap[1], &map_a, 0);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose }
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose talloc_free(certmap);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose}
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Boseint main(int argc, const char *argv[])
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose{
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose int rv;
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose int no_cleanup = 0;
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose poptContext pc;
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose int opt;
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose struct poptOption long_options[] = {
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose POPT_AUTOHELP
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose SSSD_DEBUG_OPTS
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose _("Do not delete the test database after a test run"), NULL },
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose POPT_TABLEEND
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose };
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose const struct CMUnitTest tests[] = {
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose cmocka_unit_test_setup_teardown(test_sysdb_get_certmap_not_exists,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose test_sysdb_setup,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose test_sysdb_teardown),
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose cmocka_unit_test_setup_teardown(test_sysdb_update_certmap,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose test_sysdb_setup,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose test_sysdb_teardown),
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose };
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose debug_level = SSSDBG_INVALID;
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose pc = poptGetContext(argv[0], argc, argv, long_options, 0);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose while((opt = poptGetNextOpt(pc)) != -1) {
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose switch(opt) {
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose default:
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose fprintf(stderr, "\nInvalid option %s: %s\n\n",
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose poptBadOption(pc, 0), poptStrerror(opt));
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose poptPrintUsage(pc, stderr, 0);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose return 1;
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose }
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose }
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose poptFreeContext(pc);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG_CLI_INIT(debug_level);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose tests_set_cwd();
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, LOCAL_SYSDB_FILE);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose test_dom_suite_setup(TESTS_PATH);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose rv = cmocka_run_group_tests(tests, NULL, NULL);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose if (rv == 0 && no_cleanup == 0) {
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, LOCAL_SYSDB_FILE);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose }
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose return rv;
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose}