interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / collab / tests / postpath.sh

53 lines · 3374 bytes Raw Blame History
1#!/bin/bash
2# ORACLE: host test driver (bash + curl), not product code.
3# collab/tests/postpath.sh: a POST whose segment after /patches/ or /issues/ is long must not end forged.
4# copost (collab/co9form.om) looks for the end of the id segment with a bounded scan; the bound was 128
5# while the rest of the path can be 4096 bytes, so a segment of 129 bytes or more with no slash was
6# trap 4 (exit 104), with no sign-in. Found in the bound sweep after the review of 486f1cd8.
7# A test forged on PORT (default 18500) with a private data dir reads the real store and allow-list
8# (read-only). Negative control: the same build with the old bound must exit 104 on the 129-byte POST.
9# Usage: collab/tests/postpath.sh (CORES default 14; POSTPATH_PORT; KEEP=1 keeps the temp dir)
10set -u
11H=$(cd "$(dirname "$0")" && pwd)
12export PORT=${POSTPATH_PORT:-18500} CORES=${CORES:-14}
13T=$(mktemp -d /tmp/cppost.XXXXXX)
14PASS=0; FAIL=0; PID=
15ok() { PASS=$((PASS+1)); echo "PASS $*"; }
16bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; }
17check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want $2, got $1"; fi; }
18trap '[ -n "$PID" ] && kill $PID 2>/dev/null; wait 2>/dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT
19if ss -ltn | grep -q "127.0.0.1:$PORT "; then echo "NOT_RUN: port $PORT busy"; exit 3; fi
20R=/drakestapleton/cuda-crack
21start() { # start OUT [SEDX]: build and start a test forged; PID set
22 mkdir -p "$T/data"
23 DATA=$T/data/ SEDX=${2:-} "$H/tbuild.sh" "$1" || return 1
24 FORGE_SOCIAL_DIR=$T/data/ taskset -c "$CORES" nice -n 10 "$1" 2>> "$1.log" &
25 PID=$!
26 for _ in $(seq 50); do curl -s -o /dev/null "http://127.0.0.1:$PORT/explore" && return 0; sleep 0.1; done
27 return 1
28}
29stop() { kill $PID 2> /dev/null; wait $PID 2> /dev/null; PID=; sleep 0.3; }
30seg() { printf '%*s' "$1" '' | tr ' ' a; }
31post() { curl -s -o /dev/null --max-time 10 -w '%{http_code}' -X POST --data x=1 -H "X-Forge-Base: ${2:-/}" "http://127.0.0.1:$PORT$1"; }
32start "$T/forged" || { bad "test forged did not start"; exit 1; }
33check "$(curl -s -o /dev/null -w '%{http_code}' "http://127.0.0.1:$PORT$R/patches")" 200 "fixture: the patches page of cuda-crack"
34for s in patches issues; do
35 for n in 128 129 3000; do
36 check "$(post "$R/$s/$(seg $n)")" 405 "POST $s/<$n bytes, no slash>"
37 done
38 check "$(post "$R/$s/$(seg 129)/compose")" 404 "POST $s/<129 bytes>/compose (not an id)"
39 check "$(post "$R/$s/$(seg 129)" /forge/)" 405 "[/forge/] POST $s/<129 bytes>"
40done
41check "$(curl -s -o /dev/null -w '%{http_code}' "http://127.0.0.1:$PORT/explore")" 200 "server still answers after the long POST paths"
42if kill -0 $PID 2> /dev/null; then ok "server process still running"; else bad "server process is gone"; fi
43stop
44# negative control: the old bound
45start "$T/mut" 's/^while lt e n bound 4096$/while lt e n bound 128/' || { bad "mutant did not start"; exit 1; }
46a=$(grep -c '^while lt e n bound 128$' "$T/forged.om"); b=$(grep -c '^while lt e n bound 128$' "$T/mut.om")
47[ "$b" = "$((a + 1))" ] && ok "mutant: one scan back at bound 128" || bad "mutant: scans at bound 128: $a, then $b (want one more)"
48check "$(post "$R/patches/$(seg 128)")" 405 "mutant still answers a 128-byte segment"
49post "$R/patches/$(seg 129)" > /dev/null
50wait $PID 2> /dev/null; rc=$?; PID=
51check "$rc" 104 "NEG the old bound exits on the 129-byte POST (trap 4)"
52echo "collab postpath: $PASS passed, $FAIL failed"
53[ "$FAIL" = 0 ]