]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
tests/system/tests/test_newgrp.py: change to new group
authorIker Pedrosa <ipedrosa@redhat.com>
Thu, 21 Aug 2025 10:57:16 +0000 (12:57 +0200)
committerSerge Hallyn <serge@hallyn.com>
Fri, 5 Dec 2025 22:35:36 +0000 (16:35 -0600)
Change to a new group using `newgrp`.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
tests/system/tests/test_newgrp.py [new file with mode: 0644]

diff --git a/tests/system/tests/test_newgrp.py b/tests/system/tests/test_newgrp.py
new file mode 100644 (file)
index 0000000..b955a82
--- /dev/null
@@ -0,0 +1,34 @@
+"""
+Test newgrp
+"""
+
+from __future__ import annotations
+
+import pytest
+
+from framework.roles.shadow import Shadow
+from framework.topology import KnownTopology
+
+
+@pytest.mark.topology(KnownTopology.Shadow)
+def test_newgrp__change_to_new_group(shadow: Shadow):
+    """
+    :title: Change to a new group using newgrp
+    :setup:
+        1. Create test user and group
+        2. Add user to the group
+    :steps:
+        1. Use newgrp to change to the new group
+        2. Check that the group change worked
+    :expectedresults:
+        1. newgrp command succeeds
+        2. Current group ID matches the new group
+    :customerscenario: False
+    """
+    shadow.useradd("tuser")
+    shadow.groupadd("tgroup")
+    shadow.usermod("-a -G tgroup tuser")
+
+    cmd, gid = shadow.newgrp("tgroup", run_as="tuser")
+    assert cmd.rc == 0, "newgrp command should succeed"
+    assert gid == 1001, f"Current GID should be {1001}, got {gid}"