From: Iker Pedrosa Date: Tue, 9 Sep 2025 11:14:07 +0000 (+0200) Subject: tests/system/tests/test_chpasswd.py: change multiple user passwords from file X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=eb3456e450813ba51ad83af04f9230ecfbce5857;p=thirdparty%2Fshadow.git tests/system/tests/test_chpasswd.py: change multiple user passwords from file Signed-off-by: Iker Pedrosa --- diff --git a/tests/system/tests/test_chpasswd.py b/tests/system/tests/test_chpasswd.py index 3c5589c70..1c096234d 100644 --- a/tests/system/tests/test_chpasswd.py +++ b/tests/system/tests/test_chpasswd.py @@ -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"