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

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