Skip to content
Open
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
91 changes: 91 additions & 0 deletions tests/system/tests/test_groupadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,94 @@ 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)
def test_groupadd__invalid_K_key(shadow: Shadow):
"""
: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("-K KEY=100 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__invalid_K_no_equals(shadow: Shadow):
"""
:title: Group creation fails when -K argument is missing the equals sign
:setup:
1. None required
:steps:
1. Create group with -K option without equals sign
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("-K GID_MAX 100 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 entry
2. Attempt to create group
3. Verify that groupadd command fails
:expectedresults:
1. Existing group and gshadow entries are found
2. Group is not created
3. groupadd command fails with error (group already exists)
: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}"
Loading