]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
tests/system/tests/test_passwd.py: change user password as root using stdin
authorIker Pedrosa <ipedrosa@redhat.com>
Mon, 8 Sep 2025 09:10:05 +0000 (11:10 +0200)
committerSerge Hallyn <serge@hallyn.com>
Wed, 25 Mar 2026 02:33:15 +0000 (21:33 -0500)
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
tests/system/tests/test_passwd.py [new file with mode: 0644]

diff --git a/tests/system/tests/test_passwd.py b/tests/system/tests/test_passwd.py
new file mode 100644 (file)
index 0000000..cdb2bd9
--- /dev/null
@@ -0,0 +1,42 @@
+"""
+Test passwd
+"""
+
+from __future__ import annotations
+
+import re
+
+import pytest
+
+from framework.misc import days_since_epoch, shadow_password_pattern
+from framework.roles.shadow import Shadow
+from framework.topology import KnownTopology
+
+
+@pytest.mark.topology(KnownTopology.Shadow)
+def test_passwd__change_password_as_root_with_stdin(shadow: Shadow):
+    """
+    :title: Change user password as root using stdin
+    :setup:
+        1. Create test user
+    :steps:
+        1. Change user password as root using --stdin flag
+        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("--stdin 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"