From b1f1b7aca525a0605ab84a8d29eb11a917e4e378 Mon Sep 17 00:00:00 2001 From: Akshay Sakure Date: Wed, 22 Jul 2026 22:50:03 +0530 Subject: [PATCH 1/3] Tests: Group creation succeeds when gshadow file doesn't exist This is Python transformation of the test located in `tests/grouptools/groupadd/25_groupadd_no_gshadow/groupadd.test` which checks that `groupadd` succeeds and creates group when /etc/gshadow file is not present 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 e5a0faae54..6ee672a455 100644 --- a/tests/system/tests/test_groupadd.py +++ b/tests/system/tests/test_groupadd.py @@ -150,3 +150,32 @@ 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__no_gshadow(shadow: Shadow): + """ + :title: Group creation succeeds when /etc/gshadow does not exist + :setup: + 1. Remove /etc/gshadow file + 2. Disable FORCE_SHADOW in /etc/login.defs + :steps: + 1. Create group + 2. Check group entry + 3. Check that /etc/gshadow file is not recreated + :expectedresults: + 1. Group entry is created + 2. Group entry is found + 3. /etc/gshadow file is not found + :customerscenario: False + """ + shadow.fs.rm("/etc/gshadow") + + shadow.login_defs["FORCE_SHADOW"] = "no" + + shadow.groupadd("tgroup") + + group_entry = shadow.tools.getent.group("tgroup") + assert group_entry is not None, "Group should be found" + assert group_entry.name == "tgroup", "Incorrect groupname" + assert not shadow.fs.exists("/etc/gshadow"), "/etc/gshadow file should not exist" From cb7b6a72e557c0fd2464670c37e3f74b96fdaf43 Mon Sep 17 00:00:00 2001 From: Akshay Sakure Date: Wed, 22 Jul 2026 23:03:38 +0530 Subject: [PATCH 2/3] Tests: Group creation fails when -o option mentioned without -g This is Python transformation of the test located in `tests/grouptools/groupadd/26_groupadd_-o_without_-g/groupadd.test` which checks that `groupadd` fails to create group when -o option is mentioned without -g option Signed-off-by: Akshay Sakure --- tests/system/tests/test_groupadd.py | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/system/tests/test_groupadd.py b/tests/system/tests/test_groupadd.py index 6ee672a455..3b50b76e14 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 @@ -179,3 +180,32 @@ def test_groupadd__no_gshadow(shadow: Shadow): assert group_entry is not None, "Group should be found" assert group_entry.name == "tgroup", "Incorrect groupname" assert not shadow.fs.exists("/etc/gshadow"), "/etc/gshadow file should not exist" + + +@pytest.mark.topology(KnownTopology.Shadow) +def test_groupadd__o_without_g(shadow: Shadow): + """ + :title: Groupadd command fails when -o is mentioned without -g + :setup: + 1. None required + :steps: + 1. Attempt to create group + 2. Verify that groupadd command fails + 3. Check group and gshadow entries + :expectedresults: + 1. Group entry is not created + 2. groupadd command fails with error (invalid usage) + 3. No group or gshadow entries are found + :customerscenario: False + """ + with pytest.raises(ProcessError) as exc_info: + shadow.groupadd("-o tgroup") + + assert exc_info.value.rc == 2, f"Expected return code 2 (invalid usage), 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 159959b0ea5c25c9603962bb6fada5fe82b396e2 Mon Sep 17 00:00:00 2001 From: Akshay Sakure Date: Wed, 22 Jul 2026 23:17:07 +0530 Subject: [PATCH 3/3] Tests: Group creation fails with invalid option This is Python transformation of the test located in `tests/grouptools/groupadd/27_groupadd_invalid_option/groupadd.test` which checks that `groupadd` command fails when invalid option is mentioned 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 3b50b76e14..c7e2b090c0 100644 --- a/tests/system/tests/test_groupadd.py +++ b/tests/system/tests/test_groupadd.py @@ -209,3 +209,32 @@ def test_groupadd__o_without_g(shadow: Shadow): 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_option(shadow: Shadow): + """ + :title: Group creation fails with invalid option + :setup: + 1. None required + :steps: + 1. Attempt to create group + 2. Verify that groupadd command fails + 3. Check group and gshadow entries + :expectedresults: + 1. Group entry is not created + 2. groupadd command fails with error (invalid usage) + 3. No group or gshadow entries are found + :customerscenario: False + """ + with pytest.raises(ProcessError) as exc_info: + shadow.groupadd("-invalid tgroup") + + assert exc_info.value.rc == 2, f"Expected return code 2 (invalid usage), 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"