]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Tests: Add a new user with a specified non-existing primary group
authoraborah-sudo <aborah@redhat.com>
Mon, 23 Mar 2026 05:12:09 +0000 (10:42 +0530)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Tue, 24 Mar 2026 08:04:16 +0000 (09:04 +0100)
This is the transformation to Python of the test located in
`tests/usertools/01/06_useradd_invalid_named_primary_group.test`, which checks that `useradd` can not add a new user with invalid existing group as primary

tests/system/tests/test_useradd.py

index 0fe1a3649e2a7b9f780048eb48032f880bced75a..a23cfdd43be788de822d542fe6b14ebdb8107a34 100644 (file)
@@ -331,11 +331,18 @@ def test_useradd__add_user_with_existing_uid(shadow: Shadow):
 
 
 @pytest.mark.topology(KnownTopology.Shadow)
-def test_useradd__invalid_numeric_primary_group(shadow: Shadow):
+@pytest.mark.parametrize(
+    "group_identifier",
+    [
+        pytest.param(4242, id="invalid_numeric_gid"),
+        pytest.param("nekral", id="invalid_named_group"),
+    ],
+)
+def test_useradd__invalid_primary_group(shadow: Shadow, group_identifier: int | str):
     """
-    :title: Add a new user with a specified non-existing gid
+    :title: Add a new user with a specified non-existing primary group
     :steps:
-        1. Attempt to create user with -g 4242 option
+        1. Attempt to create user with -g {group_identifier} option
         2. Verify command fails with appropriate error code and message
         3. Check passwd and group entries
         4. Check home directory
@@ -347,7 +354,7 @@ def test_useradd__invalid_numeric_primary_group(shadow: Shadow):
     :customerscenario: False
     """
     with pytest.raises(ProcessError) as exc_info:
-        shadow.useradd("test1 -g 4242")
+        shadow.useradd(f"test1 -g {group_identifier}")
 
     actual_rc = getattr(exc_info.value, "rc", getattr(exc_info.value, "returncode", None))
     assert actual_rc == 6, f"Expected return code 6 (specified group doesn't exist), got {actual_rc}"