interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / dl / tests / http-check.sh

90 lines · 5207 bytes Raw Blame History
1#!/usr/bin/env bash
2# dl/tests/http-check.sh PORT: the download routes through a running forged (with dl/ composed),
3# over real HTTP with curl. Transcripts (curl -i headers, bodies for HTML) go to dl/evidence/http-*.txt.
4# Repos: cuda-crack (public, allow-listed). Releases need tags; no public repo has tags today, so the
5# releases pages here show the empty state (the tag/asset paths are covered by check.sh's fixture).
6# CAP=1 (a trial forged with an empty data dir only): the first two requests are the process's two
7# cold builds, so a third cold archive must get 503 + Retry-After while cache hits still get 200.
8set -u
9PORT=${1:-18480}
10W=$(cd "$(dirname "$0")/../.." && pwd)
11EV=${FORGE_TEST_EVIDENCE:-$W/dl/evidence}
12U=http://127.0.0.1:$PORT
13CC=z631r2JJiVT8it4tST7RK24hpowi
14G="git --git-dir=${FORGE_TEST_STORAGE:-$HOME/.radicle/storage}/$CC"
15T=$(mktemp -d /tmp/forge-dlhttp.XXXXXX)
16pass=0; fail=0
17ok() { pass=$((pass+1)); echo "PASS $*"; }
18bad() { fail=$((fail+1)); echo "FAIL $*"; }
19chk() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: got '$1' want '$2'"; fi; }
20hdr() { tr -d '\r' < "$1" | sed -n "s/^$2: //Ip" | head -n1; }
21st() { tr -d '\r' < "$1" | head -n1 | cut -d' ' -f2; }
22# get NAME BASE PATH [curl args...]: headers to $EV/http-NAME.txt, body to $T/NAME.body
23get() {
24 local n=$1 b=$2 p=$3; shift 3
25 { echo "\$ curl -sS -D - -H 'X-Forge-Base: $b' $* '$U$p'"; } > "$EV/http-$n.txt"
26 curl -sS -D "$T/$n.h" -o "$T/$n.body" -H "X-Forge-Base: $b" "$@" "$U$p"
27 cat "$T/$n.h" >> "$EV/http-$n.txt"
28 H=$T/$n.h; B=$T/$n.body
29}
30body() { { echo; echo "[body]"; cat "$B"; } >> "$EV/http-$1.txt"; }
31rm -f "$EV"/http-*.txt
32MAIN=$($G rev-parse refs/heads/main)
33OLDCC=$($G rev-list --skip=3 -n1 "$MAIN")
34get zip /forge/ /drakestapleton/cuda-crack/archive/refs/heads/main.zip
35chk "$(st $H)" 200 "GET main.zip"
36chk "$(hdr $H Content-Type)" application/zip "zip content type"
37chk "$(hdr $H Content-Disposition)" "attachment; filename=cuda-crack-main.zip" "zip disposition"
38chk "$(hdr $H ETag)" "\"$MAIN\"" "zip ETag"
39chk "$(hdr $H Cache-Control)" "public, max-age=300" "zip Cache-Control"
40$G archive --format=zip --prefix=cuda-crack-main/ "$MAIN" > "$T/ref.zip"
41cmp -s "$B" "$T/ref.zip"; chk $? 0 "zip over HTTP byte-identical to git archive"
42unzip -tq "$B" > /dev/null; chk $? 0 "unzip -t"
43get tgz / /drakestapleton/cuda-crack/archive/refs/heads/main.tar.gz
44chk "$(st $H)" 200 "GET main.tar.gz"
45chk "$(hdr $H Content-Length)" "$(stat -c %s "$B")" "Content-Length = bytes received"
46$G archive --format=tar.gz --prefix=cuda-crack-main/ "$MAIN" > "$T/ref.tgz"
47cmp -s "$B" "$T/ref.tgz"; chk $? 0 "tar.gz over HTTP byte-identical to git archive"
48tar -tzf "$B" > /dev/null; chk $? 0 "tar -tzf"
49if [ "${CAP:-0}" = 1 ]; then
50 get cap / /drakestapleton/omega-harness/archive/refs/heads/main.zip
51 chk "$(st $H)" 503 "CAP: third cold build within 60 s -> 503"
52 ra=$(hdr $H Retry-After)
53 [ -n "$ra" ] && [ "$ra" -ge 1 ] && [ "$ra" -le 60 ]; chk $? 0 "CAP: Retry-After '$ra' in 1..60"
54 get caphit / /drakestapleton/cuda-crack/archive/refs/heads/main.zip
55 chk "$(st $H)" 200 "CAP NEG: a cache hit is still served"
56 chk "$(hdr $H Retry-After)" "" "CAP NEG: no Retry-After on a 200"
57fi
58get sha / "/drakestapleton/cuda-crack/archive/$MAIN.zip"
59chk "$(st $H)" 302 "archive/<sha of main>.zip -> 302"
60hdr $H Location | grep -q '/drakestapleton/cuda-crack/archive/refs/heads/main.zip$'; chk $? 0 "Location = the branch archive"
61$G merge-base --is-ancestor "$OLDCC" "$MAIN"; chk $? 0 "control: $OLDCC is reachable from main"
62get oldsha / "/drakestapleton/cuda-crack/archive/$OLDCC.tar.gz"
63chk "$(st $H)" 404 "NEG: reachable old commit -> 404 (no build)"
64get 304 / /drakestapleton/cuda-crack/archive/refs/heads/main.zip -H "If-None-Match: \"$MAIN\""
65chk "$(st $H)" 304 "If-None-Match -> 304"
66[ ! -s "$B" ]; chk $? 0 "304 has no body"
67get 304neg / /drakestapleton/cuda-crack/archive/refs/heads/main.zip -H 'If-None-Match: "nope"'
68chk "$(st $H)" 200 "NEG: other ETag -> 200"
69get rel /forge/ /drakestapleton/cuda-crack/releases
70chk "$(st $H)" 200 "releases page"; body rel
71grep -q 'class="empty"' "$B"; chk $? 0 "empty releases state"
72grep -q 'href="/forge/drakestapleton/cuda-crack/releases"' "$B"; chk $? 0 "Releases tab link under /forge/"
73grep -q "script" "$B"; chk $? 1 "NEG: no script in the page"
74get latest / /drakestapleton/cuda-crack/releases/latest
75chk "$(st $H)" 404 "NEG: latest without releases -> 404"
76get badref / /drakestapleton/cuda-crack/archive/refs/heads/nope.zip
77chk "$(st $H)" 404 "NEG: unknown branch -> 404"
78get trav / /drakestapleton/cuda-crack/archive/refs/heads/..%2f..%2fx.zip
79chk "$(st $H)" 400 "NEG: encoded traversal -> 400"
80get dash / /drakestapleton/cuda-crack/archive/--output=x.zip
81chk "$(st $H)" 400 "NEG: option injection -> 400"
82get rar / /drakestapleton/cuda-crack/archive/refs/heads/main.rar
83chk "$(st $H)" 404 "NEG: unknown format -> 404"
84get pearl / /drakestapleton/omega-pearl/archive/refs/heads/main.zip
85chk "$(st $H)" 404 "NEG: omega-pearl (not listed) -> 404"
86get z3g / /drakestapleton/z3gqcJUoA1n9HaHKufZs5FCSGazv5/archive/refs/heads/main.zip
87chk "$(st $H)" 404 "NEG: non-allow-listed RID -> 404"
88echo "RESULT pass=$pass fail=$fail"
89rm -rf "$T"
90[ "$fail" -eq 0 ]