diff options
author | Tim Beale <timbeale@catalyst.net.nz> | 2018-11-27 11:51:51 +1300 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2018-12-04 09:17:17 +0100 |
commit | d662c411e12fe9a81cdb2504af2a81d1d7b8c092 (patch) | |
tree | c833917d8346e2a26d508039a58577f5b353831b /python | |
parent | b0af029504d0c8bee6d7a1976356e4ac19a52c91 (diff) | |
download | samba-d662c411e12fe9a81cdb2504af2a81d1d7b8c092.tar.gz |
tests: Add test-case for 'group list --verbose'
Check that the number of members reported is correct.
(This change somehow got left off the ca570bd4827aa commit that was
actually delivered).
Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'python')
-rw-r--r-- | python/samba/tests/samba_tool/group.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/python/samba/tests/samba_tool/group.py b/python/samba/tests/samba_tool/group.py index bb701e91262..9862251ff01 100644 --- a/python/samba/tests/samba_tool/group.py +++ b/python/samba/tests/samba_tool/group.py @@ -117,6 +117,47 @@ class GroupCmdTestCase(SambaToolCmdTest): found = self.assertMatch(out, name, "group '%s' not found" % name) + def test_list_verbose(self): + (result, out, err) = self.runsubcmd("group", "list", "--verbose", + "-H", "ldap://%s" % os.environ["DC_SERVER"], + "-U%s%%%s" % (os.environ["DC_USERNAME"], + os.environ["DC_PASSWORD"])) + self.assertCmdSuccess(result, out, err, "Error running list --verbose") + + # use the output to build a dictionary, where key=group-name, + # value=num-members + output_memberships = {} + + # split the output by line, skipping the first 2 header lines + group_lines = out.split('\n')[2:-1] + for line in group_lines: + # split line by column whitespace (but keep the group name together + # if it contains spaces) + values = line.split(" ") + name = values[0] + num_members = int(values[-1]) + output_memberships[name] = num_members + + # build up a similar dict using an LDAP search + search_filter = "(objectClass=group)" + grouplist = self.samdb.search(base=self.samdb.domain_dn(), + scope=ldb.SCOPE_SUBTREE, + expression=search_filter, + attrs=["samaccountname", "member"]) + self.assertTrue(len(grouplist) > 0, "no groups found in samdb") + + ldap_memberships = {} + for groupobj in grouplist: + name = str(groupobj.get("samaccountname", idx=0)) + num_members = len(groupobj.get("member", default=[])) + ldap_memberships[name] = num_members + + # check the command output matches LDAP + self.assertTrue(output_memberships == ldap_memberships, + "Command output doesn't match LDAP results.\n" + + "Command='%s'\nLDAP='%s'" %(output_memberships, + ldap_memberships)) + def test_listmembers(self): (result, out, err) = self.runsubcmd("group", "listmembers", "Domain Users", "-H", "ldap://%s" % os.environ["DC_SERVER"], |