#!/bin/sh # Hermetic negative-path tests for the release-manifest inventory drift gate # (PB-26-113). No Android SDK, Gradle project, or merged build output required. set -eu SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) CHECK="$SCRIPT_DIR/check-release-manifest.py" TEMP_ROOT=$(mktemp -d "${TMPDIR:-/tmp}/peach-release-manifest-tests.XXXXXX") trap 'trash "$TEMP_ROOT"' EXIT HUP INT TERM MERGED="$TEMP_ROOT/AndroidManifest.xml" INVENTORY="$TEMP_ROOT/inventory.txt" fail() { printf 'FAIL: %s\n' "$1" >&2 exit 1 } write_manifest() { cat > "$MERGED" < $1 XML } write_manifest "" python3 "$CHECK" write "$MERGED" "$INVENTORY" [ -s "$INVENTORY" ] || fail "write produced no inventory" grep -q '^permission|android.permission.INTERNET$' "$INVENTORY" || fail "inventory is missing the declared permission" python3 "$CHECK" check "$MERGED" "$INVENTORY" python3 "$CHECK" write "$MERGED" "$INVENTORY" python3 "$CHECK" check "$MERGED" "$INVENTORY" # A permission added to the merged manifest after the inventory was recorded # must refuse, and must say so rather than crashing. write_manifest '' if output=$(python3 "$CHECK" check "$MERGED" "$INVENTORY" 2>&1); then fail "drifted merged manifest was accepted" fi case "$output" in *"differs from checked-in inventory"*) ;; *) fail "drift refusal did not report drift: $output" ;; esac # Missing inputs fail closed instead of reporting a clean comparison. if python3 "$CHECK" check "$TEMP_ROOT/absent.xml" "$INVENTORY" >/dev/null 2>&1; then fail "a missing merged manifest was accepted" fi if python3 "$CHECK" check "$MERGED" "$TEMP_ROOT/absent.txt" >/dev/null 2>&1; then fail "a missing inventory was accepted" fi printf 'PASS: release manifest inventory drift gate\n'