Blame SOURCES/0106-NSS-TESTS-Improve-non-fqnames-tests.patch

bb7cd1
From b4b409f2c5bd0f0b26015b0562ae0ee0e831da82 Mon Sep 17 00:00:00 2001
bb7cd1
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
bb7cd1
Date: Mon, 17 Apr 2017 09:32:39 +0200
bb7cd1
Subject: [PATCH 106/110] NSS/TESTS: Improve non-fqnames tests
bb7cd1
MIME-Version: 1.0
bb7cd1
Content-Type: text/plain; charset=UTF-8
bb7cd1
Content-Transfer-Encoding: 8bit
bb7cd1
bb7cd1
With the changes that are about to happen we have to have the subdomain's
bb7cd1
fqnames flag set by the time we populate the cr_domains list (as it
bb7cd1
actually occurs with the real code), as this list may set its own fqnames
bb7cd1
flag based on the subdomain's fqnames flag.
bb7cd1
bb7cd1
Currently the flag is set to false only when running the tests itself so
bb7cd1
the cr_domains list doesn't get populate properly (although it still
bb7cd1
works with the current code).
bb7cd1
bb7cd1
For the changes that are comming, let's introduce a new setup function
bb7cd1
that ensures that the subdomain's fqnames flag is set up in the right
bb7cd1
time.
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: Pavel Březina <pbrezina@redhat.com>
bb7cd1
(cherry picked from commit ed518f61f1a5d4cf5d87eec492c158725a73d6a1)
bb7cd1
---
bb7cd1
 src/tests/cmocka/test_nss_srv.c | 45 +++++++++++++++++++++++++++--------------
bb7cd1
 1 file changed, 30 insertions(+), 15 deletions(-)
bb7cd1
bb7cd1
diff --git a/src/tests/cmocka/test_nss_srv.c b/src/tests/cmocka/test_nss_srv.c
bb7cd1
index 2f526660cbbbf2443dbae4e213c1336feb6c661e..8c72f44f1869558893627e1f2f91b5f3b96c6317 100644
bb7cd1
--- a/src/tests/cmocka/test_nss_srv.c
bb7cd1
+++ b/src/tests/cmocka/test_nss_srv.c
bb7cd1
@@ -1709,8 +1709,6 @@ void test_nss_getgrnam_members_subdom_nonfqnames(void **state)
bb7cd1
 {
bb7cd1
     errno_t ret;
bb7cd1
 
bb7cd1
-    nss_test_ctx->subdom->fqnames = false;
bb7cd1
-
bb7cd1
     mock_input_user_or_group("testsubdomgroup");
bb7cd1
     mock_account_recv_simple();
bb7cd1
     will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM);
bb7cd1
@@ -1802,8 +1800,6 @@ void test_nss_getgrnam_mix_dom_nonfqnames(void **state)
bb7cd1
 {
bb7cd1
     errno_t ret;
bb7cd1
 
bb7cd1
-    nss_test_ctx->subdom->fqnames = false;
bb7cd1
-
bb7cd1
     ret = store_group_member(nss_test_ctx,
bb7cd1
                              testgroup_members.gr_name,
bb7cd1
                              nss_test_ctx->tctx->dom,
bb7cd1
@@ -1917,6 +1913,7 @@ void test_nss_getgrnam_mix_dom_fqdn(void **state)
bb7cd1
     assert_int_equal(ret, EOK);
bb7cd1
 }
bb7cd1
 
bb7cd1
+
bb7cd1
 void test_nss_getgrnam_mix_dom_fqdn_nonfqnames(void **state)
bb7cd1
 {
bb7cd1
     errno_t ret;
bb7cd1
@@ -1929,10 +1926,6 @@ void test_nss_getgrnam_mix_dom_fqdn_nonfqnames(void **state)
bb7cd1
                              SYSDB_MEMBER_USER);
bb7cd1
     assert_int_equal(ret, EOK);
bb7cd1
 
bb7cd1
-    nss_test_ctx->tctx->dom->fqnames = false;
bb7cd1
-    nss_test_ctx->subdom->fqnames = false;
bb7cd1
-
bb7cd1
-
bb7cd1
     mock_input_user_or_group("testgroup_members");
bb7cd1
     will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM);
bb7cd1
     will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
