]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Tests: Force creation of existing group using -f flag
authorAkshay Sakure <asakure@redhat.com>
Wed, 1 Jul 2026 09:51:43 +0000 (15:21 +0530)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Wed, 1 Jul 2026 14:22:03 +0000 (16:22 +0200)
This is Python transformation of the test located in
'tests/grouptools/groupadd/06_groupadd_-f_add_existing_group/groupadd.test'
which checks that 'groupadd' completes successfully while force-creating
an existing group using -f flag

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

index 643d9bf9691b8a252026c88d2cbede4cc299a9ca..e5a0faae546724b96fdf7d257e0c8946dd1aff90 100644 (file)
@@ -7,7 +7,6 @@ from __future__ import annotations
 import re
 
 import pytest
-
 from passlib.hash import sha512_crypt
 
 from framework.misc import shadow_password_pattern
@@ -120,3 +119,34 @@ def test_groupadd__set_password(shadow: Shadow):
         assert gshadow_entry.name == "tgroup", "Incorrect groupname"
         assert gshadow_entry.password is not None, "Password should not be None"
         assert re.match(shadow_password_pattern(), gshadow_entry.password), "Incorrect password"
+
+
+@pytest.mark.topology(KnownTopology.Shadow)
+def test_groupadd__force_group_creation(shadow: Shadow):
+    """
+    :title: Forced creation of existing group exits successfully
+    :setup:
+        1. Create group entry
+    :steps:
+        1. Check group entry
+        2. Force create existing group
+        3. Check group entry
+        4. Check gshadow entry
+    :expectedresults:
+        1. Group entry is created
+        2. groupadd -f command completes successfully
+        3. Group entry is unchanged
+        4. gshadow entry is unchanged
+    :customerscenario: False
+    """
+    shadow.groupadd("tgroup")
+    existing_group_entry = shadow.tools.getent.group("tgroup")
+    assert existing_group_entry is not None, "Group should be found"
+    shadow.groupadd("-f tgroup")
+    group_entry = shadow.tools.getent.group("tgroup")
+    assert group_entry is not None, "Group should be found"
+    assert group_entry.name == "tgroup", "Incorrect groupname"
+    if shadow.host.features["gshadow"]:
+        gshadow_entry = shadow.tools.getent.gshadow("tgroup")
+        assert gshadow_entry is not None, "Group should be found"
+        assert gshadow_entry.name == "tgroup", "Incorrect groupname"