dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0047-SYSDB-TESTS-Add-tests-for-the-domain-s-resolution-or.patch

bb7cd1
From 22a10ea2b6b8a56fc040d852867040dce067548a Mon Sep 17 00:00:00 2001
bb7cd1
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
bb7cd1
Date: Fri, 24 Mar 2017 23:15:04 +0100
bb7cd1
Subject: [PATCH 47/54] SYSDB/TESTS: Add tests for the domain's resolution
bb7cd1
 order methods
bb7cd1
MIME-Version: 1.0
bb7cd1
Content-Type: text/plain; charset=UTF-8
bb7cd1
Content-Transfer-Encoding: 8bit
bb7cd1
bb7cd1
Introduce a new and small set of tests for these new helper methods that
bb7cd1
are going to be used in different parts of the code in the follow-up
bb7cd1
patches.
bb7cd1
bb7cd1
Related:
bb7cd1
https://pagure.io/SSSD/sssd/issue/3001
bb7cd1
bb7cd1
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
bb7cd1
bb7cd1
Reviewed-by: Sumit Bose <sbose@redhat.com>
bb7cd1
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
bb7cd1
---
bb7cd1
 Makefile.am                                        |  16 ++
bb7cd1
 .../cmocka/test_sysdb_domain_resolution_order.c    | 190 +++++++++++++++++++++
bb7cd1
 2 files changed, 206 insertions(+)
bb7cd1
 create mode 100644 src/tests/cmocka/test_sysdb_domain_resolution_order.c
bb7cd1
bb7cd1
diff --git a/Makefile.am b/Makefile.am
bb7cd1
index 8052150be32d89813764e9bc436dfcb211a738d6..450785bf4c482cce1e1440f1336879150537888e 100644
bb7cd1
--- a/Makefile.am
bb7cd1
+++ b/Makefile.am
bb7cd1
@@ -263,6 +263,7 @@ if HAVE_CMOCKA
bb7cd1
         test_sysdb_certmap \
bb7cd1
         test_sysdb_sudo \
bb7cd1
         test_sysdb_utils \
bb7cd1
+        test_sysdb_domain_resolution_order \
bb7cd1
         test_wbc_calls \
bb7cd1
         test_be_ptask \
bb7cd1
         test_copy_ccache \
bb7cd1
@@ -2875,6 +2876,21 @@ test_sysdb_utils_LDADD = \
bb7cd1
     libsss_test_common.la \
bb7cd1
     $(NULL)
bb7cd1
 
bb7cd1
+test_sysdb_domain_resolution_order_SOURCES = \
bb7cd1
+    src/tests/cmocka/test_sysdb_domain_resolution_order.c \
bb7cd1
+    $(NULL)
bb7cd1
+test_sysdb_domain_resolution_order_CFLAGS = \
bb7cd1
+    $(AM_CFLAGS) \
bb7cd1
+    $(NULL)
bb7cd1
+test_sysdb_domain_resolution_order_LDADD = \
bb7cd1
+    $(CMOCKA_LIBS) \
bb7cd1
+    $(LDB_LIBS) \
bb7cd1
+    $(POPT_LIBS) \
bb7cd1
+    $(TALLOC_LIBS) \
bb7cd1
+    $(SSSD_INTERNAL_LTLIBS) \
bb7cd1
+    libsss_test_common.la \
bb7cd1
+    $(NULL)
bb7cd1
+
bb7cd1
 test_wbc_calls_SOURCES = \
bb7cd1
     src/tests/cmocka/test_wbc_calls.c \
bb7cd1
     src/sss_client/idmap/sss_nss_idmap.c \
