Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-forge/blob/main/tools/bring/tests/run.sh # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `interplane-forge / tools / bring / tests / run.sh` 628 lines ยท 51460 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # tools/bring/tests/run.sh: tests of the interplane tool (TOOL slice) on Linux aarch64. 3 # Builds the tool, the installer generator and the stand-in hub with the pinned omc, then: 4 # bring end to end against tests/standin.om on a private port (with an injected 429 and 409), 5 # the uploaded bytes, both signatures (ssh-keygen -Y verify), the statement, the final lines; 6 # no yes: nothing sent (no request, no process, no connect, no key); 7 # a partial-clone .git (lazy fetch from a counting listener): never read, never fetched; 8 # the secret scan; archive determinism and tar -tvf; strict unpack; get with its sha256 check; 9 # a busy server (503/502/504/429 on get's JSON and archive, 503 on a chunk and the finish POST): 10 # one plain line, 10 seconds, the same request again, no count; other codes stop at once; 11 # the installer generator and the scripts it writes (the same busy rule for their download); 12 # withdraw: the key, the bringer check, the text and the yes before anything is sent, the POST, the 13 # poll until 404; 14 # patch against a 429: at most 3 resends (2, 4, 8 s), then the server's reason and exit 2; 15 # the x86_64 build under qemu (EMULATED); 16 # mutants: each removes one guard and the check that guards it must fail. 17 # Process and network audit uses strace -f (execve, connect): an outside oracle, not part of the tool. 18 # Run once, under the pool lock: 19 # flock ~/handoffs/hive/queen/pool-17.lock taskset -c 17 bash tools/bring/tests/run.sh 20 set -u 21 export TZ=UTC LC_ALL=C 22 cd "$(dirname "$0")/.." 23 BR=$(pwd) 24 OMC=$HOME/work/flux/omega-mv/seed/out/omc 25 PIN=`3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194` 26 [ "$(sha256sum "$OMC" | cut -d' ' -f1)" = "$PIN" ] || { echo "omc is not the pin"; exit 1; } 27 P1=${TOOL_PORT:-19890} # stand-in hub 28 P2=$((P1 + 1)) # counting listener for the partial clone's promisor remote 29 T=$(mktemp -d /tmp/interplane-test.XXXXXX) 30 PASS=0; FAIL=0 31 ok() { PASS=$((PASS+1)); echo "PASS $*"; } 32 bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; } 33 check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want '$2', got '$1'"; fi; } 34 PIDS= 35 stopall() { for p in $PIDS; do kill "$p" 2>/dev/null; wait "$p" 2>/dev/null; done; PIDS=; } 36 trap 'stopall; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT 37 38 # ------------------------------------------------------------------ build 39 bash build.sh linux "$T/out" 2> "$T/build.err" || { echo "BUILD FAILED: $(cat "$T/build.err")"; exit 1; } 40 bash build.sh installer "$T/out" 2>> "$T/build.err" || { echo "BUILD FAILED installer: $(cat "$T/build.err")"; exit 1; } 41 "$OMC" < tests/standin.om > "$T/standin" 2>> "$T/build.err" || { echo "BUILD FAILED standin: $(cat "$T/build.err")"; exit 1; } 42 chmod 755 "$T/standin" 43 IP=$T/out/interplane-linux-aarch64 44 echo "interplane sha256 $(sha256sum "$IP" | cut -d' ' -f1)" 45 check "$("$IP" --version)" "interplane 0.1.1" "--version" 46 47 # srv NAME [count]: a fresh stand-in (or counting listener) folder and process 48 srv() { 49 mkdir -p "$T/$1" 50 "$T/standin" "${3:-serve}" "$2" "$T/$1" & PIDS="$PIDS $!" 51 for _ in $(seq 50); do (exec 3<>/dev/tcp/127.0.0.1/"$2") 2>/dev/null && break; sleep 0.1; done 52 rm -f "$T/$1/conns" "$T/$1/log" 53 } 54 ls -d /tmp/interplane-tool-* 2>/dev/null | sort > "$T/tmp.before" 55 srv hub "$P1" 56 srv lazy "$P2" count 57 # a probe connection proves the counting listener counts (positive control) 58 (exec 3<>/dev/tcp/127.0.0.1/"$P2") 2>/dev/null 59 sleep 0.2 60 check "$(wc -l < "$T/lazy/conns" 2>/dev/null | tr -d ' ')" 1 "the counting listener counts a connection (control)" 61 rm -f "$T/lazy/conns" 62 63 # run DIR HOME ANSWER TRACE CMD...: the tool with a terminal (script); ANSWER is a printf format typed there; 64 # strace -f writes execve and connect calls to TRACE 65 run() { 66 local d=$1 h=$2 a=$3 tr=$4; shift 4 67 (cd "$d" && printf "$a" | HOME=$h INTERPLANE_BASE=http://127.0.0.1:$P1 timeout "${RUNTO:-120}" \ 68 script -qec "strace -f -qq -e trace=execve,connect,openat -o $tr $*" /dev/null) 69 } 70 # exe TRACE: every program the run started, one per line (the tool itself first) 71 exe() { grep -o 'execve("[^"]*"' "$1" | cut -d'"' -f2; } 72 conns() { grep -c 'connect(' "$1"; } 73 74 mkproj() { # a small project with a sub folder, an executable and a 150 KB file (4 chunks) 75 mkdir -p "$1/sub/deep" 76 echo "# demo" > "$1/README.md" 77 printf '#!/bin/sh\necho hi\n' > "$1/run.sh"; chmod 755 "$1/run.sh" 78 head -c 150000 /dev/urandom > "$1/sub/data.bin" 79 echo "fn main to int" > "$1/sub/deep/a.om" 80 echo "password: use a long one" > "$1/notes.txt" 81 } 82 83 # ------------------------------------------------------------------ no yes: nothing sent 84 mkproj "$T/p0" 85 for ans in 'no\n' 'YES\n' 'yes \n' ' yes\n' 'y\n' '\n' 'yess\n' ''; do 86 H=$T/h0; rm -rf "$H"; mkdir -p "$H"; rm -f "$T/hub/log" "$T/hub/conns" 87 out=$(run "$T/p0" "$H" "$ans" "$T/st0" "$IP" bring 2>&1); st=$? 88 [ "$st" = 1 ] && case $out in *"Nothing sent."*) true;; *) false;; esac \ 89 && [ ! -e "$T/hub/conns" ] && [ "$(exe "$T/st0")" = "$IP" ] && [ "$(conns "$T/st0")" = 0 ] \ 90 && [ ! -e "$H/.interplane" ] \ 91 && ok "answer '$ans': exit 1, Nothing sent., no connection to the hub, no process started, no connect, no key" \ 92 || bad "answer '$ans': status $st, hub conns $(cat "$T/hub/conns" 2>/dev/null | wc -l), exec '$(exe "$T/st0" | tr '\n' ' ')', connects $(conns "$T/st0")" 93 done 94 case $out in *"Type yes to publish it, anything else to stop:"*) ok "the consent text is shown";; *) bad "consent text missing";; esac 95 # stdin is not the terminal: a yes piped to stdin (not to /dev/tty) is not consent 96 rm -f "$T/hub/conns" 97 (cd "$T/p0" && echo yes | HOME=$T/h0 INTERPLANE_BASE=http://127.0.0.1:$P1 setsid "$IP" bring > "$T/notty.out" 2>&1); st=$? 98 [ "$st" = 1 ] && [ ! -e "$T/hub/conns" ] && ok "without a terminal, yes on stdin sends nothing (status $st)" || bad "no-tty: status $st" 99 100 # ------------------------------------------------------------------ bring end to end 101 H=$T/h1; mkdir -p "$H"; rm -f "$T/hub/"*; touch "$T/hub/inject" 102 out=$(run "$T/p0" "$H" 'yes\n' "$T/st1" "$IP" bring 2>&1); st=$? 103 echo "$out" > "$T/bring1.raw" 104 tr -d '\r' < "$T/bring1.raw" > "$T/bring1.out" 105 check "$st" 0 "bring exits 0" 106 check "$(sed -n 's/^\(GET\|POST\) \([^ ]*\) .*/\1 \2/p' "$T/hub/log" | head -3 | tr '\n' ',')" "GET /login,POST /login,GET /open/," "sign-in, then the write csrf" 107 check "$(grep -c '^POST /open/up ' "$T/hub/log")" 8 "chunk posts: 4 chunks + one 429 retry + two after the 409 rewind + finish" 108 pages=$(grep -c '^GET /open/up/[0-9a-f]\{64\}\.json ' "$T/hub/log") 109 check "$pages" 2 "status polled until stored (queued once, then stored)" 110 exe "$T/st1" | sort | uniq -c | awk '{print $2}' | sort > "$T/exe1" 111 check "$(tr '\n' ' ' < "$T/exe1")" "$IP /usr/bin/curl /usr/bin/ssh-keygen " "the only programs started: the tool, curl, ssh-keygen" 112 nl=$(grep -n 'openat(AT_FDCWD, "/dev/tty"' "$T/st1" | head -1 | cut -d: -f1) 113 fx=$(grep -n 'execve("/usr/bin/\(curl\|ssh-keygen\)"' "$T/st1" | head -1 | cut -d: -f1) 114 [ -n "$nl" ] && [ -n "$fx" ] && [ "$fx" -gt "$nl" ] && ok "no program starts before /dev/tty is read (tty line $nl, first exec line $fx)" || bad "exec before tty: tty $nl exec $fx" 115 bad_conn=$(grep 'connect(' "$T/st1" | grep -v "sin_port=htons($P1)" | grep -v 'sa_family=AF_UNIX' | grep -c 'sin_port\|sin6_port') 116 check "$bad_conn" 0 "every network connect is to the hub's port $P1" 117 hub_conn=$(grep 'connect(' "$T/st1" | grep -c "sin_port=htons($P1)") 118 [ "$hub_conn" -gt 0 ] && ok "curl's connects to the hub are seen by the trace ($hub_conn), so the check above is not empty" || bad "no hub connect traced" 119 # the uploaded bytes are the archive, and its sha is the one in the statement 120 : > "$T/up.tar" 121 while read -r l; do 122 pad=$(( (4 - ${#l} % 4) % 4 )); p=$(printf '%*s' $pad '' | tr ' ' '=') 123 printf '%s%s' "$l" "$p" | basenc --base64url -d >> "$T/up.tar" 124 done < "$T/hub/up.b64" 125 (cd "$T" && "$IP" pack p0 "$T/p0.tar" > /dev/null) 126 cmp -s "$T/up.tar" "$T/p0.tar" && ok "uploaded bytes equal the archive of the folder ($(wc -c < "$T/up.tar") bytes)" || bad "uploaded bytes differ from pack" 127 SHA=$(sha256sum < "$T/up.tar" | cut -d' ' -f1) 128 grep -q "^GET /open/up/$SHA.json " "$T/hub/log" && ok "status asked for the archive's sha256" || bad "status sha" 129 # form fields: decode with printf %b after %XX -> \xXX 130 fdec() { printf '%b' "$(sed 's/+/ /g; s/%\([0-9A-Fa-f][0-9A-Fa-f]\)/\\x\1/g')"; } 131 field() { tr '&' '\n' < "$1" | sed -n "s/^$2=//p" | fdec; } 132 FF=$T/hub/finish.form 133 check "$(field "$FF" sha)" "$SHA" "finish sha" 134 check "$(field "$FF" files)" 5 "finish files (README.md notes.txt run.sh sub/data.bin sub/deep/a.om)" 135 check "$(field "$FF" bytes)" "$(wc -c < "$T/up.tar" | tr -d ' ')" "finish bytes" 136 check "$(field "$FF" name)" p0 "finish name" 137 check "$(field "$FF" consent)" yes "finish consent" 138 printf 'interplane-bring 1\nsha256 %s\nfiles 5\nbytes %s\nname p0\n' "$SHA" "$(wc -c < "$T/up.tar" | tr -d ' ')" > "$T/stmt.expect" 139 field "$FF" sig > "$T/stmt.sig" 140 echo "interplane $(cut -d' ' -f1,2 "$H/.interplane/key.pub")" > "$T/allowed" 141 ssh-keygen -Y verify -f "$T/allowed" -I interplane -n interplane-bring -s "$T/stmt.sig" < "$T/stmt.expect" > /dev/null 2>&1 \ 142 && ok "the statement signature verifies (namespace interplane-bring) over the exact statement bytes" || bad "statement signature" 143 printf 'interplane-bring 1\nsha256 %s\nfiles 6\nbytes 1\nname p0\n' "$SHA" > "$T/stmt.bad" 144 ssh-keygen -Y verify -f "$T/allowed" -I interplane -n interplane-bring -s "$T/stmt.sig" < "$T/stmt.bad" > /dev/null 2>&1 \ 145 && bad "a changed statement still verifies" || ok "a changed statement does not verify (control)" 146 LF=$T/hub/login.form 147 check "$(field "$LF" csrf)" "$(printf 'a%.0s' $(seq 64))" "login csrf from the login page" 148 check "$(field "$LF" nonce):$(field "$LF" ts)" "`00112233445566778899aabbccddeeff`:`1762848000`" "login nonce and ts" 149 field "$LF" sig > "$T/login.sig" 150 printf 'interplane-forge-login:`00112233445566778899aabbccddeeff`:`1762848000`' > "$T/chal" 151 ssh-keygen -Y verify -f "$T/allowed" -I interplane -n interplane-forge -s "$T/login.sig" < "$T/chal" > /dev/null 2>&1 \ 152 && ok "the sign-in signature verifies (namespace interplane-forge)" || bad "sign-in signature" 153 did=$(field "$LF" did) 154 case $did in did:key:z6Mk*) ok "did is did:key:z6Mk... ($did)";; *) bad "did '$did'";; esac 155 check "$(stat -c %a "$H/.interplane/key"):$(stat -c %a "$H/.interplane")" "600:700" "key mode 0600 in a 0700 folder" 156 grep -q 'Your project page: http://127.0.0.1:'"$P1"'/open/`z3gqcJUoA1n9HaHKufZs5FCSGazv5`$' "$T/bring1.out" && ok "final line: the page address" || bad "page line" 157 grep -q '^Developer details: Radicle ID rad:`z3gqcJUoA1n9HaHKufZs5FCSGazv5`, rad clone rad:`z3gqcJUoA1n9HaHKufZs5FCSGazv5`$' "$T/bring1.out" && ok "final line: developer details" || bad "developer line" 158 tb=$(wc -c < "$T/up.tar" | tr -d ' ') 159 tr '\r' '\n' < "$T/bring1.raw" | grep -qx "Sent $tb of $tb bytes" && ok "progress line reaches the total ($tb bytes)" || bad "progress" 160 # the same key is used again (made once) 161 k1=$(cat "$H/.interplane/key.pub"); rm -f "$T/hub/"* 162 out=$(run "$T/p0" "$H" 'yes\n' "$T/st2" "$IP" bring 2>&1); st=$? 163 check "$st:$(cat "$H/.interplane/key.pub")" "0:$k1" "a second bring reuses the key" 164 check "$(exe "$T/st2" | grep -c 'ssh-keygen')" 2 "second bring: two ssh-keygen runs (sign twice, no keygen)" 165 # a refusal ends with the reason and status 1 166 rm -f "$T/hub/"*; echo "the archive holds a private key" > "$T/hub/refuse" 167 out=$(run "$T/p0" "$H" 'yes\n' "$T/st3" "$IP" bring 2>&1); st=$? 168 case "$st:$out" in "1:"*"refused the project: refused: the archive holds a private key"*) ok "a refused upload ends with the reason, status 1";; *) bad "refusal: $st $out";; esac 169 rm -f "$T/hub/refuse" 170 # no temp folder is left behind by any of the runs 171 ls -d /tmp/interplane-tool-* 2>/dev/null | sort > "$T/tmp.after" 172 check "$(comm -13 "$T/tmp.before" "$T/tmp.after" | wc -l | tr -d ' ')" 0 "temp folders removed" 173 174 # ------------------------------------------------------------------ partial clone (incident 2026-11-11) 175 PC=$T/pc 176 mkdir -p "$PC"; mkproj "$PC" 177 git -C "$PC" init -q 178 git -C "$PC" config extensions.partialclone origin 179 git -C "$PC" config remote.origin.promisor true 180 git -C "$PC" config remote.origin.url "http://127.0.0.1:$P2/x" 181 git -C "$PC" config remote.origin.partialclonefilter blob:none 182 git -C "$PC" config core.repositoryformatversion 1 183 rm -f "$T/lazy/conns" "$T/hub/"* 184 H=$T/h2; mkdir -p "$H" 185 out=$(run "$T" "$H" "" "$T/st4" "$IP" pack pc "$T/pc.tar" 2>&1); st=$? 186 check "$st" 0 "pack of a partial clone" 187 case $out in *"Left out: .git: version-control metadata"*) ok "the partial clone's .git is listed as left out";; *) bad ".git not listed";; esac 188 tar -tf "$T/pc.tar" | grep -q '^\.git' && bad ".git in the archive" || ok "no .git entry in the archive ($(tar -tf "$T/pc.tar" | wc -l) entries)" 189 check "$(exe "$T/st4" | tr '\n' ' ')" "$IP " "pack starts no process (no git)" 190 check "$(conns "$T/st4")" 0 "pack makes no connect" 191 grep -q 'openat([^)]*\.git' "$T/st4" && bad "pack opened something under .git" || ok "pack never opens anything under .git" 192 for ans in 'no\n' ''; do 193 out=$(run "$PC" "$H" "$ans" "$T/st5" "$IP" bring 2>&1); st=$? 194 [ "$st" = 1 ] && [ "$(exe "$T/st5")" = "$IP" ] && [ "$(conns "$T/st5")" = 0 ] && ! grep -q 'openat([^)]*\.git/' "$T/st5" \ 195 && ok "partial clone, answer '$ans': status 1, no process, no connect, .git never opened" \ 196 || bad "partial clone no-yes '$ans': $st exec '$(exe "$T/st5" | tr '\n' ' ')' connects $(conns "$T/st5")" 197 done 198 out=$(run "$PC" "$H" 'yes\n' "$T/st6" "$IP" bring 2>&1); st=$? 199 check "$st" 0 "partial clone, yes: bring completes" 200 check "$(exe "$T/st6" | sort -u | tr '\n' ' ')" "$IP /usr/bin/curl /usr/bin/ssh-keygen " "partial clone, yes: only the tool, curl, ssh-keygen" 201 check "$(grep 'connect(' "$T/st6" | grep -c "sin_port=htons($P2)")" 0 "no connect to the promisor port $P2" 202 [ -e "$T/lazy/conns" ] && bad "counting listener has $(wc -l < "$T/lazy/conns") connections" || ok "counting listener file absent: nothing connected to $P2" 203 # control: git itself does fetch lazily from that listener 204 git -C "$PC" fetch -q origin > /dev/null 2>&1 205 [ -s "$T/lazy/conns" ] && ok "control: git fetch in that folder connects to the listener ($(wc -l < "$T/lazy/conns"))" || bad "control: git did not connect (listener does not prove absence)" 206 rm -f "$T/lazy/conns" 207 208 # the walk leaves out .git in any letter case, as a folder or as a file 209 GC=$T/gcase; mkdir -p "$GC/sub/.GIT/hooks" "$GC/b"; echo x > "$GC/sub/.GIT/hooks/x"; echo "gitdir: /x" > "$GC/b/.Git"; echo keep > "$GC/sub/keep.txt" 210 out=$(cd "$T" && "$IP" pack gcase "$T/gcase.tar" 2>&1) 211 echo "$out" | grep -qx "Left out: sub/.GIT: version-control metadata" && echo "$out" | grep -qx "Left out: b/.Git: version-control metadata" \ 212 && check "$(tar -tf "$T/gcase.tar" | tr '\n' ' ')" "sub/keep.txt " "pack leaves out sub/.GIT and b/.Git and archives the rest" || bad "case-folded .git not left out: $out" 213 214 # ------------------------------------------------------------------ secret scan 215 S=$T/sec; mkdir -p "$S/keys" "$S/src" 216 echo "# demo" > "$S/README.md" 217 echo "password: use a long one" > "$S/HOWTO.txt" 218 echo "token_count = 5" > "$S/src/tok.py" 219 printf -- '-----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAA\n-----END OPENSSH PRIVATE KEY-----\n' > "$S/notes.txt" 220 echo "const t = 'ghp_abcdefghijklmnopqrstuvwxyz0123456789'" > "$S/src/a.js" 221 echo "AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE" > "$S/src/conf.ini" 222 printf 'DB_PASSWORD = "hunter2hunter2"\n' > "$S/src/db.py" 223 echo "slack xoxb-`1234567890`-abcdefghij" > "$S/src/slack.txt" 224 echo "stripe sk_live_abcdefghijklmnop" > "$S/src/pay.txt" 225 echo "API_KEY=x" > "$S/.env" 226 echo "machine example.com login a password b" > "$S/.netrc" 227 echo "not really a key" > "$S/keys/id_`ed25519`" 228 echo "cert" > "$S/keys/server.pem" 229 head -c 65530 /dev/zero | tr '\0' 'a' > "$S/src/edge.txt"; printf 'ghp_abcdefghijklmnopqrstuvwxyz0123456789\n' >> "$S/src/edge.txt" 230 out=$(cd "$T" && "$IP" pack sec "$T/sec.tar" 2>&1) 231 want="keys/id_`ed25519` keys/server.pem notes.txt src/a.js src/conf.ini src/db.py src/edge.txt src/pay.txt src/slack.txt .env .netrc" 232 for f in $want; do 233 echo "$out" | grep -qx "Left out: $f: likely secret (name or content)" && ok "scan lists $f" || bad "scan did not list $f" 234 tar -tf "$T/sec.tar" | grep -qx "$f" && bad "$f is in the archive" || true 235 done 236 check "$(tar -tf "$T/sec.tar" | tr '\n' ' ')" "HOWTO.txt README.md src/tok.py " "only the clean files are archived" 237 grep -a -c 'PRIVATE KEY\|ghp_\|AKIA\|hunter2' "$T/sec.tar" | grep -qx 0 && ok "no planted secret byte string in the archive" || bad "a planted secret is in the archive" 238 239 # ------------------------------------------------------------------ archive determinism and ustar 240 (cd "$T" && "$IP" pack p0 "$T/d1.tar" > /dev/null && touch -d '2001-02-03 04:05:06' p0/README.md p0/sub/data.bin && "$IP" pack p0 "$T/d2.tar" > /dev/null) 241 cmp -s "$T/d1.tar" "$T/d2.tar" && ok "two archives of the folder are identical (mtime changed between): $(sha256sum < "$T/d1.tar" | cut -c1-16)" || bad "archives differ" 242 tar -tvf "$T/d1.tar" > "$T/tv" 2>&1 && ok "GNU tar -tvf reads the archive" || bad "tar -tvf: $(cat "$T/tv")" 243 check "$(awk '{print $1, $2, $4, $5}' "$T/tv" | sort -u | tr '\n' '|')" "-rw-r--r-- 0/0 1970-01-01 00:00|-rwxr-xr-x 0/0 1970-01-01 00:00|" "modes 0644/0755, uid/gid 0, mtime 0" 244 check "$(awk '{print $6}' "$T/tv" | tr '\n' ' ')" "README.md notes.txt run.sh sub/data.bin sub/deep/a.om " "sorted by path bytes" 245 check "$(awk '{print $1}' "$T/tv" | sed -n 3p)" "-rwxr-xr-x" "exec bit kept on run.sh" 246 check "$(tar -tvf "$T/d1.tar" --numeric-owner | awk '{print $2}' | sort -u)" "0/0" "numeric owner 0/0" 247 check "$(od -An -c -j 257 -N 8 "$T/d1.tar" | tr -s ' ')" " u s t a r \\0 0 0" "ustar magic and version" 248 check "$(tail -c 1024 "$T/d1.tar" | tr -d '\0' | wc -c | tr -d ' ')" 0 "two zero blocks at the end" 249 mkdir -p "$T/x1"; tar -xf "$T/d1.tar" -C "$T/x1" && diff -r --exclude=.git "$T/x1" "$T/p0" > /dev/null && ok "GNU tar extracts the same files" || bad "extract differs" 250 # long paths: 200-byte path split by the prefix rule; a 300-byte path is left out 251 LP=$T/lp; d=$(printf 'd%.0s' $(seq 90)); e=$(printf 'e%.0s' $(seq 90)); mkdir -p "$LP/$d/$e"; echo x > "$LP/$d/$e/file.txt" 252 mkdir -p "$LP/$d/$e/$(printf 'f%.0s' $(seq 120))"; echo y > "$LP/$d/$e/$(printf 'f%.0s' $(seq 120))/g" 253 out=$(cd "$T" && "$IP" pack lp "$T/lp.tar" 2>&1) 254 check "$(tar -tf "$T/lp.tar")" "$d/$e/file.txt" "a 190-byte path is stored with the ustar prefix" 255 echo "$out" | grep -q "path cannot be represented by POSIX ustar" && ok "a path over 255 bytes is listed as left out" || bad "long path not listed" 256 257 # ------------------------------------------------------------------ strict unpack 258 U=$T/un; mkdir -p "$U/src"; echo a > "$U/src/a" 259 (cd "$U/src" && tar --format=ustar -P --transform 's,^,../,' -cf "$U/dotdot.tar" a) 260 (cd "$U/src" && tar --format=ustar -P --transform 's,^,/tmp/,' -cf "$U/abs.tar" a) 261 (cd "$U/src" && tar --format=ustar -P --transform 's,^,x/../../,' -cf "$U/mid.tar" a) 262 (cd "$U/src" && ln -sf /etc/passwd lnk && tar --format=ustar -cf "$U/link.tar" lnk a) 263 for c in dotdot abs mid; do 264 (cd "$U" && "$IP" unpack "$c.tar" "out-$c" > "$U/$c.out" 2>&1); st=$? 265 [ "$st" = 1 ] && [ ! -e "$U/out-$c" ] && [ ! -e "$U/a" ] \ 266 && grep -q "invalid or unsafe POSIX ustar archive" "$U/$c.out" && ok "unpack refuses $c (status 1, nothing created)" || bad "unpack $c: status $st" 267 done 268 # a .git component, any letter case, anywhere in a path (the hub's rule): refused before anything is 269 # written. Each archive holds only the one file (no directory entries), built from its own folder. 270 mkdir -p "$U/g1/.git" "$U/g2/sub/.GIT/hooks"; echo "[core]" > "$U/g1/.git/config"; echo hook > "$U/g2/sub/.GIT/hooks/x" 271 tar --format=ustar -C "$U/g1" -cf "$U/gitcfg.tar" .git/config 272 tar --format=ustar -C "$U/g2" -cf "$U/gitup.tar" sub/.GIT/hooks/x 273 check "$(tar -tf "$U/gitcfg.tar"):$(tar -tf "$U/gitup.tar")" ".git/config:sub/.GIT/hooks/x" "the two .git archives hold what the test says" 274 for c in gitcfg gitup; do 275 (cd "$U" && "$IP" unpack "$c.tar" "out-$c" > "$U/$c.out" 2>&1); st=$? 276 [ "$st" = 1 ] && [ ! -e "$U/out-$c" ] && [ ! -e "$U/.git" ] && [ ! -e "$U/sub" ] \ 277 && grep -q "invalid or unsafe POSIX ustar archive" "$U/$c.out" && ok "unpack refuses $c.tar ($(tar -tf "$U/$c.tar")): status 1, nothing written" || bad "unpack $c: status $st, $(ls -A "$U" | tr '\n' ' ')" 278 done 279 (cd "$U" && "$IP" unpack link.tar out-link > "$U/link.out" 2>&1); st=$? 280 [ "$st" = 0 ] && [ ! -e "$U/out-link/lnk" ] && [ ! -L "$U/out-link/lnk" ] && [ -f "$U/out-link/a" ] && grep -q "Skipped a link" "$U/link.out" \ 281 && ok "a link entry is never created (listed as skipped)" || bad "link entry: $st" 282 mkdir -p "$U/exists"; echo keep > "$U/exists/mine" 283 (cd "$U" && "$IP" unpack "$T/d1.tar" exists > "$U/ex.out" 2>&1); st=$? 284 [ "$st" = 1 ] && [ "$(ls "$U/exists")" = mine ] && [ "$(cat "$U/exists/mine")" = keep ] && ok "unpack refuses an existing folder and leaves it unchanged" || bad "existing folder: $st $(ls "$U/exists")" 285 cp "$T/d1.tar" "$U/trunc.tar"; truncate -s 2000 "$U/trunc.tar" 286 (cd "$U" && "$IP" unpack trunc.tar out-trunc > /dev/null 2>&1); st=$? 287 [ "$st" = 1 ] && [ ! -e "$U/out-trunc" ] && ok "a truncated archive is refused before anything is created" || bad "truncated: $st" 288 289 # ------------------------------------------------------------------ get 290 G=$T/get; mkdir -p "$G" 291 git -C "$BR/../.." archive --format=tar HEAD open > "$T/hub/shelf.tar" 292 gsha=$(sha256sum < "$T/hub/shelf.tar" | cut -d' ' -f1) 293 printf '{"schema":"interplane/open-build/1","rid":"rad:`z3gqcJUoA1n9HaHKufZs5FCSGazv5`","name":"My Project","download":"/open/`z3gqcJUoA1n9HaHKufZs5FCSGazv5`.tar","download_sha256":"%s"}\n' "$gsha" > "$T/hub/shelf.json" 294 out=$(cd "$G" && HOME="$G" INTERPLANE_BASE=http://127.0.0.1:$P1 strace -f -qq -e trace=execve -o "$T/st7" "$IP" get "http://127.0.0.1:$P1/open/`z3gqcJUoA1n9HaHKufZs5FCSGazv5`" 2>&1); st=$? 295 check "$st:$out" "0:Saved in ./my-project" "get by page address" 296 diff -r "$G/my-project/open" "$BR/../../open" > /dev/null && ok "get unpacked the git archive (pax header skipped) byte for byte" || bad "get content differs" 297 check "$(exe "$T/st7" | sort -u | tr '\n' ' ')" "$IP /usr/bin/curl " "get starts only curl" 298 out=$(cd "$G" && HOME="$G" INTERPLANE_BASE=http://127.0.0.1:$P1 "$IP" get rad:`z3gqcJUoA1n9HaHKufZs5FCSGazv5` 2>&1); st=$? 299 check "$st" 1 "get refuses when ./my-project exists" 300 sed -i "s/$gsha/$(printf '0%.0s' $(seq 64))/" "$T/hub/shelf.json"; rm -rf "$G/my-project" 301 out=$(cd "$G" && HOME="$G" INTERPLANE_BASE=http://127.0.0.1:$P1 "$IP" get `z3gqcJUoA1n9HaHKufZs5FCSGazv5` 2>&1); st=$? 302 [ "$st" = 1 ] && [ ! -e "$G/my-project" ] && case $out in *"does not match its published SHA-256"*) true;; *) false;; esac \ 303 && ok "get refuses a sha256 mismatch and unpacks nothing" || bad "sha mismatch: $st $out" 304 cp "$T/hub/shelf.json" "$T/shelf-bad.json"; cp "$T/hub/shelf.tar" "$T/shelf.tar" 305 # get: a download holding sub/.GIT/hooks/x, with its correct sha256, is refused and nothing is written 306 cp "$U/gitup.tar" "$T/hub/shelf.tar" 307 printf '{"name":"My Project","download":"/open/`z3gqcJUoA1n9HaHKufZs5FCSGazv5`.tar","download_sha256":"%s"}\n' "$(sha256sum < "$U/gitup.tar" | cut -d' ' -f1)" > "$T/hub/shelf.json" 308 out=$(cd "$G" && HOME="$G" INTERPLANE_BASE=http://127.0.0.1:$P1 "$IP" get `z3gqcJUoA1n9HaHKufZs5FCSGazv5` 2>&1); st=$? 309 [ "$st" = 1 ] && [ ! -e "$G/my-project" ] && case $out in *"invalid or unsafe POSIX ustar archive"*) true;; *) false;; esac \ 310 && ok "get refuses a download with a .GIT component (sha256 correct) and writes nothing" || bad "get .git: $st $out" 311 cp "$T/shelf-bad.json" "$T/hub/shelf.json"; cp "$T/shelf.tar" "$T/hub/shelf.tar" 312 out=$(cd "$G" && "$IP" get "../../etc" 2>&1); st=$? 313 check "$st" 1 "get refuses a non-RID argument" 314 INTERPLANE_BASE=http://10.0.0.1 "$IP" get `z3gqcJUoA1n9HaHKufZs5FCSGazv5` > "$T/base.out" 2>&1; st=$? 315 [ "$st" = 1 ] && grep -q "INTERPLANE_BASE must be https" "$T/base.out" && ok "plain http to a non-loopback base is refused" || bad "base check $st" 316 317 # ------------------------------------------------------------------ busy server 318 # forged's cold-build cache answers 503 with Retry-After for up to a minute: get's JSON and archive 319 # GETs wait 10 seconds on 503/502/504/429 and ask again, with no count; other codes stop at once 320 BUSY='The download server is busy; trying again in 10 seconds.' 321 printf '{"schema":"interplane/open-build/1","rid":"rad:`z3gqcJUoA1n9HaHKufZs5FCSGazv5`","name":"My Project","download":"/open/`z3gqcJUoA1n9HaHKufZs5FCSGazv5`.tar","download_sha256":"%s"}\n' "$gsha" > "$T/shelf-good.json" 322 # getbusy TOOL: get into a fresh $G/my-project; output in $T/gb.out, status in st, busy lines in nb 323 getbusy() { 324 rm -rf "$G/my-project" 325 (cd "$G" && HOME="$G" INTERPLANE_BASE=http://127.0.0.1:$P1 timeout 120 "$1" get `z3gqcJUoA1n9HaHKufZs5FCSGazv5` > "$T/gb.out" 2>&1); st=$? 326 nb=$(grep -cx "$BUSY" "$T/gb.out") 327 } 328 cp "$T/shelf-good.json" "$T/hub/shelf.json"; printf 503 > "$T/hub/busyj"; printf 503 > "$T/hub/busyt" 329 SECONDS=0; getbusy "$IP"; el=$SECONDS 330 [ "$st" = 0 ] && [ "$nb" = 2 ] && [ "$el" -ge 20 ] && grep -q "Saved in ./my-project" "$T/gb.out" && diff -r "$G/my-project/open" "$BR/../../open" > /dev/null \ 331 && ok "get waits out a 503 on the JSON and one on the archive (2 busy lines, ${el}s), then saves the checked download" || bad "get busy: $st $nb ${el}s $(cat "$T/gb.out")" 332 cp "$T/shelf-bad.json" "$T/hub/shelf.json"; printf `502504429` > "$T/hub/busyt" 333 getbusy "$IP" 334 [ "$st" = 1 ] && [ "$nb" = 3 ] && [ ! -e "$G/my-project" ] && grep -q "does not match its published SHA-256" "$T/gb.out" \ 335 && ok "get waits out 502, 504 and 429 on the archive, then still refuses a sha256 mismatch" || bad "get busy codes: $st $nb $(cat "$T/gb.out")" 336 cp "$T/shelf-good.json" "$T/hub/shelf.json"; printf '503+' > "$T/hub/busyj" 337 (cd "$G" && HOME="$G" INTERPLANE_BASE=http://127.0.0.1:$P1 exec "$IP" get `z3gqcJUoA1n9HaHKufZs5FCSGazv5` > "$T/gb.out" 2>&1) & gp=$! 338 sleep 25; kill "$gp"; wait "$gp"; st=$? 339 nb=$(grep -cx "$BUSY" "$T/gb.out") 340 [ "$st" = 143 ] && [ "$nb" -ge 3 ] && [ ! -e "$G/my-project" ] && ok "get keeps waiting while the server stays busy (stopped after 25 s: $nb busy lines, nothing saved)" || bad "get busy forever: $st $nb" 341 rm -rf "/tmp/interplane-tool-$gp-"* # the killed run's temp folder 342 rm -f "$T/hub/busyj"; rm -f "$T/hub/shelf.tar" 343 SECONDS=0; getbusy "$IP"; el=$SECONDS 344 [ "$st" = 1 ] && [ "$nb" = 0 ] && [ "$el" -lt 5 ] && [ ! -e "$G/my-project" ] && grep -q "Interplane answered with HTTP 404" "$T/gb.out" \ 345 && ok "get stops at once on a 404 for the archive (status 1, no busy line, nothing saved)" || bad "get 404: $st $nb ${el}s $(cat "$T/gb.out")" 346 rm -f "$T/hub/shelf.json" 347 getbusy "$IP" 348 [ "$st" = 1 ] && [ "$nb" = 0 ] && grep -q "Interplane answered with HTTP 404" "$T/gb.out" && ok "get stops at once on a 404 for the JSON" || bad "get json 404: $st $nb" 349 cp "$T/shelf-good.json" "$T/hub/shelf.json"; cp "$T/shelf.tar" "$T/hub/shelf.tar" 350 # bring: a 503 on a chunk POST and on the finish POST (queue or storage full) waits and sends again 351 printf 503 > "$T/hub/busyp"; printf 503 > "$T/hub/busyf"; rm -f "$T/hub/up.b64" "$T/hub/finish.form"; H=$T/hb; mkdir -p "$H" 352 out=$(run "$T/p0" "$H" 'yes\n' "$T/stb" "$IP" bring 2>&1); st=$? 353 nb=$(printf '%s\n' "$out" | tr '\r' '\n' | grep -cx "$BUSY") 354 [ "$st" = 0 ] && [ "$nb" = 2 ] && [ "$(wc -l < "$T/hub/up.b64")" = 4 ] && [ -s "$T/hub/finish.form" ] && case $out in *"Your project page: "*) true;; *) false;; esac \ 355 && ok "bring waits out a 503 on a chunk and on the finish (2 busy lines) and completes" || bad "bring busy: $st $nb $out" 356 rm -f "$T/hub/busyp" "$T/hub/busyf" 357 # the write gate answers 429 after 30 writes a minute (every chunk counts): a 429 on the finish waits a 358 # second and sends the same finish again, quietly, as the chunk loop does 359 printf 429 > "$T/hub/busyf"; rm -f "$T/hub/finish.form"; H=$T/hb2; mkdir -p "$H" 360 out=$(run "$T/p0" "$H" 'yes\n' "$T/stb2" "$IP" bring 2>&1); st=$? 361 nb=$(printf '%s\n' "$out" | tr '\r' '\n' | grep -cx "$BUSY") 362 [ "$st" = 0 ] && [ "$nb" = 0 ] && [ ! -s "$T/hub/busyf" ] && [ -s "$T/hub/finish.form" ] && case $out in *"Your project page: "*) true;; *) false;; esac \ 363 && ok "bring resends the finish quietly after a 429 and completes" || bad "bring finish 429: $st $nb $out" 364 rm -f "$T/hub/busyf" 365 366 # ------------------------------------------------------------------ withdraw 367 # the shelf row names its bringer; only the computer holding that key can withdraw, and only after a yes 368 WR=`z3gqcJUoA1n9HaHKufZs5FCSGazv5` 369 OTHER=did:key:`z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK` 370 wjson() { printf '{"schema":"interplane/open-build/1","rid":"rad:%s","brought_by":"%s","name":"My Project"}\n' "$WR" "$1" > "$T/hub/shelf.json"; } 371 notjson() { sed -n "s/^\(GET\|POST\) \([^ ]*\) .*/\1 \2/p" "$T/hub/log" 2>/dev/null | grep -vcx "GET /open/$WR.json"; } 372 WQ='Withdrawing takes your project off the Interplane shelf, stops this site serving it and stops the Interplane hub sharing it on Radicle. It cannot remove copies that other computers already fetched: publishing was permanent.' 373 # $T/h1 holds the key that brought p0 above ($did) 374 wjson "$did"; rm -f "$T/hub/log" "$T/hub/withdraw.form" "$T/hub/gone" 375 out=$(run "$T" "$T/h1" 'no\n' "$T/stw1" "$IP" withdraw "http://127.0.0.1:$P1/open/$WR" 2>&1); st=$? 376 [ "$st" = 1 ] && case $out in *"Project: My Project"*"Brought by: $did"*"$WQ"*"Type yes to withdraw it, anything else to stop:"*"Nothing sent."*) true;; *) false;; esac \ 377 && [ "$(notjson)" = 0 ] && [ ! -e "$T/hub/withdraw.form" ] && [ "$(exe "$T/stw1" | grep -c ssh-keygen)" = 0 ] \ 378 && ok "withdraw: name, bringer and what withdrawing does are shown; no yes: only the shelf JSON was read, no sign-in, no POST" || bad "withdraw no: $st $out" 379 wjson "$OTHER"; rm -f "$T/hub/log" 380 out=$(run "$T" "$T/h1" 'yes\n' "$T/stw2" "$IP" withdraw "$WR" 2>&1); st=$? 381 [ "$st" = 1 ] && case $out in *"brought by another key"*) true;; *) false;; esac && case $out in *"Type yes"*) false;; *) true;; esac \ 382 && [ "$(notjson)" = 0 ] && [ ! -e "$T/hub/withdraw.form" ] && ok "withdraw: a project brought by another key is refused before the question; nothing sent" || bad "withdraw other key: $st $out" 383 # DIDs that differ from this key's only at the end: one character short, one character more 384 for bd in "${did%?}" "${did}a"; do 385 wjson "$bd"; rm -f "$T/hub/log" 386 out=$(run "$T" "$T/h1" 'yes\n' "$T/stw2b" "$IP" withdraw "$WR" 2>&1); st=$? 387 [ "$st" = 1 ] && case $out in *"brought by another key"*) true;; *) false;; esac && case $out in *"Type yes"*) false;; *) true;; esac \ 388 && [ "$(notjson)" = 0 ] && [ ! -e "$T/hub/withdraw.form" ] && ok "withdraw: brought_by $((${#bd} - ${#did})) character(s) off at the end is refused before the question" || bad "withdraw end-of-DID '$bd': $st $out" 389 done 390 H=$T/hw0; mkdir -p "$H"; wjson "$did"; rm -f "$T/hub/log" 391 out=$(run "$T" "$H" 'yes\n' "$T/stw3" "$IP" withdraw "rad:$WR" 2>&1); st=$? 392 [ "$st" = 1 ] && case $out in *"only the computer that brought a project can withdraw it"*) true;; *) false;; esac && [ ! -e "$T/hub/log" ] && [ ! -e "$H/.interplane" ] \ 393 && [ "$(exe "$T/stw3" | tr '\n' ' ')" = "$IP " ] && ok "withdraw: no key: refused plainly, no program, no request, no key made" || bad "withdraw no key: $st $out" 394 wjson "$did"; rm -f "$T/hub/log" "$T/hub/withdraw.form" "$T/hub/gone"; printf 503429 > "$T/hub/busyp" 395 out=$(run "$T" "$T/h1" 'yes\n' "$T/stw4" "$IP" withdraw "http://127.0.0.1:$P1/open/$WR/" 2>&1); st=$? 396 WF=$T/hub/withdraw.form 397 [ "$st" = 0 ] && case $out in *"Withdrawn."*) true;; *) false;; esac && [ "$(field "$WF" action) $(field "$WF" rid) $(field "$WF" csrf)" = "withdraw rad:$WR $(printf 'b%.0s' $(seq 64))" ] \ 398 && ok "withdraw: yes: POST /open/ with action=withdraw, rad: and the csrf from GET /open/; Withdrawn." || bad "withdraw yes: $st $out $(cat "$WF" 2>/dev/null)" 399 check "$(sed -n 's/^\(GET\|POST\) \([^ ]*\) .*/\1 \2/p' "$T/hub/log" | tr '\n' ',')" "GET /open/$WR.json,GET /login,POST /login,GET /open/,POST /open/,POST /open/,POST /open/,GET /open/$WR.json,GET /open/$WR.json," \ 400 "withdraw: shelf JSON, sign-in, csrf, the POST (a 503 and a 429 waited out), then the JSON polled until 404" 401 check "$(printf '%s\n' "$out" | tr '\r' '\n' | grep -cx "$BUSY")" 1 "withdraw: one busy line for the 503, none for the 429" 402 rm -f "$T/hub/busyp" "$T/hub/gone" 403 # the hub answers 303 to /login when the session is gone: that is not a withdrawal; the tool says so and stops 404 wjson "$did"; rm -f "$T/hub/log" "$T/hub/withdraw.form" "$T/hub/gone"; touch "$T/hub/signout" 405 out=$(run "$T" "$T/h1" 'yes\n' "$T/stw5" "$IP" withdraw "$WR" 2>&1); st=$? 406 [ "$st" = 1 ] && case $out in *"Interplane signed you out before the withdraw was sent; nothing was withdrawn. Run the line again."*) true;; *) false;; esac \ 407 && case $out in *"Withdrawn."*) false;; *) true;; esac && [ "$(sed -n '$s/^\(POST\) \([^ ]*\) .*/\1 \2/p' "$T/hub/log")" = "POST /open/" ] \ 408 && ok "withdraw: a 303 to /login is reported as signed out (status 1, no poll)" || bad "withdraw signout: $st $out" 409 rm -f "$T/hub/signout" 410 411 # ------------------------------------------------------------------ patch: the write gate's 429 412 # patch sends the same form again at most 3 times on a 429 (after 2, 4 and 8 seconds), then prints the 413 # server's reason in one line and exits 2; other codes stop at once. The stand-in counts the POSTs. 414 G=$T/pg; mkdir -p "$G" 415 gc() { git -c user.name=T -c user.email=t@example.invalid "$@"; } 416 (cd "$G" && git init -q -b main && echo one > a.txt && git add a.txt && gc commit -qm base \ 417 && git update-ref refs/remotes/origin/main HEAD && echo two >> a.txt && gc commit -qam "a: second line") \ 418 || bad "patch: the test repository was not made" 419 GATE='too many writes from this address or key; wait a minute' 420 ptposts() { grep -c '^POST /alice/demo/patches/new ' "$T/hub/log" 2>/dev/null; } 421 # ptrun TRACE [RUNTO]: ${PT:-$IP} patch --yes alice/demo in $G; sets out (no CRs), st and el (seconds) 422 ptrun() { 423 rm -f "$T/hub/log" "$T/hub/patch.form"; local t0=$SECONDS 424 out=$(RUNTO=${2:-60} run "$G" "$T/h1" '' "$1" "${PT:-$IP}" patch --yes alice/demo 2>&1); st=$? 425 el=$((SECONDS - t0)); out=$(printf '%s\n' "$out" | tr -d '\r') 426 } 427 printf '429+' > "$T/hub/busyq"; ptrun "$T/stq1"; n=$(ptposts) 428 [ "$st" = 2 ] && [ "$n" = 4 ] && [ "$el" -ge 14 ] && [ "$el" -le 40 ] && [ ! -e "$T/hub/patch.form" ] \ 429 && [ "$(printf '%s\n' "$out" | grep -c "^interplane: Interplane refused the patch: $GATE\$")" = 1 ] \ 430 && [ "$(printf '%s\n' "$out" | grep -c 'refused\|HTTP')" = 1 ] \ 431 && ok "patch: a server that always answers 429 gets 4 POSTs in ${el}s (waits 2, 4, 8), then one line with its reason, status 2" \ 432 || bad "patch always-429: status $st, $n POSTs, ${el}s, out: $(printf '%s' "$out" | tr '\n' '|')" 433 printf 429 > "$T/hub/busyq"; ptrun "$T/stq2"; n=$(ptposts) 434 [ "$st" = 0 ] && [ "$n" = 2 ] && [ "$el" -ge 2 ] && [ "$(field "$T/hub/patch.form" repo)" = alice/demo ] \ 435 && case $out in *"Patch page: "*"/alice/demo/patches/1"*) true;; *) false;; esac \ 436 && ok "patch: 429 once, then 201: 2 POSTs, the form kept, the patch page printed, status 0" \ 437 || bad "patch 429-then-201: status $st, $n POSTs, ${el}s, out: $(printf '%s' "$out" | tr '\n' '|')" 438 printf 409 > "$T/hub/busyq"; ptrun "$T/stq3"; n=$(ptposts) 439 [ "$st" = 2 ] && [ "$n" = 1 ] && case $out in *"Interplane answered with HTTP 409"*) true;; *) false;; esac \ 440 && ok "patch: another code (409) is not sent again: 1 POST, status 2" || bad "patch 409: status $st, $n POSTs, out: $(printf '%s' "$out" | tr '\n' '|')" 441 rm -f "$T/hub/busyq" 442 443 # ------------------------------------------------------------------ installer 444 I=$T/inst; mkdir -p "$I/bin" "$I/run" 445 cp "$IP" "$I/interplane-linux-aarch64" 446 isha=$(sha256sum < "$IP" | cut -d' ' -f1) 447 cat > "$I/bin/curl" <<'EOF' 448 #!/bin/sh 449 # test stand-in for curl: logs its arguments; answers the first line of $CURL_CODES and drops it (a 450 # line ending in + is answered every time; none left: 200); on 200 copies $CURL_FILE to the -o path, 451 # else writes an error page there; prints the code for -w and exits 0, as curl without -f does 452 echo "$*" >> "$CURL_LOG" 453 code=200 454 if [ -n "${CURL_CODES:-}" ] && [ -s "$CURL_CODES" ]; then 455 code=$(head -n 1 "$CURL_CODES") 456 case $code in *+) code=${code%+};; *) sed -i 1d "$CURL_CODES";; esac 457 fi 458 out= 459 while [ $# -gt 0 ]; do [ "$1" = -o ] && out=$2; shift; done 460 [ -n "$out" ] || exit 22 461 if [ "$code" = 200 ]; then cp "$CURL_FILE" "$out"; else echo "error $code" > "$out"; fi 462 printf '%s' "$code" 463 EOF 464 cat > "$I/bin/sleep" <<'EOF' 465 #!/bin/sh 466 # test stand-in for sleep: logs its argument, then sleeps a tenth of a second 467 echo "$*" >> "$SLEEP_LOG" 468 exec /usr/bin/sleep 0.1 469 EOF 470 chmod 755 "$I/bin/curl" "$I/bin/sleep" 471 printf '0.1.0\nhttps://interplane.io/receipts/#tool-0.1.0\nLinux-aarch64\thttps://interplane.io/drakestapleton/interplane/releases/download/v0.1.0/interplane-linux-aarch64\t%s\nDarwin-arm64\thttps://interplane.io/drakestapleton/interplane/releases/download/v0.1.0/interplane-macos-arm64\t%s\n' "$isha" "$(printf 'b%.0s' $(seq 64))" > "$I/manifest" 472 (cd "$I/run" && "$T/out/installer" < "$I/manifest"); st=$? 473 check "$st:$(ls "$I/run" | tr '\n' ' ')" "0:bring.sh get.sh withdraw.sh " "the generator writes bring.sh, get.sh and withdraw.sh" 474 sh -n "$I/run/bring.sh" && sh -n "$I/run/get.sh" && sh -n "$I/run/withdraw.sh" && ok "the scripts parse (sh -n)" || bad "script syntax" 475 grep -q "Expected SHA-256" "$I/run/bring.sh" && grep -q "Compare with" "$I/run/bring.sh" && grep -q "< /dev/tty" "$I/run/bring.sh" && grep -q "interplane\" get" "$I/run/get.sh" \ 476 && grep -q "interplane\" withdraw \"\$@\" < /dev/tty" "$I/run/withdraw.sh" && cmp -s <(head -n -1 "$I/run/get.sh") <(head -n -1 "$I/run/withdraw.sh") \ 477 && ok "scripts print the fingerprint, where to compare it, and run with stdin from /dev/tty" || bad "script content" 478 out=$(cd "$T/p0" && printf 'no\n' | PATH="$I/bin:$PATH" CURL_FILE="$IP" CURL_LOG="$I/curl.log" HOME="$I" \ 479 script -qec "sh $I/run/bring.sh" /dev/null 2>&1); st=$? 480 case "$st:$out" in "1:"*"Downloaded SHA-256: $isha"*"Expected SHA-256: $isha"*"Compare with: https://interplane.io/receipts/#tool-0.1.0"*"Nothing sent."*) ok "bring.sh: fingerprint shown, matching binary run with the terminal (answered no)";; *) bad "bring.sh match: $st $out";; esac 481 grep -q -- "--proto =https" "$I/curl.log" && ok "bring.sh downloads with curl --proto =https" || bad "curl args: $(cat "$I/curl.log")" 482 cp "$IP" "$I/evil"; printf 'x' >> "$I/evil" 483 out=$(cd "$T/p0" && printf 'yes\n' | PATH="$I/bin:$PATH" CURL_FILE="$I/evil" CURL_LOG="$I/curl.log" HOME="$I" \ 484 script -qec "sh $I/run/bring.sh" /dev/null 2>&1); st=$? 485 case "$st:$out" in "1:"*"Fingerprint mismatch. Nothing was run."*) case $out in *"Name:"*) bad "mismatch still ran the binary";; *) ok "bring.sh refuses a mismatching download and runs nothing";; esac;; *) bad "mismatch: $st $out";; esac 486 ls /tmp/tmp.*/interplane > /dev/null 2>&1 && bad "script left its download" || ok "the script removes its download" 487 # the scripts wait out a busy release server too: 503, 502, 504, 429: one line, sleep 10, ask again 488 # ib SCRIPT CODES ANSWER FILE [TIMEOUT]: bring.sh or get.sh, the stand-in curl answering CODES 489 ib() { 490 rm -f "$I/sleep.log" "$I/curl.log"; rm -rf "$I/tmpd"; mkdir -p "$I/tmpd"; printf "$2" > "$I/codes" 491 out=$(cd "$T/p0" && printf "$3" | PATH="$I/bin:$PATH" CURL_FILE="$4" CURL_LOG="$I/curl.log" CURL_CODES="$I/codes" \ 492 SLEEP_LOG="$I/sleep.log" TMPDIR="$I/tmpd" HOME="$I" timeout "${5:-60}" script -qec "sh $I/run/$1" /dev/null 2>&1); st=$? 493 out=$(printf '%s\n' "$out" | tr -d '\r') 494 nb=$(printf '%s\n' "$out" | grep -cx "$BUSY") 495 } 496 ib bring.sh '503\n503\n' 'no\n' "$IP" 497 case "$st:$nb:$out" in "1:2:"*"Downloaded SHA-256: $isha"*"Expected SHA-256: $isha"*"Nothing sent."*) ok "bring.sh waits out 503 twice (2 busy lines), checks the fingerprint, runs the binary";; *) bad "bring.sh busy: $st $nb $out";; esac 498 check "$(tr '\n' ' ' < "$I/sleep.log"):$(wc -l < "$I/curl.log" | tr -d ' ')" "10 10 :3" "bring.sh sleeps 10 seconds after each busy answer and asks again (3 downloads)" 499 ib get.sh '502\n504\n429\n' 'yes\n' "$I/evil" 500 case "$st:$nb:$out" in "1:3:"*"Fingerprint mismatch. Nothing was run."*) case $out in *"Name:"*|*"Saved in"*) bad "get.sh busy mismatch still ran the binary";; *) ok "get.sh waits out 502, 504 and 429, then still refuses a mismatching download";; esac;; *) bad "get.sh busy codes: $st $nb $out";; esac 501 ib bring.sh '503+\n' 'no\n' "$IP" 3 502 sleep 1 503 [ "$st" = 124 ] && [ "$nb" -ge 3 ] && [ -z "$(ls -A "$I/tmpd")" ] && ! pgrep -f "$I/run/bring.sh" > /dev/null && case $out in *"Downloaded"*) false;; *) true;; esac \ 504 && ok "bring.sh keeps waiting while the server stays busy; a signal stops it and removes its folder ($nb busy lines)" || bad "bring.sh busy forever: $st $nb $(ls -A "$I/tmpd")" 505 SECONDS=0; ib bring.sh '404\n' 'yes\n' "$IP"; el=$SECONDS 506 [ "$st" = 1 ] && [ "$nb" = 0 ] && [ "$el" -lt 5 ] && [ ! -e "$I/sleep.log" ] && [ -z "$(ls -A "$I/tmpd")" ] && case $out in *"The download failed with HTTP 404. Nothing was run."*) true;; *) false;; esac \ 507 && case $out in *"Downloaded"*|*"Name:"*) false;; *) true;; esac && ok "bring.sh stops at once on a 404 (status 1, nothing run)" || bad "bring.sh 404: $st $nb ${el}s $out" 508 for m in 'http://x/a' "https://x/it's" 'https://x/a b' ; do 509 mkdir -p "$I/r2"; rm -f "$I/r2/"* 510 printf '0.1.0\nhttps://interplane.io/r\nLinux-aarch64\t%s\t%s\n' "$m" "$isha" > "$I/m2" 511 (cd "$I/r2" && "$T/out/installer" < "$I/m2" 2> /dev/null); st=$? 512 [ "$st" = 1 ] && [ -z "$(ls "$I/r2")" ] && ok "the generator refuses URL '$m' and leaves no script" || bad "generator accepted '$m'" 513 done 514 printf '0.1.0\nhttps://interplane.io/r\nLinux-aarch64\thttps://a/b\t%s\nLinux-aarch64\thttps://a/c\t%s\n' "$isha" "$isha" > "$I/m3" 515 (cd "$I/r2" && "$T/out/installer" < "$I/m3" 2> /dev/null); st=$? 516 [ "$st" = 1 ] && [ -z "$(ls "$I/r2")" ] && ok "the generator refuses a duplicate target" || bad "duplicate target" 517 printf "0.1.0\nhttps://interplane.io/r\nLinux-aarch64\thttps://a/b\t%s\n" "$(printf 'A%.0s' $(seq 64))" > "$I/m4" 518 (cd "$I/r2" && "$T/out/installer" < "$I/m4" 2> /dev/null); st=$? 519 [ "$st" = 1 ] && ok "the generator refuses a non-lowercase-hex sha256" || bad "uppercase sha accepted" 520 521 # ------------------------------------------------------------------ x86_64 Linux (EMULATED under qemu) 522 if bash build.sh x86linux "$T/out" 2>> "$T/build.err" && command -v qemu-x86_64 > /dev/null; then 523 X=$T/out/interplane-linux-x86_64 524 check "$(qemu-x86_64 "$X" --version)" "interplane 0.1.1" "x86_64 --version (qemu, EMULATED)" 525 (cd "$T" && qemu-x86_64 "$X" pack p0 "$T/x86.tar" > /dev/null 2>&1) 526 cmp -s "$T/x86.tar" "$T/d1.tar" && ok "x86_64 archive equals the aarch64 archive (qemu, EMULATED)" || bad "x86_64 archive differs" 527 (cd "$T" && qemu-x86_64 "$X" pack sec "$T/x86sec.tar" > /dev/null 2>&1) 528 cmp -s "$T/x86sec.tar" "$T/sec.tar" && ok "x86_64 secret scan gives the same archive (qemu, EMULATED)" || bad "x86_64 scan differs" 529 else 530 bad "x86_64 build failed: $(tail -1 "$T/build.err")" 531 fi 532 533 # ------------------------------------------------------------------ mutants 534 # subst FILE 'old=>new' ('|' is a newline): replace the one occurrence of old 535 subst() { 536 python3 -I - "$1" "$2" <<'EOF' 537 import sys 538 s = open(sys.argv[1]).read() 539 old, new = sys.argv[2].split('=>') 540 old = old.replace('|', '\n'); new = new.replace('|', '\n') 541 assert s.count(old) == 1, (old, s.count(old)) 542 open(sys.argv[1], 'w').write(s.replace(old, new)) 543 EOF 544 } 545 # mut NAME FILE 'old=>new': build the tool with one guard removed 546 mut() { 547 rm -rf "$T/m"; mkdir -p "$T/m"; cp -r "$BR/src" "$BR/build.sh" "$T/m/" 548 subst "$T/m/src/$2" "$3" && (cd "$T/m" && bash build.sh linux "$T/m/out" 2>> "$T/build.err") && M=$T/m/out/interplane-linux-aarch64 549 } 550 M= 551 mut consent 90main.om 'ret and ok and eq n 3 beq a tyes=>ret true' && { 552 rm -f "$T/hub/"*; H=$T/hm1; mkdir -p "$H" 553 run "$T/p0" "$H" 'no\n' "$T/stm" "$M" bring > /dev/null 2>&1 554 [ -s "$T/hub/log" ] && ok "MUTANT without the exact-yes check sends on 'no' (the check is what stops it)" || bad "mutant consent sent nothing"; } || bad "mutant consent did not build" 555 mut scan 20walk.om 'if assignhit b i|ret true|end|end|ret false=>end|ret false' && { 556 (cd "$T" && "$M" pack sec "$T/msec.tar" > /dev/null 2>&1) 557 tar -tf "$T/msec.tar" | grep -qx src/db.py && ok "MUTANT without the assignment scan archives src/db.py" || bad "mutant scan still left db.py out"; } || bad "mutant scan did not build" 558 mut keyblock 20walk.om 'if or bat b i tpriv bat b i tgh=>if bat b i tgh' && { 559 (cd "$T" && "$M" pack sec "$T/msec2.tar" > /dev/null 2>&1) 560 tar -tf "$T/msec2.tar" | grep -qx notes.txt && ok "MUTANT without the private-key scan archives notes.txt" || bad "mutant keyblock still left notes.txt out"; } || bad "mutant keyblock did not build" 561 mut git 20walk.om 'if isgit nm=>if beq nm tdotdot' && { 562 (cd "$T" && strace -f -qq -e trace=execve,connect -o "$T/stm2" "$M" pack pc "$T/mpc.tar" > /dev/null 2>&1) 563 tar -tf "$T/mpc.tar" | grep -q '^\.git/' && ok "MUTANT without the .git rule archives the partial clone's .git" || bad "mutant git left .git out"; } || bad "mutant git did not build" 564 mut dotdot 30tar.om 'if or beq part p start n tdot beq part p start n tdotdot=>if beq part p start n tdot' && { 565 rm -rf "$T/mdd"; mkdir -p "$T/mdd/w" 566 (cd "$T/mdd/w" && "$M" unpack "$U/dotdot.tar" o > /dev/null 2>&1) 567 [ -e "$T/mdd/w/a" ] && ok "MUTANT without the '..' check writes outside the folder" || bad "mutant dotdot wrote nothing outside"; } || bad "mutant dotdot did not build" 568 mut gitcomp 30tar.om 'if isgit part p start n|ret false|end|=>' && { 569 rm -rf "$T/mgc"; mkdir -p "$T/mgc" 570 (cd "$T/mgc" && "$M" unpack "$U/gitcfg.tar" o > /dev/null 2>&1) 571 [ -f "$T/mgc/o/.git/config" ] && ok "MUTANT without the .git component check writes o/.git/config" || bad "mutant gitcomp wrote nothing"; } || bad "mutant gitcomp did not build" 572 mut exist 90main.om 'r = pl_mkdir part folder 0 fnl 448|if ne r 0|die texists|end=>r = pl_mkdir part folder 0 fnl 448' && { 573 rm -rf "$T/mex"; mkdir -p "$T/mex/exists"; echo keep > "$T/mex/exists/mine" 574 (cd "$T/mex" && "$M" unpack "$T/d1.tar" exists > /dev/null 2>&1) 575 [ -e "$T/mex/exists/README.md" ] && ok "MUTANT without the existing-folder check writes into it" || bad "mutant exist wrote nothing"; } || bad "mutant exist did not build" 576 mut sort 20walk.om 'while lt w get gcount 0 bound 64=>while lt w 0 bound 64' && { 577 (cd "$T" && "$M" pack p0 "$T/msort.tar" > /dev/null 2>&1) 578 [ "$(tar -tf "$T/msort.tar" | tr '\n' ' ')" != "README.md notes.txt run.sh sub/data.bin sub/deep/a.om " ] && ok "MUTANT without the sort archives in directory order" || bad "mutant sort still sorted"; } || bad "mutant sort did not build" 579 mut retry 40net.om 'if eq c 429|pl_sleep|continue|end=>' && { 580 rm -f "$T/hub/"*; touch "$T/hub/inject"; H=$T/hm2; mkdir -p "$H" 581 run "$T/p0" "$H" 'yes\n' "$T/stm3" "$M" bring > /dev/null 2>&1; st=$? 582 [ "$st" != 0 ] && ok "MUTANT that gives up on 429 fails the injected-429 bring (status $st)" || bad "mutant retry still succeeded"; } || bad "mutant retry did not build" 583 mut sha 40net.om 'if not beq h want|die tshabad|end=>' && { 584 rm -rf "$G/my-project"; cp "$T/shelf-bad.json" "$T/hub/shelf.json"; cp "$T/shelf.tar" "$T/hub/shelf.tar" 585 (cd "$G" && HOME="$G" INTERPLANE_BASE=http://127.0.0.1:$P1 "$M" get `z3gqcJUoA1n9HaHKufZs5FCSGazv5` > /dev/null 2>&1) 586 [ -d "$G/my-project" ] && ok "MUTANT without the sha256 check unpacks a mismatching download" || bad "mutant sha unpacked nothing"; } || bad "mutant sha did not build" 587 mut busy 40net.om 'if not busy c=>if true' && { 588 cp "$T/shelf-good.json" "$T/hub/shelf.json"; cp "$T/shelf.tar" "$T/hub/shelf.tar"; printf 503 > "$T/hub/busyj"; printf 503 > "$T/hub/busyt" 589 getbusy "$M"; rm -f "$T/hub/busyj" "$T/hub/busyt" 590 [ "$st" != 0 ] && [ ! -e "$G/my-project" ] && ok "MUTANT get that gives up on a busy server fails the 503 get (status $st)" || bad "mutant busy still saved"; } || bad "mutant busy did not build" 591 # the installer generator whose scripts give up on a busy server: its bring.sh fails the 503-twice case 592 rm -rf "$T/mi"; mkdir -p "$T/mi"; cp "$BR/installer.om" "$T/mi/" 593 subst "$T/mi/installer.om" 'sleep 10;;=>exit 1;;' && "$OMC" < "$T/mi/installer.om" > "$T/mi/installer" 2>> "$T/build.err" && chmod 755 "$T/mi/installer" \ 594 && rm -f "$I/run/"* && (cd "$I/run" && "$T/mi/installer" < "$I/manifest") && { 595 ib bring.sh '503\n503\n' 'no\n' "$IP" 596 case $out in *"Downloaded SHA-256"*) bad "mutant installer still downloaded after a 503";; *) ok "MUTANT installer whose scripts give up on 503 fails the 503-twice case (status $st)";; esac; } || bad "mutant installer did not build" 597 mut fin429 40net.om 'while or eq c 503 eq c 429 bound=>while eq c 503 bound' && { 598 printf 429 > "$T/hub/busyf"; H=$T/hm4; mkdir -p "$H" 599 run "$T/p0" "$H" 'yes\n' "$T/stm4" "$M" bring > /dev/null 2>&1; st=$?; rm -f "$T/hub/busyf" 600 [ "$st" != 0 ] && ok "MUTANT without the finish 429 resend fails the bring after the whole upload (status $st)" || bad "mutant fin429 still succeeded"; } || bad "mutant fin429 did not build" 601 mut bringer 40net.om 'if not beq part by 0 bl part d 0 dl|die tnotmine|end=>' && { 602 wjson "$OTHER"; rm -f "$T/hub/withdraw.form" "$T/hub/gone" 603 run "$T" "$T/h1" 'yes\n' "$T/stm5" "$M" withdraw "$WR" > /dev/null 2>&1 604 [ -s "$T/hub/withdraw.form" ] && ok "MUTANT without the brought_by check sends the withdraw POST" || bad "mutant bringer sent nothing"; rm -f "$T/hub/gone"; } || bad "mutant bringer did not build" 605 # brought_by compared as a prefix either way: caught by the DIDs one character off at the end 606 mut bprefix 40net.om 'if not beq part by 0 bl part d 0 dl=>if not bat part by 0 bl 0 part d 0 dl' && { 607 wjson "${did}a"; rm -f "$T/hub/withdraw.form" 608 out=$(run "$T" "$T/h1" 'no\n' "$T/stm6" "$M" withdraw "$WR" 2>&1) 609 case $out in *"Type yes"*) ok "MUTANT comparing brought_by as a prefix asks for a DID one character longer";; *) bad "mutant bprefix still refused";; esac; } || bad "mutant bprefix did not build" 610 mut dprefix 40net.om 'if not beq part by 0 bl part d 0 dl=>if not bat part d 0 dl 0 part by 0 bl' && { 611 wjson "${did%?}"; rm -f "$T/hub/withdraw.form" 612 out=$(run "$T" "$T/h1" 'no\n' "$T/stm7" "$M" withdraw "$WR" 2>&1) 613 case $out in *"Type yes"*) ok "MUTANT comparing this DID's prefix asks for a DID one character shorter";; *) bad "mutant dprefix still refused";; esac; } || bad "mutant dprefix did not build" 614 # a 303 accepted whatever its Location: on a 303 to /login it polls on instead of stopping 615 mut wdloc 40net.om 'if wdopen part lo 0 ln=>if true' && { 616 wjson "$did"; rm -f "$T/hub/withdraw.form" "$T/hub/gone"; touch "$T/hub/signout" 617 out=$(RUNTO=10 run "$T" "$T/h1" 'yes\n' "$T/stm8" "$M" withdraw "$WR" 2>&1); st=$?; rm -f "$T/hub/signout" 618 case "$st:$out" in "1:"*"signed you out"*) bad "mutant wdloc still stopped";; *) ok "MUTANT accepting any 303 does not stop on a 303 to /login (status $st)";; esac; } || bad "mutant wdloc did not build" 619 # the patch 429 loop as it was (a second apart, no count): the always-429 control must fail (30 s cap) 620 mut ptcap 50patch.om 'w = ulong 2|while and eq c 429 le w 8 bound 3|for i ulong w bound 8|pl_sleep|end|c = http part p 0 n true tbody|w = mul w 2|end=>while eq c 429 bound `9223372036854775807`|pl_sleep|c = http part p 0 n true tbody|end' && { 621 printf '429+' > "$T/hub/busyq"; PT=$M ptrun "$T/stm9" 30; n=$(ptposts) 622 pkill -f "^$T/m/out/" 2>/dev/null; rm -f "$T/hub/busyq" 623 [ "$st" != 2 ] && [ "$n" -gt 4 ] && ok "MUTANT with the unbounded patch 429 loop fails the always-429 control (status $st, $n POSTs in ${el}s)" \ 624 || bad "mutant ptcap still stopped: status $st, $n POSTs"; } || bad "mutant ptcap did not build" 625 626 stopall 627 echo "TOOL TESTS pass=$PASS fail=$FAIL" 628 [ "$FAIL" = 0 ]