From 0d6216a6bda51d4fe2f9cc65461acb8853a9d0e6 Mon Sep 17 00:00:00 2001 From: Akshay Sakure Date: Fri, 17 Jul 2026 19:33:57 +0530 Subject: [PATCH 1/3] Tests: Group creation using -K option with invalid key fails This is Python transformation of the test located in `tests/grouptools/groupadd/14_groupadd_invalid_-K_option/groupadd.test` which checks if `groupadd` fails to create group when invalid key is is mentioned with -K option 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 71c7b0e22b..5bcff19150 100644 --- a/tests/system/tests/test_groupadd.py +++ b/tests/system/tests/test_groupadd.py @@ -340,3 +340,32 @@ def test_groupadd__locked_file(shadow: Shadow, lock_file: str): if shadow.host.features["gshadow"]: gshadow_entry = shadow.tools.getent.gshadow("tgroup") assert gshadow_entry is None, "Group should not be found" + + +@pytest.mark.topology(KnownTopology.Shadow) +def test_groupadd__invalid_key(shadow: Shadow): + """ + :title: Group creation with invalid key fails + :setup: + 1. None required + :steps: + 1. Create group with invalid key + 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 argument) + 3. No group or gshadow entries are found + :customerscenario: False + """ + with pytest.raises(ProcessError) as exc_info: + shadow.groupadd("-K KEY=100 tgroup") + + assert exc_info.value.rc == 3, f"Expected return code 3 (invalid argument), 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("tgroup") + assert gshadow_entry is None, "Group should not be found" From a50ad90b1f430ba212cb17b8f13c3dfff2c6c8f2 Mon Sep 17 00:00:00 2001 From: Akshay Sakure Date: Fri, 17 Jul 2026 19:40:16 +0530 Subject: [PATCH 2/3] Tests: Group creation fails when -K argument is missing the equals sign This is Python transformation of the test located in `tests/grouptools/groupadd/15_groupadd_invalid_-K_no_=/groupadd.test` which checks if `groupadd` fails to create group with -K option when argument is missing the equals(=) sign Signed-off-by: Akshay Sakure --- tests/system/tests/test_groupadd.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/system/tests/test_groupadd.py b/tests/system/tests/test_groupadd.py index 5bcff19150..cab0908c9a 100644 --- a/tests/system/tests/test_groupadd.py +++ b/tests/system/tests/test_groupadd.py @@ -343,7 +343,14 @@ def test_groupadd__locked_file(shadow: Shadow, lock_file: str): @pytest.mark.topology(KnownTopology.Shadow) -def test_groupadd__invalid_key(shadow: Shadow): +@pytest.mark.parametrize( + "key", + [ + pytest.param("KEY=100", id="invalid_key"), + pytest.param("GID_MAX", id="no_equals_sign"), + ], +) +def test_groupadd__invalid_key(shadow: Shadow, key: str): """ :title: Group creation with invalid key fails :setup: @@ -359,7 +366,7 @@ def test_groupadd__invalid_key(shadow: Shadow): :customerscenario: False """ with pytest.raises(ProcessError) as exc_info: - shadow.groupadd("-K KEY=100 tgroup") + shadow.groupadd(f"-K {key} tgroup") assert exc_info.value.rc == 3, f"Expected return code 3 (invalid argument), got {exc_info.value.rc}" From a7052298edbf7f8ff188e8f6365e209fb43a755d Mon Sep 17 00:00:00 2001 From: Akshay Sakure Date: Fri, 17 Jul 2026 19:45:39 +0530 Subject: [PATCH 3/3] Tests: Group creation fails when group already exists This is Python transformation of the test located in `tests/grouptools/groupadd/16_groupadd_existing_group/groupadd.test` which checks that `groupadd` fails to create group when group 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 cab0908c9a..0cdd984393 100644 --- a/tests/system/tests/test_groupadd.py +++ b/tests/system/tests/test_groupadd.py @@ -376,3 +376,47 @@ def test_groupadd__invalid_key(shadow: Shadow, key: str): if shadow.host.features["gshadow"]: gshadow_entry = shadow.tools.getent.gshadow("tgroup") assert gshadow_entry is None, "Group should not be found" + + +@pytest.mark.topology(KnownTopology.Shadow) +def test_groupadd__existing_group(shadow: Shadow): + """ + :title: Group creation fails when group already exists + :setup: + 1. Create group + :steps: + 1. Check existing group and gshadow entries + 2. Attempt to create group + 3. Verify that groupadd command fails + 4. Check existing group and gshadow entries + :expectedresults: + 1. Existing group and gshadow entries are found + 2. Group is not created + 3. groupadd command fails with error (group already exists) + 4. Existing group and gshadow entries are still found + :customerscenario: False + """ + shadow.groupadd("tgroup") + + existing_group_entry = shadow.tools.getent.group("tgroup") + assert existing_group_entry is not None, "Group should be found" + assert existing_group_entry.name == "tgroup", "Incorrect groupname" + + if shadow.host.features["gshadow"]: + existing_gshadow_entry = shadow.tools.getent.gshadow("tgroup") + assert existing_gshadow_entry is not None, "Group should be found" + assert existing_gshadow_entry.name == "tgroup", "Incorrect groupname" + + with pytest.raises(ProcessError) as exc_info: + shadow.groupadd("tgroup") + + assert exc_info.value.rc == 9, f"Expected return code 9 (group already exists), got {exc_info.value.rc}" + + existing_group_entry = shadow.tools.getent.group("tgroup") + assert existing_group_entry is not None, "Group should be found" + assert existing_group_entry.name == "tgroup", "Incorrect groupname" + + if shadow.host.features["gshadow"]: + existing_gshadow_entry = shadow.tools.getent.gshadow("tgroup") + assert existing_gshadow_entry is not None, "Group should be found" + assert existing_gshadow_entry.name == "tgroup", "Incorrect groupname"