From a85d86129a8ff4e0ca5874fe9a858a81d5627043 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 9 Mar 2012 14:32:55 +0100 Subject: s4:selftest: add a new test for "samba-tool user list" --- .../python/samba/tests/samba_tool/user.py | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'source4/scripting') diff --git a/source4/scripting/python/samba/tests/samba_tool/user.py b/source4/scripting/python/samba/tests/samba_tool/user.py index 3e00ed3cf4..3861a001df 100644 --- a/source4/scripting/python/samba/tests/samba_tool/user.py +++ b/source4/scripting/python/samba/tests/samba_tool/user.py @@ -19,7 +19,10 @@ import os import time import ldb from samba.tests.samba_tool.base import SambaToolCmdTest -from samba import nttime2unix +from samba import ( + nttime2unix, + dsdb + ) class UserCmdTestCase(SambaToolCmdTest): """Tests for samba-tool user subcommands""" @@ -174,6 +177,29 @@ class UserCmdTestCase(SambaToolCmdTest): self.assertWithin(expires, twodays, 5, "Ensure account expires is within 5 seconds of the expected time") + def test_list(self): + (result, out, err) = self.runsubcmd("user", "list", + "-H", "ldap://%s" % os.environ["DC_SERVER"], + "-U%s%%%s" % (os.environ["DC_USERNAME"], + os.environ["DC_PASSWORD"])) + self.assertCmdSuccess(result, "Error runing list") + + search_filter = ("(&(objectClass=user)(userAccountControl:%s:=%u))" % + (ldb.OID_COMPARATOR_AND, dsdb.UF_NORMAL_ACCOUNT)) + + userlist = self.samdb.search(base=self.samdb.domain_dn(), + scope=ldb.SCOPE_SUBTREE, + expression=search_filter, + attrs=["samaccountname"]) + + self.assertTrue(len(userlist) > 0, "no users found in samdb") + + for userobj in userlist: + name = userobj.get("samaccountname", idx=0) + found = self.assertMatch(out, name, + "user '%s' not found" % name) + + def _randomUser(self, base={}): """create a user with random attribute values, you can specify base attributes""" user = { -- cgit