Blame SOURCES/0034-TESTS-Add-a-unit-test-for-UPNs-stored-by-sss_ncache_.patch

5fca41
From 05b37ac18ed8da00ce560ed52244c6ad7abfa6a9 Mon Sep 17 00:00:00 2001
5fca41
From: Jakub Hrozek <jhrozek@redhat.com>
5fca41
Date: Wed, 13 Mar 2019 17:41:29 +0100
5fca41
Subject: [PATCH 34/35] TESTS: Add a unit test for UPNs stored by
5fca41
 sss_ncache_prepopulate
5fca41
5fca41
Reviewed-by: Sumit Bose <sbose@redhat.com>
5fca41
(cherry picked from commit 48c1e3ac34ec5b2d7cf27d7393d049c880bca319)
5fca41
---
5fca41
 src/tests/cmocka/test_negcache.c | 111 +++++++++++++++++++++++++------
5fca41
 1 file changed, 92 insertions(+), 19 deletions(-)
5fca41
5fca41
diff --git a/src/tests/cmocka/test_negcache.c b/src/tests/cmocka/test_negcache.c
5fca41
index a0210928b..9bddddd8d 100644
5fca41
--- a/src/tests/cmocka/test_negcache.c
5fca41
+++ b/src/tests/cmocka/test_negcache.c
5fca41
@@ -39,6 +39,7 @@
5fca41
 #include "lib/idmap/sss_idmap.h"
5fca41
 #include "util/util.h"
5fca41
 #include "util/util_sss_idmap.h"
5fca41
+#include "db/sysdb_private.h"
5fca41
 #include "responder/common/responder.h"
5fca41
 #include "responder/common/negcache.h"
5fca41
 
5fca41
@@ -52,6 +53,7 @@
5fca41
 #define TEST_CONF_DB "test_nss_conf.ldb"
5fca41
 #define TEST_DOM_NAME "nss_test"
5fca41
 #define TEST_ID_PROVIDER "ldap"
5fca41
+#define TEST_SUBDOM_NAME "test.subdomain"
5fca41
 
