]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
integration-test: skip several test cases when nss module is not supported
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 29 Nov 2025 01:02:19 +0000 (10:02 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 7 Dec 2025 00:10:29 +0000 (09:10 +0900)
test/units/TEST-13-NSPAWN.nss-mymachines.sh
test/units/TEST-46-HOMED.sh
test/units/TEST-71-HOSTNAME.sh
test/units/TEST-74-AUX-UTILS.capsule.sh
test/units/TEST-75-RESOLVED.sh
test/units/util.sh

index a14c53154cc202b94465107a36358bb458788225..e4a961671288ef90d2b4885ffe4a40983db86ce9 100755 (executable)
@@ -7,6 +7,10 @@ set -o pipefail
 # shellcheck source=test/units/util.sh
 . "$(dirname "$0")"/util.sh
 
+if ! check_nss_module mymachine; then
+    exit 0
+fi
+
 at_exit() {
     set +e
 
index bb6d64bfed629456676bd4c35850cb9862dc8de7..d7d29e08936db177da76e1b42681109b0bd59441 100755 (executable)
@@ -233,7 +233,13 @@ testcase_basic() {
     PASSWORD=xEhErW0ndafV4s homectl with test-user -- rm /home/test-user/xyz
     PASSWORD=xEhErW0ndafV4s homectl with test-user -- test ! -f /home/test-user/xyz
     (! PASSWORD=xEhErW0ndafV4s homectl with test-user -- test -f /home/test-user/xyz)
-    [[ "$(PASSWORD=xEhErW0ndafV4s homectl with test-user -- stat -c %U /home/test-user/hoge)" == "test-user" ]]
+    if check_nss_module systemd; then
+        [[ "$(PASSWORD=xEhErW0ndafV4s homectl with test-user -- stat -c %U /home/test-user/hoge)" == "test-user" ]]
+        [[ "$(PASSWORD=xEhErW0ndafV4s homectl with test-user -- stat -c %u /home/test-user/hoge)" == "$(id -u test-user)" ]]
+    fi
+    # The machine ID may start with a numeric, and in that case the field name must be quoted.
+    [[ "$(PASSWORD=xEhErW0ndafV4s homectl with test-user -- stat -c %u /home/test-user/hoge)" == \
+       "$(homectl inspect --json=short test-user | jq .binding.\""$(cat /etc/machine-id)"\".uid)" ]]
     [[ "$(PASSWORD=xEhErW0ndafV4s homectl with test-user -- cat /home/test-user/hoge)" == "$(cat "$TMP_SKEL"/hoge)" ]]
 
     # Regression tests
@@ -587,6 +593,11 @@ testcase_ssh() {
         return 0
     fi
 
+    # 'ssh homedsshtest@localhost' requires systemd NSS module.
+    if ! check_nss_module systemd; then
+        return 0
+    fi
+
     if ! command -v ssh >/dev/null || ! command -v sshd >/dev/null; then
         echo "ssh/sshd is not installed, skipping the ssh test."
         return 0
@@ -690,17 +701,24 @@ testcase_alias() {
     userdbctl user aliastest2@myrealm
     userdbctl user aliastest3@myrealm
 
-    getent passwd aliastest
-    getent passwd aliastest2
-    getent passwd aliastest3
-    getent passwd aliastest@myrealm
-    getent passwd aliastest2@myrealm
-    getent passwd aliastest3@myrealm
+    if check_nss_module systemd; then
+        getent passwd aliastest
+        getent passwd aliastest2
+        getent passwd aliastest3
+        getent passwd aliastest@myrealm
+        getent passwd aliastest2@myrealm
+        getent passwd aliastest3@myrealm
+    fi
 
     homectl remove aliastest
 }
 
 testcase_quota() {
+    # 'run0 -u' requires systemd NSS module.
+    if ! check_nss_module systemd; then
+        return 0
+    fi
+
     NEWPASSWORD=quux homectl create tmpfsquota --storage=subvolume --dev-shm-limit=50K --tmp-limit=50K -P
     for p in /dev/shm /tmp; do
         if findmnt -n -o options "$p" | grep -q usrquota; then
@@ -725,6 +743,11 @@ testcase_quota() {
 }
 
 testcase_subarea() {
+    # 'run0 -u' requires systemd NSS module.
+    if ! check_nss_module systemd; then
+        return 0
+    fi
+
     NEWPASSWORD=quux homectl create subareatest --storage=subvolume -P
     run0 --property=SetCredential=pam.authtok.systemd-run0:quux -u subareatest mkdir Areas
     run0 --property=SetCredential=pam.authtok.systemd-run0:quux -u subareatest cp -av /etc/skel Areas/furb
index 8ec3bd6cfbf0e01951f3652f80d29bb30f0b128f..ffb110be68832e6766cc9715855de561bb0df87b 100755 (executable)
@@ -166,6 +166,10 @@ testcase_hardware_serial() {
 testcase_nss-myhostname() {
     local database host i
 
+    if ! check_nss_module myhostname; then
+        return 0
+    fi
+
     HOSTNAME="$(hostnamectl hostname)"
 
     # Set up a dummy network for _gateway and _outbound labels
@@ -316,7 +320,6 @@ EOF
     assert_in "CHASSIS=watch" "$(cat /run/alternate-path/mymachine-info)"
 }
 
-
 run_testcases
 
 touch /testok
index 06f6a1ca6e2ca45ddb180d030c7129c90a0230b3..c2c3073ea80a039f6c0bd355b1b3b419bc16ffab 100755 (executable)
@@ -4,6 +4,13 @@
 set -eux
 set -o pipefail
 
+# shellcheck source=test/units/util.sh
+. "$(dirname "$0")"/util.sh
+
+if ! check_nss_module systemd; then
+    exit 0
+fi
+
 at_exit() {
     set +e
     systemctl --no-block stop capsule@foobar.service
index 51820016ddeec191c9e44fccf8e239a022146b05..5ec588309bfa9d50b67e622355216cb9d9f31bc1 100755 (executable)
@@ -408,6 +408,11 @@ manual_testcase_02_mdns_llmnr() {
 
 testcase_03_23951() {
     : "--- nss-resolve/nss-myhostname tests"
+
+    if ! check_nss_module resolve; then
+        return 0
+    fi
+
     # Sanity check
     TIMESTAMP=$(date '+%F %T')
     # Issue: https://github.com/systemd/systemd/issues/23951
@@ -426,6 +431,10 @@ testcase_03_23951() {
 }
 
 testcase_04_18812() {
+    if ! check_nss_module resolve; then
+        return 0
+    fi
+
     # Issue: https://github.com/systemd/systemd/issues/18812
     # PR: https://github.com/systemd/systemd/pull/18896
     # Follow-up issue: https://github.com/systemd/systemd/issues/23152
@@ -446,6 +455,10 @@ testcase_04_18812() {
 }
 
 testcase_05_25088() {
+    if ! check_nss_module resolve; then
+        return 0
+    fi
+
     # Issue: https://github.com/systemd/systemd/issues/25088
     run getent -s resolve hosts 127.128.0.5
     grep -qEx '127\.128\.0\.5\s+localhost5(\s+localhost5?\.localdomain[45]?){4}' "$RUN_OUT"
index 445b71836ad78185bd6c0306ecb3bec0691fe68c..c62f8d9574b8282257c570618020ad680fb2d042 100755 (executable)
@@ -458,3 +458,37 @@ built_with_musl() (
     set +ex
     ! systemd-analyze --quiet condition 'ConditionVersion=glibc $= ?*'
 )
+
+check_nss_module() (
+    set +e
+
+    local name="${1:?}"
+    local have=
+    local i
+
+    if [[ ! -e /etc/nsswitch.conf ]]; then
+        : "/etc/nsswitch.conf not found."
+        return 1
+    fi
+
+    if ! find /usr/lib* -name "libnss_${name}.so.*" 2>/dev/null | grep . >/dev/null; then
+        : "NSS module $name not found."
+        return 1
+    fi
+
+    if [[ "$name" == systemd ]]; then
+        for i in passwd group shadow; do
+            if ! grep -qE "^$i:.*[[:space:]]*systemd" /etc/nsswitch.conf; then
+                : "systemd NSS module is not enabled for $i database."
+                return 1
+            fi
+        done
+    else
+        if ! grep -qE "^hosts:.*[[:space:]]*$name" /etc/nsswitch.conf; then
+            : "$name NSS module is not enabled for hosts database."
+            return 1
+        fi
+    fi
+
+    return 0
+)