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/open/tests/up.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 / open / tests / up.sh` 861 lines ยท 80152 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # open/tests/up.sh: the gate for the one-command bring and get, hub side (contract 3 # ~/handoffs/yourtrained-cortex/briefs/one-command-contract.md, slice HUB). 4 # forged (a test copy built from this tree: private port, private data folder) takes the upload 5 # from throwaway `ed25519` keys signed in the way social/tests does it; the intake (open/intake.om) 6 # runs outside it against a stand-in rad in a throwaway HOME (init prints a RID and makes the 7 # storage folder as a bare clone). No network, no real Radicle node, no real key. 8 # Ends with mutants: the same checks must FAIL on a copy with one guard removed. 9 # flock -o ~/handoffs/hive/queen/pool-16.lock env FORGED_CPUS=16 bash open/tests/up.sh 10 set -u 11 export LC_ALL=C 12 cd "$(dirname "$0")/../.." 13 ROOT=$(pwd) 14 OMV=$HOME/work/flux/omega-mv 15 OMC=$OMV/seed/out/omc 16 PIN=`3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194` 17 [ "$(sha256sum "$OMC" | cut -d' ' -f1)" = "$PIN" ] || { echo "omc is not the pin"; exit 1; } 18 PORT=${UP_TEST_PORT:-19880} 19 LPORT=${UP_TEST_LISTEN_PORT:-19882} 20 CORES=${FORGED_CPUS:-16} 21 T=$(mktemp -d /tmp/openup.XXXXXX) 22 PASS=0; FAIL=0 23 ok() { PASS=$((PASS+1)); echo "PASS $*"; } 24 bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; } 25 check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want '$2', got '$1'"; fi; } 26 PID=; LPID= 27 stop() { [ -n "$PID" ] && { kill "$PID" 2>/dev/null; wait "$PID" 2>/dev/null; }; PID=; } 28 trap 'stop; [ -n "$LPID" ] && kill "$LPID" 2>/dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT 29 # FORGED_CPUS: the cores the builds and the test forged run on (taskset), or off for no taskset 30 tset() { if [ "$CORES" = off ]; then nice -n 10 "$@"; else taskset -c "$CORES" nice -n 10 "$@"; fi; } 31 omc() { tset "$OMC"; } 32 TAB=$(printf '\t') 33 B58=123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz 34 35 # ------------------------------------------------------------------ builds 36 bintake() { { printf 'om2\n'; cat "$OMV/om/tls/sha2.om" "$1"; } | omc > "$2" 2>> "$T/omc.err" && chmod 700 "$2"; } 37 bintake open/intake.om "$T/intake" || { echo "BUILD FAILED open/intake.om: $(tail -2 "$T/omc.err")"; exit 1; } 38 mkdir -p "$T/data" "$T/social"; mkdir -m 700 "$T/slwork" 39 bforged() { # OUT [python edit OLD=>NEW on open/route.om] 40 if [ -n "${2:-}" ]; then mutsrc open/route.om "$T/route-mut.om" "$2" || return 1; R=$T/route-mut.om; else R=$ROOT/open/route.om; fi 41 { printf 'om2\n'; cat $(env -u FORGED_CPUS FORGE_TRY="salvage open" ./run.sh units | sed "s|^open/route.om\$|$R|"); } \ 42 | sed -e "s|^text tfdata \".*\"|text tfdata \"$T/data/\"|" -e "s/18480/$PORT/g" | omc > "$1" 2>> "$T/omc.err" && chmod 700 "$1" 43 } 44 mutsrc() { # SRC OUT 'OLD=>NEW' ('|' is a line feed); OLD must occur exactly once 45 python3 -I - "$1" "$2" "$3" <<'EOF' 46 import sys 47 s = open(sys.argv[1]).read() 48 old, new = sys.argv[3].split('=>') 49 old = old.replace('|', '\n'); new = new.replace('|', '\n') 50 assert s.count(old) == 1, (old, s.count(old)) 51 open(sys.argv[2], 'w').write(s.replace(old, new)) 52 EOF 53 } 54 bforged "$T/forged" || { echo "BUILD FAILED forged: $(tail -2 "$T/omc.err")"; exit 1; } 55 56 # ------------------------------------------------------------------ the server and keys 57 start() { 58 ss -ltn | grep -q "127.0.0.1:$PORT " && { echo "port $PORT is in use by another program: set UP_TEST_PORT"; exit 1; } 59 if [ "$CORES" = off ]; then 60 FORGE_SOCIAL_DIR="$T/social/" INTERPLANE_SALVAGE_DIR="$T/salvage/" nice -n 10 "$1" 2>> "$T/forged.err" & 61 else 62 FORGE_SOCIAL_DIR="$T/social/" INTERPLANE_SALVAGE_DIR="$T/salvage/" taskset -c "$CORES" nice -n 10 "$1" 2>> "$T/forged.err" & 63 fi 64 PID=$! 65 for i in $(seq 50); do curl -s -o /dev/null "http://127.0.0.1:$PORT/" && return 0; sleep 0.1; done 66 echo "server did not start"; cat "$T/forged.err"; exit 1 67 } 68 B="http://127.0.0.1:$PORT" 69 # every request names its own client address in X-Real-IP (what nginx sets in front of forged), so the 70 # per-IP sign-in and write limits, which this gate does not test, do not decide its outcomes; IP=x fixes it 71 IPN=10; IP= 72 nip() { n=$(( $(cat "$T/ipn" 2>/dev/null || echo 10) + 1 )); [ "$n" -gt 250 ] && n=11; echo "$n" > "$T/ipn"; echo "127.0.0.$n"; } 73 # code METHOD PATH [curl args]: the status; the body in $T/body, the head in $T/hdr. A POST answered 74 # 429 (forged's write limits, 30 a minute per address and per key, which this gate keeps as they are) 75 # waits as Retry-After says, else to the next minute, and is sent again, so no outcome here depends on 76 # how fast the machine runs the gate. NORETRY=1 turns that off for the case that tests the limit. 77 # forged adds translation hints while it sends an HTML page (server/tr.om); the content checks read 78 # HTML pages without them (server/tests/translate.sh gates the hints); other bodies stay as sent. 79 code() { m=$1; p=$2; shift 2 80 for try in 1 2 3 4; do 81 c=$(curl -s -H "X-Real-IP: ${IP:-$(nip)}" -o "$T/body" -D "$T/hdr" -X "$m" "$@" "$B$p" -w '%{http_code}') 82 [ "$c" = 429 ] && [ "$m" = POST ] && [ -z "${NORETRY:-}" ] || break 83 ra=$(hdr retry-after); case "$ra" in ''|*[!0-9]*) ra=$((61 - $(date +%s) % 60)) ;; esac 84 sleep "$ra" 85 done 86 grep -qi '^content-type: text/html' "$T/hdr" && sed -i 's/\([^<]*\)<\/span>/\1/g; s/ translate="no"//g' "$T/body" 87 echo "$c" 88 } 89 hdr() { grep -i "^$1:" "$T/hdr" | head -1 | cut -d' ' -f2- | tr -d '\r'; } 90 field() { grep -o "name=\"$1\" value=\"[^\"]*\"" "$T/body" | head -1 | sed 's/.*value="//; s/"$//'; } 91 did() { python3 -I - "$1" <<'EOF' 92 import sys, base64 93 blob = base64.b64decode(open(sys.argv[1]).read().split()[1]) 94 raw = b'\xed\x01' + blob[-32:] 95 A = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' 96 n = int.from_bytes(raw, 'big'); s = '' 97 while n: n, r = divmod(n, 58); s = A[r] + s 98 print('did:key:z' + s) 99 EOF 100 } 101 for k in 1 2 3 4 5 6 7 8; do ssh-keygen -q -t `ed25519` -N '' -C "t$k" -f "$T/k$k"; eval "K$k=\$(did \"\$T/k$k.pub\")"; done 102 signin() { # KEYFILE DID: CK (cookie header) and TOK (the write csrf) for that key 103 IP=$(nip) 104 code GET /login >/dev/null 105 PREN=$(hdr set-cookie | sed -n 's/^\([A-Za-z_-]*forge_pre\)=.*/\1/p') 106 PRE=$(hdr set-cookie | sed -n 's/^[A-Za-z_-]*forge_pre=\([0-9a-f]*\);.*/\1/p') 107 CSRF=$(field csrf); NONCE=$(field nonce); TS=$(field ts) 108 printf '%s' "interplane-forge-login:$NONCE:$TS" | ssh-keygen -Y sign -f "$1" -n interplane-forge > "$T/sig" 2>/dev/null 109 code POST /login -H "Cookie: $PREN=$PRE" --data-urlencode "csrf=$CSRF" --data-urlencode "nonce=$NONCE" --data-urlencode "ts=$TS" --data-urlencode "did=$2" --data-urlencode "sig@$T/sig" > "$T/lc"; LC=$(cat "$T/lc"); cp "$T/body" "$T/lbody" 110 SES=$(hdr set-cookie | sed -n 's/^__Host-forge_session=\([0-9a-f]*\);.*/\1/p') 111 CK="Cookie: __Host-forge_session=$SES" 112 code GET /open/ -H "$CK" > /dev/null; TOK=$(field csrf); IP= 113 [ "${#SES}" = 64 ] && [ "${#TOK}" = 32 ] || { echo "sign-in: login $LC $(sed -n "s/.*]*>\([^<]*\)<.*/\1/p" "$T/lbody" | head -2 | tr "\n" " ")"; return 1; } 114 } 115 116 # ------------------------------------------------------------------ archives 117 # mktar OUT SPEC...: a canonical ustar of the contract (sorted, regular files, mode 0644 or 0755, 118 # uid/gid 0, mtime 0, two zero blocks). SPEC is path=content, path:x=content (mode 0755), or a 119 # hostile entry: path@sym=target, path@dev, path@dup (the entry twice), raw:path=content (no path 120 # check, no sort). Content "@size:N" is N bytes of 'a'. 121 mktar() { python3 -I - "$@" <<'EOF' 122 import sys 123 import os 124 out, specs = sys.argv[1], sys.argv[2:] 125 ents = [] 126 def hdr(name, size, mode, typ=b'0', link=b''): 127 h = bytearray(512) 128 pre = b'' 129 if len(name) > 100: 130 i = name.rfind(b'/', 0, 156) 131 pre, name = name[:i], name[i+1:] 132 h[0:len(name)] = name 133 h[100:108] = b'%07o\0' % mode 134 h[108:116] = b'`0000000`\0'; h[116:124] = b'`0000000`\0' 135 h[124:136] = b'%011o\0' % size; h[136:148] = b'`00000000000`\0' 136 h[156:157] = typ; h[157:157+len(link)] = link 137 h[257:263] = b'ustar\0'; h[263:265] = b'00' 138 h[345:345+len(pre)] = pre 139 h[148:156] = b' ' * 8 140 h[148:156] = b'%06o\0 ' % sum(h) 141 return bytes(h) 142 def body(c): 143 c = c.encode() 144 if c.startswith(b'@size:'): c = b'a' * int(c[6:]) 145 if c.startswith(b'@rand:'): c = os.urandom(int(c[6:])) 146 return c 147 for s in specs: 148 raw = s.startswith('raw:') 149 if raw: s = s[4:] 150 if '@sym=' in s: 151 p, t = s.split('@sym=', 1); ents.append((p.encode(), hdr(p.encode(), 0, 0o644, b'2', t.encode()), b'')); continue 152 if s.endswith('@dev'): 153 p = s[:-4]; ents.append((p.encode(), hdr(p.encode(), 0, 0o644, b'3'), b'')); continue 154 p, c = s.split('=', 1) 155 dup = p.endswith('@dup') 156 if dup: p = p[:-4] 157 mode = 0o644 158 if p.endswith(':x'): p, mode = p[:-2], 0o755 159 c = body(c); n = p.encode() 160 e = (n, hdr(n, len(c), mode), c) 161 ents.append(e) 162 if dup: ents.append(e) 163 if not any(s.startswith('raw:') for s in specs): 164 ents.sort(key=lambda e: e[0]) 165 with open(out, 'wb') as f: 166 for n, h, c in ents: 167 f.write(h); f.write(c); f.write(b'\0' * ((512 - len(c) % 512) % 512)) 168 f.write(b'\0' * 1024) 169 EOF 170 } 171 nfiles() { python3 -I -c 'import sys; d=open(sys.argv[1],"rb").read(); i=0; n=0 172 while i+512<=len(d) and d[i:i+512]!=bytes(512): 173 s=int(d[i+124:i+135] or b"0",8); n+=1; i+=512+(s+511)//512*512 174 print(n)' "$1"; } 175 sha() { sha256sum "$1" | cut -d' ' -f1; } 176 # stmt SHA FILES BYTES NAME: the bring statement, exact bytes 177 stmt() { printf 'interplane-bring 1\nsha256 %s\nfiles %s\nbytes %s\nname %s\n' "$1" "$2" "$3" "$4"; } 178 # chunks FILE: the base64url (no padding) of 45000-byte pieces into $T/c.0, $T/c.1, ...; echoes the count 179 chunks() { rm -f "$T"/c.*; python3 -I - "$1" "$T/c" <<'EOF' 180 import sys, base64 181 d = open(sys.argv[1], 'rb').read(); n = 0 182 for i in range(0, len(d), 45000): 183 open('%s.%d' % (sys.argv[2], n), 'wb').write(base64.urlsafe_b64encode(d[i:i+45000]).rstrip(b'=')) 184 n += 1 185 print(n) 186 EOF 187 } 188 post() { code POST /open/up -H "$CK" -H "Origin: https://interplane.io" --data-urlencode "csrf=$TOK" "$@"; } 189 # rpost: post, and on 429 (the existing write limits) wait and send the same request again, as the 190 # contract tells the tool to 191 rpost() { for i in $(seq 90); do c=$(post "$@"); [ "$c" != 429 ] && { echo "$c"; return; }; sleep 2; done; echo "$c"; } 192 rchunk() { rpost --data-urlencode action=chunk --data-urlencode "sha=$1" --data-urlencode "seq=$2" --data-urlencode "data@$3"; } 193 chunk() { post --data-urlencode action=chunk --data-urlencode "sha=$1" --data-urlencode "seq=$2" --data-urlencode "data@$3"; } 194 # up KEYFILE DID TAR NAME [SIGKEY] [SHA] [FILES] [BYTES]: sign in, send every chunk, finish; sets 195 # USHA, UC (finish status) and UBODY 196 up() { 197 signin "$1" "$2" || { bad "sign-in failed for $2"; return 1; } 198 USHA=${6:-$(sha "$3")}; fl=${7:-$(nfiles "$3")}; by=${8:-$(stat -c %s "$3")} 199 n=$(chunks "$3") 200 for s in $(seq 0 $((n-1))); do c=$(rchunk "$USHA" "$s" "$T/c.$s"); [ "$c" = 200 ] || { UC=$c; UBODY=$(cat "$T/body"); return 1; }; done 201 stmt "$USHA" "$fl" "$by" "$4" > "$T/stmt" 202 ssh-keygen -Y sign -f "${5:-$1}" -n interplane-bring < "$T/stmt" > "$T/bsig" 2>/dev/null 203 UC=$(rpost --data-urlencode action=finish --data-urlencode "sha=$USHA" --data-urlencode "files=$fl" --data-urlencode "bytes=$by" \ 204 --data-urlencode "name=$4" --data-urlencode "note=${NOTE:-unfinished: $4}" --data-urlencode consent=yes --data-urlencode "sig@$T/bsig") 205 UBODY=$(cat "$T/body") 206 } 207 status() { code GET "/open/up/$1.json" -H "$CK" > /dev/null; python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); assert d["schema"]=="interplane/open-upload/1"; print(d["state"]+"|"+str(d["rid"])+"|"+str(d["page"]))' "$T/body" 2>/dev/null; } 208 209 # ------------------------------------------------------------------ the intake world 210 # world NAME: a fresh throwaway HOME (stand-in rad), storage and work folder; forged's open folder 211 # ($T/data/open/) is shared and emptied 212 world() { 213 W=$T/$1; rm -rf "$W" "$T/data/open" 214 mkdir -p -m 700 "$W/home/.local/bin" "$W/home/stub" "${STORE:-$W/home/store}" "$W/work" "$T/data/open" 215 S=${STORE:-$W/home/store}; S=${S%/}/ 216 echo '*' > "$W/work/allow" 217 cat > "$W/home/.local/bin/rad" <<'EOF' 218 #!/bin/sh 219 # stand-in for rad: logs its arguments. init PATH --name ... clones PATH (bare) into the storage 220 # folder under a new RID and prints it as rad init does; unseed and seed RID log only; seed alone 221 # prints stub/policy; inspect --delegates prints stub/delegates 222 S=$HOME/stub 223 echo "$*" >> "$S/rad.log" 224 case $1 in 225 init) 226 [ -e "$S/initfail" ] && exit 1 227 printf '%s\n' "$@" > "$S/argv.last" 228 for a; do case $a in --private|--no-seed|--existing) echo "$a" >> "$S/flags";; esac; done 229 for a; do p=$a; done 230 n=$(( $(cat "$S/n" 2>/dev/null || echo 0) + 1 )); echo "$n" > "$S/n" 231 r=z3Stored$(printf 'Rid%013d' "$n" | tr 0 x) 232 git clone -q --bare --no-local -- "$p" "$(cat "$S/store")$r" > /dev/null 2>&1 || exit 1 233 echo "Initializing public Radicle repository in $p.." 234 echo "Your Repository ID (RID) is rad:$r" 235 exit 0 ;; 236 seed) [ -n "${2:-}" ] && exit 0; cat "$S/policy" 2>/dev/null; exit 0 ;; 237 unseed) exit 0 ;; 238 self) cat "$S/self" 2>/dev/null || echo did:key:z6MkHubStandInKeyabcdefghijkmnopqrstuvwxyzAB; exit 0 ;; 239 inspect) [ "${3:-}" = --visibility ] && { echo public; exit 0; } 240 [ "${3:-}" = --delegates ] && { cat "$S/delegates" 2>/dev/null; exit 0; } 241 echo '{"xyz.radicle.project":{"defaultBranch":"main","description":"d","name":"held-project"}}'; exit 0 ;; 242 esac 243 exit 2 244 EOF 245 chmod 700 "$W/home/.local/bin/rad" 246 printf '%s' "$S" > "$W/home/stub/store" 247 # the reserves are set to one byte, so the machine's own free space decides nothing here except 248 # in part 12; the intake's first pass writes open/space, which forged needs to take files 249 printf 'OPEN_RESERVE_STORAGE_BYTES=1\nOPEN_RESERVE_DATA_BYTES=1\n' > "$W/work/reserve" 250 "$T/intake" "$T/data/open/" "$W/state" "$W/work/" "$S" "$W/home" once 2>> "$W/intake.err" 251 : > "$W/home/stub/rad.log" 252 } 253 intake() { "${BIN:-$T/intake}" "$T/data/open/" "$W/state" "$W/work/" "$S" "$W/home" once 2>> "$W/intake.err"; } 254 row() { awk -F'\t' -v r="$1" '$1==r' "$W/work/list.tsv" 2>/dev/null; } 255 st() { row "$1" | cut -f2; } 256 calls() { grep -c -- "$1" "$W/home/stub/rad.log"; } 257 ridof() { status "$1" | cut -d'|' -f2 | sed 's/^rad://'; } 258 upst() { status "$1" | cut -d'|' -f1; } 259 # plant KEY N STATE: N rows of that key in the private list (rids z2PlantKey...) 260 plant() { awk -v d="$1" -v n="$2" -v s="$3" -v a="$B58" -v t="$4" 'BEGIN { for (i = 0; i < n; i++) printf "z2Plant%s%s%s\t%s\t%s\t2026-11-11\t%s\tplanted\t\t\n", t, substr(a, int(i / 58) % 58 + 1, 1), substr(a, i % 58 + 1, 1) "abcdefghijkmnopq", s, d, (n > 0 ? 1 : 0) }' >> "$W/work/list.tsv"; } 261 dh() { printf '%s' "$1" | sha256sum | cut -c1-16; } 262 rid() { printf 'z2abcdefghijkmnopqrstuvw%s' "$1"; } 263 # spoolup KEYFILE DID TAR NAME: what forged leaves for a finished upload (spool, signature, U line), 264 # written here directly, so a large archive does not wait on forged's per-key write limit 265 spoolup() { 266 USHA=$(sha "$3"); b=$(stat -c %s "$3"); fl=$(nfiles "$3"); h=$(dh "$2"); mkdir -p "$T/data/open/up" 267 python3 -I - "$3" "$T/data/open/up/$USHA.$h.b64" <<'EOF' 268 import sys, base64 269 d = open(sys.argv[1], 'rb').read(); t = 0 270 with open(sys.argv[2], 'wb') as f: 271 for n, i in enumerate(range(0, len(d), 45000)): 272 c = d[i:i+45000]; t += len(c) 273 f.write(base64.urlsafe_b64encode(c).rstrip(b'=') + b'\t%020d\t%020d\n' % (n, t)) 274 EOF 275 stmt "$USHA" "$fl" "$b" "$4" | ssh-keygen -Y sign -f "$1" -n interplane-bring > "$T/data/open/up/$USHA.$h.sig" 2>/dev/null 276 printf 'U\t%s\t%s\t%s\t%s\t%s\t%s\n' "$USHA" "$2" "$fl" "$b" "$4" "spooled: $4" >> "$T/data/open/queue" 277 } 278 # ustate DID: the intake's status of the last spooled upload of that key 279 ustate() { python3 -I -c 'import json,sys; print(json.load(open(sys.argv[1]))["state"])' "$T/data/open/up/$USHA.$(dh "$1").json" 2>/dev/null; } 280 # alarmk NAME: "value/threshold|key|volume" of a firing alarm 281 alarmk() { awk -F'\t' -v n="$1" '$1==n {print $2"/"$3"|"$5"|"$6}' "$W/work/alarms.txt" 2>/dev/null; } 282 283 start "$T/forged" 284 mktar "$T/good.tar" README.md='# demo, half way 285 ' src/main.om='note main 286 ' run.sh:x='#!/bin/sh 287 echo hi 288 ' 289 290 # ------------------------------------------------------------------ 1. a good upload 291 world g1 292 rm -rf "$T/data/open"; intake; [ -d "$T/data/open" ] && [ ! -L "$T/data/open" ] && grep -Eq "^free [0-9]+ reserve 1 at [0-9]+$" "$T/data/open/space" && ok "a fresh install: the intake makes the open dir and writes the space file forged needs" || bad "no open dir or space file on a fresh install" 293 up "$T/k1" "$K1" "$T/good.tar" demo-project 294 check "$UC" 200 "finish of a good upload"; check "$UBODY" "queued $USHA" "finish answers queued " 295 check "$(upst "$USHA")" queued "status before the intake: queued" 296 SP=$(ls "$T/data/open/up/" | sort | tr '\n' ' ') 297 case "$SP" in "$USHA."????????????????".b64 $USHA."????????????????".sig ") ok "forged wrote only ..b64 and .sig under open/up/";; *) bad "spool files: $SP";; esac 298 check "$(cut -f1,2,3,4,5,6 "$T/data/open/queue")" "U$TAB$USHA$TAB$K1${TAB}3$TAB$(stat -c %s "$T/good.tar")${TAB}demo-project" "one U queue line: sha, did, files, bytes, name" 299 check "$(cut -f7 "$T/data/open/queue")" "unfinished: demo-project" "the U line carries the note" 300 intake 301 GOOD=$(ridof "$USHA") 302 check "$(upst "$USHA")" stored "status after the intake: stored" 303 check "$(status "$USHA" | cut -d'|' -f3)" "/open/$GOOD" "status names the page" 304 check "$(st "$GOOD")" stored "the shelf row is in state stored" 305 check "$(row "$GOOD" | cut -f3,6,8)" "$K1${TAB}demo-project${TAB}unfinished: demo-project" "row: the bringer's did, the name, the note" 306 check "$(calls "^init --public --no-confirm --name=demo-project --description=unfinished: demo-project --default-branch main ")" 1 "rad init ran once with the contract's arguments" 307 check "$(ls "$T/data/open/up/" | grep -vc '\.json$')" 0 "spool removed after the intake" 308 check "$(ls -A "$W/work" | grep -c 'upload')" 0 "scratch removed after the intake" 309 G=$S$GOOD 310 check "$(git --git-dir="$G" log -1 --format='%an|%cn' HEAD)" "$K1|Interplane hub" "first commit: author the person's DID, committer Interplane hub" 311 check "$(git --git-dir="$G" ls-tree -r --name-only HEAD | tr '\n' ' ')" ".interplane/brought.sig .interplane/brought.txt README.md run.sh src/main.om " "the commit holds the files and the two .interplane files" 312 check "$(git --git-dir="$G" ls-tree HEAD run.sh | cut -c1-6)" 100755 "the exec bit is kept" 313 git --git-dir="$G" show HEAD:.interplane/brought.txt > "$T/bt"; git --git-dir="$G" show HEAD:.interplane/brought.sig > "$T/bs" 314 head -5 "$T/bt" > "$T/bt5" 315 cmp -s "$T/bt5" <(stmt "$USHA" 3 "$(stat -c %s "$T/good.tar")" demo-project) && ok "brought.txt starts with the exact statement" || bad "brought.txt statement: $(head -5 "$T/bt")" 316 check "$(sed -n 6p "$T/bt")" "$(printf '%s\t17\tREADME.md' "$(printf '# demo, half way\n' | sha256sum | cut -d' ' -f1)")" "brought.txt: one line per file (sha256, bytes, path)" 317 printf 'p %s\n' "$(cut -d' ' -f1,2 "$T/k1.pub")" > "$T/as" 318 ssh-keygen -Y verify -f "$T/as" -I p -n interplane-bring -s "$T/bs" < "$T/bt5" > /dev/null 2>&1 && ok "anyone can verify brought.sig over the statement with ssh-keygen -Y verify" || bad "brought.sig does not verify" 319 code GET /open/ > /dev/null 320 grep -q "Stored by the Interplane hub: the hub's key signs the repository's history. The person who brought it signed the list of files." "$T/body" && ok "the shelf row says who signed what" || bad "no who-signs-what sentence on the shelf" 321 grep -q "href=\"/open/$GOOD\"" "$T/body" && ok "the shelf lists the stored project" || bad "stored project not on the shelf" 322 code GET /open.json > /dev/null 323 python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); p=[x for x in d["projects"] if x["rid"]==sys.argv[2]][0]; assert p["stored_by_hub"] is True and p["download"]=="/open/"+sys.argv[2]+".tar" and len(p["download_sha256"])==64; print(p["download_sha256"])' "$T/body" "$GOOD" > "$T/dsha" && ok "shelf JSON: stored_by_hub true, download, download_sha256" || bad "shelf JSON fields: $(head -c 400 "$T/body")" 324 code GET "/open/$GOOD.json" > /dev/null 325 python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); assert d["stored_by_hub"] is True and d["download"]=="/open/"+sys.argv[2]+".tar" and d["download_sha256"]==sys.argv[3] and "README.md" in d["files"]' "$T/body" "$GOOD" "$(cat "$T/dsha")" && ok "page JSON: the same fields and the snapshot" || bad "page JSON: $(head -c 400 "$T/body")" 326 c=$(code GET "/open/$GOOD.tar"); check "$c" 200 "GET /open/.tar" 327 check "$(hdr content-type)" application/x-tar "the download is application/x-tar" 328 check "$(hdr content-disposition)" 'attachment; filename="demo-project.tar"' "attachment .tar" 329 check "$(sha "$T/body")" "$(cat "$T/dsha")" "the download matches download_sha256" 330 check "$(tar -tf "$T/body" | sort | tr '\n' ' ')" ".interplane/ .interplane/brought.sig .interplane/brought.txt README.md run.sh src/ src/main.om " "the download is git archive of HEAD" 331 c=$(code GET "/open/`z2abcdefghijkmnopqrstuvwxyzAB`.tar"); check "$c" 404 "NEG no snapshot: 404" 332 # the project page of a stored project: no empty label, the developer section, all of it escaped 333 code GET "/open/$GOOD" > /dev/null; cp "$T/body" "$T/page.html" 334 grep -q '

For developers

' "$T/page.html" && ok "the page of a stored project has the developer section (pj-dev, pj-terms)" || bad "no developer section" 335 grep -q '
Download
' "$T/page.html" && ! grep -q -e 'Radicle ID' -e 'rad clone' -e "rad:$GOOD" "$T/page.html" && ok "it shows the download first, with no Radicle ID, clone line or rad: id" || bad "developer section: id or clone line" 336 grep -q "/open/$GOOD.tar\">$GOOD.tar, SHA-256 $(cat "$T/dsha")" "$T/page.html" && ok "it shows the download and its SHA-256" || bad "developer section: download" 337 grep -q "
The hub's key
did:key:z6MkHubStandInKeyabcdefghijkmnopqrstuvwxyzAB" "$T/page.html" && ok "the hub's key comes from the node (rad self --did, read by the intake)" || bad "hub key not shown" 338 grep -q "Stored by the Interplane hub. The hub's key (did:key:z6MkHubStandInKeyabcdefghijkmnopqrstuvwxyzAB) created this repository" "$T/page.html" && ok "the paragraph names the hub's key" || bad "paragraph without the hub key" 339 KEYLINE=$(sed -n 's|.*
Their public key
\(ssh-`ed25519` [A-Za-z0-9+/=]*\).*|\1|p' "$T/page.html") 340 check "$KEYLINE" "$(cut -d' ' -f1,2 "$T/k1.pub")" "the bringer's public key, encoded from the did:key, equals their ssh key" 341 printf '%s\n' "$KEYLINE" > "$T/their.pub" 342 ssh-keygen -Y check-novalidate -n interplane-bring -f "$T/their.pub" -s "$T/bs" < "$T/bt5" > /dev/null 2>&1 && ok "the page's check command works as written (ssh-keygen -Y check-novalidate ... -f )" || bad "the page's check command fails" 343 printf 'p %s\n' "$KEYLINE" > "$T/their.as"; ssh-keygen -Y verify -f "$T/their.as" -I p -n interplane-bring -s "$T/bs" < "$T/bt5" > /dev/null 2>&1 && ok "and the shown key verifies brought.sig" || bad "the shown key does not verify brought.sig" 344 grep -q "Unfinished: unfinished: demo-project

" "$T/page.html" && ok "a note is shown with its label" || bad "note label missing" 345 346 c=$(code GET "/open/up/$USHA.json"); check "$c" 403 "NEG status signed out: 403" 347 signin "$T/k2" "$K2"; c=$(code GET "/open/up/$USHA.json" -H "$CK"); check "$c" 404 "NEG another key's status: 404" 348 c=$(code GET /bring.sh); check "$c" 404 "bring.sh without open/tools/: 404" 349 mkdir -p "$T/data/open/tools"; printf '#!/bin/sh\necho bring\n' > "$T/data/open/tools/bring.sh"; printf '#!/bin/sh\necho get\n' > "$T/data/open/tools/get.sh" 350 c=$(code GET /bring.sh); check "$c|$(cat "$T/body")" "200|#!/bin/sh 351 echo bring" "bring.sh served from open/tools/" 352 c=$(code GET /get.sh); check "$c|$(cat "$T/body")" "200|#!/bin/sh 353 echo get" "get.sh served from open/tools/" 354 c=$(code GET /withdraw.sh); check "$c" 404 "withdraw.sh without open/tools/withdraw.sh: 404" 355 printf '#!/bin/sh\necho withdraw\n' > "$T/data/open/tools/withdraw.sh" 356 c=$(code GET /withdraw.sh); check "$c|$(cat "$T/body")" "200|#!/bin/sh 357 echo withdraw" "withdraw.sh served from open/tools/" 358 c=$(code GET /open/alarms.json); python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); assert d["schema"]=="interplane/open-alarms/1"; n={a["name"] for a in d["alarms"]}; assert len(n)==12, n' "$T/body" && ok "/open/alarms.json is served with 12 checks ($c)" || bad "alarms.json: $c $(head -c 300 "$T/body")" 359 GOODW=$W 360 361 # ------------------------------------------------------------------ 2. the write gate (forged) 362 signin "$T/k1" "$K1"; mktar "$T/s.tar" a=b 363 S1=$(sha "$T/s.tar"); chunks "$T/s.tar" > /dev/null 364 c=$(code POST /open/up -H "Origin: https://interplane.io" --data-urlencode action=chunk --data-urlencode "sha=$S1" --data-urlencode seq=0 --data-urlencode "data@$T/c.0"); check "$c" 403 "NEG a POST without a session: 403" 365 check "$(ls "$T/data/open/up/" | grep -c "^$S1")" 0 "NEG not signed in: nothing written" 366 c=$(code POST /open/up -H "$CK" -H "Origin: https://interplane.io" --data-urlencode "csrf=${TOK%?}x" --data-urlencode action=chunk --data-urlencode "sha=$S1" --data-urlencode seq=0 --data-urlencode "data@$T/c.0"); check "$c" 403 "NEG a wrong CSRF token: 403" 367 c=$(code POST /open/up -H "$CK" -H "Origin: https://evil.example" --data-urlencode "csrf=$TOK" --data-urlencode action=chunk --data-urlencode "sha=$S1" --data-urlencode seq=0 --data-urlencode "data@$T/c.0"); check "$c" 403 "NEG a foreign Origin: 403" 368 check "$(ls "$T/data/open/up/" | grep -c "^$S1")" 0 "NEG wrong CSRF or Origin: nothing written" 369 c=$(chunk "$S1" 1 "$T/c.0"); check "$c|$(cat "$T/body")" "409|next 0" "NEG out-of-order seq: 409 next 0" 370 c=$(chunk "$S1" 0 "$T/c.0"); check "$c|$(cat "$T/body")" "200|next 1" "chunk 0: 200 next 1" 371 c=$(chunk "$S1" 0 "$T/c.0"); check "$c|$(cat "$T/body")" "409|next 1" "a repeated chunk is harmless: 409 next 1" 372 check "$(wc -l < "$T/data/open/up/$S1".*.b64)" 1 "the repeat appended nothing" 373 c=$(chunk "${S1%?}G" 0 "$T/c.0"); check "$c" 400 "NEG a sha that is not lowercase hex: 400" 374 printf 'ab+/' > "$T/cbad"; c=$(chunk "$S1" 1 "$T/cbad"); check "$c" 400 "NEG data that is not base64url: 400" 375 c=$(post --data-urlencode action=finish --data-urlencode "sha=$S1" --data-urlencode files=1 --data-urlencode bytes=$(( $(stat -c %s "$T/s.tar") + 1 )) --data-urlencode name=s --data-urlencode consent=yes --data-urlencode "sig@$T/bsig"); check "$c" 409 "NEG finish with more bytes than were sent: 409 next" 376 c=$(post --data-urlencode action=finish --data-urlencode "sha=$S1" --data-urlencode files=1 --data-urlencode bytes=$(( $(stat -c %s "$T/s.tar") - 1 )) --data-urlencode name=s --data-urlencode consent=yes --data-urlencode "sig@$T/bsig"); check "$c" 400 "NEG finish with fewer bytes than were sent: 400" 377 c=$(post --data-urlencode action=finish --data-urlencode "sha=$S1" --data-urlencode files=1 --data-urlencode bytes=$(stat -c %s "$T/s.tar") --data-urlencode name=Bad_Name --data-urlencode consent=yes --data-urlencode "sig@$T/bsig"); check "$c" 400 "NEG a name outside [a-z0-9-]: 400" 378 c=$(post --data-urlencode action=finish --data-urlencode "sha=$S1" --data-urlencode files=1 --data-urlencode bytes=$(stat -c %s "$T/s.tar") --data-urlencode name=s --data-urlencode "sig@$T/bsig"); check "$c" 400 "NEG finish without consent: 400" 379 c=$(post --data-urlencode action=finish --data-urlencode "sha=$S1" --data-urlencode files=1 --data-urlencode bytes=$(stat -c %s "$T/s.tar") --data-urlencode name=s --data-urlencode consent=yes --data-urlencode "sig=not armored"); check "$c" 400 "NEG a signature that is not armored: 400" 380 check "$(grep -c "$S1" "$T/data/open/queue" 2>/dev/null)" 0 "NEG refused finishes queue nothing" 381 # another key's spool: K2 starts its own, never K1's 382 signin "$T/k2" "$K2" 383 c=$(chunk "$S1" 1 "$T/c.0"); check "$c|$(cat "$T/body")" "409|next 0" "NEG another key cannot continue K1's upload (its own spool is empty)" 384 check "$(ls "$T/data/open/up/" | grep -c "^$S1")" 1 "NEG K1's spool is untouched and K2 made none" 385 c=$(post --data-urlencode action=finish --data-urlencode "sha=$S1" --data-urlencode files=1 --data-urlencode bytes=$(stat -c %s "$T/s.tar") --data-urlencode name=s --data-urlencode consent=yes --data-urlencode "sig@$T/bsig"); check "$c" 404 "NEG another key cannot finish K1's upload" 386 # past the former 50 MiB: no size limit in forged; a chunk is taken while there is room 387 signin "$T/k1" "$K1" 388 f=$(ls "$T/data/open/up/$S1".*.b64); printf 'AAAA\t%020d\t%020d\n' 1 `52428799` >> "$f" 389 c=$(chunk "$S1" 2 "$T/c.0"); check "$c" 200 "a chunk past the former 50 MiB is taken (there is room)" 390 rm -f "$f" 391 # 2b. room: forged writes under open/ only while the intake's measure, open/space, leaves room 392 SPF=$T/data/open/space; cp "$SPF" "$T/space.saved" 393 head -c 45000 /dev/urandom | python3 -I -c 'import sys, base64; sys.stdout.buffer.write(base64.urlsafe_b64encode(sys.stdin.buffer.read()).rstrip(b"="))' > "$T/cbig" 394 xsha() { printf '%063d%s' 0 "$1"; } 395 spool0() { ls "$T/data/open/up/" | grep -c "^$1" ; } 396 printf 'free 1000 reserve 999999 at 7\n' > "$SPF"; c=$(chunk "$(xsha a)" 0 "$T/cbig"); check "$c|$(cat "$T/body")" "503|503 this computer is nearly full; try again later" "NEG no room by the measure: the chunk is refused with the reason" 397 check "$(spool0 "$(xsha a)")" 0 "NEG no room: nothing written" 398 n=0; for bad in 'free 1x reserve 1 at 1\n' 'free 1 reserve 1 at 1' 'free 1 reserve 1 at 1\nmore\n' 'free `12345678901234567890` reserve 1 at 1\n' 'free 1 reserve 1 at 1\n' '\n' "free `999999999999999999` reserve 1 at 1$(printf '%070d' 0)\n"; do 399 printf "$bad" > "$SPF"; c=$(chunk "$(xsha b)" 0 "$T/cbig"); [ "$c|$(cat "$T/body")" = "503|503 the hub is not ready to take files; try again later" ] && n=$((n+1)); done 400 check "$n|$(spool0 "$(xsha b)")" "7|0" "NEG seven malformed space files: refused as not ready, nothing written" 401 cp "$T/space.saved" "$T/space.real"; rm -f "$SPF"; ln -s "$T/space.real" "$SPF"; c=$(chunk "$(xsha c)" 0 "$T/cbig"); check "$c" 503 "NEG a space file that is a link is not followed" 402 rm -f "$SPF"; mkfifo "$SPF"; c=$(timeout 20 curl -s -H "X-Real-IP: $(nip)" -o "$T/body" -X POST -H "$CK" -H "Origin: https://interplane.io" --data-urlencode "csrf=$TOK" --data-urlencode action=chunk --data-urlencode "sha=$(xsha c)" --data-urlencode seq=0 --data-urlencode "data@$T/cbig" -w '%{http_code}' "$B/open/up"); check "$c" 503 "NEG a FIFO as the space file: refused at once, forged does not wait" 403 rm -f "$SPF"; c=$(chunk "$(xsha c)" 0 "$T/cbig"); check "$c|$(cat "$T/body")" "503|503 the hub is not ready to take files; try again later" "NEG no space file: a chunk is refused" 404 qb=$(cat "$T/data/open/queue" 2>/dev/null | wc -l) 405 c=$(code POST /open/ -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode action=bring --data-urlencode "rid=rad:$(rid 7)" --data-urlencode consent=yes --data-urlencode note=); check "$c" 303 "no space file: a bring line (at most 400 bytes) is still queued" 406 printf 'free 1000 reserve 999999 at 8\n' > "$SPF" 407 c=$(code POST /open/ -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode action=bring --data-urlencode "rid=rad:$(rid 8)" --data-urlencode consent=yes --data-urlencode note=); check "$c" 503 "NEG no room: a bring line is refused" 408 grep -q "This computer is nearly full" "$T/body" && ok "and the page says the computer is nearly full" || bad "no room text on the page" 409 check "$(wc -l < "$T/data/open/queue")" "$((qb+1))" "NEG no room: the queue did not grow" 410 # a stale measure: forged counts what it wrote since it, so it refuses before the room is used up 411 stale() { printf 'free 101000 reserve 1000 at %s\n' "$1" > "$SPF"; } 412 signin "$T/k7" "$K7"; stale 9; c1=$(chunk "$(xsha d)" 0 "$T/cbig"); c2=$(chunk "$(xsha d)" 1 "$T/cbig"); check "$c1|$c2" "200|503" "a stale measure with room for one chunk: the first is taken, forged's own count refuses the second" 413 check "$(wc -l < "$(ls "$T/data/open/up/$(xsha d)".*.b64)")" 1 "and only one chunk was written" 414 stale 10; c=$(chunk "$(xsha d)" 1 "$T/cbig"); check "$c" 200 "a new measure starts the count again" 415 cp "$T/space.saved" "$SPF" 416 # the per-IP write limit (30 a minute), unchanged 417 signin "$T/k8" "$K8"; IP=127.0.0.254; NORETRY=1; n429=0; for i in $(seq 32); do c=$(chunk "$S1" 9 "$T/c.0"); [ "$c" = 429 ] && n429=$((n429+1)); done; IP=; NORETRY= 418 [ "$n429" -ge 1 ] && [ "$(head -c 3 "$T/body")" = 429 ] && ok "the existing per-IP write limit answers 429 (text) after 30 writes" || bad "no 429 after 32 writes from one address" 419 420 # ------------------------------------------------------------------ 3. what the intake refuses 421 refused() { # NAME TAR WANT-STATE [up args...]: upload, run the intake, the status must be WANT 422 name=$1; tar=$2; want=$3; shift 3 423 up "$T/k1" "$K1" "$tar" "$name" "$@" 424 [ "$UC" = 200 ] || { bad "$name: finish answered $UC $UBODY"; return; } 425 intake 426 check "$(upst "$USHA")" "$want" "NEG $name: $want" 427 check "$(ls "$S" | grep -c Stored)" "$((STORED))" "NEG $name: no repository made" 428 check "$(ls "$T/data/open/up/" | grep -vc '\.json$')" 0 "NEG $name: spool removed" 429 } 430 world r1; STORED=0 431 mktar "$T/b.tar" a=one 432 refused badsig "$T/b.tar" "refused: bad bring signature" "$T/k2" 433 mktar "$T/b2.tar" a=two 434 refused wrongsha "$T/b2.tar" "refused: wrong archive sha256" "" "$(sha "$T/b.tar")" 435 # a wrong byte count that forged let through (a forged copy that is not this one): the queue line 436 # wrongbytes TAR NAME: upload, then make the queue line and the signed statement claim 512 bytes more 437 # (what a compromised forged could queue, signed by the bringer's own key), so only the byte count differs 438 wrongbytes() { up "$T/k1" "$K1" "$1" "$2"; b=$(stat -c %s "$1") 439 sed -i "s/\t$b\t$2\t/\t$((b+512))\t$2\t/" "$T/data/open/queue" 440 stmt "$USHA" "$(nfiles "$1")" "$((b+512))" "$2" | ssh-keygen -Y sign -f "$T/k1" -n interplane-bring > "$(ls "$T/data/open/up/$USHA".*.sig)" 2>/dev/null; } 441 mktar "$T/b3.tar" a=three; wrongbytes "$T/b3.tar" bytes3; intake 442 check "$(upst "$USHA")" "refused: wrong archive byte count" "NEG a queue line with a wrong byte count" 443 mktar "$T/b4.tar" a=four 444 refused filecount "$T/b4.tar" "refused: archive is not canonical ustar" "" "" 2 445 mktar "$T/h1.tar" 'raw:a/../../escape=x'; refused dotdot "$T/h1.tar" "refused: archive is not canonical ustar" 446 mktar "$T/h2.tar" 'raw:/etc/evil=x'; refused abspath "$T/h2.tar" "refused: archive is not canonical ustar" 447 mktar "$T/h3.tar" a=x 'b@sym=/etc/passwd'; refused symlink "$T/h3.tar" "refused: archive is not canonical ustar" 448 mktar "$T/h4.tar" a=x 'b@dev'; refused device "$T/h4.tar" "refused: archive is not canonical ustar" 449 mktar "$T/h5.tar" 'a@dup=x'; refused duplicate "$T/h5.tar" "refused: archive is not canonical ustar" 450 mktar "$T/h6.tar" 'raw:b=x' 'raw:a=y'; refused unsorted "$T/h6.tar" "refused: archive is not canonical ustar" 451 mktar "$T/h7.tar" a=x 'id=-----BEGIN OPENSSH PRIVATE KEY----- 452 b3BlbnNzaC1rZXk 453 -----END OPENSSH PRIVATE KEY----- 454 '; refused privkey "$T/h7.tar" "refused: the archive holds a private key" 455 mktar "$T/h7c.tar" a=x "k=$(head -c 505 /dev/zero | tr '\0' a)-----BEGIN RSA PRIVATE KEY-----"; refused privkey-across-blocks "$T/h7c.tar" "refused: the archive holds a private key" 456 mktar "$T/h8.tar" '.git/config=x' a=y; refused dotgit "$T/h8.tar" "refused: the archive holds a .git folder" 457 mktar "$T/h9.tar" 'sub/.GIT/hooks/post-checkout=x' a=y; refused dotgit-upper "$T/h9.tar" "refused: the archive holds a .git folder" 458 mktar "$T/h10.tar" 'x.git/a=x' 'a.Git=y'; up "$T/k1" "$K1" "$T/h10.tar" dotgitname; intake 459 check "$(upst "$USHA")" stored "a name that only contains .git (x.git/, a.Git) is not a .git folder" 460 STORED=1 461 # another key's spool, named by a queue line (what a compromised forged could write) 462 mktar "$T/b5.tar" a=five; up "$T/k1" "$K1" "$T/b5.tar" five 463 sed -i "s/\t$K1\t\(1\t[0-9]*\tfive\)/\t$K2\t\1/" "$T/data/open/queue"; intake 464 check "$(ls "$S" | grep -c Stored)" 1 "NEG a U line naming K1's upload under K2 makes nothing (K2 has no such spool)" 465 check "$(ls "$T/data/open/up/" | grep -c "^$USHA.*\.b64")" 1 "NEG K1's spool is left alone" 466 # hostile queue lines: none may reach rad 467 before=$(calls init) 468 for l in "U${TAB}xyz${TAB}$K1${TAB}1${TAB}1${TAB}n${TAB}" "U${TAB}$USHA${TAB}$K1${TAB}1${TAB}1${TAB}N${TAB}" "U${TAB}$USHA${TAB}$K1${TAB}-1${TAB}1${TAB}n${TAB}" "U${TAB}$USHA${TAB}${TAB}1${TAB}1${TAB}n${TAB}" "U${TAB}$USHA${TAB}$K1${TAB}1${TAB}1${TAB}n${TAB}x${TAB}extra" "U${TAB}$USHA${TAB}$K1${TAB}1${TAB}`99999999999999999999`${TAB}n${TAB}"; do printf '%s\n' "$l" >> "$T/data/open/queue"; done; intake 469 check "$(calls init)" "$before" "NEG six malformed U lines never reach rad" 470 # no number a key or on the shelf: the ninth project of a key and the 201st on the shelf are stored, 471 # and their alarms name the key and the volume; a denied key and the remove file still refuse 472 world q1; plant "$K1" 4 open A; plant "$K1" 4 stored B 473 up "$T/k1" "$K1" "$T/good.tar" ninth; intake; check "$(upst "$USHA")" stored "the ninth project of a key is stored" 474 v=$(alarmk key_shelf_rows); check "${v%|*}" "9/8|$K1" "key_shelf_rows fires at 9 of the former 8 and names the key"; [ "${v##*|}" -ge 9216 ] && ok "and the key's volume (${v##*|} bytes)" || bad "key volume '${v##*|}'" 475 world q2; plant "$K3" 200 open C 476 up "$T/k1" "$K1" "$T/good.tar" two-hundred-first; intake; check "$(upst "$USHA")" stored "the 201st project on the shelf is stored" 477 v=$(alarmk shelf_rows); check "${v%%|*}" "201/200" "shelf_rows fires at 201 of the former 200"; check "$(echo "$v" | cut -d'|' -f2)" "$K3" "and names the key with the most rows" 478 world q3; echo "$K1" > "$W/work/remove"; STORED=0 479 refused denied-key "$T/good.tar" "refused: removed by the operator" 480 world q4; echo "$K2" > "$W/work/allow"; STORED=0 481 refused not-invited "$T/good.tar" "refused: intake is open to invited keys for now" 482 483 # ------------------------------------------------------------------ 4. withdraw and the remove file 484 world d1 485 up "$T/k1" "$K1" "$T/good.tar" withdraw-me; intake; R=$(ridof "$USHA") 486 [ -d "$S$R" ] && [ -f "$T/data/open/a/$R.tar" ] && ok "stored, with its download" || bad "withdraw setup: $R" 487 signin "$T/k2" "$K2"; code POST /open/ -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode action=withdraw --data-urlencode "rid=rad:$R" > /dev/null; intake 488 check "$(st "$R")" stored "NEG another key cannot withdraw a stored project" 489 signin "$T/k1" "$K1"; c=$(code POST /open/ -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode action=withdraw --data-urlencode "rid=rad:$R"); check "$c" 303 "the bringer withdraws" 490 intake 491 check "$(st "$R")" withdrawn "withdrawn: the row says so" 492 check "$(calls "^unseed rad:$R")" 1 "withdrawn: rad unseed" 493 [ ! -e "$S$R" ] && ok "withdrawn: storage removed" || bad "withdrawn: storage still there" 494 [ ! -e "$T/data/open/a/$R.tar" ] && [ ! -e "$T/data/open/a/$R.sha256" ] && [ ! -e "$T/data/open/p/$R.txt" ] && ok "withdrawn: download and snapshot removed" || bad "withdrawn: files left" 495 c=$(code GET "/open/$R.tar"); check "$c" 404 "withdrawn: the download is 404" 496 world d2 497 up "$T/k1" "$K1" "$T/good.tar" take-me-down; intake; R=$(ridof "$USHA") 498 echo "rad:$R" > "$W/work/remove"; intake 499 check "$(st "$R")" "refused: removed by the operator" "the remove file takes a stored project down" 500 check "$(calls "^unseed rad:$R")" 1 "taken down: unseeded" 501 [ ! -e "$S$R" ] && [ ! -e "$T/data/open/a/$R.tar" ] && ok "taken down: storage and download removed" || bad "taken down: files left" 502 503 # ------------------------------------------------------------------ 5. brought content is never executed 504 world x1 505 MK=$T/marker-ran 506 mktar "$T/x.tar" "Makefile=all: 507 touch $MK 508 " "hooks/post-checkout:x=#!/bin/sh 509 touch $MK 510 " "configure:x=#!/bin/sh 511 touch $MK 512 " 513 up "$T/k1" "$K1" "$T/x.tar" no-exec; intake; R=$(ridof "$USHA") 514 check "$(st "$R")" stored "the project with a Makefile and hooks/post-checkout is stored" 515 c=$(code GET "/open/$R.tar"); check "$c" 200 "and its download is served" 516 [ ! -e "$MK" ] && ok "the marker is absent: nothing brought was executed" || bad "a brought file was executed" 517 # negative control: the marker path is writable and the files do run when run on purpose 518 mkdir -p "$T/xc" && tar -xf "$T/body" -C "$T/xc" && sh "$T/xc/hooks/post-checkout" && [ -e "$MK" ] && ok "control: the planted hook touches the marker when run on purpose" || bad "control: the planted hook does not work" 519 rm -f "$MK" 520 521 # ------------------------------------------------------------------ 6. no network for git (partial clone) 522 ss -ltn | grep -q "127.0.0.1:$LPORT " && { echo "port $LPORT is in use by another program: set UP_TEST_LISTEN_PORT"; exit 1; } 523 python3 -I - "$LPORT" "$T/conns" <<'EOF' & 524 import socket, sys 525 s = socket.socket(); s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 526 s.bind(('127.0.0.1', int(sys.argv[1]))); s.listen(16); n = 0 527 open(sys.argv[2], 'w').write('0') 528 while True: 529 c, _ = s.accept(); n += 1; open(sys.argv[2], 'w').write(str(n)); c.close() 530 EOF 531 LPID=$!; sleep 0.5 532 promisor() { # STORAGE-DIR RID: a bare repository whose blobs are missing and whose promisor remote is the listener 533 P=$1$2; F=$T/pc-src; rm -rf "$F" "$P"; git init -q --template= -b main "$F" 534 echo "readme" > "$F/README.md"; git -C "$F" add README.md; git -C "$F" -c user.name=x -c user.email= commit -q -m one 535 git init -q --bare --template= "$P"; cp -r "$F/.git/objects/." "$P/objects/" 536 git --git-dir="$P" update-ref refs/heads/main "$(git -C "$F" rev-parse HEAD)"; git --git-dir="$P" symbolic-ref HEAD refs/heads/main 537 git --git-dir="$P" config core.repositoryformatversion 1 538 git --git-dir="$P" config extensions.partialclone origin 539 git --git-dir="$P" config remote.origin.url "http://127.0.0.1:$LPORT/x" 540 git --git-dir="$P" config remote.origin.promisor true 541 b=$(git -C "$F" rev-parse HEAD:README.md); rm -f "$P/objects/${b:0:2}/${b:2}" 542 git --git-dir="$P" cat-file -e "$b" 2>/dev/null && return 1; return 0 543 } 544 nonet() { # BIN: run the intake (startup archive of every shelf row, then a second bring = snapshot) 545 world n1; PR=z2PromisorFixtureabcdefghijk 546 promisor "$S" "$PR" || { bad "fixture: the blob is not missing"; return; } 547 printf '%s\topen\t%s\t2026-11-11\t1\tpc\t\t\n' "$PR" "$K1" > "$W/work/list.tsv" 548 printf 'B\t%s\t%s\tagain\n' "$PR" "$K1" >> "$T/data/open/queue" 549 echo 0 > "$T/conns"; BIN=$1 timeout 120 "$1" "$T/data/open/" "$W/state" "$W/work/" "$S" "$W/home" once 2>> "$W/intake.err"; echo "rc=$?" > "$T/nonet-rc" 550 sleep 0.3 551 } 552 nonet "$T/intake" 553 check "$(cat "$T/conns")" 0 "partial clone: no connection was attempted by any git command" 554 [ ! -e "$T/data/open/a/$PR.tar" ] && ok "partial clone: the archive step failed cleanly (no download)" || bad "partial clone: a download was written" 555 check "$(grep -c '^R' "$T/data/open/p/$PR.txt" 2>/dev/null)" 0 "partial clone: the README part of the snapshot failed cleanly" 556 check "$(grep -c '^H' "$T/data/open/p/$PR.txt" 2>/dev/null)" 1 "partial clone: the rest of the snapshot is written" 557 check "$(cat "$T/nonet-rc")" rc=0 "partial clone: the intake finished" 558 559 # ------------------------------------------------------------------ 7. the sandboxed server cannot write the work dir 560 # A probe in forged's place, under infra/spark/forged-sandbox.sh with the same mounts: it tries to 561 # create a file in the path it is given and exits 0 when it could. 562 printf 'fn main to int\np = new uchar 512 0\nn = argread 1 p 0 512\nif le n 0\nret 3\nend\nfd = fopen p 0 ulong n 577 384\nif lt fd 0\nret 1\nend\nret 0\nend\n' | omc > "$T/probe" && chmod 700 "$T/probe" 563 SB=$T/sb; mkdir -p -m 700 "$SB/data/logs" "$SB/work" "$SB/public"; : > "$SB/data/forged-supervisor.pid"; : > "$SB/public/RIDS.md" 564 sbx() { env -i HOME="$HOME" PATH=/usr/bin:/bin FORGE_DATA="$SB/data" FORGED_PUBLIC_DIR="$SB/public" FORGED_NETNS=off FORGED_SANDBOX=on \ 565 FORGED_PATH_HOME="$SB/home" bash infra/spark/forged-sandbox.sh "$T/probe" "$1" > "$SB/out" 2>&1; echo $?; } 566 check "$(sbx "$SB/home/forge-data/written")" 0 "control: the sandboxed probe can write its data folder" 567 check "$(sbx "$SB/work/written")" 1 "the sandboxed probe cannot write the work dir" 568 [ ! -e "$SB/work/written" ] && ok "nothing appeared in the work dir" || bad "the work dir was written" 569 570 # ------------------------------------------------------------------ 8. alarms: each fires at its threshold and refuses nothing 571 alarm() { awk -F'\t' -v n="$1" '$1==n {print $2"/"$3}' "$W/work/alarms.txt" 2>/dev/null; } 572 aup() { up "$T/k1" "$K1" "$T/good.tar" "$1"; intake; check "$(upst "$USHA")" stored "alarm $1: the upload is still stored"; } 573 world a1; plant "$K1" 7 open D; aup key-at-8 574 v=$(alarmk key_shelf_rows); check "${v%|*}" "8/8|$K1" "alarm key_shelf_rows fires at the former 8 and names the key" 575 world a2; plant "$K1" 6 open E; aup key-at-7 576 check "$(alarm key_shelf_rows)" "" "alarm key_shelf_rows is quiet at 7" 577 world a3; plant "$K3" 199 open F; aup shelf-at-200 578 check "$(alarmk shelf_rows | cut -d'|' -f1,2)" "200/200|$K3" "alarm shelf_rows fires at the former 200 and names the key with the most rows" 579 world a4; plant "$K3" 198 open G; aup shelf-at-199 580 check "$(alarm shelf_rows)" "" "alarm shelf_rows is quiet at 199" 581 world a5; printf 'z2PlantKibabcdefghijkmnopq\topen\t%s\t2026-11-11\t51200\tbig\t\t\n' "$K3" > "$W/work/list.tsv"; aup kib-at-51200 582 check "$(alarmk largest_project_kib)" "51200/51200|$K3|`52428800`" "alarm largest_project_kib fires at the former 51200 KiB, names the key and the volume" 583 world a6; printf 'z2PlantKibabcdefghijkmnopq\topen\t%s\t2026-11-11\t51199\tbig\t\t\n' "$K3" > "$W/work/list.tsv"; aup kib-at-51199 584 check "$(alarm largest_project_kib)" "" "alarm largest_project_kib is quiet at 51199" 585 world a7; head -c `1048576` /dev/zero | tr '\0' x > "$T/data/open/queue"; echo >> "$T/data/open/queue"; aup queue 586 grep -q "^queue_bytes${TAB}1048[0-9]*${TAB}`1048576`" "$W/intake.err" && ok "alarm queue_bytes fires at the former `1048576` (stderr), and forged took the upload past it" || bad "queue alarm: $(grep queue_bytes "$W/intake.err" | head -2)" 587 world a8; mkdir -p "$T/data/open/up"; truncate -s `1073741824` "$T/data/open/up/sparse"; aup spool 588 v=$(alarm spool_bytes); [ "${v%/*}" -ge `1073741824` ] 2>/dev/null && [ "${v#*/}" = `1073741824` ] && grep -q "^spool_bytes${TAB}" "$W/intake.err" && ok "alarm spool_bytes fires at 1 GiB ($v, also on stderr)" || bad "spool alarm: '$v' $(grep spool_bytes "$W/intake.err" | head -2)" 589 rm -f "$T/data/open/up/sparse" 590 world a9; head -c 52428 /dev/zero | tr '\0' x > "$W/home/stub/policy"; aup seed-at-52428 591 check "$(alarm rad_seed_output_bytes)" 52428/52428 "alarm rad_seed_output_bytes fires at 52428 of the 65535-byte buffer" 592 world a10; head -c 52427 /dev/zero | tr '\0' x > "$W/home/stub/policy"; aup seed-at-52427 593 check "$(alarm rad_seed_output_bytes)" "" "alarm rad_seed_output_bytes is quiet at 52427" 594 world a11; HR=z2HeadDegatesabcdefghijkmnp; mkdir -p "$S$HR" 595 printf 'rad:%s held-project allow all\n' "$HR" > "$W/home/stub/policy"; { printf '%s (k1)\n' "$K1"; head -c 52428 /dev/zero | tr '\0' x; } > "$W/home/stub/delegates" 596 printf 'B\t%s\t%s\tx\n' "$HR" "$K1" >> "$T/data/open/queue"; aup delegates 597 check "$(st "$HR")" held "alarm delegates: the held bring still goes on" 598 case "$(alarm rad_delegates_output_bytes)" in 52*/52428) ok "alarm rad_delegates_output_bytes fires past 52428";; *) bad "delegates alarm: $(alarm rad_delegates_output_bytes)";; esac 599 world a12; intake; check "$(alarm storage_free_bytes)$(alarm data_free_bytes)" "" "storage_free_bytes and data_free_bytes are quiet with one-byte reserves" 600 printf 'OPEN_RESERVE_STORAGE_BYTES=`999999999999999999`\nOPEN_RESERVE_DATA_BYTES=`999999999999999999`\n' > "$W/work/reserve"; intake 601 case "$(alarm storage_free_bytes)|$(alarm data_free_bytes)" in */`1999999999999999998`\|*/`1999999999999999998`) ok "storage_free_bytes and data_free_bytes fire at twice their reserve";; *) bad "free alarms: $(alarm storage_free_bytes) $(alarm data_free_bytes)";; esac 602 # list_bytes: the list's size, alarmed at 80 percent of the former 262,143-byte read buffer (the 603 # list has no size limit now: it is read a row at a time) 604 plantbig() { # KEY BYTES: open rows of exactly 900 bytes each until the list holds at least BYTES 605 python3 -I - "$1" "$2" "$W/work/list.tsv" <<'EOF' 606 import sys 607 d, want, f = sys.argv[1], int(sys.argv[2]), sys.argv[3] 608 A = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' 609 i = 0; total = 0 610 with open(f, 'a') as o: 611 while total < want: 612 head = 'z2Wide%s%s%s\topen\t%s\t2026-11-11\t1\tw\t%s\t' % (A[i // 3364 % 58], A[i // 58 % 58], A[i % 58] + 'abcdefghijkmnopq', d, 'd' * 400) 613 row = head + 'n' * (899 - len(head)) + '\n' 614 assert len(row) == 900 615 o.write(row); total += 900; i += 1 616 EOF 617 } 618 world a14; plantbig "$K3" 209715; aup list-80 619 case "$(alarm list_bytes)" in */209715) ok "alarm list_bytes fires at 80 percent of the former list buffer ($(alarm list_bytes))";; *) bad "list alarm: '$(alarm list_bytes)'";; esac 620 # a 1 MiB list (4 times the former read buffer, which refused at 261,300 bytes): an upload is 621 # stored, every planted row stays byte for byte with the new row last, and forged lists them all 622 world a15; plantbig "$K3" `1048576`; cp "$W/work/list.tsv" "$T/a15.before"; up "$T/k1" "$K1" "$T/good.tar" list-big; intake 623 check "$(upst "$USHA")" stored "an upload into a 1 MiB list is stored" 624 n=$(stat -c %s "$T/a15.before"); cmp -s -n "$n" "$T/a15.before" "$W/work/list.tsv" && [ "$(( $(wc -l < "$W/work/list.tsv") - $(wc -l < "$T/a15.before") ))" = 1 ] && [ "$(tail -1 "$W/work/list.tsv" | cut -f2)" = stored ] && ok "every planted row kept byte for byte, the stored row last ($(stat -c %s "$W/work/list.tsv") bytes)" || bad "1 MiB list: rows lost or changed ($(wc -l < "$W/work/list.tsv") rows)" 625 cmp -s "$W/work/list.tsv" "$T/data/open/list.tsv" && ok "the published 1 MiB list is the private list, byte for byte" || bad "the published list differs" 626 c=$(code GET /open.json); python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); n=int(sys.argv[2]); assert len(d["projects"])==n and d["projects"][-1]["rid"]==sys.argv[3], (len(d["projects"]), n)' "$T/body" "$(wc -l < "$W/work/list.tsv")" "$(tail -1 "$W/work/list.tsv" | cut -f1)" && ok "forged lists all $(wc -l < "$W/work/list.tsv") rows of the 1 MiB shelf, the stored one last ($c)" || bad "/open.json with a 1 MiB list: $c" 627 # a 60 MiB project (no size limit): stored, and largest_project_kib names the key and the volume 628 world a16; mktar "$T/big60.tar" "random.bin=@rand:`62914560`" a=b; spoolup "$T/k1" "$K1" "$T/big60.tar" sixty; intake 629 check "$(ustate "$K1")" stored "a 60 MiB project is stored" 630 v=$(alarmk largest_project_kib); check "$(echo "$v" | cut -d'|' -f2)" "$K1" "largest_project_kib names its key"; [ "${v##*|}" -ge `52428800` ] && ok "and a volume past the former 50 MiB (${v##*|} bytes)" || bad "volume '${v##*|}'" 631 grep -q '"name":"rad_seed_output_bytes"' "$T/data/open/alarms.json" && ok "alarms.json lists the checks" || bad "alarms.json" 632 633 # ------------------------------------------------------------------ 9. the open folder is forged's: links planted there are never followed 634 # A compromised forged can put links in open/. The intake must never write, rename or unlink 635 # through one: each case plants links to files and folders outside, runs the intake and checks that 636 # every outside file is as it was. The same functions run against mutants below. 637 OUTS=$T/outside 638 fixrepo() { # RID [MIB]: a bare repository in the storage folder (MIB of zeros in one file) and an open row of K1 for it 639 F=$T/fx-src; rm -rf "$F" "$S$1"; git init -q --template= -b main "$F" 640 printf '# fixture %s\n' "$1" > "$F/README.md"; [ -n "${2:-}" ] && head -c $(( $2 * `1048576` )) /dev/zero > "$F/zeros.bin" 641 git -C "$F" add -A; git -C "$F" -c user.name=x -c user.email= -c commit.gpgsign=false commit -q -m one 642 git clone -q --bare --no-local "$F" "$S$1" 643 printf '%s\topen\t%s\t2026-11-11\t8\tfixture\t\t\n' "$1" "$K1" >> "$W/work/list.tsv" 644 } 645 victim() { printf 'victim %s\n' "$1" > "$2"; } 646 intact() { printf 'victim %s\n' "$1" | cmp -s - "$2"; } 647 outdir() { O=$OUTS/$1; rm -rf "$O"; mkdir -p "$O"; } 648 LA=z2LinkTarTargetabcdefghijk; LB=z2LinkDirAabcdefghijkmnop; LP=z2LinkDirPabcdefghijkmnop 649 linka() { # BIN: a/.tar, .sha256 and .tar.tmp are links to outside files 650 world la; outdir la; fixrepo "$LA"; mkdir -p "$T/data/open/a"; victim tar "$O/tar"; victim sha "$O/sha" 651 ln -s "$O/tar" "$T/data/open/a/$LA.tar"; ln -s "$O/sha" "$T/data/open/a/$LA.sha256"; ln -s "$O/tar" "$T/data/open/a/$LA.tar.tmp" 652 BIN=$1 intake; intact tar "$O/tar" && intact sha "$O/sha" 653 } 654 linkdira() { # BIN: a/ is a link to an outside folder holding .tar 655 world lda; outdir lda; fixrepo "$LB"; victim tar "$O/$LB.tar"; ln -s "$O" "$T/data/open/a" 656 BIN=$1 intake; intact tar "$O/$LB.tar" && [ "$(ls -A "$O" | wc -l)" = 1 ] 657 } 658 linkdirp() { # BIN: p/ is a link to an outside folder holding .txt; the lister refreshes, then withdraws 659 world ldp; outdir ldp; fixrepo "$LP"; victim txt "$O/$LP.txt"; ln -s "$O" "$T/data/open/p" 660 printf 'B\t%s\t%s\tagain\n' "$LP" "$K1" >> "$T/data/open/queue"; BIN=$1 intake 661 intact txt "$O/$LP.txt" || return 1 662 printf 'W\t%s\t%s\n' "$LP" "$K1" >> "$T/data/open/queue"; BIN=$1 intake 663 intact txt "$O/$LP.txt" && [ "$(ls -A "$O" | wc -l)" = 1 ] 664 } 665 linkdirup() { # BIN: up/ is a link to an outside folder holding a real spool and the status file's name 666 world ldu; outdir ldu; up "$T/k1" "$K1" "$T/good.tar" linked-up 667 mv "$T/data/open/up/"* "$O/"; rmdir "$T/data/open/up"; ln -s "$O" "$T/data/open/up" 668 f=$(ls "$O" | sed -n 's/\.b64$//p'); victim json "$O/$f.json" 669 BIN=$1 intake; intact json "$O/$f.json" && [ -f "$O/$f.b64" ] && [ -f "$O/$f.sig" ] && [ "$(ls "$S" | grep -c Stored)" = 0 ] 670 } 671 linkopen() { # BIN: open itself is a link to an outside folder 672 world lo; outdir lo; victim list "$O/list.tsv"; victim alarms "$O/alarms.json"; rm -rf "$T/data/open"; ln -s "$O" "$T/data/open" 673 BIN=$1 intake; r=1; intact list "$O/list.tsv" && intact alarms "$O/alarms.json" && [ "$(ls -A "$O" | wc -l)" = 2 ] && r=0 674 rm -f "$T/data/open"; mkdir -p "$T/data/open"; return $r 675 } 676 linkfile() { # BIN: open/alarms.json and list.tsv are links to outside files 677 world lf; outdir lf; victim alarms "$O/alarms"; victim list "$O/list"; ln -s "$O/alarms" "$T/data/open/alarms.json"; ln -s "$O/list" "$T/data/open/list.tsv" 678 printf 'B\t%s\t%s\tx\n' "$(rid 9)" "$K1" >> "$T/data/open/queue" 679 BIN=$1 intake; intact alarms "$O/alarms" && intact list "$O/list" && [ ! -L "$T/data/open/alarms.json" ] && [ ! -L "$T/data/open/list.tsv" ] 680 } 681 linka "$T/intake" && ok "a/.tar, .sha256 and .tar.tmp linked outside: the outside files are unchanged" || bad "a/.tar link: an outside file changed" 682 [ -f "$T/data/open/a/$LA.tar" ] && [ ! -L "$T/data/open/a/$LA.tar" ] && [ "$(sha "$T/data/open/a/$LA.tar")" = "$(cat "$T/data/open/a/$LA.sha256")" ] && ok "and the download replaced the links with real files (sha256 matches)" || bad "no real download after the links" 683 linkdira "$T/intake" && ok "a/ linked to an outside folder: nothing written there" || bad "a/ link: the outside folder changed" 684 [ -L "$T/data/open/a" ] && [ ! -e "$T/data/open/a/$LB.sha256" ] && ok "and no download is made through it (the link is left as it was)" || bad "a download appeared through the a/ link" 685 linkdirp "$T/intake" && ok "p/ linked to an outside folder: refresh and withdraw write and remove nothing there" || bad "p/ link: the outside folder changed" 686 check "$(st "$LP")" withdrawn "p/ link: the withdraw itself still happened" 687 linkdirup "$T/intake" && ok "up/ linked to an outside folder: the spool there is not read, the status file not written" || bad "up/ link: the outside folder changed or a repository was made" 688 linkopen "$T/intake" && ok "open linked to an outside folder: nothing written there" || bad "open link: the outside folder changed" 689 linkfile "$T/intake" && ok "alarms.json and list.tsv linked to outside files: replaced by the rename, the outside files unchanged" || bad "file link: an outside file changed" 690 691 # ------------------------------------------------------------------ 10. the download stops at the data reserve while it is written 692 BIGR=z2BigArchiveabcdefghijkmn; NEARR=z2NearCapArchiveabcdefghi 693 world cap; fixrepo "$NEARR" 10; fixrepo "$BIGR" 60; cp "$W/work/list.tsv" "$T/data/open/list.tsv" 694 datares() { F=$(df -B1 --output=avail "$T/data/open" | tail -1); printf 'OPEN_RESERVE_STORAGE_BYTES=1\nOPEN_RESERVE_DATA_BYTES=%s\n' $((F - 40 * `1048576`)) > "$W/work/reserve"; } 695 datares; echo "data filesystem: $F bytes free; reserve set 40 MiB below that"; intake 696 [ ! -e "$T/data/open/a/$BIGR.tar" ] && [ ! -e "$T/data/open/a/$BIGR.tar.tmp" ] && [ ! -e "$T/data/open/a/$BIGR.sha256" ] && ok "a download that would cross the data reserve: none, no temp file" || bad "a download crossed the reserve: $(ls -l "$T/data/open/a/")" 697 code GET "/open/$BIGR.json" > /dev/null; check "$(python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); print(d["download"], d["download_sha256"])' "$T/body")" "None None" "page JSON: download null" 698 c=$(code GET "/open/$BIGR.tar"); check "$c" 404 "GET it: 404" 699 [ -f "$T/data/open/a/$NEARR.tar" ] && [ "$(sha "$T/data/open/a/$NEARR.tar")" = "$(cat "$T/data/open/a/$NEARR.sha256")" ] && ok "a 10 MiB download within the room is written" || bad "no download within the room" 700 printf 'OPEN_RESERVE_STORAGE_BYTES=1\nOPEN_RESERVE_DATA_BYTES=1\n' > "$W/work/reserve"; intake 701 z=$(stat -c %s "$T/data/open/a/$BIGR.tar" 2>/dev/null || echo 0); [ "$z" -gt `52428800` ] && [ "$(sha "$T/data/open/a/$BIGR.tar")" = "$(cat "$T/data/open/a/$BIGR.sha256")" ] && ok "with room, a download past the former 50 MiB is written ($z bytes)" || bad "no big download with room: $z" 702 code GET /open/ > /dev/null; grep -q "href=\"/open/$NEARR\"" "$T/body" && ! grep -q "Unfinished:" "$T/body" && ok "a shelf card with an empty note has no Unfinished label" || bad "empty Unfinished label on the shelf" 703 code GET "/open/$NEARR" > /dev/null; ! grep -q "Unfinished:" "$T/body" && ! grep -q "pj-dev" "$T/body" && ok "its page has no empty label and, not stored by the hub, no developer section" || bad "empty label or developer section on a fetched row's page" 704 code GET "/open/$NEARR.json" > /dev/null; grep -q '"unfinished":""' "$T/body" && ok "the JSON keeps \"unfinished\": \"\"" || bad "JSON unfinished" 705 # a hostile hub DID line in the snapshot is escaped 706 world dv; printf 'did:key:z6Mk"&\n' > "$W/home/stub/self"; spoolup "$T/k1" "$K1" "$T/good.tar" dev-escape; intake; DVR=$(sed -n 's/.*"rid":"rad:\([^"]*\)".*/\1/p' "$T/data/open/up/$USHA.$(dh "$K1").json") 707 code GET "/open/$DVR" > /dev/null; grep -q "did:key:z6Mk<script>alert(1)</script>"&" "$T/body" && ! grep -q ""&\n' > "$W/home/stub/self"; spoolup "$T/k1" "$K1" "$T/good.tar" dev-escape-m; intake; DVR=$(sed -n 's/.*"rid":"rad:\([^"]*\)".*/\1/p' "$T/data/open/up/$USHA.$(dh "$K1").json"); code GET "/open/$DVR" > /dev/null; grep -q "" "$T/body" && ok "MUTANT without the escape of the hub key line puts the script tag on the page" || bad "mutant noescdev: no raw tag"; stop; fi 842 # a queue line written only in part (a full disk; here a test build whose write of the U line is 5 843 # bytes short) is cut back: the next line starts clean. The same build without the cut is the mutant. 844 QW='n = add n get gonotel 0|put b n 10|n = add n 1|w = write int fd b 0 n|if ne w long n|if ge sz 0|r = ftrunc int fd sz|end' 845 shortq() { # NAME EDIT: run the build, finish one upload; prints "finish status|queue bytes before|after|last byte" 846 if mf "$1" "$QW=>$2"; then world "m$1"; mktar "$T/sq.tar" "a=$1"; q0=$(cat "$T/data/open/queue" 2>/dev/null | wc -c) 847 up "$T/k1" "$K1" "$T/sq.tar" "short-$1" > /dev/null 2>&1 848 echo "$UC|$q0|$(cat "$T/data/open/queue" 2>/dev/null | wc -c)|$(tail -c 1 "$T/data/open/queue" 2>/dev/null | od -An -c | tr -d ' ')"; stop 849 fi 850 } 851 v=$(shortq shortq 'n = add n get gonotel 0|put b n 10|n = add n 1|w = write int fd b 0 sub n 5|if ne w long n|if ge sz 0|r = ftrunc int fd sz|end') 852 case "$v" in 503\|*) a=$(echo "$v" | cut -d'|' -f2); b=$(echo "$v" | cut -d'|' -f3); [ "$a" = "$b" ] && ok "a queue line written short is answered 503 and cut back ($v)" || bad "short write left a fragment: $v";; *) bad "short write: $v";; esac 853 v=$(shortq shortqnotrunc 'n = add n get gonotel 0|put b n 10|n = add n 1|w = write int fd b 0 sub n 5|if ne w long n') 854 a=$(echo "$v" | cut -d'|' -f2); b=$(echo "$v" | cut -d'|' -f3); [ -n "$b" ] && [ "$b" -gt "$a" ] && ok "MUTANT without the cut leaves a fragment in the queue ($v)" || bad "mutant shortqnotrunc: $v" 855 if mf noroom 'fn ohroom n ulong to ulong|b = new uchar 96 0=>fn ohroom n ulong to ulong|if true|ret 0|end|b = new uchar 96 0'; then mkdir -p "$T/data/open"; signin "$T/k1" "$K1" 856 printf 'free 1000 reserve 999999 at 11\n' > "$SPF"; c=$(chunk "$(xsha e)" 0 "$T/cbig"); [ "$c" = 200 ] && ok "MUTANT where forged ignores the space file writes with no room" || bad "mutant noroom (no room): $c" 857 stale 12; c1=$(chunk "$(xsha f)" 0 "$T/cbig"); c2=$(chunk "$(xsha f)" 1 "$T/cbig"); [ "$c2" = 200 ] && ok "MUTANT where forged ignores the space file writes past a stale measure" || bad "mutant noroom (stale): $c1 $c2"; stop; fi 858 if mf nostored 'if ohis s e 1 toheld|ret true|end|ret ohis s e 1 tostor=>ret ohis s e 1 toheld'; then mkdir -p "$T/data/open"; cp "$GOODW/work/list.tsv" "$T/data/open/list.tsv"; c=$(code GET "/open/$GOOD.tar"); [ "$c" = 404 ] && ok "MUTANT that does not count stored rows on the shelf hides the stored project ($c)" || bad "mutant nostored: $c"; stop; fi 859 860 echo "RESULT pass=$PASS fail=$FAIL" 861 [ "$FAIL" = 0 ]