]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: slightly extend uid0's coverage
authorFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 22 Dec 2023 13:09:58 +0000 (14:09 +0100)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Sat, 23 Dec 2023 15:37:30 +0000 (16:37 +0100)
test/units/testsuite-74.run.sh

index 1b4daf8bf480786ced6b52241f50343a0b978110..69907d4f385ca3cb1d3609a38253961fda16d239 100755 (executable)
@@ -230,6 +230,15 @@ assert_eq "$A" "$B"
 # Check that invoking the tool under the uid0 alias name works
 uid0 ls /
 assert_eq "$(uid0 echo foo)" "foo"
+# Check if we set some expected environment variables
+for arg in "" "--user=root" "--user=testuser"; do
+    assert_eq "$(uid0 ${arg:+"$arg"} bash -c 'echo $SUDO_USER')" "$USER"
+    assert_eq "$(uid0 ${arg:+"$arg"} bash -c 'echo $SUDO_UID')" "$(id -u "$USER")"
+    assert_eq "$(uid0 ${arg:+"$arg"} bash -c 'echo $SUDO_GID')" "$(id -u "$USER")"
+done
+# Let's chain a couple of uid0 calls together, for fun
+readarray -t cmdline < <(printf "%.0suid0\n" {0..31})
+assert_eq "$("${cmdline[@]}" bash -c 'echo $SUDO_USER')" "$USER"
 
 umount /proc/version
 rm "$V"