|
|
905b4d |
From de4be65f95ae8bd10995948e086bb71f047c2887 Mon Sep 17 00:00:00 2001
|
|
|
905b4d |
From: Sumit Bose <sbose@redhat.com>
|
|
|
905b4d |
Date: Tue, 28 Oct 2014 15:53:16 +0100
|
|
|
905b4d |
Subject: [PATCH 63/64] Add test for sysdb_add_overrides_to_object()
|
|
|
905b4d |
|
|
|
905b4d |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
905b4d |
---
|
|
|
905b4d |
Makefile.am | 16 +++
|
|
|
905b4d |
src/tests/cmocka/test_sysdb_views.c | 235 ++++++++++++++++++++++++++++++++++++
|
|
|
905b4d |
2 files changed, 251 insertions(+)
|
|
|
905b4d |
create mode 100644 src/tests/cmocka/test_sysdb_views.c
|
|
|
905b4d |
|
|
|
905b4d |
diff --git a/Makefile.am b/Makefile.am
|
|
|
905b4d |
index ac8ad1566a5c931bf43526e2d29a57a5f8ade1cf..60bc67f1ac60c72dc64b3d1adccc9ef1ec989ad5 100644
|
|
|
905b4d |
--- a/Makefile.am
|
|
|
905b4d |
+++ b/Makefile.am
|
|
|
905b4d |
@@ -215,6 +215,7 @@ if HAVE_CMOCKA
|
|
|
905b4d |
sss_sifp-tests \
|
|
|
905b4d |
test_search_bases \
|
|
|
905b4d |
sdap-tests \
|
|
|
905b4d |
+ test_sysdb_views \
|
|
|
905b4d |
$(NULL)
|
|
|
905b4d |
|
|
|
905b4d |
if BUILD_IFP
|
|
|
905b4d |
@@ -2060,6 +2061,21 @@ sss_sifp_tests_LDADD = \
|
|
|
905b4d |
$(SSSD_INTERNAL_LTLIBS)
|
|
|
905b4d |
endif # BUILD_IFP
|
|
|
905b4d |
|
|
|
905b4d |
+test_sysdb_views_SOURCES = \
|
|
|
905b4d |
+ src/tests/cmocka/test_sysdb_views.c \
|
|
|
905b4d |
+ $(NULL)
|
|
|
905b4d |
+test_sysdb_views_CFLAGS = \
|
|
|
905b4d |
+ $(AM_CFLAGS) \
|
|
|
905b4d |
+ $(NULL)
|
|
|
905b4d |
+test_sysdb_views_LDADD = \
|
|
|
905b4d |
+ $(CMOCKA_LIBS) \
|
|
|
905b4d |
+ $(LDB_LIBS) \
|
|
|
905b4d |
+ $(POPT_LIBS) \
|
|
|
905b4d |
+ $(TALLOC_LIBS) \
|
|
|
905b4d |
+ $(SSSD_INTERNAL_LTLIBS) \
|
|
|
905b4d |
+ libsss_test_common.la \
|
|
|
905b4d |
+ $(NULL)
|
|
|
905b4d |
+
|
|
|
905b4d |
endif # HAVE_CMOCKA
|
|
|
905b4d |
|
|
|
905b4d |
noinst_PROGRAMS = pam_test_client
|
|
|
905b4d |
diff --git a/src/tests/cmocka/test_sysdb_views.c b/src/tests/cmocka/test_sysdb_views.c
|
|
|
905b4d |
new file mode 100644
|
|
|
905b4d |
index 0000000000000000000000000000000000000000..38525d6ded8fdbbd1a657f8ca742e51d6ba2b102
|
|
|
905b4d |
--- /dev/null
|
|
|
905b4d |
+++ b/src/tests/cmocka/test_sysdb_views.c
|
|
|
905b4d |
@@ -0,0 +1,235 @@
|
|
|
905b4d |
+/*
|
|
|
905b4d |
+ SSSD
|
|
|
905b4d |
+
|
|
|
905b4d |
+ sysdb_views - Tests for view and override related sysdb calls
|
|
|
905b4d |
+
|
|
|
905b4d |
+ Authors:
|
|
|
905b4d |
+ Sumit Bose <sbose@redhat.com>
|
|
|
905b4d |
+
|
|
|
905b4d |
+ Copyright (C) 2014 Red Hat
|
|
|
905b4d |
+
|
|
|
905b4d |
+ This program is free software; you can redistribute it and/or modify
|
|
|
905b4d |
+ it under the terms of the GNU General Public License as published by
|
|
|
905b4d |
+ the Free Software Foundation; either version 3 of the License, or
|
|
|
905b4d |
+ (at your option) any later version.
|
|
|
905b4d |
+
|
|
|
905b4d |
+ This program is distributed in the hope that it will be useful,
|
|
|
905b4d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
905b4d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
905b4d |
+ GNU General Public License for more details.
|
|
|
905b4d |
+
|
|
|
905b4d |
+ You should have received a copy of the GNU General Public License
|
|
|
905b4d |
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
905b4d |
+*/
|
|
|
905b4d |
+
|
|
|
905b4d |
+#include <stdarg.h>
|
|
|
905b4d |
+#include <stddef.h>
|
|
|
905b4d |
+#include <setjmp.h>
|
|
|
905b4d |
+#include <cmocka.h>
|
|
|
905b4d |
+#include <popt.h>
|
|
|
905b4d |
+
|
|
|
905b4d |
+#include "tests/cmocka/common_mock.h"
|
|
|
905b4d |
+
|
|
|
905b4d |
+#define TESTS_PATH "tests_sysdb"
|
|
|
905b4d |
+#define TEST_CONF_FILE "tests_conf.ldb"
|
|
|
905b4d |
+
|
|
|
905b4d |
+struct sysdb_test_ctx {
|
|
|
905b4d |
+ struct sysdb_ctx *sysdb;
|
|
|
905b4d |
+ struct confdb_ctx *confdb;
|
|
|
905b4d |
+ struct tevent_context *ev;
|
|
|
905b4d |
+ struct sss_domain_info *domain;
|
|
|
905b4d |
+};
|
|
|
905b4d |
+
|
|
|
905b4d |
+static int _setup_sysdb_tests(struct sysdb_test_ctx **ctx, bool enumerate)
|
|
|
905b4d |
+{
|
|
|
905b4d |
+ struct sysdb_test_ctx *test_ctx;
|
|
|
905b4d |
+ char *conf_db;
|
|
|
905b4d |
+ int ret;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ const char *val[2];
|
|
|
905b4d |
+ val[1] = NULL;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ /* Create tests directory if it doesn't exist */
|
|
|
905b4d |
+ /* (relative to current dir) */
|
|
|
905b4d |
+ ret = mkdir(TESTS_PATH, 0775);
|
|
|
905b4d |
+ assert_true(ret == 0 || errno == EEXIST);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ test_ctx = talloc_zero(global_talloc_context, struct sysdb_test_ctx);
|
|
|
905b4d |
+ assert_non_null(test_ctx);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ /* Create an event context
|
|
|
905b4d |
+ * It will not be used except in confdb_init and sysdb_init
|
|
|
905b4d |
+ */
|
|
|
905b4d |
+ test_ctx->ev = tevent_context_init(test_ctx);
|
|
|
905b4d |
+ assert_non_null(test_ctx->ev);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ conf_db = talloc_asprintf(test_ctx, "%s/%s", TESTS_PATH, TEST_CONF_FILE);
|
|
|
905b4d |
+ assert_non_null(conf_db);
|
|
|
905b4d |
+ DEBUG(SSSDBG_MINOR_FAILURE, "CONFDB: %s\n", conf_db);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ /* Connect to the conf db */
|
|
|
905b4d |
+ ret = confdb_init(test_ctx, &test_ctx->confdb, conf_db);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ val[0] = "LOCAL";
|
|
|
905b4d |
+ ret = confdb_add_param(test_ctx->confdb, true,
|
|
|
905b4d |
+ "config/sssd", "domains", val);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ val[0] = "local";
|
|
|
905b4d |
+ ret = confdb_add_param(test_ctx->confdb, true,
|
|
|
905b4d |
+ "config/domain/LOCAL", "id_provider", val);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ val[0] = enumerate ? "TRUE" : "FALSE";
|
|
|
905b4d |
+ ret = confdb_add_param(test_ctx->confdb, true,
|
|
|
905b4d |
+ "config/domain/LOCAL", "enumerate", val);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ val[0] = "TRUE";
|
|
|
905b4d |
+ ret = confdb_add_param(test_ctx->confdb, true,
|
|
|
905b4d |
+ "config/domain/LOCAL", "cache_credentials", val);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = sssd_domain_init(test_ctx, test_ctx->confdb, "local",
|
|
|
905b4d |
+ TESTS_PATH, &test_ctx->domain);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ test_ctx->sysdb = test_ctx->domain->sysdb;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ *ctx = test_ctx;
|
|
|
905b4d |
+ return EOK;
|
|
|
905b4d |
+}
|
|
|
905b4d |
+
|
|
|
905b4d |
+#define setup_sysdb_tests(ctx) _setup_sysdb_tests((ctx), false)
|
|
|
905b4d |
+
|
|
|
905b4d |
+static void test_sysdb_setup(void **state)
|
|
|
905b4d |
+{
|
|
|
905b4d |
+ int ret;
|
|
|
905b4d |
+ struct sysdb_test_ctx *test_ctx;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ assert_true(leak_check_setup());
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = setup_sysdb_tests(&test_ctx);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ *state = (void *) test_ctx;
|
|
|
905b4d |
+}
|
|
|
905b4d |
+
|
|
|
905b4d |
+static void test_sysdb_teardown(void **state)
|
|
|
905b4d |
+{
|
|
|
905b4d |
+ struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
|
|
|
905b4d |
+ struct sysdb_test_ctx);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ talloc_free(test_ctx);
|
|
|
905b4d |
+ assert_true(leak_check_teardown());
|
|
|
905b4d |
+}
|
|
|
905b4d |
+
|
|
|
905b4d |
+void test_sysdb_add_overrides_to_object(void **state)
|
|
|
905b4d |
+{
|
|
|
905b4d |
+ int ret;
|
|
|
905b4d |
+ struct ldb_message *orig;
|
|
|
905b4d |
+ struct ldb_message *override;
|
|
|
905b4d |
+ struct ldb_message_element *el;
|
|
|
905b4d |
+ char *tmp_str;
|
|
|
905b4d |
+ struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
|
|
|
905b4d |
+ struct sysdb_test_ctx);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ orig = ldb_msg_new(test_ctx);
|
|
|
905b4d |
+ assert_non_null(orig);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ tmp_str = talloc_strdup(orig, "ORIGNAME");
|
|
|
905b4d |
+ ret = ldb_msg_add_string(orig, SYSDB_NAME, tmp_str);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ tmp_str = talloc_strdup(orig, "ORIGGECOS");
|
|
|
905b4d |
+ ret = ldb_msg_add_string(orig, SYSDB_GECOS, tmp_str);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ override = ldb_msg_new(test_ctx);
|
|
|
905b4d |
+ assert_non_null(override);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ tmp_str = talloc_strdup(override, "OVERRIDENAME");
|
|
|
905b4d |
+ ret = ldb_msg_add_string(override, SYSDB_NAME, tmp_str);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ tmp_str = talloc_strdup(override, "OVERRIDEGECOS");
|
|
|
905b4d |
+ ret = ldb_msg_add_string(override, SYSDB_GECOS, tmp_str);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ tmp_str = talloc_strdup(override, "OVERRIDEKEY1");
|
|
|
905b4d |
+ ret = ldb_msg_add_string(override, SYSDB_SSH_PUBKEY, tmp_str);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ tmp_str = talloc_strdup(override, "OVERRIDEKEY2");
|
|
|
905b4d |
+ ret = ldb_msg_add_string(override, SYSDB_SSH_PUBKEY, tmp_str);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = sysdb_add_overrides_to_object(test_ctx->domain, orig, override, NULL);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ assert_string_equal(ldb_msg_find_attr_as_string(orig, SYSDB_NAME, NULL),
|
|
|
905b4d |
+ "ORIGNAME");
|
|
|
905b4d |
+ assert_string_equal(ldb_msg_find_attr_as_string(orig, SYSDB_GECOS, NULL),
|
|
|
905b4d |
+ "ORIGGECOS");
|
|
|
905b4d |
+ assert_string_equal(ldb_msg_find_attr_as_string(orig,
|
|
|
905b4d |
+ OVERRIDE_PREFIX SYSDB_NAME,
|
|
|
905b4d |
+ NULL),
|
|
|
905b4d |
+ "OVERRIDENAME");
|
|
|
905b4d |
+ assert_string_equal(ldb_msg_find_attr_as_string(orig,
|
|
|
905b4d |
+ OVERRIDE_PREFIX SYSDB_GECOS,
|
|
|
905b4d |
+ NULL),
|
|
|
905b4d |
+ "OVERRIDEGECOS");
|
|
|
905b4d |
+
|
|
|
905b4d |
+ el = ldb_msg_find_element(orig, OVERRIDE_PREFIX SYSDB_SSH_PUBKEY);
|
|
|
905b4d |
+ assert_non_null(el);
|
|
|
905b4d |
+ assert_int_equal(el->num_values, 2);
|
|
|
905b4d |
+ assert_int_equal(ldb_val_string_cmp(&el->values[0], "OVERRIDEKEY1"), 0);
|
|
|
905b4d |
+ assert_int_equal(ldb_val_string_cmp(&el->values[1], "OVERRIDEKEY2"), 0);
|
|
|
905b4d |
+}
|
|
|
905b4d |
+
|
|
|
905b4d |
+int main(int argc, const char *argv[])
|
|
|
905b4d |
+{
|
|
|
905b4d |
+ int rv;
|
|
|
905b4d |
+ int no_cleanup = 0;
|
|
|
905b4d |
+ poptContext pc;
|
|
|
905b4d |
+ int opt;
|
|
|
905b4d |
+ struct poptOption long_options[] = {
|
|
|
905b4d |
+ POPT_AUTOHELP
|
|
|
905b4d |
+ SSSD_DEBUG_OPTS
|
|
|
905b4d |
+ {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
|
|
|
905b4d |
+ _("Do not delete the test database after a test run"), NULL },
|
|
|
905b4d |
+ POPT_TABLEEND
|
|
|
905b4d |
+ };
|
|
|
905b4d |
+
|
|
|
905b4d |
+ const UnitTest tests[] = {
|
|
|
905b4d |
+ unit_test_setup_teardown(test_sysdb_add_overrides_to_object,
|
|
|
905b4d |
+ test_sysdb_setup, test_sysdb_teardown),
|
|
|
905b4d |
+ };
|
|
|
905b4d |
+
|
|
|
905b4d |
+ /* Set debug level to invalid value so we can deside if -d 0 was used. */
|
|
|
905b4d |
+ debug_level = SSSDBG_INVALID;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ pc = poptGetContext(argv[0], argc, argv, long_options, 0);
|
|
|
905b4d |
+ while((opt = poptGetNextOpt(pc)) != -1) {
|
|
|
905b4d |
+ switch(opt) {
|
|
|
905b4d |
+ default:
|
|
|
905b4d |
+ fprintf(stderr, "\nInvalid option %s: %s\n\n",
|
|
|
905b4d |
+ poptBadOption(pc, 0), poptStrerror(opt));
|
|
|
905b4d |
+ poptPrintUsage(pc, stderr, 0);
|
|
|
905b4d |
+ return 1;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+ poptFreeContext(pc);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ DEBUG_CLI_INIT(debug_level);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ tests_set_cwd();
|
|
|
905b4d |
+ rv = run_tests(tests);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ if (rv == 0 && no_cleanup == 0) {
|
|
|
905b4d |
+ test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_FILE, LOCAL_SYSDB_FILE);
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+ return rv;
|
|
|
905b4d |
+}
|
|
|
905b4d |
--
|
|
|
905b4d |
1.9.3
|
|
|
905b4d |
|