From 9e8cc236bd3111b81289fe35187e6d8e5d843ea8 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 8 Feb 2023 10:17:05 +0100 Subject: [PATCH] python:tests: Make sure we do not run into issues with already existing users UNEXPECTED(failure): samba.tests.samba_tool.user.samba.tests.samba_tool.user.UserCmdTestCase.test_getpwent(ad_dc_ntvfs:local) REASON: Exception: Exception: Traceback (most recent call last): File "/builddir/build/BUILD/samba-4.18.0rc2/bin/python/samba/tests/samba_tool/user.py", line 1044, in test_getpwent self.assertCmdSuccess(result, out, err) File "/builddir/build/BUILD/samba-4.18.0rc2/bin/python/samba/tests/samba_tool/base.py", line 97, in assertCmdSuccess self.assertIsNone(exit, msg=msg.replace("\n]\n", "\n] \n")) AssertionError: -1 is not None : exit[-1] stdout[] stderr[ERROR(ldb): Failed to add user 'mockbuild': - LDAP error 68 LDAP_ENTRY_ALREADY_EXISTS - <00002071: samldb: samAccountName 'mockbuild' already in use!> <> ]: UNEXPECTED(failure): samba.tests.samba_tool.user.samba.tests.samba_tool.user.UserCmdTestCase.test_list(ad_dc_ntvfs:local) REASON: Exception: Exception: Traceback (most recent call last): File "/builddir/build/BUILD/samba-4.18.0rc2/bin/python/samba/tests/samba_tool/user.py", line 69, in setUp self.assertCmdSuccess(result, out, err) File "/builddir/build/BUILD/samba-4.18.0rc2/bin/python/samba/tests/samba_tool/base.py", line 97, in assertCmdSuccess self.assertIsNone(exit, msg=msg.replace("\n]\n", "\n] \n")) AssertionError: -1 is not None : exit[-1] stdout[] stderr[ERROR(ldb): Failed to add user 'sambatool1': - LDAP error 68 LDAP_ENTRY_ALREADY_EXISTS - <00002071: samldb: samAccountNa me 'sambatool1' already in use!> <> BUG: https://bugzilla.samba.org/show_bug.cgi?id=15308 Signed-off-by: Andreas Schneider Reviewed-by: Douglas Bagnall Reviewed-by: Andrew Bartlett (cherry picked from commit af27b1d37573d165983933d3789a18b12fad0272) --- python/samba/tests/samba_tool/user.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/python/samba/tests/samba_tool/user.py b/python/samba/tests/samba_tool/user.py index 700cb89c968..ffae45dd529 100644 --- a/python/samba/tests/samba_tool/user.py +++ b/python/samba/tests/samba_tool/user.py @@ -62,6 +62,11 @@ class UserCmdTestCase(SambaToolCmdTest): self.users.append(self._randomUnixUser({"name": "unixuser3"})) self.users.append(self._randomUnixUser({"name": "unixuser4"})) + # Make sure users don't exist + for user in self.users: + if self._find_user(user["name"]): + self.runsubcmd("user", "delete", user["name"]) + # setup the 12 users and ensure they are correct for user in self.users: (result, out, err) = user["createUserFn"](user) @@ -999,6 +1004,10 @@ sAMAccountName: %s "gecos": gecos, "loginShell": u[6], }) + + # Remove user if it already exists + if self._find_user(u[0]): + self.runsubcmd("user", "delete", u[0]) # check if --rfc2307-from-nss sets the same values as we got from pwd.getpwuid() (result, out, err) = self.runsubcmd("user", "create", user["name"], user["password"], "--surname=%s" % user["surname"], @@ -1023,6 +1032,10 @@ sAMAccountName: %s # # get a user with all random posix attributes user = self._randomPosixUser({"name": u[0]}) + + # Remove user if it already exists + if self._find_user(u[0]): + self.runsubcmd("user", "delete", u[0]) # create a user with posix attributes from nss but override all of them with the # random ones just obtained (result, out, err) = self.runsubcmd("user", "create", user["name"], user["password"], -- 2.11.4.GIT