extdom: add unit-test for get_user_grouplist()

Reviewed-By: Tomas Babej <tbabej@redhat.com>
This commit is contained in:
Sumit Bose authored and Tomas Babej committed 2015-07-08 01:56:52 +02:00
1 parent 2dd5b46d25
commit 7b524e7835
4 files changed
+1045 -2

No files matched your search

@@ -185,6 +185,8 @@ int getgrnam_r_wrapper(size_t buf_max, const char *name,
struct group *grp, char **_buf, size_t *_buf_len);
int getgrgid_r_wrapper(size_t buf_max, gid_t gid,
struct group *grp, char **_buf, size_t *_buf_len);
int get_user_grouplist(const char *name, gid_t gid,
size_t *_ngroups, gid_t **_groups);
int pack_ber_sid(const char *sid, struct berval **berval);
int pack_ber_name(const char *domain_name, const char *name,
struct berval **berval);
@@ -213,6 +213,46 @@ void test_getgrgid_r_wrapper(void **state)
free(buf);
}
void test_get_user_grouplist(void **state)
{
int ret;
size_t ngroups;
gid_t *groups;
size_t c;
/* This is a bit odd behaviour of getgrouplist() it does not check if the
* user exists, only if memberships of the user can be found. */
ret = get_user_grouplist("non_exisiting_user", 23456, &ngroups, &groups);
assert_int_equal(ret, LDAP_SUCCESS);
assert_int_equal(ngroups, 1);
assert_int_equal(groups[0], 23456);
free(groups);
ret = get_user_grouplist("member0001", 23456, &ngroups, &groups);
assert_int_equal(ret, LDAP_SUCCESS);
assert_int_equal(ngroups, 3);
assert_int_equal(groups[0], 23456);
assert_int_equal(groups[1], 11111);
assert_int_equal(groups[2], 22222);
free(groups);
ret = get_user_grouplist("member0003", 23456, &ngroups, &groups);
assert_int_equal(ret, LDAP_SUCCESS);
assert_int_equal(ngroups, 2);
assert_int_equal(groups[0], 23456);
assert_int_equal(groups[1], 22222);
free(groups);
ret = get_user_grouplist("user_big", 23456, &ngroups, &groups);
assert_int_equal(ret, LDAP_SUCCESS);
assert_int_equal(ngroups, 1001);
assert_int_equal(groups[0], 23456);
for (c = 1; c < ngroups; c++) {
assert_int_equal(groups[c], 29999 + c);
}
free(groups);
}
struct test_data {
struct extdom_req *req;
struct ipa_extdom_ctx *ctx;
@@ -398,6 +438,7 @@ int main(int argc, const char *argv[])
unit_test(test_getpwuid_r_wrapper),
unit_test(test_getgrnam_r_wrapper),
unit_test(test_getgrgid_r_wrapper),
unit_test(test_get_user_grouplist),
unit_test_setup_teardown(test_set_err_msg,
extdom_req_setup, extdom_req_teardown),
unit_test_setup_teardown(test_encode,
@@ -400,8 +400,8 @@ int check_request(struct extdom_req *req, enum extdom_version version)
return LDAP_SUCCESS;
}
static int get_user_grouplist(const char *name, gid_t gid,
size_t *_ngroups, gid_t **_groups )
int get_user_grouplist(const char *name, gid_t gid,
size_t *_ngroups, gid_t **_groups)
{
int ret;
int ngroups;
File diff suppressed because it is too large. Load diff