]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
tests/system/tests/test_passwd.py: change user password as root in interactive mode
authorIker Pedrosa <ipedrosa@redhat.com>
Tue, 9 Sep 2025 07:23:30 +0000 (09:23 +0200)
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/18_passwd_root_change_password_user/passwd.test`,
which checks that `passwd` is able to change a user's password running
as root in interactive mode.

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

index cdb2bd9d162662c5a550a05a0fef0a67ed8864eb..a946aa816d1bf2407ac41a5d42fc57075703ac9d 100644 (file)
@@ -40,3 +40,32 @@ def test_passwd__change_password_as_root_with_stdin(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__change_password_as_root_interactive(shadow: Shadow):
+    """
+    :title: Change user password as root in interactive mode
+    :setup:
+        1. Create test user
+    :steps:
+        1. Change user password as root in interactive mode
+        2. Check the user's shadow entry
+    :expectedresults:
+        1. User's password is changed
+        2. User's shadow entry is correct
+    :customerscenario: False
+    """
+    shadow.useradd("tuser")
+
+    shadow.passwd("tuser", new_password="Secret123")
+
+    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 re.match(shadow_password_pattern(), shadow_entry.password), "Incorrect password"
+    assert shadow_entry.last_changed == days_since_epoch(), "Incorrect last changed"
+    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"