5fca41
 /* register_cli_protocol_version is required in test since it links with
5fca41
  * responder_common.c module
5fca41
@@ -582,6 +584,29 @@ static int check_gid_in_ncache(struct sss_nc_ctx *ctx,
5fca41
     return ret;
5fca41
 }
5fca41
 
5fca41
+static int add_confdb_params(struct sss_test_conf_param params[],
5fca41
+                             struct confdb_ctx *cdb, const char *section)
5fca41
+{
5fca41
+    const char *val[2];
5fca41
+    int ret;
5fca41
+
5fca41
+    val[1] = NULL;
5fca41
+
5fca41
+    for (int i = 0; params[i].key; i++) {
5fca41
+        val[0] = params[i].value;
5fca41
+        ret = confdb_add_param(cdb, true, section, params[i].key, val);
5fca41
+        assert_int_equal(ret, EOK);
5fca41
+    }
5fca41
+
5fca41
+    return EOK;
5fca41
+}
5fca41
+
5fca41
+static int add_nss_params(struct sss_test_conf_param nss_params[],
5fca41
+                          struct confdb_ctx *cdb)
5fca41
+{
5fca41
+    return add_confdb_params(nss_params, cdb, CONFDB_NSS_CONF_ENTRY);
5fca41
+}
5fca41
+
5fca41
 static void test_sss_ncache_prepopulate(void **state)
5fca41
 {
5fca41
     int ret;
5fca41
@@ -589,9 +614,14 @@ static void test_sss_ncache_prepopulate(void **state)
5fca41
     struct tevent_context *ev;
5fca41
     struct sss_nc_ctx *ncache;
5fca41
     struct sss_test_ctx *tc;
5fca41
-    struct sss_domain_info *dom;
5fca41
+    const char *const testdom[4] = { TEST_SUBDOM_NAME, "TEST.SUB", "test", "S-3" };
5fca41
+    struct sss_domain_info *subdomain;
5fca41
 
5fca41
-    struct sss_test_conf_param params[] = {
5fca41
+    struct sss_test_conf_param nss_params[] = {
5fca41
+        { "filter_users", "testuser_nss@UPN.REALM, testuser_nss_short" },
5fca41
+        { NULL, NULL },
5fca41
+    };
5fca41
+    struct sss_test_conf_param dom_params[] = {
5fca41
         { "filter_users", "testuser1, testuser2@"TEST_DOM_NAME", testuser3@somedomain" },
5fca41
         { "filter_groups", "testgroup1, testgroup2@"TEST_DOM_NAME", testgroup3@somedomain" },
5fca41
         { NULL, NULL },
5fca41
@@ -602,22 +632,35 @@ static void test_sss_ncache_prepopulate(void **state)
5fca41
     ev = tevent_context_init(ts);
5fca41
     assert_non_null(ev);
5fca41
 
5fca41
-    dom = talloc_zero(ts, struct sss_domain_info);
5fca41
-    assert_non_null(dom);
5fca41
-    dom->name = discard_const_p(char, TEST_DOM_NAME);
5fca41
-
5fca41
     ts->nctx = mock_nctx(ts);
5fca41
     assert_non_null(ts->nctx);
5fca41
 
5fca41
     tc = create_dom_test_ctx(ts, TESTS_PATH, TEST_CONF_DB,
5fca41
-                             TEST_DOM_NAME, TEST_ID_PROVIDER, params);
5fca41
+                             TEST_DOM_NAME, TEST_ID_PROVIDER, dom_params);
5fca41
     assert_non_null(tc);
5fca41
 
5fca41
+    ret = add_nss_params(nss_params, tc->confdb);
5fca41
+    assert_int_equal(ret, EOK);
5fca41
+
5fca41
+    subdomain = new_subdomain(tc, tc->dom,
5fca41
+                              testdom[0], testdom[1], testdom[2], testdom[3],
5fca41
+                              false, false, NULL, NULL, 0,
5fca41
+                              tc->confdb);
5fca41
+    assert_non_null(subdomain);
5fca41
+
5fca41
+    ret = sysdb_subdomain_store(tc->sysdb,
5fca41
+                                testdom[0], testdom[1], testdom[2], testdom[3],
5fca41
+                                false, false, NULL, 0, NULL);
5fca41
+    assert_int_equal(ret, EOK);
5fca41
+
5fca41
+    ret = sysdb_update_subdomains(tc->dom, tc->confdb);
5fca41
+    assert_int_equal(ret, EOK);
5fca41
+
5fca41
     ncache = ts->ctx;
5fca41
-    ts->rctx = mock_rctx(ts, ev, dom, ts->nctx);
5fca41
+    ts->rctx = mock_rctx(ts, ev, tc->dom, ts->nctx);
5fca41
     assert_non_null(ts->rctx);
5fca41
 
5fca41
-    ret = sss_names_init(ts, tc->confdb, TEST_DOM_NAME, &dom->names);
5fca41
+    ret = sss_names_init(ts, tc->confdb, TEST_DOM_NAME, &tc->dom->names);
5fca41
     assert_int_equal(ret, EOK);
5fca41
 
5fca41
     ret = sss_ncache_prepopulate(ncache, tc->confdb, ts->rctx);
5fca41
@@ -625,34 +668,37 @@ static void test_sss_ncache_prepopulate(void **state)
5fca41
 
5fca41
     sleep(SHORTSPAN);
5fca41
 
5fca41
-    ret = check_user_in_ncache(ncache, dom, "testuser1");
5fca41
+    ret = check_user_in_ncache(ncache, tc->dom, "testuser1");
5fca41
     assert_int_equal(ret, EEXIST);
5fca41
 
5fca41
-    ret = check_group_in_ncache(ncache, dom, "testgroup1");
5fca41
+    ret = check_group_in_ncache(ncache, tc->dom, "testgroup1");
5fca41
     assert_int_equal(ret, EEXIST);
5fca41
 
5fca41
-    ret = check_user_in_ncache(ncache, dom, "testuser2");
5fca41
+    ret = check_user_in_ncache(ncache, tc->dom, "testuser2");
5fca41
     assert_int_equal(ret, EEXIST);
5fca41
 
5fca41
-    ret = check_group_in_ncache(ncache, dom, "testgroup2");
5fca41
+    ret = check_group_in_ncache(ncache, tc->dom, "testgroup2");
5fca41
     assert_int_equal(ret, EEXIST);
5fca41
 
5fca41
-    ret = check_user_in_ncache(ncache, dom, "testuser3");
5fca41
+    ret = check_user_in_ncache(ncache, tc->dom, "testuser3");
5fca41
     assert_int_equal(ret, ENOENT);
5fca41
 
5fca41
-    ret = check_group_in_ncache(ncache, dom, "testgroup3");
5fca41
+    ret = check_group_in_ncache(ncache, tc->dom, "testgroup3");
5fca41
     assert_int_equal(ret, ENOENT);
5fca41
 
5fca41
-    ret = check_user_in_ncache(ncache, dom, "testuser3@somedomain");
5fca41
+    ret = check_user_in_ncache(ncache, tc->dom, "testuser3@somedomain");
5fca41
     assert_int_equal(ret, ENOENT);
5fca41
 
5fca41
-    ret = check_group_in_ncache(ncache, dom, "testgroup3@somedomain");
5fca41
+    ret = sss_ncache_check_upn(ncache, tc->dom, "testuser3@somedomain");
5fca41
+    assert_int_equal(ret, EEXIST);
5fca41
+
5fca41
+    ret = check_group_in_ncache(ncache, tc->dom, "testgroup3@somedomain");
5fca41
     assert_int_equal(ret, ENOENT);
5fca41
 
5fca41
-    ret = check_user_in_ncache(ncache, dom, "root");
5fca41
+    ret = check_user_in_ncache(ncache, tc->dom, "root");
5fca41
     assert_int_equal(ret, EEXIST);
5fca41
 
5fca41
-    ret = check_group_in_ncache(ncache, dom, "root");
5fca41
+    ret = check_group_in_ncache(ncache, tc->dom, "root");
5fca41
     assert_int_equal(ret, EEXIST);
5fca41
 
5fca41
     ret = check_uid_in_ncache(ncache, 0);
5fca41
@@ -660,6 +706,33 @@ static void test_sss_ncache_prepopulate(void **state)
5fca41
 
5fca41
     ret = check_gid_in_ncache(ncache, 0);
5fca41
     assert_int_equal(ret, EEXIST);
5fca41
+
5fca41
+    ret = sss_ncache_check_upn(ncache, tc->dom, "testuser_nss@UPN.REALM");
5fca41
+    assert_int_equal(ret, EEXIST);
5fca41
+
5fca41
+    ret = sss_ncache_check_upn(ncache, tc->dom->subdomains, "testuser_nss@UPN.REALM");
5fca41
+    assert_int_equal(ret, EEXIST);
5fca41
+
5fca41
+    ret = sss_ncache_check_upn(ncache, tc->dom, "testuser_nss_short@" TEST_DOM_NAME);
5fca41
+    assert_int_equal(ret, EEXIST);
5fca41
+
5fca41
+    ret = sss_ncache_check_upn(ncache, tc->dom->subdomains, "testuser_nss_short@" TEST_SUBDOM_NAME);
5fca41
+    assert_int_equal(ret, EEXIST);
5fca41
+
5fca41
+    ret = check_user_in_ncache(ncache, tc->dom, "testuser_nss_short");
5fca41
+    assert_int_equal(ret, EEXIST);
5fca41
+
5fca41
+    ret = check_user_in_ncache(ncache, tc->dom->subdomains, "testuser_nss_short");
5fca41
+    assert_int_equal(ret, EEXIST);
5fca41
+
5fca41
+    ret = sss_ncache_check_upn(ncache, tc->dom, "testuser1@" TEST_DOM_NAME);
5fca41
+    assert_int_equal(ret, EEXIST);
5fca41
+
5fca41
+    ret = sss_ncache_check_upn(ncache, tc->dom, "testuser2@" TEST_DOM_NAME);
5fca41
+    assert_int_equal(ret, EEXIST);
5fca41
+
5fca41
+    ret = sss_ncache_check_upn(ncache, tc->dom, "testuser3@somedomain");
5fca41
+    assert_int_equal(ret, EEXIST);
5fca41
 }
5fca41
 
5fca41
 static void test_sss_ncache_default_domain_suffix(void **state)
5fca41
-- 
5fca41
2.20.1
5fca41