Skip to content

Commit

Permalink
TESTS: Add sysdb test for renaming incomplete groups
Browse files Browse the repository at this point in the history
The test added also test the negative case, when a group has been added
but it has a different sid, uuid and original dn, which results in an
EEXIST return.

Related:
https://pagure.io/SSSD/sssd/issue/3202

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
  • Loading branch information
fidencio committed Aug 10, 2017
1 parent 138ac13 commit 24e5381
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/tests/sysdb-tests.c
Expand Up @@ -989,6 +989,71 @@ START_TEST (test_sysdb_add_incomplete_group)
}
END_TEST

START_TEST (test_sysdb_rename_incomplete_group)
{
struct sysdb_test_ctx *test_ctx;
struct test_data *data;
int ret;
struct ldb_message *msg = NULL;
const char *old_fqdn_groupname;
const char *stored_fqdn_groupname;
char *new_groupname;

/* Setup */
ret = setup_sysdb_tests(&test_ctx);
if (ret != EOK) {
fail("Could not set up the test");
return;
}

data = test_data_new_group(test_ctx, _i);
fail_if(data == NULL);

/* "Rename" the already added incomplete group by adding
* the very same group with a different name. */
old_fqdn_groupname = data->groupname;
new_groupname = talloc_asprintf(data, "foo%d", _i);
fail_if(new_groupname == NULL, "talloc_asprintf() failed\n");
data->groupname = sss_create_internal_fqname(test_ctx,
new_groupname,
test_ctx->domain->name);
fail_if(data->groupname == NULL,
"sss_create_internal_fqname() failed\n");

ret = test_add_incomplete_group(data);
fail_if(ret != EOK, "Could not add incomplete group %s: %s [%d]",
data->groupname, sss_strerror(ret), ret);

/* Check whether the name stored is the new one */
ret = sysdb_search_group_by_gid(test_ctx, test_ctx->domain, data->gid,
NULL, &msg);
fail_if(ret != EOK,
"Cannot find the group \"%s\" by its gid",
data->groupname);
stored_fqdn_groupname = ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
fail_if(strcmp(data->groupname, stored_fqdn_groupname) != 0,
"Failed renaming group \"%s\" to \"%s\". The stored name is \"%s\".",
old_fqdn_groupname, data->groupname, stored_fqdn_groupname);


/*
* Negative test:
* Change the group sid, uuid and original_fd ...
* So the old group must not be removed from cache as it's a case of
* id collision.
*/
ret = sysdb_add_incomplete_group(data->ctx->domain, data->groupname,
data->gid, "foo", "foo", "foo",
true, 0);
fail_if(ret != EEXIST,
"Adding a completely different group with the gid should not "
"delete the old group and EEXIST must be returned! ret [%d]: %s\n",
ret, sss_strerror(ret));

talloc_free(test_ctx);
}
END_TEST

START_TEST (test_sysdb_getpwnam)
{
struct sysdb_test_ctx *test_ctx;
Expand Down Expand Up @@ -7044,6 +7109,9 @@ Suite *create_sysdb_suite(void)
tcase_add_loop_test(tc_sysdb,
test_sysdb_add_incomplete_group,
28000, 28010);
tcase_add_loop_test(tc_sysdb,
test_sysdb_rename_incomplete_group,
28000, 28010);
tcase_add_loop_test(tc_sysdb,
test_sysdb_remove_local_group_by_gid,
28000, 28010);
Expand Down

0 comments on commit 24e5381

Please sign in to comment.