Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions tests/system/tests/test_groupadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading