sssd/0119-NSS-TESTS-Improve-non-...

164 lines
6.4 KiB
Diff

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