bb7cd1
diff --git a/src/tests/cmocka/test_sysdb_domain_resolution_order.c b/src/tests/cmocka/test_sysdb_domain_resolution_order.c
bb7cd1
new file mode 100644
bb7cd1
index 0000000000000000000000000000000000000000..59a85ce431be9ac27c1e8e6b5e4e5f8300af549e
bb7cd1
--- /dev/null
bb7cd1
+++ b/src/tests/cmocka/test_sysdb_domain_resolution_order.c
bb7cd1
@@ -0,0 +1,190 @@
bb7cd1
+/*
bb7cd1
+    SSSD
bb7cd1
+
bb7cd1
+    sysdb_domain_resolution_order - Tests for domain resolution order calls
bb7cd1
+
bb7cd1
+    Authors:
bb7cd1
+        Fabiano Fidêncio <fidencio@redhat.com>
bb7cd1
+
bb7cd1
+    Copyright (C) 2017 Red Hat
bb7cd1
+
bb7cd1
+    This program is free software; you can redistribute it and/or modify
bb7cd1
+    it under the terms of the GNU General Public License as published by
bb7cd1
+    the Free Software Foundation; either version 3 of the License, or
bb7cd1
+    (at your option) any later version.
bb7cd1
+
bb7cd1
+    This program is distributed in the hope that it will be useful,
bb7cd1
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
bb7cd1
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
bb7cd1
+    GNU General Public License for more details.
bb7cd1
+
bb7cd1
+    You should have received a copy of the GNU General Public License
bb7cd1
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
bb7cd1
+*/
bb7cd1
+
bb7cd1
+#include <stdarg.h>
bb7cd1
+#include <stddef.h>
bb7cd1
+#include <setjmp.h>
bb7cd1
+#include <cmocka.h>
bb7cd1
+#include <popt.h>
bb7cd1
+
bb7cd1
+#include "tests/cmocka/common_mock.h"
bb7cd1
+#include "tests/common.h"
bb7cd1
+#include "db/sysdb_domain_resolution_order.h"
bb7cd1
+#include "db/sysdb_private.h" /* for sysdb->ldb member */
bb7cd1
+
bb7cd1
+#define TESTS_PATH "tp_" BASE_FILE_STEM
bb7cd1
+#define TEST_CONF_DB "test_sysdb_domain_resolution_order.ldb"
bb7cd1
+
bb7cd1
+#define TEST_DOM_NAME "test_sysdb_domain_resolution_order"
bb7cd1
+
bb7cd1
+#define TEST_ID_PROVIDER "ldap"
bb7cd1
+
bb7cd1
+struct domain_resolution_order_test_ctx {
bb7cd1
+    struct sss_test_ctx *tctx;
bb7cd1
+};
bb7cd1
+
bb7cd1
+static int test_sysdb_domain_resolution_order_setup(void **state)
bb7cd1
+{
bb7cd1
+    struct domain_resolution_order_test_ctx *test_ctx;
bb7cd1
+
bb7cd1
+    assert_true(leak_check_setup());
bb7cd1
+
bb7cd1
+    test_ctx = talloc_zero(global_talloc_context,
bb7cd1
+                           struct domain_resolution_order_test_ctx);
bb7cd1
+    assert_non_null(test_ctx);
bb7cd1
+
bb7cd1
+    test_dom_suite_setup(TESTS_PATH);
bb7cd1
+
bb7cd1
+    test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH,
bb7cd1
+                                         TEST_CONF_DB, TEST_DOM_NAME,
bb7cd1
+                                         TEST_ID_PROVIDER, NULL);
bb7cd1
+    assert_non_null(test_ctx->tctx);
bb7cd1
+
bb7cd1
+    *state = test_ctx;
bb7cd1
+    return 0;
bb7cd1
+}
bb7cd1
+
bb7cd1
+static int test_sysdb_domain_resolution_order_teardown(void **state)
bb7cd1
+{
bb7cd1
+    struct domain_resolution_order_test_ctx *test_ctx =
bb7cd1
+        talloc_get_type(*state, struct domain_resolution_order_test_ctx);
bb7cd1
+
bb7cd1
+    test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
bb7cd1
+    talloc_free(test_ctx);
bb7cd1
+    assert_true(leak_check_teardown());
bb7cd1
+    return 0;
bb7cd1
+}
bb7cd1
+
bb7cd1
+static void test_sysdb_domain_resolution_order_ops(void **state)
bb7cd1
+{
bb7cd1
+    errno_t ret;
bb7cd1
+    struct domain_resolution_order_test_ctx *test_ctx =
bb7cd1
+        talloc_get_type(*state, struct domain_resolution_order_test_ctx);
bb7cd1
+    const char *domains_in = NULL;
bb7cd1
+    const char *domains_out = NULL;
bb7cd1
+    struct ldb_dn *dn;
bb7cd1
+
bb7cd1
+    dn = ldb_dn_new_fmt(test_ctx, test_ctx->tctx->dom->sysdb->ldb,
bb7cd1
+                        SYSDB_DOM_BASE, test_ctx->tctx->dom->name);
bb7cd1
+
bb7cd1
+    /* Adding domainResolutionOrder for the first time */
bb7cd1
+    domains_in = "foo:bar:foobar";
bb7cd1
+    ret = sysdb_update_domain_resolution_order(test_ctx->tctx->dom->sysdb,
bb7cd1
+                                               dn, domains_in);
bb7cd1
+    assert_int_equal(ret, EOK);
bb7cd1
+
bb7cd1
+    ret = sysdb_get_domain_resolution_order(test_ctx,
bb7cd1
+                                            test_ctx->tctx->dom->sysdb, dn,
bb7cd1
+                                            &domains_out);
bb7cd1
+    assert_int_equal(ret, EOK);
bb7cd1
+    assert_true(strcmp(domains_in, domains_out) == 0);
bb7cd1
+
bb7cd1
+    /* Setting the domainResolutionOrder to ":" ...
bb7cd1
+     *
bb7cd1
+     * It means, the domainResolutionOrder is set, but if there's another
bb7cd1
+     * domainResolutionOrder with lower precedence those must be ignored.
bb7cd1
+     */
bb7cd1
+    domains_in = ":";
bb7cd1
+    ret = sysdb_update_domain_resolution_order(test_ctx->tctx->dom->sysdb,
bb7cd1
+                                               dn, domains_in);
bb7cd1
+    assert_int_equal(ret, EOK);
bb7cd1
+
bb7cd1
+    ret = sysdb_get_domain_resolution_order(test_ctx,
bb7cd1
+                                            test_ctx->tctx->dom->sysdb, dn,
bb7cd1
+                                            &domains_out);
bb7cd1
+    assert_int_equal(ret, EOK);
bb7cd1
+    assert_true(strcmp(domains_in, domains_out) == 0);
bb7cd1
+
bb7cd1
+    /* Changing the domainResolutionOrder */
bb7cd1
+    domains_in = "bar:foobar:foo";
bb7cd1
+    ret = sysdb_update_domain_resolution_order(test_ctx->tctx->dom->sysdb,
bb7cd1
+                                               dn, domains_in);
bb7cd1
+    assert_int_equal(ret, EOK);
bb7cd1
+
bb7cd1
+    ret = sysdb_get_domain_resolution_order(test_ctx,
bb7cd1
+                                            test_ctx->tctx->dom->sysdb, dn,
bb7cd1
+                                            &domains_out);
bb7cd1
+    assert_int_equal(ret, EOK);
bb7cd1
+    assert_true(strcmp(domains_out, domains_out) == 0);
bb7cd1
+
bb7cd1
+    /* Removing the domainResolutionOrder attribute */
bb7cd1
+    domains_in = NULL;
bb7cd1
+    ret = sysdb_update_domain_resolution_order(test_ctx->tctx->dom->sysdb,
bb7cd1
+                                               dn, domains_in);
bb7cd1
+    assert_int_equal(ret, EOK);
bb7cd1
+
bb7cd1
+    ret = sysdb_get_domain_resolution_order(test_ctx,
bb7cd1
+                                            test_ctx->tctx->dom->sysdb, dn,
bb7cd1
+                                            &domains_out);
bb7cd1
+    assert_int_equal(ret, ENOENT);
bb7cd1
+    assert_true(domains_out == NULL);
bb7cd1
+}
bb7cd1
+
bb7cd1
+int main(int argc, const char *argv[])
bb7cd1
+{
bb7cd1
+    int rv;
bb7cd1
+    int no_cleanup = 0;
bb7cd1
+    poptContext pc;
bb7cd1
+    int opt;
bb7cd1
+    struct poptOption long_options[] = {
bb7cd1
+        POPT_AUTOHELP
bb7cd1
+        SSSD_DEBUG_OPTS
bb7cd1
+        {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
bb7cd1
+         _("Do not delete the test database after a test run"), NULL },
bb7cd1
+        POPT_TABLEEND
bb7cd1
+    };
bb7cd1
+
bb7cd1
+    const struct CMUnitTest tests[] = {
bb7cd1
+        cmocka_unit_test_setup_teardown(test_sysdb_domain_resolution_order_ops,
bb7cd1
+                                        test_sysdb_domain_resolution_order_setup,
bb7cd1
+                                        test_sysdb_domain_resolution_order_teardown),
bb7cd1
+    };
bb7cd1
+
bb7cd1
+    /* Set debug level to invalid value so we can deside if -d 0 was used. */
bb7cd1
+    debug_level = SSSDBG_INVALID;
bb7cd1
+
bb7cd1
+    pc = poptGetContext(argv[0], argc, argv, long_options, 0);
bb7cd1
+    while((opt = poptGetNextOpt(pc)) != -1) {
bb7cd1
+        switch(opt) {
bb7cd1
+        default:
bb7cd1
+            fprintf(stderr, "\nInvalid option %s: %s\n\n",
bb7cd1
+                    poptBadOption(pc, 0), poptStrerror(opt));
bb7cd1
+            poptPrintUsage(pc, stderr, 0);
bb7cd1
+            return 1;
bb7cd1
+        }
bb7cd1
+    }
bb7cd1
+    poptFreeContext(pc);
bb7cd1
+
bb7cd1
+    DEBUG_CLI_INIT(debug_level);
bb7cd1
+
bb7cd1
+    tests_set_cwd();
bb7cd1
+    test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, LOCAL_SYSDB_FILE);
bb7cd1
+    test_dom_suite_setup(TESTS_PATH);
bb7cd1
+    rv = cmocka_run_group_tests(tests, NULL, NULL);
bb7cd1
+
bb7cd1
+    if (rv == 0 && no_cleanup == 0) {
bb7cd1
+        test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, LOCAL_SYSDB_FILE);
bb7cd1
+    }
bb7cd1
+    return rv;
bb7cd1
+}
bb7cd1
-- 
bb7cd1
2.9.3
bb7cd1