From 68acfaaf09fbd79aeb92e5aa07f10cd372806738 Mon Sep 17 00:00:00 2001 From: Akshay Sakure Date: Fri, 17 Jul 2026 18:44:52 +0530 Subject: [PATCH 1/2] Tests: Group creation fails when /etc/group is locked This is Python transformation of the test located in `tests/grouptools/groupadd/08_groupadd_locked_group/groupadd.test` which checks if `groupadd` fails to create group when /etc/group file is locked Signed-off-by: Akshay Sakure --- tests/system/tests/test_groupadd.py | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/system/tests/test_groupadd.py b/tests/system/tests/test_groupadd.py index b0d8774a1b..47e6f802cd 100644 --- a/tests/system/tests/test_groupadd.py +++ b/tests/system/tests/test_groupadd.py @@ -298,3 +298,34 @@ def test_groupadd__invalid_name(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__locked_group_file(shadow: Shadow): + """ + :title: Group creation fails when /etc/group is locked + :setup: + 1. Create /etc/group.lock to simulate a locked file + :steps: + 1. Attempt to create group + 2. Verify that groupadd command fails + 3. Check group and gshadow entries + :expectedresults: + 1. Group is not created + 2. groupadd command fails with error (cannot lock file) + 3. No group or gshadow entries are found + :customerscenario: False + """ + shadow.fs.touch("/etc/group.lock") + + with pytest.raises(ProcessError) as exc_info: + shadow.groupadd("tgroup") + + assert exc_info.value.rc == 10, f"Expected rc=10 (cannot lock file), 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 bf64feb359a94a376a2213bb7e77327213e4a000 Mon Sep 17 00:00:00 2001 From: Akshay Sakure Date: Fri, 17 Jul 2026 18:49:37 +0530 Subject: [PATCH 2/2] Tests: Group creation fails when /etc/gshadow is locked This is Python transformation of the test located in `tests/grouptools/groupadd/09_groupadd_locked_gshadow/groupadd.test` which checks if `groupadd` fails to create group when /etc/gshadow is locked Signed-off-by: Akshay Sakure --- tests/system/tests/test_groupadd.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/system/tests/test_groupadd.py b/tests/system/tests/test_groupadd.py index 47e6f802cd..4597d57b0b 100644 --- a/tests/system/tests/test_groupadd.py +++ b/tests/system/tests/test_groupadd.py @@ -301,22 +301,29 @@ def test_groupadd__invalid_name(shadow: Shadow): @pytest.mark.topology(KnownTopology.Shadow) -def test_groupadd__locked_group_file(shadow: Shadow): +@pytest.mark.parametrize( + "lock_file", + [ + pytest.param("/etc/group.lock", id="group_file"), + pytest.param("/etc/gshadow.lock", id="gshadow_file"), + ], +) +def test_groupadd__locked_file(shadow: Shadow, lock_file: str): """ - :title: Group creation fails when /etc/group is locked + :title: Group creation fails when a lock file exists :setup: - 1. Create /etc/group.lock to simulate a locked file + 1. Create lock file :steps: 1. Attempt to create group 2. Verify that groupadd command fails 3. Check group and gshadow entries :expectedresults: 1. Group is not created - 2. groupadd command fails with error (cannot lock file) + 2. groupadd command fails with rc=10 (cannot lock file) 3. No group or gshadow entries are found :customerscenario: False """ - shadow.fs.touch("/etc/group.lock") + shadow.fs.touch(lock_file) with pytest.raises(ProcessError) as exc_info: shadow.groupadd("tgroup")