]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
tests/system/tests/test_chgpasswd.py: change multiple group passwords interactive
authorIker Pedrosa <ipedrosa@redhat.com>
Wed, 10 Sep 2025 14:57:41 +0000 (16:57 +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/grouptools/chgpasswd/02_chgpasswd_multiple_groups/chgpasswd.test`,
which checks that `chgpasswd` is able to change the password of multiple
groups in batch.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
tests/system/tests/test_chgpasswd.py [new file with mode: 0644]

diff --git a/tests/system/tests/test_chgpasswd.py b/tests/system/tests/test_chgpasswd.py
new file mode 100644 (file)
index 0000000..29a13df
--- /dev/null
@@ -0,0 +1,47 @@
+"""
+Test chgpasswd
+"""
+
+from __future__ import annotations
+
+import re
+
+import pytest
+
+from framework.misc import shadow_password_pattern
+from framework.roles.shadow import Shadow
+from framework.topology import KnownTopology
+
+
+@pytest.mark.topology(KnownTopology.Shadow)
+@pytest.mark.builtwith(shadow="gshadow")
+def test_chgpasswd__change_passwords_interactive(shadow: Shadow):
+    """
+    :title: Change multiple group passwords interactive
+    :setup:
+        1. Create test groups
+    :steps:
+        1. Change group passwords using chgpasswd interactively
+        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")
+
+    passwords_data = "tgroup1:Secret123\ntgroup2:Secret456"
+    shadow.chgpasswd(passwords_data=passwords_data)
+
+    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"