]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Tests: Rename user who is member of a group
authoraborah-sudo <aborah@redhat.com>
Fri, 8 May 2026 08:27:59 +0000 (13:57 +0530)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Tue, 12 May 2026 07:24:17 +0000 (09:24 +0200)
This is the transformation to Python of the test located in
`tests/usertools/01/10_usermod_rename_user_in_group.test`
which checks that `usermod` can rename user who is member of a group

tests/system/tests/test_usermod.py

index 8378ef11373367759496d4aa6969707c5bdaca9a..e4f42d2a5a9bdc806192e38e9ece968ed9db0ad5 100644 (file)
@@ -171,3 +171,38 @@ def test_usermod__set_expire_date_with_empty_date(shadow: Shadow, expiration_dat
     assert result is not None, "User should be found"
     assert result.name == "tuser1", "Incorrect username"
     assert result.expiration_date is None, "Expiration date should be empty"
+
+
+@pytest.mark.topology(KnownTopology.Shadow)
+def test_usermod__rename_user_in_group(shadow: Shadow):
+    """
+    :title: Rename user who is member of a group
+    :setup:
+        1. Create group
+        2. Create user with additional group membership
+        3. Rename user
+    :steps:
+        1. Check passwd entry
+        2. Check group entry for user's primary group
+        3. Check group entry for secondary group membership
+    :expectedresults:
+        1. Passwd entry for renamed user exists
+        2. User's primary group still exists with old name
+        3. User is member of group with new name
+    :customerscenario: False
+    """
+    shadow.groupadd("tgroup")
+    shadow.useradd("-G tgroup tuser1")
+    shadow.usermod("-l tuser2 tuser1")
+
+    passwd_entry = shadow.tools.getent.passwd("tuser2")
+    assert passwd_entry is not None, "User should be found"
+    assert passwd_entry.name == "tuser2", "Incorrect username"
+
+    group_entry = shadow.tools.getent.group("tuser1")
+    assert group_entry is not None, "Primary group should still exist"
+    assert group_entry.name == "tuser1", "Primary group should keep old name"
+
+    tgroup_group = shadow.tools.getent.group("tgroup")
+    assert tgroup_group is not None, "tgroup group should exist"
+    assert "tuser2" in tgroup_group.members, "User should be in tgroup group with new name"