summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-06-20 22:39:46 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2017-06-21 00:52:14 -0400
commita1e6d2e2a8ef388463a4a5bad709b82b21624da4 (patch)
tree050b550384f8e092b1b5daa167fe5e6c9a971508
parent78773bf0f927c66f6e74a6bda9a0737c1d4e0f8a (diff)
test: conf.sh: verify that LIBREUSER is correct when `sudo sudo -u $LIBREUSER`
https://labs.parabola.nu/issues/1372
-rw-r--r--test/lib-conf-test.sh13
-rwxr-xr-xtest/testenv6
2 files changed, 16 insertions, 3 deletions
diff --git a/test/lib-conf-test.sh b/test/lib-conf-test.sh
index d79c5f2..e1a27e6 100644
--- a/test/lib-conf-test.sh
+++ b/test/lib-conf-test.sh
@@ -23,6 +23,19 @@ it_figures_out_HOME_when_root() {
[[ $LIBREHOME != /root ]]
}
+it_nests_LIBREUSER() {
+ require sudo || return 0
+ [[ $USER != root ]]
+ cd "$tmpdir"
+ echo '. $(librelib conf.sh); echo "$LIBREUSER"' > test.sh
+
+ LIBREUSER=$(testsudo bash ./test.sh)
+ [[ $LIBREUSER == "$USER" ]]
+
+ LIBREUSER=$(testsudo testsudo -u "$USER" bash ./test.sh)
+ [[ $LIBREUSER == "$USER" ]]
+}
+
it_respects_custom_HOME() {
cd "$tmpdir"
echo '. $(librelib conf.sh); echo "$LIBREHOME"' > test.sh
diff --git a/test/testenv b/test/testenv
index 7072326..3bb827f 100755
--- a/test/testenv
+++ b/test/testenv
@@ -51,12 +51,12 @@ export _librelib_conf_sh_pkgconfdir="$destdir/etc/libretools.d"
# Hack to respect our variables in sudo
_sudo() {
local vars=(TMPDIR PATH LIBRETOOLS_LIBDIR XDG_CACHE_HOME XDG_CONFIG_HOME _librelib_conf_sh_sysconfdir)
- local args=()
+ local env=()
local var
for var in "${vars[@]}"; do
- args+=("$var=${!var}")
+ env+=("$var=${!var}")
done
- sudo env "${args[@]}" "$@"
+ sudo "${env[@]}" "$@"
}
printf '%s\n' \
'#!/bin/bash' \