interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / dl / tests / pinned-archives.sh

83 lines · 4762 bytes Raw Blame History
1#!/usr/bin/env bash
2# ORACLE: exercise the deployed edge CGI's commit archives with private Git fixtures, no sockets.
3# The product CGI and nginx snippet stay byte-identical to their deployed copies. Only this
4# private executable's fixed public root is substituted. Every accepted class has a refused twin.
5set -euo pipefail
6cd "$(dirname "$0")/../.."
7T=$(mktemp -d /tmp/forge-pinned-archive.XXXXXX)
8trap '[ "${KEEP_TEST_TMP:-0}" = 1 ] || rm -rf "$T"' EXIT
9run() { taskset -c "${CORES:-4,5}" nice -n 10 "$@"; }
10pass=0
11ok() { pass=$((pass+1)); echo "PASS $*"; }
12die() { echo "FAIL $*"; exit 1; }
13export GIT_AUTHOR_NAME=fixture GIT_AUTHOR_EMAIL=fixture@invalid GIT_COMMITTER_NAME=fixture GIT_COMMITTER_EMAIL=fixture@invalid
14export GIT_AUTHOR_DATE=2026-01-01T00:00:00Z GIT_COMMITTER_DATE=2026-01-01T00:00:00Z
15mkdir -p "$T/public" "$T/w"
16git -C "$T/w" init -q -b main
17printf 'one\n' > "$T/w/README"
18git -C "$T/w" add README; git -C "$T/w" commit -qm one
19old=$(git -C "$T/w" rev-parse HEAD)
20printf 'two\n' >> "$T/w/README"; git -C "$T/w" commit -qam two
21head=$(git -C "$T/w" rev-parse HEAD)
22branch=$(printf branch | git -C "$T/w" commit-tree "$old^{tree}")
23tag=$(printf tag | git -C "$T/w" commit-tree "$old^{tree}")
24dangling=$(printf dangling | git -C "$T/w" commit-tree "$old^{tree}")
25git clone -q --bare "$T/w" "$T/public/fixture.git"
26G=(git --git-dir="$T/public/fixture.git")
27# Objects unreachable from main are copied explicitly, then only two get canonical refs.
28for c in "$branch" "$tag" "$dangling"; do "${G[@]}" fetch -q "$T/w" "$c"; done
29"${G[@]}" update-ref refs/heads/other "$branch"
30"${G[@]}" update-ref refs/tags/only-tag "$tag"
31"${G[@]}" update-ref refs/noncanonical/hidden "$dangling"
32blob=$("${G[@]}" rev-parse "$head:README")
33sed "s|^export GIT_PROJECT_ROOT=.*|export GIT_PROJECT_ROOT=$T/public|" infra/bazinga/omega-read > "$T/omega-read"
34req() {
35 local path=$1 method=${2:-GET}
36 run env PATH_INFO="/fixture$path" REQUEST_METHOD="$method" QUERY_STRING= sh "$T/omega-read" > "$T/response"
37 # CGI headers end in CRLF CRLF. Keep archive bytes unmodified.
38 if head -1 "$T/response" | grep -q '^Status:'; then
39 status=$(head -1 "$T/response" | tr -d '\r' | cut -d' ' -f2)
40 else status=200; fi
41 LC_ALL=C awk '{ n += length($0) + 1; if ($0 == "\r") {print n; exit} }' "$T/response" > "$T/offset"
42 dd if="$T/response" of="$T/body" bs=1 skip="$(cat "$T/offset")" status=none
43 LC_ALL=C awk '$0 == "\r" {exit} {sub(/\r$/, ""); print}' "$T/response" > "$T/headers"
44}
45accept() {
46 local sha=$1 fmt=$2 path=${3:-/commits/$1.$2}
47 req "$path"
48 [ "$status" = 200 ] || die "$path status $status"
49 grep -qF "Content-Disposition: attachment; filename=fixture-$sha.$fmt" "$T/headers" || die disposition
50 grep -qF "ETag: \"$sha\"" "$T/headers" || die etag
51 grep -qFx 'Cache-Control: no-cache' "$T/headers" || die cache
52 local mime=application/zip; [ "$fmt" != tar.gz ] || mime=application/gzip
53 grep -qFx "Content-Type: $mime" "$T/headers" || die type
54 "${G[@]}" archive --format="$fmt" --prefix="fixture-$sha/" "$sha" > "$T/want"
55 cmp -s "$T/want" "$T/body" || die "$path body"
56 ok "$path status, type, disposition, cache, etag and archive bytes"
57}
58refuse() { req "$1"; [ "$status" = 404 ] && [ ! -s "$T/body" ] || die "$1 expected empty 404"; ok "NEG $1 empty 404"; }
59for sha in "$head" "$old" "$branch" "$tag"; do
60 for fmt in zip tar.gz; do accept "$sha" "$fmt"; refuse "/commits/${sha:0:39}.$fmt"; done
61done
62refuse "/commits/${head:0:7}.zip"
63for sha in "$dangling" "$blob" 0000000000000000000000000000000000000000 "${head^^}" "${head}0"; do refuse "/commits/$sha.zip"; done
64for suffix in '' .tar .tgz .ZIP .zip. .zip/; do refuse "/commits/$head$suffix"; done
65req "/commits/$head.zip" HEAD
66[ "$status" = 200 ] && [ ! -s "$T/body" ] || die 'HEAD response'
67ok 'HEAD has the same archive headers and no body'
68req /refs/heads/main.zip
69[ "$status" = 200 ] || die 'old branch route'
70"${G[@]}" archive --format=zip --prefix=fixture-main/ "$head" > "$T/want"
71cmp -s "$T/want" "$T/body" || die 'old branch bytes'
72ok 'old /refs/heads/main.zip keeps its branch prefix'
73refuse /refs/heads/missing.zip
74req /archive/main.zip
75[ "$status" = 200 ] && cmp -s "$T/want" "$T/body" || die 'old CGI archive alias'
76ok 'old CGI /archive/main.zip alias stays equal'
77# Mutant: remove reachability check. The same dangling request must now violate the refusal.
78sed '/\[ -n "$visible" \] || notfound/d' "$T/omega-read" > "$T/mutant"
79mv "$T/omega-read" "$T/good"; mv "$T/mutant" "$T/omega-read"
80req "/commits/$dangling.zip"
81[ "$status" = 200 ] && [ -s "$T/body" ] || die 'reachability mutant not detected'
82ok 'NEG reachability mutant exposes hidden commit and fails the refusal oracle'
83echo "pinned archives: $pass pass, 0 fail"