From 21cb28b6f41eb65758b4ebd7002e2e06e8750c84 Mon Sep 17 00:00:00 2001 From: Akshay Sakure Date: Tue, 21 Jul 2026 18:59:00 +0530 Subject: [PATCH 1/2] Tests: Group creation fails when GID already exists This is Python transformation of the test located in `tests/grouptools/groupadd/20_groupadd_add_existing_GID/groupadd.test` which checks that `groupadd` fails to create group when GID already exists Signed-off-by: Akshay Sakure --- tests/system/tests/test_groupadd.py | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/system/tests/test_groupadd.py b/tests/system/tests/test_groupadd.py index e5a0faae54..562584dd3a 100644 --- a/tests/system/tests/test_groupadd.py +++ b/tests/system/tests/test_groupadd.py @@ -8,6 +8,7 @@ import pytest from passlib.hash import sha512_crypt +from pytest_mh.conn import ProcessError from framework.misc import shadow_password_pattern from framework.roles.shadow import Shadow @@ -150,3 +151,46 @@ def test_groupadd__force_group_creation(shadow: Shadow): gshadow_entry = shadow.tools.getent.gshadow("tgroup") assert gshadow_entry is not None, "Group should be found" assert gshadow_entry.name == "tgroup", "Incorrect groupname" + + +@pytest.mark.topology(KnownTopology.Shadow) +def test_groupadd__existing_GID(shadow: Shadow): + """ + :title: Group creation fails when specified GID already exists + :setup: + 1. Create group with specific GID + :steps: + 1. Check existing group and gshadow entry + 2. Attempt to create group with existing GID + 3. Verify that groupadd command fails + 4. Check group and gshadow entries + :expectedresults: + 1. Existing group and gshadow entries are found + 2. Group is not created + 3. groupadd command fails with error (GID already exists) + 4. No group or gshadow entries are found + :customerscenario: False + """ + shadow.groupadd("-g 1500 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 == 1500, "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" + + with pytest.raises(ProcessError) as exc_info: + shadow.groupadd("-g 1500 tgroup2") + + assert exc_info.value.rc == 4, f"Expected return code 4 (GID already exists), got {exc_info.value.rc}" + + group_entry = shadow.tools.getent.group("tgroup2") + assert group_entry is None, "Group should not be found" + + if shadow.host.features["gshadow"]: + gshadow_entry = shadow.tools.getent.gshadow("tgroup2") + assert gshadow_entry is None, "Group should not be found" From 55362c82112b905df6aa5e093d600359c4e4c696 Mon Sep 17 00:00:00 2001 From: Akshay Sakure Date: Tue, 21 Jul 2026 19:21:54 +0530 Subject: [PATCH 2/2] Tests: Group creation fails with invalid numeric GID 4294967295 This is Python transformation of the test located in `tests/grouptools/groupadd/21_groupadd_invalid_GID_4294967295/groupadd.test` which checks that `groupadd` fails to create group when invalid numeric GID 4294967295 is specified Signed-off-by: Akshay Sakure --- tests/system/tests/test_groupadd.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/system/tests/test_groupadd.py b/tests/system/tests/test_groupadd.py index 562584dd3a..1c36b53487 100644 --- a/tests/system/tests/test_groupadd.py +++ b/tests/system/tests/test_groupadd.py @@ -194,3 +194,32 @@ def test_groupadd__existing_GID(shadow: Shadow): if shadow.host.features["gshadow"]: gshadow_entry = shadow.tools.getent.gshadow("tgroup2") assert gshadow_entry is None, "Group should not be found" + + +@pytest.mark.topology(KnownTopology.Shadow) +def test_groupadd__invalid_GID_4294967295(shadow: Shadow): + """ + :title: Group creation fails when invalid numeric GID 4294967295 is specified + :setup: + 1. None required + :steps: + 1. Attempt to create group with invalid GID 4294967295 + 2. Verify that groupadd command fails + 3. Check group and gshadow entries + :expectedresults: + 1. Group is not created + 2. groupadd command fails with error (invalid group ID) + 3. No group or gshadow entries are found + :customerscenario: False + """ + with pytest.raises(ProcessError) as exc_info: + shadow.groupadd("-g 4294967295 tgroup") + + assert exc_info.value.rc == 3, f"Expected return code 3 (invalid group ID), got {exc_info.value.rc}" + + group_entry = shadow.tools.getent.group("tgroup") + assert group_entry is None, "Group should not be found" + + if shadow.host.features["gshadow"]: + gshadow_entry = shadow.tools.getent.gshadow("tgroup2") + assert gshadow_entry is None, "Group should not be found"