]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Tests: Unlock user password master
authoraborah-sudo <aborah@redhat.com>
Tue, 12 May 2026 02:05:26 +0000 (07:35 +0530)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Tue, 12 May 2026 07:24:17 +0000 (09:24 +0200)
This is the transformation to Python of the test located in
`tests/usertools/01/11_usermod_lock_password.test`
which checks that `usermod` can lock user password

tests/system/tests/test_usermod.py

index eda96cb07bedcec93519b985b4374c4d3478db79..4459dbb01d8f60f10f4cd8cf9a2ab6005076814f 100644 (file)
@@ -233,3 +233,44 @@ def test_usermod__change_password(shadow: Shadow):
     assert shadow_entry.password is not None, "Password should not be None"
     assert shadow_entry.password.startswith("$6$"), "Password should be SHA-512 crypt hash"
     assert shadow_entry.password == password_hash, "Password hash should match the generated hash"
+
+
+@pytest.mark.topology(KnownTopology.Shadow)
+def test_usermod__unlock_password(shadow: Shadow):
+    """
+    :title: Unlock user password
+    :setup:
+        1. Create user
+        2. Set password
+    :steps:
+        1. Lock password with usermod -L
+        2. Check shadow entry has locked password
+        3. Unlock password with usermod -U
+        4. Check shadow entry has unlocked password
+    :expectedresults:
+        1. Password is locked
+        2. Password has ! prefix when locked
+        3. Password is unlocked
+        4. Password no longer has ! prefix
+    :customerscenario: False
+    """
+    shadow.useradd("tuser1")
+
+    password = "Secret123"
+    password_hash = sha512_crypt.hash(password)
+
+    shadow.usermod(f"-p '{password_hash}' tuser1")
+    shadow.usermod("-L tuser1")
+
+    shadow_entry = shadow.tools.getent.shadow("tuser1")
+    assert shadow_entry is not None, "User should be found"
+    assert shadow_entry.password is not None, "Password should not be None"
+    assert shadow_entry.password.startswith("!"), "Password should be locked with ! prefix"
+    assert shadow_entry.password == f"!{password_hash}", "Password should have ! prefix when locked"
+
+    shadow.usermod("-U tuser1")
+
+    shadow_entry = shadow.tools.getent.shadow("tuser1")
+    assert shadow_entry is not None, "User should be found"
+    assert shadow_entry.password is not None, "Password should not be None"
+    assert shadow_entry.password == password_hash, "Password should be unlocked"