From c37e5e6059caf513003a16c18c034bbe067bb7b8 Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Sat, 4 Jun 2022 08:30:53 +0200 Subject: [PATCH] tests/custom-tmpdir: try running mmdebstrap in a TMPDIR with special shell characters in its path --- mmdebstrap | 4 ++-- tests/custom-tmpdir | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/mmdebstrap b/mmdebstrap index 4ef6af1..8007183 100755 --- a/mmdebstrap +++ b/mmdebstrap @@ -4896,8 +4896,8 @@ sub main() { } # initialize gpg trustdb with empty one { - `@gpgcmd --update-trustdb >/dev/null 2>/dev/null`; - $? == 0 or error "gpg failed to initialize trustdb: $?"; + 0 == system(@gpgcmd, '--update-trustdb') + or error "gpg failed to initialize trustdb:: $?"; } # find all the fingerprints of the keys apt currently # knows about diff --git a/tests/custom-tmpdir b/tests/custom-tmpdir index cf9fe5c..a9dfa21 100644 --- a/tests/custom-tmpdir +++ b/tests/custom-tmpdir @@ -5,14 +5,18 @@ if [ ! -e /mmdebstrap-testenv ]; then echo "this test modifies the system and should only be run inside a container" >&2 exit 1 fi +# https://www.etalabs.net/sh_tricks.html +quote () { printf %s\\n "$1" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/'/" ; } adduser --gecos user --disabled-password user sysctl -w kernel.unprivileged_userns_clone=1 homedir=$(runuser -u user -- sh -c 'cd && pwd') -runuser -u user -- mkdir "$homedir/tmp" -runuser -u user -- env TMPDIR="$homedir/tmp" {{ CMD }} --mode=unshare --variant=apt \ - --setup-hook='case "$1" in "'"$homedir/tmp/mmdebstrap."'"??????????) exit 0;; *) exit 1;; esac' \ +# apt:test/integration/test-apt-key +TMPDIR_ADD="This is fü\$\$ing cràzy, \$(apt -v)\$!" +runuser -u user -- mkdir "$homedir/$TMPDIR_ADD" +runuser -u user -- env TMPDIR="$homedir/$TMPDIR_ADD" {{ CMD }} --mode=unshare --variant=apt \ + --setup-hook='case "$1" in '"$(quote "$homedir/$TMPDIR_ADD/mmdebstrap.")"'??????????) exit 0;; *) echo "$1"; exit 1;; esac' \ {{ DIST }} /tmp/debian-chroot.tar {{ MIRROR }} tar -tf /tmp/debian-chroot.tar | sort | diff -u tar1.txt - # use rmdir as a quick check that nothing is remaining in TMPDIR -runuser -u user -- rmdir "$homedir/tmp" +runuser -u user -- rmdir "$homedir/$TMPDIR_ADD" rm /tmp/debian-chroot.tar