]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
tests: basic user creation
authorIker Pedrosa <ipedrosa@redhat.com>
Fri, 8 Nov 2024 11:15:52 +0000 (12:15 +0100)
committerSerge Hallyn <serge@hallyn.com>
Sat, 11 Jan 2025 02:21:07 +0000 (20:21 -0600)
This is the transformation to Python of the test located in
`tests/usertools/01/01_useradd_add_user.test`, which checks that
`useradd` is able to create a new user and its corresponding group and
home folder.

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

diff --git a/tests/system/tests/test_useradd.py b/tests/system/tests/test_useradd.py
new file mode 100644 (file)
index 0000000..a3748fe
--- /dev/null
@@ -0,0 +1,41 @@
+"""
+Test useradd
+"""
+
+from __future__ import annotations
+
+import pytest
+
+from framework.roles.shadow import Shadow
+from framework.topology import KnownTopology
+
+
+@pytest.mark.topology(KnownTopology.Shadow)
+def test_useradd__add_user(shadow: Shadow):
+    """
+    :title: Basic user creation
+    :setup:
+        1. Create user
+    :steps:
+        1. User exists and UID is 1000
+        2. Group exists and GID is 1000
+        3. Home folder exists
+    :expectedresults:
+        1. User is found and UID matches
+        2. Group is found and GID matches
+        3. Home folder is found
+    :customerscenario: False
+    """
+    shadow.useradd("tuser")
+
+    result = shadow.tools.id("tuser")
+    assert result is not None, "User should be found"
+    assert result.user.name == "tuser", "Incorrect username"
+    assert result.user.id == 1000, "Incorrect UID"
+
+    result = shadow.tools.getent.group("tuser")
+    assert result is not None, "Group should be found"
+    assert result.name == "tuser", "Incorrect groupname"
+    assert result.gid == 1000, "Incorrect GID"
+
+    assert shadow.fs.exists("/home/tuser"), "Home folder should be found"