]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
tests: useradd: btrfs subvolume creation for system users
authorHadi Chokr <hadichokr@icloud.com>
Fri, 17 Jul 2026 06:47:36 +0000 (06:47 +0000)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Tue, 28 Jul 2026 15:11:47 +0000 (17:11 +0200)
Check that a system user created with --btrfs-subvolume-home gets a
plain home directory by default, and a subvolume when
BTRFS_SUBVOLUME_SYSTEM=yes is set in /etc/default/useradd.

Signed-off-by: Hadi Chokr <hadichokr@icloud.com>
tests/system/tests/privileged/test_privileged_useradd.py

index fbee3a8f5a8ffdcee103b0991a429df5f1f930ff..b29e2f89564adb4d3a192317fdfc72c5875a3c8b 100644 (file)
@@ -33,3 +33,55 @@ def test_useradd__btrfs_subvolume_home(shadow: Shadow) -> None:
         assert shadow.fs.exists("/home/tuser"), "Home directory should exist"
 
         assert shadow.host.btrfs.subvolume_exists("/home", "tuser")
+
+
+def test_useradd__btrfs_subvolume_home_system_user(shadow: Shadow) -> None:
+    """
+    :title: Btrfs subvolume home is skipped for system users by default
+    :steps:
+        1. Create a system user, requesting its home directory as a Btrfs subvolume
+        2. Verify the user is a system user
+        3. Verify the home directory exists
+        4. Verify the home directory is not a Btrfs subvolume
+    :expectedresults:
+        1. The user is created
+        2. The UID is in the system range
+        3. The user home directory exists at /home/tsysuser
+        4. /home/tsysuser is a regular directory, not a subvolume
+    :customerscenario: False
+    """
+    with shadow.host.btrfs.loopback_mount("/home"):
+        shadow.useradd("tsysuser -r -m --btrfs-subvolume-home")
+
+        passwd_entry = shadow.tools.getent.passwd("tsysuser")
+        assert passwd_entry is not None, "User should be found"
+        assert passwd_entry.uid is not None and passwd_entry.uid < 1000, "User should be a system user"
+
+        assert shadow.fs.exists("/home/tsysuser"), "Home directory should exist"
+
+        assert not shadow.host.btrfs.subvolume_exists("/home", "tsysuser"), "Home should not be a subvolume"
+
+
+def test_useradd__btrfs_subvolume_home_system_user_enabled(shadow: Shadow) -> None:
+    """
+    :title: Btrfs subvolume home is created for system users with BTRFS_SUBVOLUME_SYSTEM=yes
+    :setup:
+        1. Enable Btrfs subvolume creation for system users in the useradd defaults
+    :steps:
+        1. Create a system user, requesting its home directory as a Btrfs subvolume
+        2. Verify the home directory exists
+        3. Verify the home directory is a Btrfs subvolume
+    :expectedresults:
+        1. The user is created
+        2. The user home directory exists at /home/tsysuser
+        3. /home/tsysuser is listed as a Btrfs subvolume
+    :customerscenario: False
+    """
+    with shadow.host.btrfs.loopback_mount("/home"):
+        shadow.useradd_defaults["BTRFS_SUBVOLUME_SYSTEM"] = "yes"
+
+        shadow.useradd("tsysuser -r -m --btrfs-subvolume-home")
+
+        assert shadow.fs.exists("/home/tsysuser"), "Home directory should exist"
+
+        assert shadow.host.btrfs.subvolume_exists("/home", "tsysuser"), "Home should be a subvolume"