]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Tests: Change user password
authoraborah-sudo <aborah@redhat.com>
Fri, 8 May 2026 08:31:53 +0000 (14:01 +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_change_password.test`
which checks that `usermod` can change user password

tests/system/tests/test_usermod.py

index e4f42d2a5a9bdc806192e38e9ece968ed9db0ad5..eda96cb07bedcec93519b985b4374c4d3478db79 100644 (file)
@@ -5,6 +5,7 @@ Test usermod
 from __future__ import annotations
 
 import pytest
+from passlib.hash import sha512_crypt
 from pytest_mh.conn import ProcessError
 
 from framework.roles.shadow import Shadow
@@ -206,3 +207,29 @@ def test_usermod__rename_user_in_group(shadow: Shadow):
     tgroup_group = shadow.tools.getent.group("tgroup")
     assert tgroup_group is not None, "tgroup group should exist"
     assert "tuser2" in tgroup_group.members, "User should be in tgroup group with new name"
+
+
+@pytest.mark.topology(KnownTopology.Shadow)
+def test_usermod__change_password(shadow: Shadow):
+    """
+    :title: Change user password
+    :setup:
+        1. Create user
+        2. Change password using usermod -p
+    :steps:
+        1. Check shadow entry has new password
+    :expectedresults:
+        1. Password is updated in shadow file
+    :customerscenario: False
+    """
+    shadow.useradd("tuser1")
+
+    password = "Secret123"
+    password_hash = sha512_crypt.hash(password)
+    shadow.usermod(f"-p '{password_hash}' 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("$6$"), "Password should be SHA-512 crypt hash"
+    assert shadow_entry.password == password_hash, "Password hash should match the generated hash"