|
|
bb7cd1 |
From f318eff5277d783972ef0d585ff05c473db44714 Mon Sep 17 00:00:00 2001
|
|
|
bb7cd1 |
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
|
|
|
bb7cd1 |
Date: Wed, 1 Mar 2017 20:46:10 +0000
|
|
|
bb7cd1 |
Subject: [PATCH 44/54] NSS/TESTS: Improve setup/teardown for subdomains tests
|
|
|
bb7cd1 |
MIME-Version: 1.0
|
|
|
bb7cd1 |
Content-Type: text/plain; charset=UTF-8
|
|
|
bb7cd1 |
Content-Transfer-Encoding: 8bit
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
This patch basically makes the getgrnam_members_subdom(),
|
|
|
bb7cd1 |
getgrnam_mix_dom(), getgrnam_mix_dom_fqdn() and getgrnam_mix_subdom()
|
|
|
bb7cd1 |
more independent of each other.
|
|
|
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 |
src/tests/cmocka/test_nss_srv.c | 182 +++++++++++++++++++++++++++++++++-------
|
|
|
bb7cd1 |
1 file changed, 150 insertions(+), 32 deletions(-)
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
diff --git a/src/tests/cmocka/test_nss_srv.c b/src/tests/cmocka/test_nss_srv.c
|
|
|
bb7cd1 |
index cbe0dccdc1d883eae1a9621f12997ef43d05178e..b468204fb1729618830513322f0d901c4c801e94 100644
|
|
|
bb7cd1 |
--- a/src/tests/cmocka/test_nss_srv.c
|
|
|
bb7cd1 |
+++ b/src/tests/cmocka/test_nss_srv.c
|
|
|
bb7cd1 |
@@ -418,6 +418,26 @@ static errno_t store_user(struct nss_test_ctx *ctx,
|
|
|
bb7cd1 |
return ret;
|
|
|
bb7cd1 |
}
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
+static errno_t delete_user(struct nss_test_ctx *ctx,
|
|
|
bb7cd1 |
+ struct sss_domain_info *dom,
|
|
|
bb7cd1 |
+ struct passwd *user)
|
|
|
bb7cd1 |
+{
|
|
|
bb7cd1 |
+ errno_t ret;
|
|
|
bb7cd1 |
+ char *fqname;
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ fqname = sss_create_internal_fqname(ctx,
|
|
|
bb7cd1 |
+ user->pw_name,
|
|
|
bb7cd1 |
+ dom->name);
|
|
|
bb7cd1 |
+ if (fqname == NULL) {
|
|
|
bb7cd1 |
+ return ENOMEM;
|
|
|
bb7cd1 |
+ }
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = sysdb_delete_user(dom, fqname, user->pw_uid);
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ talloc_free(fqname);
|
|
|
bb7cd1 |
+ return ret;
|
|
|
bb7cd1 |
+}
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
static errno_t set_user_attr(struct nss_test_ctx *ctx,
|
|
|
bb7cd1 |
struct sss_domain_info *dom,
|
|
|
bb7cd1 |
struct passwd *user,
|
|
|
bb7cd1 |
@@ -491,6 +511,27 @@ static errno_t store_group(struct nss_test_ctx *ctx,
|
|
|
bb7cd1 |
return ret;
|
|
|
bb7cd1 |
}
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
+static errno_t delete_group(struct nss_test_ctx *ctx,
|
|
|
bb7cd1 |
+ struct sss_domain_info *dom,
|
|
|
bb7cd1 |
+ struct group *group)
|
|
|
bb7cd1 |
+{
|
|
|
bb7cd1 |
+ errno_t ret;
|
|
|
bb7cd1 |
+ char *fqname;
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ fqname = sss_create_internal_fqname(ctx,
|
|
|
bb7cd1 |
+ group->gr_name,
|
|
|
bb7cd1 |
+ dom->name);
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ if (fqname == NULL) {
|
|
|
bb7cd1 |
+ return ENOMEM;
|
|
|
bb7cd1 |
+ }
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = sysdb_delete_group(dom, fqname, group->gr_gid);
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ talloc_free(fqname);
|
|
|
bb7cd1 |
+ return ret;
|
|
|
bb7cd1 |
+}
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
static void assert_groups_equal(struct group *expected,
|
|
|
bb7cd1 |
struct group *gr, const int nmem)
|
|
|
bb7cd1 |
{
|
|
|
bb7cd1 |
@@ -540,6 +581,42 @@ static errno_t store_group_member(struct nss_test_ctx *ctx,
|
|
|
bb7cd1 |
return ret;
|
|
|
bb7cd1 |
}
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
+static errno_t remove_group_member(struct nss_test_ctx *ctx,
|
|
|
bb7cd1 |
+ const char *shortname_group,
|
|
|
bb7cd1 |
+ struct sss_domain_info *group_dom,
|
|
|
bb7cd1 |
+ const char *shortname_member,
|
|
|
bb7cd1 |
+ struct sss_domain_info *member_dom,
|
|
|
bb7cd1 |
+ enum sysdb_member_type type)
|
|
|
bb7cd1 |
+{
|
|
|
bb7cd1 |
+ errno_t ret;
|
|
|
bb7cd1 |
+ char *group_fqname = NULL;
|
|
|
bb7cd1 |
+ char *member_fqname = NULL;
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ group_fqname = sss_create_internal_fqname(ctx,
|
|
|
bb7cd1 |
+ shortname_group,
|
|
|
bb7cd1 |
+ group_dom->name);
|
|
|
bb7cd1 |
+ if (group_fqname == NULL) {
|
|
|
bb7cd1 |
+ return ENOMEM;
|
|
|
bb7cd1 |
+ }
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ member_fqname = sss_create_internal_fqname(ctx,
|
|
|
bb7cd1 |
+ shortname_member,
|
|
|
bb7cd1 |
+ member_dom->name);
|
|
|
bb7cd1 |
+ if (member_fqname == NULL) {
|
|
|
bb7cd1 |
+ talloc_free(group_fqname);
|
|
|
bb7cd1 |
+ return ENOMEM;
|
|
|
bb7cd1 |
+ }
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = sysdb_remove_group_member(group_dom,
|
|
|
bb7cd1 |
+ group_fqname,
|
|
|
bb7cd1 |
+ member_fqname,
|
|
|
bb7cd1 |
+ type,
|
|
|
bb7cd1 |
+ false);
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ talloc_free(group_fqname);
|
|
|
bb7cd1 |
+ talloc_free(member_fqname);
|
|
|
bb7cd1 |
+ return ret;
|
|
|
bb7cd1 |
+}
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
/* ====================== The tests =============================== */
|
|
|
bb7cd1 |
struct passwd getpwnam_usr = {
|
|
|
bb7cd1 |
@@ -1599,34 +1676,6 @@ void test_nss_getgrnam_members_subdom(void **state)
|
|
|
bb7cd1 |
{
|
|
|
bb7cd1 |
errno_t ret;
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
- ret = store_group(nss_test_ctx, nss_test_ctx->subdom,
|
|
|
bb7cd1 |
- &testsubdomgroup, 0);
|
|
|
bb7cd1 |
- assert_int_equal(ret, EOK);
|
|
|
bb7cd1 |
-
|
|
|
bb7cd1 |
- ret = store_user(nss_test_ctx, nss_test_ctx->subdom,
|
|
|
bb7cd1 |
- &submember1, NULL, 0);
|
|
|
bb7cd1 |
- assert_int_equal(ret, EOK);
|
|
|
bb7cd1 |
-
|
|
|
bb7cd1 |
- ret = store_user(nss_test_ctx, nss_test_ctx->subdom,
|
|
|
bb7cd1 |
- &submember2, NULL, 0);
|
|
|
bb7cd1 |
- assert_int_equal(ret, EOK);
|
|
|
bb7cd1 |
-
|
|
|
bb7cd1 |
- ret = store_group_member(nss_test_ctx,
|
|
|
bb7cd1 |
- testsubdomgroup.gr_name,
|
|
|
bb7cd1 |
- nss_test_ctx->subdom,
|
|
|
bb7cd1 |
- submember1.pw_name,
|
|
|
bb7cd1 |
- nss_test_ctx->subdom,
|
|
|
bb7cd1 |
- SYSDB_MEMBER_USER);
|
|
|
bb7cd1 |
- assert_int_equal(ret, EOK);
|
|
|
bb7cd1 |
-
|
|
|
bb7cd1 |
- ret = store_group_member(nss_test_ctx,
|
|
|
bb7cd1 |
- testsubdomgroup.gr_name,
|
|
|
bb7cd1 |
- nss_test_ctx->subdom,
|
|
|
bb7cd1 |
- submember2.pw_name,
|
|
|
bb7cd1 |
- nss_test_ctx->subdom,
|
|
|
bb7cd1 |
- SYSDB_MEMBER_USER);
|
|
|
bb7cd1 |
- assert_int_equal(ret, EOK);
|
|
|
bb7cd1 |
-
|
|
|
bb7cd1 |
mock_input_user_or_group("testsubdomgroup@"TEST_SUBDOM_NAME);
|
|
|
bb7cd1 |
will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM);
|
|
|
bb7cd1 |
will_return_always(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
bb7cd1 |
@@ -1757,6 +1806,14 @@ void test_nss_getgrnam_mix_dom_fqdn(void **state)
|
|
|
bb7cd1 |
{
|
|
|
bb7cd1 |
errno_t ret;
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
+ ret = store_group_member(nss_test_ctx,
|
|
|
bb7cd1 |
+ testgroup_members.gr_name,
|
|
|
bb7cd1 |
+ nss_test_ctx->tctx->dom,
|
|
|
bb7cd1 |
+ submember1.pw_name,
|
|
|
bb7cd1 |
+ nss_test_ctx->subdom,
|
|
|
bb7cd1 |
+ SYSDB_MEMBER_USER);
|
|
|
bb7cd1 |
+ assert_int_equal(ret, EOK);
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
nss_test_ctx->tctx->dom->fqnames = true;
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
mock_input_user_or_group("testgroup_members@"TEST_DOM_NAME);
|
|
|
bb7cd1 |
@@ -3220,6 +3277,35 @@ static int nss_subdom_test_setup(void **state)
|
|
|
bb7cd1 |
assert_int_equal(ret, EOK);
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
nss_test_ctx->subdom = nss_test_ctx->tctx->dom->subdomains;
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = store_group(nss_test_ctx, nss_test_ctx->subdom,
|
|
|
bb7cd1 |
+ &testsubdomgroup, 0);
|
|
|
bb7cd1 |
+ assert_int_equal(ret, EOK);
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = store_user(nss_test_ctx, nss_test_ctx->subdom,
|
|
|
bb7cd1 |
+ &submember1, NULL, 0);
|
|
|
bb7cd1 |
+ assert_int_equal(ret, EOK);
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = store_user(nss_test_ctx, nss_test_ctx->subdom,
|
|
|
bb7cd1 |
+ &submember2, NULL, 0);
|
|
|
bb7cd1 |
+ assert_int_equal(ret, EOK);
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = store_group_member(nss_test_ctx,
|
|
|
bb7cd1 |
+ testsubdomgroup.gr_name,
|
|
|
bb7cd1 |
+ nss_test_ctx->subdom,
|
|
|
bb7cd1 |
+ submember1.pw_name,
|
|
|
bb7cd1 |
+ nss_test_ctx->subdom,
|
|
|
bb7cd1 |
+ SYSDB_MEMBER_USER);
|
|
|
bb7cd1 |
+ assert_int_equal(ret, EOK);
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = store_group_member(nss_test_ctx,
|
|
|
bb7cd1 |
+ testsubdomgroup.gr_name,
|
|
|
bb7cd1 |
+ nss_test_ctx->subdom,
|
|
|
bb7cd1 |
+ submember2.pw_name,
|
|
|
bb7cd1 |
+ nss_test_ctx->subdom,
|
|
|
bb7cd1 |
+ SYSDB_MEMBER_USER);
|
|
|
bb7cd1 |
+ assert_int_equal(ret, EOK);
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
return 0;
|
|
|
bb7cd1 |
}
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
@@ -3241,6 +3327,38 @@ static int nss_test_teardown(void **state)
|
|
|
bb7cd1 |
return 0;
|
|
|
bb7cd1 |
}
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
+static int nss_subdom_test_teardown(void **state)
|
|
|
bb7cd1 |
+{
|
|
|
bb7cd1 |
+ errno_t ret;
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = remove_group_member(nss_test_ctx,
|
|
|
bb7cd1 |
+ testsubdomgroup.gr_name,
|
|
|
bb7cd1 |
+ nss_test_ctx->subdom,
|
|
|
bb7cd1 |
+ submember2.pw_name,
|
|
|
bb7cd1 |
+ nss_test_ctx->subdom,
|
|
|
bb7cd1 |
+ SYSDB_MEMBER_USER);
|
|
|
bb7cd1 |
+ assert_int_equal(ret, EOK);
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = remove_group_member(nss_test_ctx,
|
|
|
bb7cd1 |
+ testsubdomgroup.gr_name,
|
|
|
bb7cd1 |
+ nss_test_ctx->subdom,
|
|
|
bb7cd1 |
+ submember1.pw_name,
|
|
|
bb7cd1 |
+ nss_test_ctx->subdom,
|
|
|
bb7cd1 |
+ SYSDB_MEMBER_USER);
|
|
|
bb7cd1 |
+ assert_int_equal(ret, EOK);
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = delete_user(nss_test_ctx, nss_test_ctx->subdom, &submember2);
|
|
|
bb7cd1 |
+ assert_int_equal(ret, EOK);
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = delete_user(nss_test_ctx, nss_test_ctx->subdom, &submember1);
|
|
|
bb7cd1 |
+ assert_int_equal(ret, EOK);
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = delete_group(nss_test_ctx, nss_test_ctx->subdom, &testsubdomgroup);
|
|
|
bb7cd1 |
+ assert_int_equal(ret, EOK);
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ return nss_test_teardown(state);
|
|
|
bb7cd1 |
+}
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
struct passwd testbysid = {
|
|
|
bb7cd1 |
.pw_name = discard_const("testsiduser"),
|
|
|
bb7cd1 |
.pw_uid = 12345,
|
|
|
bb7cd1 |
@@ -3904,16 +4022,16 @@ int main(int argc, const char *argv[])
|
|
|
bb7cd1 |
nss_fqdn_test_setup, nss_test_teardown),
|
|
|
bb7cd1 |
cmocka_unit_test_setup_teardown(test_nss_getgrnam_members_subdom,
|
|
|
bb7cd1 |
nss_subdom_test_setup,
|
|
|
bb7cd1 |
- nss_test_teardown),
|
|
|
bb7cd1 |
+ nss_subdom_test_teardown),
|
|
|
bb7cd1 |
cmocka_unit_test_setup_teardown(test_nss_getgrnam_mix_dom,
|
|
|
bb7cd1 |
nss_subdom_test_setup,
|
|
|
bb7cd1 |
- nss_test_teardown),
|
|
|
bb7cd1 |
+ nss_subdom_test_teardown),
|
|
|
bb7cd1 |
cmocka_unit_test_setup_teardown(test_nss_getgrnam_mix_dom_fqdn,
|
|
|
bb7cd1 |
nss_subdom_test_setup,
|
|
|
bb7cd1 |
- nss_test_teardown),
|
|
|
bb7cd1 |
+ nss_subdom_test_teardown),
|
|
|
bb7cd1 |
cmocka_unit_test_setup_teardown(test_nss_getgrnam_mix_subdom,
|
|
|
bb7cd1 |
nss_subdom_test_setup,
|
|
|
bb7cd1 |
- nss_test_teardown),
|
|
|
bb7cd1 |
+ nss_subdom_test_teardown),
|
|
|
bb7cd1 |
cmocka_unit_test_setup_teardown(test_nss_getgrnam_space,
|
|
|
bb7cd1 |
nss_test_setup, nss_test_teardown),
|
|
|
bb7cd1 |
cmocka_unit_test_setup_teardown(test_nss_getgrnam_space_sub,
|
|
|
bb7cd1 |
--
|
|
|
bb7cd1 |
2.9.3
|
|
|
bb7cd1 |
|