summaryrefslogtreecommitdiffstats
path: root/src/tests/sysdb-tests.c
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2010-08-02 10:47:10 -0400
committerStephen Gallagher <sgallagh@redhat.com>2010-08-03 13:54:38 -0400
commitd59e1d2397c92a2c9f43eb310d99d81cc835b37e (patch)
treebef54f33c54332d4cc6f867143b0484e3d3c773c /src/tests/sysdb-tests.c
parentdae0af263a9490c57962c2d43ede2083d618e637 (diff)
downloadsssd_unused-d59e1d2397c92a2c9f43eb310d99d81cc835b37e.tar.gz
sssd_unused-d59e1d2397c92a2c9f43eb310d99d81cc835b37e.tar.xz
sssd_unused-d59e1d2397c92a2c9f43eb310d99d81cc835b37e.zip
Add sysdb_update_members function
This function will take a user, a list of groups that this user should be added to and a list of groups the user should be removed from and will recursively call sysdb_[add|remove]_group_member Includes a unit test
Diffstat (limited to 'src/tests/sysdb-tests.c')
-rw-r--r--src/tests/sysdb-tests.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
index ee179503..dac5a0b7 100644
--- a/src/tests/sysdb-tests.c
+++ b/src/tests/sysdb-tests.c
@@ -2105,6 +2105,59 @@ START_TEST (test_sysdb_attrs_to_list)
}
END_TEST
+START_TEST (test_sysdb_update_members)
+{
+ struct sysdb_test_ctx *test_ctx;
+ char **add_groups;
+ char **del_groups;
+ const char *user = "testuser27000";
+ errno_t ret;
+
+ /* Setup */
+ ret = setup_sysdb_tests(&test_ctx);
+ fail_unless(ret == EOK, "Could not set up the test");
+
+ /* Add a user to two groups */
+ add_groups = talloc_array(test_ctx, char *, 3);
+ add_groups[0] = talloc_strdup(add_groups, "testgroup28001");
+ add_groups[1] = talloc_strdup(add_groups, "testgroup28002");
+ add_groups[2] = NULL;
+
+ ret = sysdb_update_members(test_ctx->sysdb, test_ctx->domain, user,
+ (const char **)add_groups, NULL);
+ fail_unless(ret == EOK, "Could not add groups");
+ talloc_zfree(add_groups);
+
+ /* Remove a user from one group and add to another */
+ del_groups = talloc_array(test_ctx, char *, 2);
+ del_groups[0] = talloc_strdup(del_groups, "testgroup28001");
+ del_groups[1] = NULL;
+ add_groups = talloc_array(test_ctx, char *, 2);
+ add_groups[0] = talloc_strdup(add_groups, "testgroup28003");
+ add_groups[1] = NULL;
+
+ ret = sysdb_update_members(test_ctx->sysdb, test_ctx->domain, user,
+ (const char **)add_groups,
+ (const char **)del_groups);
+ fail_unless(ret == EOK, "Group replace failed");
+ talloc_zfree(add_groups);
+ talloc_zfree(del_groups);
+
+ /* Remove a user from two groups */
+ del_groups = talloc_array(test_ctx, char *, 3);
+ del_groups[0] = talloc_strdup(del_groups, "testgroup28002");
+ del_groups[1] = talloc_strdup(del_groups, "testgroup28003");
+ del_groups[2] = NULL;
+
+ ret = sysdb_update_members(test_ctx->sysdb, test_ctx->domain,
+ user, NULL,
+ (const char **)del_groups);
+ fail_unless(ret == EOK, "Could not remove groups");
+
+ talloc_zfree(test_ctx);
+}
+END_TEST
+
Suite *create_sysdb_suite(void)
{
Suite *s = suite_create("sysdb");
@@ -2129,6 +2182,9 @@ Suite *create_sysdb_suite(void)
/* test the change */
tcase_add_loop_test(tc_sysdb, test_sysdb_get_user_attr, 27000, 27010);
+ /* Add and remove users in a group with sysdb_update_members */
+ tcase_add_test(tc_sysdb, test_sysdb_update_members);
+
/* Remove the other half by gid */
tcase_add_loop_test(tc_sysdb, test_sysdb_remove_local_group_by_gid, 28000, 28010);