test_sysdb_certmap.c revision 57c5ea8825c7179fd93382dbcbb07e828e5aec19
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen sysdb_certmap - Tests for sysdb certmap related calls
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen Jakub Hrozek <jhrozek@redhat.com>
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen Copyright (C) 2017 Red Hat
ba4626cd5be3d225a7a89aa338d92b8fb411fd1cTimo Sirainen This program is free software; you can redistribute it and/or modify
f7d018e7e0980044e3d537958126e44ef4c45056Timo Sirainen it under the terms of the GNU General Public License as published by
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen the Free Software Foundation; either version 3 of the License, or
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen (at your option) any later version.
ba4626cd5be3d225a7a89aa338d92b8fb411fd1cTimo Sirainen This program is distributed in the hope that it will be useful,
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen but WITHOUT ANY WARRANTY; without even the implied warranty of
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen GNU General Public License for more details.
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen You should have received a copy of the GNU General Public License
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen along with this program. If not, see <http://www.gnu.org/licenses/>.
dd3d20d9b5821077164183a260af9bde0db3ff3fTimo Sirainen test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH,
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen talloc_get_type(*state, struct certmap_test_ctx);
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
c72cfe4a2bda39fff3b8a8bd64b31a7cc14d7d11Timo Sirainenstatic void test_sysdb_get_certmap_not_exists(void **state)
e564ff0581fc44b78badf8da36e68f9f7a27807eTimo Sirainen struct certmap_test_ctx *ctctx = talloc_get_type(*state,
7cd055a212d44067e2d94452c05691d696c9f699Timo Sirainen ret = sysdb_get_certmap(ctctx, ctctx->tctx->sysdb, &certmap,
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainenstatic void check_certmap(struct certmap_info *m, struct certmap_info *r,
ba4626cd5be3d225a7a89aa338d92b8fb411fd1cTimo Sirainen assert_string_equal(m->map_rule, r->map_rule);
1128c114416bdc4df0b41d3e15429a1522e5cfe4Timo Sirainen assert_string_equal(m->match_rule, r->match_rule);
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen for (d = 0; r->domains[d]; d++) {
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen assert_true(string_in_list(m->domains[d], discard_const(r->domains),
caf029d36a826106e48b8682f15ea0fc01fdd8f4Timo Sirainenstatic void test_sysdb_update_certmap(void **state)
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen const char *domains[] = { "dom1.test", "dom2.test", "dom3.test", NULL };
61f39b0358a72ebc693d84ba5bac74489ee7df41Timo Sirainen struct certmap_info map_a = { discard_const("map_a"), 11, discard_const("abc"), discard_const("def"), NULL };
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen struct certmap_info map_b = { discard_const("map_b"), UINT_MAX, discard_const("abc"), NULL, domains };
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen struct certmap_info *certmap_empty[] = { NULL };
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen struct certmap_info *certmap_a[] = { &map_a, NULL };
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen struct certmap_info *certmap_b[] = { &map_b, NULL };
b6c9cc2bf7517adcc0b9f98696c61bde321900f6Timo Sirainen struct certmap_info *certmap_ab[] = { &map_a, &map_b, NULL };
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen struct certmap_test_ctx *ctctx = talloc_get_type(*state,
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen ret = sysdb_update_certmap(ctctx->tctx->sysdb, NULL, false);
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen ret = sysdb_update_certmap(ctctx->tctx->sysdb, certmap_empty, false);
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen ret = sysdb_get_certmap(ctctx, ctctx->tctx->sysdb, &certmap,
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen ret = sysdb_update_certmap(ctctx->tctx->sysdb, certmap_a, false);
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen ret = sysdb_get_certmap(ctctx, ctctx->tctx->sysdb, &certmap,
709ee5a909d482f31611f9e6cc10d893a272e061Timo Sirainen assert_string_equal(certmap[0]->name, map_a.name);
709ee5a909d482f31611f9e6cc10d893a272e061Timo Sirainen assert_string_equal(certmap[0]->map_rule, map_a.map_rule);
709ee5a909d482f31611f9e6cc10d893a272e061Timo Sirainen assert_string_equal(certmap[0]->match_rule, map_a.match_rule);
709ee5a909d482f31611f9e6cc10d893a272e061Timo Sirainen assert_int_equal(certmap[0]->priority, map_a.priority);
709ee5a909d482f31611f9e6cc10d893a272e061Timo Sirainen ret = sysdb_update_certmap(ctctx->tctx->sysdb, certmap_b, true);
709ee5a909d482f31611f9e6cc10d893a272e061Timo Sirainen ret = sysdb_get_certmap(ctctx, ctctx->tctx->sysdb, &certmap,
709ee5a909d482f31611f9e6cc10d893a272e061Timo Sirainen ret = sysdb_update_certmap(ctctx->tctx->sysdb, certmap_ab, false);
709ee5a909d482f31611f9e6cc10d893a272e061Timo Sirainen ret = sysdb_get_certmap(ctctx, ctctx->tctx->sysdb, &certmap,
a1044a46a8f3512173f4ea2684ef1fc3e61645c7Timo Sirainen {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
a1044a46a8f3512173f4ea2684ef1fc3e61645c7Timo Sirainen _("Do not delete the test database after a test run"), NULL },
a1044a46a8f3512173f4ea2684ef1fc3e61645c7Timo Sirainen cmocka_unit_test_setup_teardown(test_sysdb_get_certmap_not_exists,
a1044a46a8f3512173f4ea2684ef1fc3e61645c7Timo Sirainen cmocka_unit_test_setup_teardown(test_sysdb_update_certmap,
1fb5e50695bbbc0da082e5a6f19f29d2bb2f6531Timo Sirainen /* Set debug level to invalid value so we can decide if -d 0 was used. */
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen pc = poptGetContext(argv[0], argc, argv, long_options, 0);
b772ddf3cfb606dddaa465b317a0dc01bf06c6e4Timo Sirainen fprintf(stderr, "\nInvalid option %s: %s\n\n",
a1044a46a8f3512173f4ea2684ef1fc3e61645c7Timo Sirainen test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, LOCAL_SYSDB_FILE);
a1044a46a8f3512173f4ea2684ef1fc3e61645c7Timo Sirainen rv = cmocka_run_group_tests(tests, NULL, NULL);