summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am16
-rw-r--r--src/tests/cmocka/test_sysdb_subdomains.c184
-rw-r--r--src/tests/sysdb-tests.c73
3 files changed, 200 insertions, 73 deletions
diff --git a/Makefile.am b/Makefile.am
index 9927391fe..4e042922d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -216,6 +216,7 @@ if HAVE_CMOCKA
test_sdap_access \
sdap-tests \
test_sysdb_views \
+ test_sysdb_subdomains \
test_sysdb_utils \
test_be_ptask \
test_copy_ccache \
@@ -2235,6 +2236,21 @@ test_sysdb_views_LDADD = \
libsss_test_common.la \
$(NULL)
+test_sysdb_subdomains_SOURCES = \
+ src/tests/cmocka/test_sysdb_subdomains.c \
+ $(NULL)
+test_sysdb_subdomains_CFLAGS = \
+ $(AM_CFLAGS) \
+ $(NULL)
+test_sysdb_subdomains_LDADD = \
+ $(CMOCKA_LIBS) \
+ $(LDB_LIBS) \
+ $(POPT_LIBS) \
+ $(TALLOC_LIBS) \
+ $(SSSD_INTERNAL_LTLIBS) \
+ libsss_test_common.la \
+ $(NULL)
+
test_sysdb_utils_SOURCES = \
src/tests/cmocka/test_sysdb_utils.c \
$(NULL)
diff --git a/src/tests/cmocka/test_sysdb_subdomains.c b/src/tests/cmocka/test_sysdb_subdomains.c
new file mode 100644
index 000000000..e9c190549
--- /dev/null
+++ b/src/tests/cmocka/test_sysdb_subdomains.c
@@ -0,0 +1,184 @@
+/*
+ SSSD
+
+ sysdb_subdomains - Tests for subdomains and related calls
+
+ Authors:
+ Jakub Hrozek <jhrozek@redhat.com>
+
+ Copyright (C) 2015 Red Hat
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <popt.h>
+
+#include "tests/cmocka/common_mock.h"
+#include "tests/common.h"
+#include "db/sysdb_private.h" /* for sysdb->ldb member */
+
+#define TESTS_PATH "test_sysdb_subdomains"
+#define TEST_CONF_DB "test_sysdb_subdomains.ldb"
+#define TEST_DOM_NAME "test_sysdb_subdomains"
+#define TEST_ID_PROVIDER "local"
+
+struct subdom_test_ctx {
+ struct sss_test_ctx *tctx;
+};
+
+static int test_sysdb_subdom_setup(void **state)
+{
+ struct subdom_test_ctx *test_ctx;
+ struct sss_test_conf_param params[] = {
+ { NULL, NULL }, /* Sentinel */
+ };
+
+ assert_true(leak_check_setup());
+
+ test_ctx = talloc_zero(global_talloc_context,
+ struct subdom_test_ctx);
+ assert_non_null(test_ctx);
+
+ test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH,
+ TEST_CONF_DB, TEST_DOM_NAME,
+ TEST_ID_PROVIDER, params);
+ assert_non_null(test_ctx->tctx);
+
+ *state = test_ctx;
+ return 0;
+}
+
+static int test_sysdb_subdom_teardown(void **state)
+{
+ struct subdom_test_ctx *test_ctx =
+ talloc_get_type(*state, struct subdom_test_ctx);
+
+ talloc_free(test_ctx);
+ assert_true(leak_check_teardown());
+ return 0;
+}
+
+static void test_sysdb_subdomain_create(void **state)
+{
+ errno_t ret;
+ struct subdom_test_ctx *test_ctx =
+ talloc_get_type(*state, struct subdom_test_ctx);
+
+ const char *const dom1[4] = { "dom1.sub", "DOM1.SUB", "dom1", "S-1" };
+ const char *const dom2[4] = { "dom2.sub", "DOM2.SUB", "dom2", "S-2" };
+
+ ret = sysdb_subdomain_store(test_ctx->tctx->sysdb,
+ dom1[0], dom1[1], dom1[2], dom1[3],
+ false, false, NULL, 0);
+ assert_int_equal(ret, EOK);
+
+ ret = sysdb_update_subdomains(test_ctx->tctx->dom);
+ assert_int_equal(ret, EOK);
+
+ assert_non_null(test_ctx->tctx->dom->subdomains);
+ assert_string_equal(test_ctx->tctx->dom->subdomains->name, dom1[0]);
+ assert_int_equal(test_ctx->tctx->dom->subdomains->trust_direction, 0);
+
+ ret = sysdb_subdomain_store(test_ctx->tctx->sysdb,
+ dom2[0], dom2[1], dom2[2], dom2[3],
+ false, false, NULL, 1);
+ assert_int_equal(ret, EOK);
+
+ ret = sysdb_update_subdomains(test_ctx->tctx->dom);
+ assert_int_equal(ret, EOK);
+
+ assert_non_null(test_ctx->tctx->dom->subdomains->next);
+ assert_string_equal(test_ctx->tctx->dom->subdomains->next->name, dom2[0]);
+ assert_int_equal(test_ctx->tctx->dom->subdomains->next->trust_direction, 1);
+
+ /* Reverse the trust directions */
+ ret = sysdb_subdomain_store(test_ctx->tctx->sysdb,
+ dom1[0], dom1[1], dom1[2], dom1[3],
+ false, false, NULL, 1);
+ assert_int_equal(ret, EOK);
+
+ ret = sysdb_subdomain_store(test_ctx->tctx->sysdb,
+ dom2[0], dom2[1], dom2[2], dom2[3],
+ false, false, NULL, 0);
+ assert_int_equal(ret, EOK);
+
+ ret = sysdb_update_subdomains(test_ctx->tctx->dom);
+ assert_int_equal(ret, EOK);
+
+ assert_int_equal(test_ctx->tctx->dom->subdomains->trust_direction, 1);
+ assert_int_equal(test_ctx->tctx->dom->subdomains->next->trust_direction, 0);
+
+ ret = sysdb_subdomain_delete(test_ctx->tctx->sysdb, dom2[0]);
+ assert_int_equal(ret, EOK);
+
+ ret = sysdb_subdomain_delete(test_ctx->tctx->sysdb, dom1[0]);
+ assert_int_equal(ret, EOK);
+
+ ret = sysdb_update_subdomains(test_ctx->tctx->dom);
+ assert_int_equal(ret, EOK);
+
+ assert_true(test_ctx->tctx->dom->subdomains->disabled);
+}
+
+int main(int argc, const char *argv[])
+{
+ int rv;
+ int no_cleanup = 0;
+ poptContext pc;
+ int opt;
+ struct poptOption long_options[] = {
+ POPT_AUTOHELP
+ SSSD_DEBUG_OPTS
+ {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
+ _("Do not delete the test database after a test run"), NULL },
+ POPT_TABLEEND
+ };
+
+ const struct CMUnitTest tests[] = {
+ cmocka_unit_test_setup_teardown(test_sysdb_subdomain_create,
+ test_sysdb_subdom_setup,
+ test_sysdb_subdom_teardown),
+ };
+
+ /* Set debug level to invalid value so we can deside if -d 0 was used. */
+ debug_level = SSSDBG_INVALID;
+
+ pc = poptGetContext(argv[0], argc, argv, long_options, 0);
+ while((opt = poptGetNextOpt(pc)) != -1) {
+ switch(opt) {
+ default:
+ fprintf(stderr, "\nInvalid option %s: %s\n\n",
+ poptBadOption(pc, 0), poptStrerror(opt));
+ poptPrintUsage(pc, stderr, 0);
+ return 1;
+ }
+ }
+ poptFreeContext(pc);
+
+ DEBUG_CLI_INIT(debug_level);
+
+ tests_set_cwd();
+ test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, LOCAL_SYSDB_FILE);
+ test_dom_suite_setup(TESTS_PATH);
+ rv = cmocka_run_group_tests(tests, NULL, NULL);
+
+ if (rv == 0 && no_cleanup == 0) {
+ test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, LOCAL_SYSDB_FILE);
+ }
+ return rv;
+}
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
index 81e31363b..4478e24a6 100644
--- a/src/tests/sysdb-tests.c
+++ b/src/tests/sysdb-tests.c
@@ -5223,78 +5223,6 @@ START_TEST(test_sysdb_delete_by_sid)
}
END_TEST
-START_TEST(test_sysdb_subdomain_create)
-{
- struct sysdb_test_ctx *test_ctx;
- errno_t ret;
- const char *const dom1[4] = { "dom1.sub", "DOM1.SUB", "dom1", "S-1" };
- const char *const dom2[4] = { "dom2.sub", "DOM2.SUB", "dom2", "S-2" };
-
- ret = setup_sysdb_tests(&test_ctx);
- fail_if(ret != EOK, "Could not set up the test");
-
- ret = sysdb_subdomain_store(test_ctx->sysdb,
- dom1[0], dom1[1], dom1[2], dom1[3],
- false, false, NULL, 0);
- fail_if(ret != EOK, "Could not set up the test (dom1)");
-
- ret = sysdb_update_subdomains(test_ctx->domain);
- fail_unless(ret == EOK, "sysdb_update_subdomains failed with [%d][%s]",
- ret, strerror(ret));
-
- fail_if(test_ctx->domain->subdomains == NULL, "Empty sub-domain list.");
- fail_if(strcmp(test_ctx->domain->subdomains->name, dom1[0]) != 0,
- "Unexpected sub-domain found, expected [%s], got [%s]",
- dom1[0], test_ctx->domain->subdomains->name);
- fail_unless(test_ctx->domain->subdomains->trust_direction == 0);
-
- ret = sysdb_subdomain_store(test_ctx->sysdb,
- dom2[0], dom2[1], dom2[2], dom2[3],
- false, false, NULL, 1);
- fail_if(ret != EOK, "Could not set up the test (dom2)");
-
- ret = sysdb_update_subdomains(test_ctx->domain);
- fail_unless(ret == EOK, "sysdb_update_subdomains failed with [%d][%s]",
- ret, strerror(ret));
-
- fail_if(test_ctx->domain->subdomains->next == NULL, "Missing sub-domain");
- fail_if(strcmp(test_ctx->domain->subdomains->next->name, dom2[0]) != 0,
- "Unexpected sub-domain found, expected [%s], got [%s]",
- dom2[0], test_ctx->domain->subdomains->next->name);
- fail_unless(test_ctx->domain->subdomains->next->trust_direction == 1);
-
- /* Reverse the trust directions */
- ret = sysdb_subdomain_store(test_ctx->sysdb,
- dom1[0], dom1[1], dom1[2], dom1[3],
- false, false, NULL, 1);
- fail_if(ret != EOK, "Could not set up the test (dom1)");
-
- ret = sysdb_subdomain_store(test_ctx->sysdb,
- dom2[0], dom2[1], dom2[2], dom2[3],
- false, false, NULL, 0);
- fail_if(ret != EOK, "Could not set up the test (dom2)");
-
- ret = sysdb_update_subdomains(test_ctx->domain);
- fail_unless(ret == EOK, "sysdb_update_subdomains failed with [%d][%s]",
- ret, strerror(ret));
-
- fail_unless(test_ctx->domain->subdomains->trust_direction == 1);
- fail_unless(test_ctx->domain->subdomains->next->trust_direction == 0);
-
- ret = sysdb_subdomain_delete(test_ctx->sysdb, dom2[0]);
- fail_if(ret != EOK, "Could not delete subdomain");
-
- ret = sysdb_subdomain_delete(test_ctx->sysdb, dom1[0]);
- fail_if(ret != EOK, "Could not delete subdomain");
-
- ret = sysdb_update_subdomains(test_ctx->domain);
- fail_unless(ret == EOK, "sysdb_update_subdomains failed with [%d][%s]",
- ret, strerror(ret));
-
- fail_unless(test_ctx->domain->subdomains->disabled, "Subdomain not disabled.");
-}
-END_TEST
-
const char *const testdom[4] = { "test.sub", "TEST.SUB", "test", "S-3" };
START_TEST(test_sysdb_subdomain_store_user)
@@ -6571,7 +6499,6 @@ Suite *create_sysdb_suite(void)
TCase *tc_subdomain = tcase_create("SYSDB sub-domain Tests");
- tcase_add_test(tc_subdomain, test_sysdb_subdomain_create);
tcase_add_test(tc_subdomain, test_sysdb_subdomain_store_user);
tcase_add_test(tc_subdomain, test_sysdb_subdomain_user_ops);
tcase_add_test(tc_subdomain, test_sysdb_subdomain_group_ops);