summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@parabola.nu>2024-02-20 11:44:50 -0700
committerLuke T. Shumaker <lukeshu@parabola.nu>2024-02-20 22:09:26 -0700
commit1a4a9191147dc613a907851c27c2611c478eb10c (patch)
tree4d9ce1f93c635cd4235ac333e1dc45e0592cdccf
parent43b63d5292ad06a58b7c481f36b416c7c6faf8fc (diff)
fix: test: librechroot.bats: Don't use unnamed UIDs
I'm not sure exactly what changed (default PAM policy?), but by default `sudo -u #NN` to use unnamed numeric UIDs no longer works.
-rw-r--r--test/cases/librechroot.bats39
1 files changed, 30 insertions, 9 deletions
diff --git a/test/cases/librechroot.bats b/test/cases/librechroot.bats
index 7d05ebc..ca61e1e 100644
--- a/test/cases/librechroot.bats
+++ b/test/cases/librechroot.bats
@@ -49,19 +49,31 @@ load ../lib/common
@test "librechroot obeys depends in PKGBUILD" {
require network sudo || skip
- # Make sure it's not in the base install
+ # NB: We chown `/startdir` because chcleanup runs `makepkg
+ # --printsrcinfo > .SRCINFO` as the user that owns
+ # `/startdir/PKGBUILD`, and `makepkg` doesn't like to be run
+ # as root. Unfortunately, this test runs with a chroot that
+ # doesn't have the `builduser` set up, and it'd be a pain to
+ # set it up. So choose an arbitrary user from
+ # `/usr/lib/sysusers.d/arch.conf`.
+ local builduser_uid="${SUDO_UID:-$UID}"
+ local builduser_gid="$(id -g "$builduser_uid")"
+ testsudo librechroot -l "$BATS_TEST_NAME" run sh -c "
+ echo 'builduser:x:${builduser_gid}:' >>/etc/group
+ echo 'builduser:x:${builduser_uid}:${builduser_gid}:builduser:/build:/bin/bash' >>/etc/passwd
+ echo 'builduser:!!:$(( $(date -u +%s) / 86400 ))::::::' >>/etc/shadow"
+
+ # Pre-flight: Make sure `lsof` isn't in the base install
not testsudo librechroot -l "$BATS_TEST_NAME" run lsof
- # Make sure it removes it without the PKGBUILD
+ # Make sure librechroot removes `lsof` when the PKGBUILD is not present.
testsudo librechroot -l "$BATS_TEST_NAME" install-name lsof
testsudo librechroot -l "$BATS_TEST_NAME" run lsof
testsudo librechroot -l "$BATS_TEST_NAME" clean-pkgs
not testsudo librechroot -l "$BATS_TEST_NAME" run lsof
- # Make sure it leaves it with the PKGBUILD
+ # Make sure librechroot keeps `lsof` when the PKGBUILD is present.
testsudo librechroot -l "$BATS_TEST_NAME" install-name lsof
testsudo librechroot -l "$BATS_TEST_NAME" run sh -c 'printf "%s\n" "$1" > /startdir/PKGBUILD' -- "$(cat fixtures/librechroot/PKGBUILD-arches)"
- # uid=99 is 'nobody', but we say '99' because sometimes 'nobody' is uid=65534.
- # https://bugs.archlinux.org/task/56828
- testsudo librechroot -l "$BATS_TEST_NAME" run chown -R 99:99 /startdir
+ testsudo librechroot -l "$BATS_TEST_NAME" run chown -R builduser: /startdir
testsudo librechroot -l "$BATS_TEST_NAME" clean-pkgs
testsudo librechroot -l "$BATS_TEST_NAME" run lsof
}
@@ -69,12 +81,21 @@ load ../lib/common
@test "librechroot can install libretools with chcleanup" {
require network sudo || skip
+ # NB: We chown `/startdir` because chcleanup runs `makepkg
+ # --printsrcinfo > .SRCINFO` as the user that owns
+ # `/startdir/PKGBUILD`, and `makepkg` doesn't like to be run
+ # as root.
+ local builduser_uid="${SUDO_UID:-$UID}"
+ local builduser_gid="$(id -g "$builduser_uid")"
+ testsudo librechroot -l "$BATS_TEST_NAME" run sh -c "
+ echo 'builduser:x:${builduser_gid}:' >>/etc/group
+ echo 'builduser:x:${builduser_uid}:${builduser_gid}:builduser:/build:/bin/bash' >>/etc/passwd
+ echo 'builduser:!!:$(( $(date -u +%s) / 86400 ))::::::' >>/etc/shadow"
+
not testsudo librechroot -l "$BATS_TEST_NAME" run test -f /usr/bin/chcleanup
testsudo librechroot -l "$BATS_TEST_NAME" run mkdir /startdir
testsudo librechroot -l "$BATS_TEST_NAME" run sh -c 'printf "%s\n" "$1" > /startdir/PKGBUILD' -- "$(cat fixtures/librechroot/PKGBUILD-libretools)"
- # uid=99 is 'nobody', but we say '99' because sometimes 'nobody' is uid=65534.
- # https://bugs.archlinux.org/task/56828
- testsudo librechroot -l "$BATS_TEST_NAME" run chown -R 99:99 /startdir
+ testsudo librechroot -l "$BATS_TEST_NAME" run chown -R builduser: /startdir
testsudo librechroot -l "$BATS_TEST_NAME" clean-pkgs
testsudo librechroot -l "$BATS_TEST_NAME" run test -f /usr/bin/chcleanup
}