]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
tests/system/tests/test_passwd.py: lock user password
authorIker Pedrosa <ipedrosa@redhat.com>
Mon, 23 Feb 2026 13:35:28 +0000 (14:35 +0100)
committerSerge Hallyn <serge@hallyn.com>
Wed, 25 Mar 2026 02:33:15 +0000 (21:33 -0500)
This is the transformation to Python of the test located in
`tests/passwd/06_passwd_-l_root_lock_account/passwd.test`,
which checks that `passwd` is able to lock a user's password.

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

index a946aa816d1bf2407ac41a5d42fc57075703ac9d..d01353c403c2cb2b1c9f8c9093e5e3b3bc111316 100644 (file)
@@ -69,3 +69,28 @@ def test_passwd__change_password_as_root_interactive(shadow: Shadow):
     assert shadow_entry.min_days == 0, "Incorrect min days"
     assert shadow_entry.max_days == 99999, "Incorrect max days"
     assert shadow_entry.warn_days == 7, "Incorrect warn days"
+
+
+@pytest.mark.topology(KnownTopology.Shadow)
+def test_passwd__lock_password(shadow: Shadow):
+    """
+    :title: Lock user password
+    :setup:
+        1. Create test user
+    :steps:
+        1. Lock user password using -l flag
+        2. Check the user's shadow entry
+    :expectedresults:
+        1. User's password is locked
+        2. User's shadow entry shows locked password (starts with !)
+    :customerscenario: False
+    """
+    shadow.useradd("tuser")
+
+    shadow.passwd("-l tuser")
+
+    shadow_entry = shadow.tools.getent.shadow("tuser")
+    assert shadow_entry is not None, "User should be found"
+    assert shadow_entry.name == "tuser", "Incorrect username"
+    assert shadow_entry.password is not None, "Password should not be None"
+    assert shadow_entry.password.startswith("!"), "Password should be locked"