]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
tests/: extend basic useradd test
authorIker Pedrosa <ipedrosa@redhat.com>
Mon, 10 Mar 2025 08:50:56 +0000 (09:50 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Wed, 21 May 2025 08:04:42 +0000 (10:04 +0200)
The test framework PoC only provided basic checks. I've added additional
functionality to the framework by checking shadow and gshadow entries
and I've extended the basic useradd test to check those too.

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

index 7effd61b1d13411bb4907122d30550c824e32618..e80f87668d77b73c59cf815058ecca930a8d3b8c 100644 (file)
@@ -6,6 +6,7 @@ from __future__ import annotations
 
 import pytest
 
+from framework.misc import days_since_epoch
 from framework.roles.shadow import Shadow
 from framework.topology import KnownTopology
 
@@ -17,27 +18,53 @@ def test_useradd__add_user(shadow: Shadow):
     :setup:
         1. Create user
     :steps:
-        1. User exists and UID is 1000
-        2. Group exists and GID is 1000
-        3. Home folder exists
+        1. Check passwd entry
+        2. Check shadow entry
+        3. Check group entry
+        4. Check gshadow entry
+        5. Check home folder
     :expectedresults:
-        1. User is found and UID matches
-        2. Group is found and GID matches
-        3. Home folder is found
+        1. passwd entry for the user exists and the attributes are correct
+        2. shadow entry for the user exists and the attributes are correct
+        3. group entry for the user exists and the attributes are correct
+        4. gshadow entry for the user exists and the attributes are correct
+        5. Home folder exists
     :customerscenario: False
     """
     shadow.useradd("tuser")
 
-    result = shadow.tools.id("tuser")
+    result = shadow.tools.getent.passwd("tuser")
     assert result is not None, "User should be found"
-    assert result.user.name == "tuser", "Incorrect username"
-    assert result.user.id == 1000, "Incorrect UID"
+    assert result.name == "tuser", "Incorrect username"
+    assert result.password == "x", "Incorrect password"
+    assert result.uid == 1000, "Incorrect UID"
+    assert result.gid == 1000, "Incorrect GID"
+    assert result.home == "/home/tuser", "Incorrect home"
+    if "Debian" in shadow.host.distro_name:
+        assert result.shell == "/bin/sh", "Incorrect shell"
+    else:
+        assert result.shell == "/bin/bash", "Incorrect shell"
+
+    result = shadow.tools.getent.shadow("tuser")
+    assert result is not None, "User should be found"
+    assert result.name == "tuser", "Incorrect username"
+    assert result.password == "!", "Incorrect password"
+    assert result.last_changed == days_since_epoch(), "Incorrect last changed"
+    assert result.min_days == 0, "Incorrect min days"
+    assert result.max_days == 99999, "Incorrect max days"
+    assert result.warn_days == 7, "Incorrect warn days"
 
     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"
 
+    if shadow.host.features["gshadow"]:
+        result = shadow.tools.getent.gshadow("tuser")
+        assert result is not None, "User should be found"
+        assert result.name == "tuser", "Incorrect username"
+        assert result.password == "!", "Incorrect password"
+
     assert shadow.fs.exists("/home/tuser"), "Home folder should be found"