tests: Require OSTREE_TEST_SUDO to be set to use `sudo`
authorColin Walters <walters@verbum.org>
Tue, 22 Nov 2022 15:26:44 +0000 (10:26 -0500)
committerColin Walters <walters@verbum.org>
Tue, 22 Nov 2022 15:27:28 +0000 (10:27 -0500)
IMO, tools invoking `sudo` automatically is a huge anti-pattern.
Require this to be opt-in.

In practice also...these tests really want to be *integration*
and not unit tests because involving `sudo` alongside uninstalled
binaries just creates a giant mess.

Closes: https://github.com/ostreedev/ostree/issues/2761
tests/libtest.sh
tests/test-basic-bare-split-xattrs.sh
tests/test-repo-finder-mount-integration.sh

index af0003631b96c90c717a77f78b5c52b68c2073f9..264094b1e3d7b90dd31c08863c6dddbcb8d0e02e 100755 (executable)
@@ -614,6 +614,12 @@ skip_without_user_xattrs () {
     fi
 }
 
+skip_without_sudo () {
+    if test -z "${OSTREE_TEST_SUDO:-}"; then
+        skip "this test needs sudo, skipping without OSTREE_TEST_SUDO being set"
+    fi
+}
+
 # Usage: if ! skip_one_without_whiteouts_devices; then ... more tests ...; fi
 skip_one_without_whiteouts_devices() {
     if ! can_create_whiteout_devices; then
index bf828eb75c1acfb49cdbd7f2aa26d0c912b70225..b30e9d6d14b6de9d03c53a5c48ff1d64b4b44aed 100755 (executable)
@@ -9,7 +9,9 @@ set -euo pipefail
 mode="bare-split-xattrs"
 OSTREE="${CMD_PREFIX} ostree --repo=${test_tmpdir}/repo"
 
+skip_without_sudo
 SUDO="sudo --non-interactive"
+
 PRIVILEGED="false"
 if [ $(id -u) -eq 0 ]; then
   PRIVILEGED="true"
index e7a0f86a9c4c87c29c2b135ba7534fc5e46ce931..b1a8d422aed4e8d932ac30c3b44a111e9f2d1ea7 100755 (executable)
@@ -24,6 +24,7 @@ set -euo pipefail
 
 . $(dirname $0)/libtest.sh
 
+skip_without_sudo
 SUDO="sudo --non-interactive"
 
 # Skip the test if a well-known USB stick is not available.