]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
tests/system/tests/test_chpasswd.py: change multiple user passwords from file
authorIker Pedrosa <ipedrosa@redhat.com>
Tue, 9 Sep 2025 11:14:07 +0000 (13:14 +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_chpasswd.py

index 3c5589c70af4fcc16d516c7f7db1f216793400fa..1c096234daf1c4634c815d18055f304c48bff507 100644 (file)
@@ -52,3 +52,46 @@ def test_chpasswd__change_passwords_interactive(shadow: Shadow):
     assert shadow_entry2.min_days == 0, "Incorrect min days"
     assert shadow_entry2.max_days == 99999, "Incorrect max days"
     assert shadow_entry2.warn_days == 7, "Incorrect warn days"
+
+
+@pytest.mark.topology(KnownTopology.Shadow)
+def test_chpasswd__change_passwords_from_file(shadow: Shadow):
+    """
+    :title: Change multiple user passwords from file
+    :setup:
+        1. Create test users and password file
+    :steps:
+        1. Change user passwords using chpasswd from file
+        2. Check the users' shadow entries
+    :expectedresults:
+        1. Users' passwords are changed
+        2. Users' shadow entries are correct
+    :customerscenario: False
+    """
+    shadow.useradd("tuser1")
+    shadow.useradd("tuser2")
+
+    temp_file = "/tmp/test_chpasswd_data.txt"
+    passwords_data = "tuser1:Secret123\ntuser2:Secret456"
+    shadow.fs.write(temp_file, passwords_data)
+    shadow.chpasswd(file=temp_file)
+
+    shadow_entry1 = shadow.tools.getent.shadow("tuser1")
+    assert shadow_entry1 is not None, "tuser1 should be found"
+    assert shadow_entry1.name == "tuser1", "Incorrect username"
+    assert shadow_entry1.password is not None, "Password should not be None"
+    assert re.match(shadow_password_pattern(), shadow_entry1.password), "Incorrect password"
+    assert shadow_entry1.last_changed == days_since_epoch(), "Incorrect last changed"
+    assert shadow_entry1.min_days == 0, "Incorrect min days"
+    assert shadow_entry1.max_days == 99999, "Incorrect max days"
+    assert shadow_entry1.warn_days == 7, "Incorrect warn days"
+
+    shadow_entry2 = shadow.tools.getent.shadow("tuser2")
+    assert shadow_entry2 is not None, "tuser2 should be found"
+    assert shadow_entry2.name == "tuser2", "Incorrect username"
+    assert shadow_entry2.password is not None, "Password should not be None"
+    assert re.match(shadow_password_pattern(), shadow_entry2.password), "Incorrect password"
+    assert shadow_entry2.last_changed == days_since_epoch(), "Incorrect last changed"
+    assert shadow_entry2.min_days == 0, "Incorrect min days"
+    assert shadow_entry2.max_days == 99999, "Incorrect max days"
+    assert shadow_entry2.warn_days == 7, "Incorrect warn days"