]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
tests/system/tests/test_chgpasswd.py: change multiple group passwords from file
authorIker Pedrosa <ipedrosa@redhat.com>
Thu, 11 Sep 2025 07:11:41 +0000 (09:11 +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_chgpasswd.py

index 29a13df3d3cb8f00577f4226810bd2e3538eb787..b96baf03fb025bc49ffe42af1c27cadb67f08b65 100644 (file)
@@ -45,3 +45,39 @@ def test_chgpasswd__change_passwords_interactive(shadow: Shadow):
     assert gshadow_entry2.name == "tgroup2", "Incorrect groupname"
     assert gshadow_entry2.password is not None, "Password should not be None"
     assert re.match(shadow_password_pattern(), gshadow_entry2.password), "Incorrect password"
+
+
+@pytest.mark.topology(KnownTopology.Shadow)
+@pytest.mark.builtwith(shadow="gshadow")
+def test_chgpasswd__change_passwords_from_file(shadow: Shadow):
+    """
+    :title: Change multiple group passwords from file
+    :setup:
+        1. Create test groups and password file
+    :steps:
+        1. Change group passwords using chgpasswd from file
+        2. Check the groups' gshadow entries
+    :expectedresults:
+        1. Groups' passwords are changed
+        2. Groups' gshadow entries are correct
+    :customerscenario: False
+    """
+    shadow.groupadd("tgroup1")
+    shadow.groupadd("tgroup2")
+
+    temp_file = "/tmp/test_chgpasswd_data.txt"
+    passwords_data = "tgroup1:Secret123\ntgroup2:Secret456\n"
+    shadow.fs.write(temp_file, passwords_data, dedent=False)
+    shadow.chgpasswd(file=temp_file)
+
+    gshadow_entry1 = shadow.tools.getent.gshadow("tgroup1")
+    assert gshadow_entry1 is not None, "tgroup1 should be found"
+    assert gshadow_entry1.name == "tgroup1", "Incorrect groupname"
+    assert gshadow_entry1.password is not None, "Password should not be None"
+    assert re.match(shadow_password_pattern(), gshadow_entry1.password), "Incorrect password"
+
+    gshadow_entry2 = shadow.tools.getent.gshadow("tgroup2")
+    assert gshadow_entry2 is not None, "tgroup2 should be found"
+    assert gshadow_entry2.name == "tgroup2", "Incorrect groupname"
+    assert gshadow_entry2.password is not None, "Password should not be None"
+    assert re.match(shadow_password_pattern(), gshadow_entry2.password), "Incorrect password"