]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Tests: Add group with existing GID using -o flag
authorAkshay Sakure <asakure@redhat.com>
Mon, 6 Jul 2026 11:56:01 +0000 (17:26 +0530)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Wed, 29 Jul 2026 16:19:16 +0000 (18:19 +0200)
This is Python transformation of the test located in
'tests/grouptools/groupadd/10_groupadd_-o_add_existing_GID/groupadd.test'
which can create group with existing (non-unique) GID using -o flag

Signed-off-by: Akshay Sakure <asakure@redhat.com>
tests/system/tests/test_groupadd.py

index 8af2567010f30c09f9d872db561eba16594cb6d6..81729e4aee0cb50de2f1b1668bdf64a2dfe2545a 100644 (file)
@@ -191,3 +191,44 @@ def test_groupadd__force_group_creation_with_existing_gid(shadow: Shadow):
         gshadow_entry = shadow.tools.getent.gshadow("tgroup2")
         assert gshadow_entry is not None, "Group should be found"
         assert gshadow_entry.name == "tgroup2", "Incorrect groupname"
+
+
+@pytest.mark.topology(KnownTopology.Shadow)
+def test_groupadd__create_group_with_existing_gid(shadow: Shadow):
+    """
+    :title: Create group with existing GID using -o flag
+    :setup:
+        1. Create group with specific GID
+    :steps:
+        1. Check existing group and gshadow entry
+        2. Create new group with existing GID
+        3. Check new group and gshadow entry
+    :expectedresults:
+        1. Group entry is found with specific GID along with gshadow entry
+        2. groupadd command completes successfully
+        3. Group entry is created with existing GID along with gshadow entry
+    :customerscenario: False
+    """
+    shadow.groupadd("-g 1001 tgroup1")
+
+    existing_group_entry = shadow.tools.getent.group("tgroup1")
+    assert existing_group_entry is not None, "Group should be found"
+    assert existing_group_entry.name == "tgroup1", "Incorrect groupname"
+    assert existing_group_entry.gid == 1001, "Incorrect GID"
+
+    if shadow.host.features["gshadow"]:
+        existing_gshadow_entry = shadow.tools.getent.gshadow("tgroup1")
+        assert existing_gshadow_entry is not None, "Group should be found"
+        assert existing_gshadow_entry.name == "tgroup1", "Incorrect groupname"
+
+    shadow.groupadd("-g 1001 -o tgroup2")
+
+    group_entry = shadow.tools.getent.group("tgroup2")
+    assert group_entry is not None, "Group should be found"
+    assert group_entry.name == "tgroup2", "Incorrect groupname"
+    assert group_entry.gid == 1001, "Group should have duplicate GID"
+
+    if shadow.host.features["gshadow"]:
+        gshadow_entry = shadow.tools.getent.gshadow("tgroup2")
+        assert gshadow_entry is not None, "Group should be found"
+        assert gshadow_entry.name == "tgroup2", "Incorrect groupname"