From d1c3bf3d010a8833446378fd6d4d511ee6cdb453 Mon Sep 17 00:00:00 2001 From: Iker Pedrosa Date: Wed, 20 Nov 2024 14:58:54 +0100 Subject: [PATCH] tests: recreate deleted user 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 --- tests/system/tests/test_useradd.py | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/system/tests/test_useradd.py b/tests/system/tests/test_useradd.py index a3748fe47..7effd61b1 100644 --- a/tests/system/tests/test_useradd.py +++ b/tests/system/tests/test_useradd.py @@ -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" -- 2.47.3