]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Tests: Add a new user with home directory creation
authoraborah-sudo <aborah@redhat.com>
Fri, 17 Apr 2026 04:34:49 +0000 (10:04 +0530)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Tue, 5 May 2026 07:24:31 +0000 (09:24 +0200)
This is the transformation to Python of the test located in
`tests/usertools/01/17_useradd_create_homedir.test`
which checks that `useradd` can add a new user with --create-home

tests/system/tests/test_useradd.py

index 7fba00f363f00725b7d74b942a2b848347a394e8..f99618de30737e62506c1920dd6a8bc5b01a06ba 100644 (file)
@@ -566,3 +566,35 @@ def test_useradd_default_primary_group_with_supplementary(shadow: Shadow):
         group_entry = shadow.tools.getent.group(group_name)
         assert group_entry is not None, f"Group {group_name} should exist"
         assert username in group_entry.members, f"User {username} should be a member of {group_name} group"
+
+
+@pytest.mark.topology(KnownTopology.Shadow)
+def test_useradd__create_homedir(shadow: Shadow):
+    """
+    :title: Add a new user with home directory creation
+    :setup:
+        1. Set CREATE_HOME=no in /etc/login.defs to ensure home directory isn't created by default
+        2. Create user with --create-home option
+    :steps:
+        1. Check passwd and group entry
+        2. Verify home directory exists
+    :expectedresults:
+        1. Passwd and group entry exists with correct attributes
+        2. Home directory is created at /home/test1
+    :customerscenario: False
+    """
+    shadow.login_defs["CREATE_HOME"] = "no"
+
+    shadow.useradd("--create-home test1")
+
+    passwd_entry = shadow.tools.getent.passwd("test1")
+    assert passwd_entry is not None, "User test1 should be found in passwd"
+    assert passwd_entry.name == "test1", "Incorrect username"
+    assert passwd_entry.home == "/home/test1", "Incorrect home directory"
+
+    group_entry = shadow.tools.getent.group("test1")
+    assert group_entry is not None, "Group test1 should be found"
+    assert group_entry.name == "test1", "Incorrect group name"
+
+    home_dir = "/home/test1"
+    assert shadow.fs.exists(home_dir), f"Home directory {home_dir} should exist when using --create-home flag"