]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
tests: recreate deleted user
authorIker Pedrosa <ipedrosa@redhat.com>
Wed, 20 Nov 2024 13:58:54 +0000 (14:58 +0100)
committerSerge Hallyn <serge@hallyn.com>
Sat, 11 Jan 2025 02:21:07 +0000 (20:21 -0600)
This is the transformation to Python of the test located in
`tests/usertools/01/02_useradd_recreate_deleted_user.test`, which checks
that `useradd` is able to create again a removed user.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
tests/system/tests/test_useradd.py

index a3748fe47c8be8d1a2b32c0821b7fe82833b8fa4..7effd61b1d13411bb4907122d30550c824e32618 100644 (file)
@@ -39,3 +39,38 @@ def test_useradd__add_user(shadow: Shadow):
     assert result.gid == 1000, "Incorrect GID"
 
     assert shadow.fs.exists("/home/tuser"), "Home folder should be found"
+
+
+@pytest.mark.topology(KnownTopology.Shadow)
+def test_useradd__recreate_deleted_user(shadow: Shadow):
+    """
+    :title: Recreate deleted user
+    :setup:
+        1. Create user
+        2. Delete the user
+        3. Create again the deleted user
+    :steps:
+        1. User exists and UID is 1000
+        2. Group exists and GID is 1000
+        3. Home folder exists
+    :expectedresults:
+        1. User is found and UID matches
+        2. Group is found and GID matches
+        3. Home folder is found
+    :customerscenario: False
+    """
+    shadow.useradd("tuser")
+    shadow.userdel("tuser")
+    shadow.useradd("tuser")
+
+    result = shadow.tools.id("tuser")
+    assert result is not None, "User should be found"
+    assert result.user.name == "tuser", "Incorrect username"
+    assert result.user.id == 1000, "Incorrect UID"
+
+    result = shadow.tools.getent.group("tuser")
+    assert result is not None, "Group should be found"
+    assert result.name == "tuser", "Incorrect groupname"
+    assert result.gid == 1000, "Incorrect GID"
+
+    assert shadow.fs.exists("/home/tuser"), "Home folder should be found"