eBPF-based security platform
testing: cover failures in the Bash image builder
KP Singh5bd6e27adfb2
diff --git a/testing/Makefile b/testing/Makefileindex f0d9eb1d..9199379c 100644--- a/testing/Makefile+++ b/testing/Makefile@@ -118,11 +118,12 @@ TEST_VM_BUNDLE_SOURCES := $(sort $(wildcard \$(ROOT)/vendor/libbpf/include/asm/*.h \$(ROOT)/testing/helper/*.c $(ROOT)/testing/helper/*.h $(ROOT)/testing/helper/*.py \$(ROOT)/testing/tamperproof/*.c $(ROOT)/contrib/verity-*.sh \- $(ROOT)/tools/gen-image/shirudo-gen-* $(ROOT)/tools/gen-image/*.in \+ $(ROOT)/tools/gen-image/shirudo-gen-* $(ROOT)/tools/gen-image/*.sh \+ $(ROOT)/tools/gen-image/*.in \$(ROOT)/contrib/verity-vm/* \$(ROOT)/testing/upatch/kernel-obs/exec/*.c $(ROOT)/completion/* $(ROOT)/systemd/*.in \$(ROOT)/systemd/*.timer $(ROOT)/testing/fixtures/*.c $(ROOT)/testing/fixtures/*.lua \- $(ROOT)/testing/fixtures/*.conf \+ $(ROOT)/testing/fixtures/*.conf $(ROOT)/testing/fixtures/*.sh \$(ROOT)/testing/fixtures/decoders/* \$(ROOT)/upatches/kernel-obs/*.c $(ROOT)/upatches/kernel-obs/*.h $(ROOT)/upatches/kernel-obs/*.list \$(ROOT)/upatches/kernel-obs/*.py $(ROOT)/upatches/kernel-obs/Beefile \diff --git a/testing/fixtures/image-veritysetup-failure.sh b/testing/fixtures/image-veritysetup-failure.shnew file mode 100755index 00000000..ee5c85ec--- /dev/null+++ b/testing/fixtures/image-veritysetup-failure.sh@@ -0,0 +1,9 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo++case "$IMAGE_BUILD_FAILURE:$1" in+format:format|verify:verify) exit 42 ;;+publish:verify) printf sentinel >"$IMAGE_OUTPUT.roothash" ;;+esac+exec "$REAL_VERITY" "$@"diff --git a/testing/t0045-config-image.sh b/testing/t0045-config-image.shindex f4c6ad52..6e751e13 100755--- a/testing/t0045-config-image.sh+++ b/testing/t0045-config-image.sh@@ -185,6 +185,40 @@ test_expect_success 'builder never overwrites existing outputs and cleans partia[ ! -e "$W/existing.p7s" ]'+test_expect_success 'failed format, signing or verification leaves no output files' '+ mkdir "$W/build-wrapper" &&+ ln -s "$(pwd)/fixtures/image-veritysetup-failure.sh" "$W/build-wrapper/veritysetup" &&+ for stage in format verify; do+ ! PATH="$W/build-wrapper:$PATH" IMAGE_BUILD_FAILURE="$stage" REAL_VERITY="$REAL_VERITY" \+ "$B" image build "$W/data" -o "$W/failed-$stage" --keys-dir "$W/keys" || exit 1+ done &&+ ! "$B" image build "$W/data" -o "$W/failed-sign" \+ --key "$W/missing-key" --cert "$W/keys/cert.der" &&+ for stage in format sign verify; do+ for suffix in img verity roothash p7s; do+ [ ! -e "$W/failed-$stage.$suffix" ] || exit 1+ done+ done &&+ [ -z "$(find "$W" -name ".shirudo-image.*" -print -quit)" ]+'++test_expect_success 'a late output conflict preserves that file and removes partial output' '+ ! PATH="$W/build-wrapper:$PATH" IMAGE_BUILD_FAILURE=publish REAL_VERITY="$REAL_VERITY" \+ IMAGE_OUTPUT="$W/late" "$B" image build "$W/data" -o "$W/late" --keys-dir "$W/keys" &&+ [ "$(cat "$W/late.roothash")" = sentinel ] &&+ [ ! -e "$W/late.img" ] && [ ! -e "$W/late.verity" ] && [ ! -e "$W/late.p7s" ] &&+ [ -z "$(find "$W" -name ".shirudo-image.*" -print -quit)" ]+'++test_expect_success 'installed helper finds the image scripts beside it' '+ mkdir -p "$W/operator/gen-image" &&+ cp "$B" "$W/operator/shirudo-build" &&+ cp ../tools/gen-image/shirudo-gen-* ../tools/gen-image/common.sh \+ ../tools/gen-image/runtime-service.conf.in "$W/operator/gen-image/" &&+ "$W/operator/shirudo-build" image build "$W/data" -o "$W/installed" --keys-dir "$W/keys" &&+ verify "$W/installed" "$W/keys/cert.der"+'+test_expect_success 'offline verification retains its authenticated file descriptors' 'copy_bundle && mkdir "$W/wrapper" &&printf "%s\n" "#!/bin/sh" \