diff --git a/tests/system/tests/test_groupadd.py b/tests/system/tests/test_groupadd.py index b0d8774a1b..4597d57b0b 100644 --- a/tests/system/tests/test_groupadd.py +++ b/tests/system/tests/test_groupadd.py @@ -298,3 +298,41 @@ 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) +@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 a lock file exists + :setup: + 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 rc=10 (cannot lock file) + 3. No group or gshadow entries are found + :customerscenario: False + """ + shadow.fs.touch(lock_file) + + 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"