bb7cd1
@@ -2044,8 +2037,6 @@ void test_nss_getgrnam_mix_subdom_nonfqnames(void **state)
bb7cd1
 {
bb7cd1
     errno_t ret;
bb7cd1
 
bb7cd1
-    nss_test_ctx->subdom->fqnames = false;
bb7cd1
-
bb7cd1
     ret = store_group_member(nss_test_ctx,
bb7cd1
                              testsubdomgroup.gr_name,
bb7cd1
                              nss_test_ctx->subdom,
bb7cd1
@@ -3417,9 +3408,11 @@ static int nss_test_setup_extra_attr(void **state)
bb7cd1
     return 0;
bb7cd1
 }
bb7cd1
 
bb7cd1
-static int nss_subdom_test_setup(void **state)
bb7cd1
+static int nss_subdom_test_setup_common(void **state, bool nonfqnames)
bb7cd1
 {
bb7cd1
     const char *const testdom[4] = { TEST_SUBDOM_NAME, "TEST.SUB", "test", "S-3" };
bb7cd1
+    struct sss_domain_info *dom;
bb7cd1
+
bb7cd1
     struct sss_domain_info *subdomain;
bb7cd1
     errno_t ret;
bb7cd1
 
bb7cd1
@@ -3440,6 +3433,17 @@ static int nss_subdom_test_setup(void **state)
bb7cd1
                                   nss_test_ctx->tctx->confdb);
bb7cd1
     assert_int_equal(ret, EOK);
bb7cd1
 
bb7cd1
+    if (nonfqnames) {
bb7cd1
+        for (dom = nss_test_ctx->rctx->domains;
bb7cd1
+             dom != NULL;
bb7cd1
+             dom = get_next_domain(dom, SSS_GND_ALL_DOMAINS)) {
bb7cd1
+            if (strcmp(dom->name, subdomain->name) == 0) {
bb7cd1
+                dom->fqnames = false;
bb7cd1
+                break;
bb7cd1
+            }
bb7cd1
+        }
bb7cd1
+    }
bb7cd1
+
bb7cd1
     ret = sss_resp_populate_cr_domains(nss_test_ctx->rctx);
bb7cd1
     assert_int_equal(ret, EOK);
bb7cd1
     assert_non_null(nss_test_ctx->rctx->cr_domains);
bb7cd1
@@ -3475,6 +3479,17 @@ static int nss_subdom_test_setup(void **state)
bb7cd1
     assert_int_equal(ret, EOK);
bb7cd1
 
bb7cd1
     return 0;
bb7cd1
+
bb7cd1
+}
bb7cd1
+
bb7cd1
+static int nss_subdom_test_setup(void **state)
bb7cd1
+{
bb7cd1
+    return nss_subdom_test_setup_common(state, false);
bb7cd1
+}
bb7cd1
+
bb7cd1
+static int nss_subdom_test_setup_nonfqnames(void **state)
bb7cd1
+{
bb7cd1
+    return nss_subdom_test_setup_common(state, true);
bb7cd1
 }
bb7cd1
 
bb7cd1
 static int nss_fqdn_fancy_test_setup(void **state)
bb7cd1
@@ -4192,25 +4207,25 @@ int main(int argc, const char *argv[])
bb7cd1
                                         nss_subdom_test_setup,
bb7cd1
                                         nss_subdom_test_teardown),
bb7cd1
         cmocka_unit_test_setup_teardown(test_nss_getgrnam_members_subdom_nonfqnames,
bb7cd1
-                                        nss_subdom_test_setup,
bb7cd1
+                                        nss_subdom_test_setup_nonfqnames,
bb7cd1
                                         nss_subdom_test_teardown),
bb7cd1
         cmocka_unit_test_setup_teardown(test_nss_getgrnam_mix_dom,
bb7cd1
                                         nss_subdom_test_setup,
bb7cd1
                                         nss_subdom_test_teardown),
bb7cd1
         cmocka_unit_test_setup_teardown(test_nss_getgrnam_mix_dom_nonfqnames,
bb7cd1
-                                        nss_subdom_test_setup,
bb7cd1
+                                        nss_subdom_test_setup_nonfqnames,
bb7cd1
                                         nss_subdom_test_teardown),
bb7cd1
         cmocka_unit_test_setup_teardown(test_nss_getgrnam_mix_dom_fqdn,
bb7cd1
                                         nss_subdom_test_setup,
bb7cd1
                                         nss_subdom_test_teardown),
bb7cd1
         cmocka_unit_test_setup_teardown(test_nss_getgrnam_mix_dom_fqdn_nonfqnames,
bb7cd1
-                                        nss_subdom_test_setup,
bb7cd1
+                                        nss_subdom_test_setup_nonfqnames,
bb7cd1
                                         nss_subdom_test_teardown),
bb7cd1
         cmocka_unit_test_setup_teardown(test_nss_getgrnam_mix_subdom,
bb7cd1
                                         nss_subdom_test_setup,
bb7cd1
                                         nss_subdom_test_teardown),
bb7cd1
         cmocka_unit_test_setup_teardown(test_nss_getgrnam_mix_subdom_nonfqnames,
bb7cd1
-                                        nss_subdom_test_setup,
bb7cd1
+                                        nss_subdom_test_setup_nonfqnames,
bb7cd1
                                         nss_subdom_test_teardown),
bb7cd1
         cmocka_unit_test_setup_teardown(test_nss_getgrnam_space,
bb7cd1
                                         nss_test_setup, nss_test_teardown),
bb7cd1
-- 
bb7cd1
2.9.3
bb7cd1