interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / dl / tests / http-check.sh
| 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. |
| 8 | set -u |
| 9 | PORT=${1:-18480} |
| 10 | W=$(cd "$(dirname "$0")/../.." && pwd) |
| 11 | EV=${FORGE_TEST_EVIDENCE:-$W/dl/evidence} |
| 12 | U=http://127.0.0.1:$PORT |
| 13 | CC=z631r2JJiVT8it4tST7RK24hpowi |
| 14 | G="git --git-dir=${FORGE_TEST_STORAGE:-$HOME/.radicle/storage}/$CC" |
| 15 | T=$(mktemp -d /tmp/forge-dlhttp.XXXXXX) |
| 16 | pass=0; fail=0 |
| 17 | ok() { pass=$((pass+1)); echo "PASS $*"; } |
| 18 | bad() { fail=$((fail+1)); echo "FAIL $*"; } |
| 19 | chk() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: got '$1' want '$2'"; fi; } |
| 20 | hdr() { tr -d '\r' < "$1" | sed -n "s/^$2: //Ip" | head -n1; } |
| 21 | st() { 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 |
| 23 | get() { |
| 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 | } |
| 30 | body() { { echo; echo "[body]"; cat "$B"; } >> "$EV/http-$1.txt"; } |
| 31 | rm -f "$EV"/http-*.txt |
| 32 | MAIN=$($G rev-parse refs/heads/main) |
| 33 | OLDCC=$($G rev-list --skip=3 -n1 "$MAIN") |
| 34 | get zip /forge/ /drakestapleton/cuda-crack/archive/refs/heads/main.zip |
| 35 | chk "$(st $H)" 200 "GET main.zip" |
| 36 | chk "$(hdr $H Content-Type)" application/zip "zip content type" |
| 37 | chk "$(hdr $H Content-Disposition)" "attachment; filename=cuda-crack-main.zip" "zip disposition" |
| 38 | chk "$(hdr $H ETag)" "\"$MAIN\"" "zip ETag" |
| 39 | chk "$(hdr $H Cache-Control)" "public, max-age=300" "zip Cache-Control" |
| 40 | $G archive --format=zip --prefix=cuda-crack-main/ "$MAIN" > "$T/ref.zip" |
| 41 | cmp -s "$B" "$T/ref.zip"; chk $? 0 "zip over HTTP byte-identical to git archive" |
| 42 | unzip -tq "$B" > /dev/null; chk $? 0 "unzip -t" |
| 43 | get tgz / /drakestapleton/cuda-crack/archive/refs/heads/main.tar.gz |
| 44 | chk "$(st $H)" 200 "GET main.tar.gz" |
| 45 | chk "$(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" |
| 47 | cmp -s "$B" "$T/ref.tgz"; chk $? 0 "tar.gz over HTTP byte-identical to git archive" |
| 48 | tar -tzf "$B" > /dev/null; chk $? 0 "tar -tzf" |
| 49 | if [ "${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" |
| 57 | fi |
| 58 | get sha / "/drakestapleton/cuda-crack/archive/$MAIN.zip" |
| 59 | chk "$(st $H)" 302 "archive/<sha of main>.zip -> 302" |
| 60 | hdr $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" |
| 62 | get oldsha / "/drakestapleton/cuda-crack/archive/$OLDCC.tar.gz" |
| 63 | chk "$(st $H)" 404 "NEG: reachable old commit -> 404 (no build)" |
| 64 | get 304 / /drakestapleton/cuda-crack/archive/refs/heads/main.zip -H "If-None-Match: \"$MAIN\"" |
| 65 | chk "$(st $H)" 304 "If-None-Match -> 304" |
| 66 | [ ! -s "$B" ]; chk $? 0 "304 has no body" |
| 67 | get 304neg / /drakestapleton/cuda-crack/archive/refs/heads/main.zip -H 'If-None-Match: "nope"' |
| 68 | chk "$(st $H)" 200 "NEG: other ETag -> 200" |
| 69 | get rel /forge/ /drakestapleton/cuda-crack/releases |
| 70 | chk "$(st $H)" 200 "releases page"; body rel |
| 71 | grep -q 'class="empty"' "$B"; chk $? 0 "empty releases state" |
| 72 | grep -q 'href="/forge/drakestapleton/cuda-crack/releases"' "$B"; chk $? 0 "Releases tab link under /forge/" |
| 73 | grep -q "script" "$B"; chk $? 1 "NEG: no script in the page" |
| 74 | get latest / /drakestapleton/cuda-crack/releases/latest |
| 75 | chk "$(st $H)" 404 "NEG: latest without releases -> 404" |
| 76 | get badref / /drakestapleton/cuda-crack/archive/refs/heads/nope.zip |
| 77 | chk "$(st $H)" 404 "NEG: unknown branch -> 404" |
| 78 | get trav / /drakestapleton/cuda-crack/archive/refs/heads/..%2f..%2fx.zip |
| 79 | chk "$(st $H)" 400 "NEG: encoded traversal -> 400" |
| 80 | get dash / /drakestapleton/cuda-crack/archive/--output=x.zip |
| 81 | chk "$(st $H)" 400 "NEG: option injection -> 400" |
| 82 | get rar / /drakestapleton/cuda-crack/archive/refs/heads/main.rar |
| 83 | chk "$(st $H)" 404 "NEG: unknown format -> 404" |
| 84 | get pearl / /drakestapleton/omega-pearl/archive/refs/heads/main.zip |
| 85 | chk "$(st $H)" 404 "NEG: omega-pearl (not listed) -> 404" |
| 86 | get z3g / /drakestapleton/z3gqcJUoA1n9HaHKufZs5FCSGazv5/archive/refs/heads/main.zip |
| 87 | chk "$(st $H)" 404 "NEG: non-allow-listed RID -> 404" |
| 88 | echo "RESULT pass=$pass fail=$fail" |
| 89 | rm -rf "$T" |
| 90 | [ "$fail" -eq 0 ] |