Validate local archive architecture

This commit is contained in:
rcourtman 2026-04-05 22:26:43 +01:00
parent 690cc94e17
commit a2ecd4198a
3 changed files with 195 additions and 26 deletions

View file

@ -78,6 +78,7 @@ EOF
restore_selinux_contexts() { :; }
install_additional_agent_binaries() { return 0; }
deploy_agent_scripts() { return 0; }
validate_pulse_binary_architecture() { return 0; }
chown() { :; }
ln() { :; }
curl() { echo "unexpected curl call" >&2; return 99; }
@ -113,6 +114,45 @@ test_prefetch_pulse_archive_for_container_sets_output_var() {
)
}
test_install_pulse_archive_rejects_mismatched_arch_without_replacing_existing_binary() {
(
load_installer
local tmpdir archive_root archive_path
tmpdir="$(mktemp -d)"
archive_root="${tmpdir}/archive"
archive_path="${tmpdir}/pulse-v5.1.99-linux-arm64.tar.gz"
mkdir -p "${archive_root}/bin"
cat > "${archive_root}/bin/pulse" <<'EOF'
#!/usr/bin/env bash
echo "v5.1.99"
EOF
chmod +x "${archive_root}/bin/pulse"
tar -czf "${archive_path}" -C "${archive_root}" .
INSTALL_DIR="${tmpdir}/opt/pulse"
mkdir -p "${INSTALL_DIR}/bin"
cat > "${INSTALL_DIR}/bin/pulse" <<'EOF'
#!/usr/bin/env bash
echo "v5.1.10"
EOF
chmod +x "${INSTALL_DIR}/bin/pulse"
validate_pulse_binary_architecture() { return 1; }
if install_pulse_archive "${archive_path}" "v5.1.99"; then
echo "install_pulse_archive unexpectedly succeeded on mismatched archive" >&2
rm -rf "${tmpdir}"
return 1
fi
[[ "$("${INSTALL_DIR}/bin/pulse" --version)" == "v5.1.10" ]]
[[ ! -e "${INSTALL_DIR}/bin/pulse.old" ]]
rm -rf "${tmpdir}"
)
}
test_parse_args_rejects_archive_with_source() {
local tmpdir output_file
tmpdir="$(mktemp -d)"
@ -139,6 +179,7 @@ main() {
assert_success "infer_release_from_archive_name parses prerelease tarballs" test_infer_release_from_archive_name_supports_prerelease
assert_success "download_pulse installs from local archive without network" test_download_pulse_installs_from_local_archive_without_network
assert_success "prefetch helper writes archive path via output variable" test_prefetch_pulse_archive_for_container_sets_output_var
assert_success "wrong-arch archives fail before replacing the installed binary" test_install_pulse_archive_rejects_mismatched_arch_without_replacing_existing_binary
assert_success "parse_args rejects archive with source builds" test_parse_args_rejects_archive_with_source
if (( failures > 0 )); then