From: aborah-sudo Date: Mon, 23 Mar 2026 05:12:09 +0000 (+0530) Subject: Tests: Add a new user with a specified non-existing primary group X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=778b4a498ee463d6df9f45ded5230fc6c090cc1c;p=thirdparty%2Fshadow.git Tests: Add a new user with a specified non-existing primary group 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 --- diff --git a/tests/system/tests/test_useradd.py b/tests/system/tests/test_useradd.py index 0fe1a3649..a23cfdd43 100644 --- a/tests/system/tests/test_useradd.py +++ b/tests/system/tests/test_useradd.py @@ -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}"