summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2024-11-18 19:41:07 +0100
committerMike Yuan <me@yhndnzj.com>2024-11-19 00:38:18 +0100
commitb718b86e1b8477f58461f3c456c944abb1428c0f (patch)
treefbfec276816b00692314235946435ffb3e1eb37f /test
parentcore/exec-invoke: minor cleanup for apply_working_directory() error handling (diff)
downloadsystemd-b718b86e1b8477f58461f3c456c944abb1428c0f.tar.xz
systemd-b718b86e1b8477f58461f3c456c944abb1428c0f.zip
core/exec-invoke: suppress placeholder home only in build_environment()
Currently, get_fixed_user() employs USER_CREDS_SUPPRESS_PLACEHOLDER, meaning home path is set to NULL if it's empty or root. However, the path is also used for applying WorkingDirectory=~, and we'd spuriously use the invoking user's home as fallback even if User= is changed in that case. Let's instead delegate such suppression to build_environment(), so that home is proper initialized for usage at other steps. shell doesn't actually suffer from such problem, but it's changed too for consistency. Alternative to #34789
Diffstat (limited to 'test')
-rwxr-xr-xtest/units/TEST-07-PID1.working-directory.sh20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/units/TEST-07-PID1.working-directory.sh b/test/units/TEST-07-PID1.working-directory.sh
new file mode 100755
index 0000000000..1cff3e0602
--- /dev/null
+++ b/test/units/TEST-07-PID1.working-directory.sh
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+set -eux
+set -o pipefail
+
+# shellcheck source=test/units/util.sh
+. "$(dirname "$0")"/util.sh
+
+(! systemd-run --wait -p DynamicUser=yes \
+ -p EnvironmentFile=-/usr/lib/systemd/systemd-asan-env \
+ -p WorkingDirectory='~' true)
+
+assert_eq "$(systemd-run --pipe --uid=root -p WorkingDirectory='~' pwd)" "/root"
+assert_eq "$(systemd-run --pipe --uid=nobody -p WorkingDirectory='~' pwd)" "/"
+assert_eq "$(systemd-run --pipe --uid=testuser -p WorkingDirectory='~' pwd)" "/home/testuser"
+
+(! systemd-run --wait -p DynamicUser=yes -p User=testuser \
+ -p EnvironmentFile=-/usr/lib/systemd/systemd-asan-env \
+ -p WorkingDirectory='~' true)