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
80 changes: 80 additions & 0 deletions tests/system/tests/test_groupadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,83 @@ 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)
@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:
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(f"-K {key} 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"


@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}"
Comment thread
ikerexxe marked this conversation as resolved.

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"
Loading