57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz sysdb_certmap - Tests for sysdb certmap related calls
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose Jakub Hrozek <jhrozek@redhat.com>
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose Copyright (C) 2017 Red Hat
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 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 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 test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose talloc_get_type(*state, struct certmap_test_ctx);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bosestatic void test_sysdb_get_certmap_not_exists(void **state)
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose struct certmap_test_ctx *ctctx = talloc_get_type(*state,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_get_certmap(ctctx, ctctx->tctx->sysdb, &certmap,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bosestatic void check_certmap(struct certmap_info *m, struct certmap_info *r,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_string_equal(m->match_rule, r->match_rule);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose for (d = 0; r->domains[d]; d++) {
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose assert_true(string_in_list(m->domains[d], discard_const(r->domains),
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bosestatic void test_sysdb_update_certmap(void **state)
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_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_test_ctx *ctctx = talloc_get_type(*state,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_update_certmap(ctctx->tctx->sysdb, NULL, false);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_update_certmap(ctctx->tctx->sysdb, certmap_empty, false);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_get_certmap(ctctx, ctctx->tctx->sysdb, &certmap,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_update_certmap(ctctx->tctx->sysdb, certmap_a, false);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_get_certmap(ctctx, ctctx->tctx->sysdb, &certmap,
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 ret = sysdb_update_certmap(ctctx->tctx->sysdb, certmap_b, true);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_get_certmap(ctctx, ctctx->tctx->sysdb, &certmap,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_update_certmap(ctctx->tctx->sysdb, certmap_ab, false);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_get_certmap(ctctx, ctctx->tctx->sysdb, &certmap,
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 cmocka_unit_test_setup_teardown(test_sysdb_get_certmap_not_exists,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose cmocka_unit_test_setup_teardown(test_sysdb_update_certmap,
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose pc = poptGetContext(argv[0], argc, argv, long_options, 0);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, LOCAL_SYSDB_FILE);