]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Tests: Group creation with invalid GID using -g flag fails master
authorAkshay Sakure <asakure@redhat.com>
Mon, 6 Jul 2026 12:21:35 +0000 (17:51 +0530)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Wed, 29 Jul 2026 16:19:16 +0000 (18:19 +0200)
This is Python transformation of the test located in
`tests/grouptools/groupadd/11_groupadd_invalid_GID/groupadd.test`
which checks that `groupadd` fails to create group with invalid GID
using -g flag

Signed-off-by: Akshay Sakure <asakure@redhat.com>
tests/system/tests/test_groupadd.py

index 81729e4aee0cb50de2f1b1668bdf64a2dfe2545a..850ac9a947a7395b84d0c8b1b629d914bb5ff56d 100644 (file)
@@ -8,6 +8,7 @@ import re
 
 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
@@ -232,3 +233,32 @@ def test_groupadd__create_group_with_existing_gid(shadow: Shadow):
         gshadow_entry = shadow.tools.getent.gshadow("tgroup2")
         assert gshadow_entry is not None, "Group should be found"
         assert gshadow_entry.name == "tgroup2", "Incorrect groupname"
+
+
+@pytest.mark.topology(KnownTopology.Shadow)
+def test_groupadd__invalid_gid(shadow: Shadow):
+    """
+    :title: Group creation with invalid GID fails
+    :setup:
+        1. None required
+    :steps:
+        1. Create group with invalid GID
+        2. Verify if 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("-g 1001x 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"