From: Akshay Sakure Date: Mon, 6 Jul 2026 11:56:01 +0000 (+0530) Subject: Tests: Add group with existing GID using -o flag X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=c4174cab28ebbc0c9e2285a9929318f8a4e7aa79;p=thirdparty%2Fshadow.git Tests: Add group with existing GID using -o flag 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 --- diff --git a/tests/system/tests/test_groupadd.py b/tests/system/tests/test_groupadd.py index 8af256701..81729e4ae 100644 --- a/tests/system/tests/test_groupadd.py +++ b/tests/system/tests/test_groupadd.py @@ -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"