diff --git a/tests/system/tests/test_groupadd.py b/tests/system/tests/test_groupadd.py index e5a0faae54..fab4eb0353 100644 --- a/tests/system/tests/test_groupadd.py +++ b/tests/system/tests/test_groupadd.py @@ -8,6 +8,7 @@ import pytest from passlib.hash import sha512_crypt +from pytest_mh.conn import ProcessError from framework.misc import shadow_password_pattern from framework.roles.shadow import Shadow @@ -150,3 +151,59 @@ def test_groupadd__force_group_creation(shadow: Shadow): gshadow_entry = shadow.tools.getent.gshadow("tgroup") assert gshadow_entry is not None, "Group should be found" assert gshadow_entry.name == "tgroup", "Incorrect groupname" + + +@pytest.mark.topology(KnownTopology.Shadow) +def test_groupadd__usage(shadow: Shadow): + """ + :title: Groupadd command displays usage with -h option and exits successfully + :setup: + 1. None required + :steps: + 1. Run groupadd command with -h option + 2. Verify that groupadd command exits successfully + :expectedresults: + 1. Command shows usage help + 2. groupadd command completes successfully + :customerscenario: False + """ + result = shadow.groupadd("-h") + assert result.rc == 0, f"Expected return code 0(success), got {result.rc}" + + +@pytest.mark.topology(KnownTopology.Shadow) +def test_groupadd__no_group(shadow: Shadow): + """ + :title: Groupadd command fails when no group is mentioned + :setup: + 1. None required + :steps: + 1. Run groupadd command without any argument + 2. Verify that groupadd command fails + :expectedresults: + 1. Command without any argument fails + 2. groupadd command fails with error (invalid usage) + :customerscenario: False + """ + with pytest.raises(ProcessError) as exc_info: + shadow.host.conn.run("groupadd") + assert exc_info.value.rc == 2, f"Expected return code 2(invalid usage), got {exc_info.value.rc}" + + +@pytest.mark.topology(KnownTopology.Shadow) +def test_groupadd__two_groups(shadow: Shadow): + """ + :title: Groupadd command fails when two groups are mentioned + :setup: + 1. None required + :steps: + 1. Run groupadd command with two groupnames + 2. Verify that groupadd command fails + :expectedresults: + 1. Command with two groupnames fails + 2. groupadd command fails with error (invalid usage) + :customerscenario: False + """ + with pytest.raises(ProcessError) as exc_info: + shadow.groupadd("tgroup1 tgroup2") + assert exc_info.value.rc == 2, f"Expected return code 0(invalid usage), got {exc_info.value.rc}"