From: Iker Pedrosa Date: Thu, 21 Aug 2025 10:57:16 +0000 (+0200) Subject: tests/system/tests/test_newgrp.py: change to new group X-Git-Tag: 4.19.0-rc1~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73895aa11bc479cad58aa40f4a7f585636b940d9;p=thirdparty%2Fshadow.git tests/system/tests/test_newgrp.py: change to new group Change to a new group using `newgrp`. Signed-off-by: Iker Pedrosa --- diff --git a/tests/system/tests/test_newgrp.py b/tests/system/tests/test_newgrp.py new file mode 100644 index 000000000..b955a8226 --- /dev/null +++ b/tests/system/tests/test_newgrp.py @@ -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}"