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/quiet/tests/check.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 / quiet / tests / check.sh` 421 lines ยท 25103 bytes Raw Blame History 1 #!/bin/bash 2 # ORACLE: drives a test forged and the Omega tool. git, rad, curl and ssh-keygen are oracles. 3 # The throwaway node has no route out. It does not touch port 18480, the live node, or the live data dir. 4 # QUIET_MUTANT= is applied to the test forged and to the tool (quiet/tests/mutants.sh). 5 # The test ends its own radicle-node: the launcher is sudo -> unshare -> runuser -> rad, and the node is 6 # rad's child, so killing the launcher alone left one node behind per run. 7 # untr FILE: forged adds translation hints while it sends an HTML page (server/tr.om); the checks here 8 # read pages without them (server/tests/translate.sh gates the hints). Other bodies are left as sent. 9 untr() { case "$(head -c 15 "$1" 2>/dev/null)" in '\([^<]*\)<\/span>/\1/g; s/ translate="no"//g' "$1" ;; esac; } 10 set -u 11 cd "$(dirname "$0")/../.." 12 REALHOME=/home/drakestapleton 13 OMV=$REALHOME/work/flux/omega-mv 14 OMC=$OMV/seed/out/omc 15 PIN=`3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194` 16 PORT=${QUIET_PORT:-18521} 17 CORES=${FORGED_CPUS:-10,11} 18 # the queen pool lock that owns CORES (pool-10-11 or pool-12-14 with FORGED_CPUS=12,13,14) 19 LOCK=${QUIET_LOCK:-$REALHOME/handoffs/hive/queen/pool-10-11.lock} 20 T=$(mktemp -d /tmp/forge-quiet.XXXXXX) 21 PASS=0 22 FAIL=0 23 PID= 24 NPID= 25 FAKE=$T/home 26 export HOME="$FAKE" 27 export RAD_HOME="$FAKE/.radicle" 28 export RAD_PASSPHRASE=simplify-test-pass 29 export PATH="$FAKE/.local/bin:/usr/bin:/bin" 30 ok() { PASS=$((PASS+1)); echo "PASS $*"; } 31 bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; } 32 # mynodes: pids of radicle-node processes whose RAD_HOME is this test's (never another run's) 33 mynodes() { 34 for p in $(pgrep -u "$(id -u)" -x radicle-node); do 35 tr '\0' '\n' < "/proc/$p/environ" 2>/dev/null | grep -q -x "RAD_HOME=$RAD_HOME" && echo "$p" 36 done 37 return 0 38 } 39 stopnode() { 40 rad node stop > /dev/null 2>&1 || true 41 if [ -n "$NPID" ]; then sudo -n kill "$NPID" 2>/dev/null || true; wait "$NPID" 2>/dev/null || true; NPID=; fi 42 for p in $(mynodes); do kill "$p" 2>/dev/null || true; done 43 for _ in 1 2 3 4 5 6 7 8 9 10; do [ -z "$(mynodes)" ] && break; sleep 0.2; done 44 for p in $(mynodes); do kill -9 "$p" 2>/dev/null || true; done 45 } 46 trap 'stopnode; [ -n "$PID" ] && kill "$PID" 2>/dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT 47 got=$(sha256sum "$OMC" | cut -d' ' -f1) 48 [ "$got" = "$PIN" ] || { echo "omc pin mismatch"; exit 1; } 49 mkdir -p "$FAKE/.local/bin" 50 ln -s "$REALHOME/.radicle/bin/rad" "$FAKE/.local/bin/rad" 51 ln -s "$REALHOME/.radicle/bin/radicle-node" "$FAKE/.local/bin/radicle-node" 52 ln -s "$REALHOME/.radicle/bin/git-remote-rad" "$FAKE/.local/bin/git-remote-rad" 53 printf '%s\n' "$RAD_PASSPHRASE" | rad auth --alias simplify-test --stdin > "$T/auth.out" 2>&1 \ 54 || { echo "rad auth failed"; cat "$T/auth.out"; exit 1; } 55 SRC=$T/src 56 mkdir -p "$SRC" 57 git -C "$SRC" init -q -b main 58 git -C "$SRC" config user.email forge@localhost 59 git -C "$SRC" config user.name forge-d 60 printf 'throwaway\n' > "$SRC/README.md" 61 git -C "$SRC" add README.md 62 git -C "$SRC" -c commit.gpgsign=false commit -qm init 63 rad init --public --no-seed --name forge-d-l1008 --description "throwaway for L1008 D" --default-branch main --no-confirm "$SRC" > "$T/init.out" 2>&1 \ 64 || { echo "rad init failed"; cat "$T/init.out"; exit 1; } 65 RID=$(grep -o 'rad:z[1-9A-HJ-NP-Za-km-z]*' "$T/init.out" | head -1) 66 RID=${RID#rad:} 67 [ -n "$RID" ] || { echo "no RID"; cat "$T/init.out"; exit 1; } 68 echo "RID $RID" 69 mkdir -p "$T/storage" "$T/data" 70 ln -s "$RAD_HOME/storage/$RID" "$T/storage/$RID" 71 cat > "$T/RIDS.md" < "$T/node.log" 2>&1 & 81 NPID=$! 82 up=0 83 for i in $(seq 1 20); do 84 if rad node status 2>/dev/null | head -1 | grep -q 'Node ID'; then up=1; break; fi 85 sleep 1 86 done 87 [ "$up" = 1 ] || { echo "isolated node did not start"; cat "$T/node.log"; exit 1; } 88 89 U=$(HOME=$REALHOME FORGE_TRY=quiet ./run.sh units | tr '\n' ' ') 90 { printf 'om2\n'; cat $U; } > "$T/all.om" 91 sed -i \ 92 -e "s|haddr4 a `2130706433` 18480|haddr4 a `2130706433` $PORT|" \ 93 -e "s|/home/drakestapleton/handoffs/radicle/RIDS.md|$T/RIDS.md|" \ 94 -e "s|/home/drakestapleton/.radicle/storage/|$T/storage/|g" \ 95 -e "s|/home/drakestapleton/forge-data/|$T/data/|g" \ 96 "$T/all.om" 97 grep -q "$T/data/" "$T/all.om" || { echo "data dir not redirected"; exit 1; } 98 if [ -n "${QUIET_MUTANT:-}" ]; then 99 cp "$T/all.om" "$T/all.orig.om" 100 sed -i -e "$QUIET_MUTANT" "$T/all.om" 101 cmp -s "$T/all.om" "$T/all.orig.om" && { echo "MUTANT changed nothing in the server source"; exit 1; } 102 echo "MUTANT $QUIET_MUTANT" 103 fi 104 flock "$LOCK" taskset -c "$CORES" nice -n 10 "$OMC" < "$T/all.om" > "$T/forged" 2> "$T/omc.err" \ 105 || { echo "BUILD FAILED"; cat "$T/omc.err"; exit 1; } 106 chmod +x "$T/forged" 107 if [ -n "${QUIET_MUTANT:-}" ]; then 108 # the units of contrib/build.sh, with the same mutant 109 { printf 'om2\n'; cat "$OMV/om/tls/sha2.om" server/util.om quiet/qn2bind.om quiet/qn1dig.om contrib/forge-contribute.om; } \ 110 | sed -e "$QUIET_MUTANT" | flock "$LOCK" taskset -c "$CORES" nice -n 10 "$OMC" > "$T/forge-contribute" 2> "$T/omc-tool.err" \ 111 || { echo "TOOL BUILD FAILED"; cat "$T/omc-tool.err"; exit 1; } 112 chmod +x "$T/forge-contribute" 113 else 114 flock "$LOCK" taskset -c "$CORES" nice -n 10 env HOME="$REALHOME" FORGED_CPUS="$CORES" sh contrib/build.sh "$T/forge-contribute" \ 115 || { echo "TOOL BUILD FAILED"; exit 1; } 116 fi 117 118 B="http://127.0.0.1:$PORT" 119 srv() { 120 FORGE_SOCIAL_DIR="$T/data/" taskset -c "$CORES" nice -n 10 "$T/forged" >> "$T/forged.out" 2>> "$T/forged.err" & 121 PID=$! 122 for i in $(seq 50); do curl -sf -o /dev/null "$B/" && return 0; sleep 0.1; done 123 return 1 124 } 125 # alive NAME: the server process is still there and answers. When it is gone its exit code is 126 # reported (104 is trap 4, a loop past its bound) and it is started again, so the next case is judged alone. 127 # A process that is ending can still be there for a moment after its last request failed: when the 128 # liveness request fails, the process is watched for 5 s more, so that its exit is recorded under 129 # this case and not under the next one. Alive but silent after that is its own failure. 130 alive() { 131 if kill -0 "$PID" 2>/dev/null; then 132 if [ "$(curl -s -o /dev/null -m 5 -w '%{http_code}' "$B/")" = 200 ]; then ok "$1: server still answers"; return 0; fi 133 for _ in $(seq 25); do kill -0 "$PID" 2>/dev/null || break; sleep 0.2; done 134 if kill -0 "$PID" 2>/dev/null; then bad "$1: server runs but does not answer"; return 1; fi 135 fi 136 wait "$PID" 2>/dev/null; rc=$? 137 bad "$1: server exited rc=$rc" 138 srv || { echo "server did not start again"; exit 1; } 139 return 1 140 } 141 srv || { echo "server did not start"; cat "$T/forged.err"; exit 1; } 142 143 code() { # method path [curl args...] 144 m=$1; p=$2; shift 2 145 c=$(curl -s -o "$T/body" -D "$T/hdr" -X "$m" "$@" "$B$p" -w '%{http_code}'); untr "$T/body"; printf %s "$c" 146 } 147 hdr() { grep -i "^$1:" "$T/hdr" | head -1 | cut -d' ' -f2- | tr -d '\r'; } 148 field() { grep -o "name=\"$1\" value=\"[^\"]*\"" "$T/body" | head -1 | sed 's/.*value="//; s/"$//'; } 149 150 ssh-keygen -q -t `ed25519` -N '' -C t1 -f "$T/k1" 151 D1=$(python3 - "$T/k1.pub" <<'PY' 152 import sys, base64 153 blob = base64.b64decode(open(sys.argv[1]).read().split()[1]) 154 raw = b'\xed\x01' + blob[-32:] 155 A = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' 156 n = int.from_bytes(raw, 'big'); s = '' 157 while n: 158 n, r = divmod(n, 58); s = A[r] + s 159 print('did:key:z' + '1' * (len(raw) - len(raw.lstrip(b'\0'))) + s) 160 PY 161 ) 162 c=$(code GET /login) 163 [ "$c" = 200 ] && ok "GET /login" || bad "GET /login $c" 164 PREN=$(hdr set-cookie | sed -n 's/^\([A-Za-z_-]*forge_pre\)=.*/\1/p') 165 PRE=$(hdr set-cookie | sed -n 's/^[A-Za-z_-]*forge_pre=\([0-9a-f]*\);.*/\1/p') 166 CSRF=$(field csrf); NONCE=$(field nonce); TS=$(field ts) 167 printf '%s' "interplane-forge-login:$NONCE:$TS" | ssh-keygen -Y sign -f "$T/k1" -n interplane-forge > "$T/sig" 2>/dev/null 168 c=$(code POST /login -H "Cookie: ${PREN}=$PRE" --data-urlencode "csrf=$CSRF" --data-urlencode "nonce=$NONCE" \ 169 --data-urlencode "ts=$TS" --data-urlencode "did=$D1" --data-urlencode "sig@$T/sig") 170 [ "$c" = 303 ] && ok "sign in" || bad "sign in $c" 171 SESSN=$(hdr set-cookie | sed -n 's/^\([A-Za-z_-]*forge_session\)=.*/\1/p') 172 SESS=$(hdr set-cookie | sed -n 's/^[A-Za-z_-]*forge_session=\([^;]*\);.*/\1/p') 173 CK="Cookie: ${SESSN}=$SESS" 174 c=$(code GET /settings -H "$CK") 175 [ "$c" = 200 ] && ok "settings" || bad "settings $c" 176 CSRF=$(field csrf) 177 c=$(code POST /settings/name -H "$CK" --data-urlencode "csrf=$CSRF" --data-urlencode "name=tester-one") 178 [ "$c" = 303 ] && ok "display name tester-one" || bad "display name $c" 179 180 # quiet by default: a read does not create a digest file 181 for base in / /forge/; do 182 c=$(code GET /notifications -H "$CK" -H "X-Forge-Base: $base") 183 grep -q 'No digest file' "$T/body" && grep -q 'Quiet by default' "$T/body" && [ "$c" = 200 ] \ 184 && ok "[$base] quiet page" || bad "[$base] quiet page $c" 185 c=$(code GET /notifications.json -H "$CK" -H "X-Forge-Base: $base") 186 grep -q '"quiet":true' "$T/body" && [ "$c" = 200 ] && ok "[$base] quiet JSON" || bad "[$base] quiet JSON $c" 187 done 188 [ ! -e "$T/data/quiet/out/tester-one" ] && ok "NEG read did not create a digest file" || bad "digest file created on read" 189 c=$(code GET /notifications.json) 190 [ "$c" = 401 ] && ok "NEG signed-out JSON is 401" || bad "signed-out JSON $c" 191 192 # subscription is an event: it writes the digest 193 c=$(code GET /notifications -H "$CK") 194 CSRF=$(field csrf) 195 c=$(code POST /notifications -H "$CK" --data-urlencode "csrf=$CSRF" --data-urlencode "agent=bay24" --data-urlencode "repo=forge-d-l1008") 196 [ "$c" = 303 ] && ok "save filter" || bad "save filter $c" 197 grep -q 'count=0' "$T/data/quiet/out/tester-one" && ok "filter event wrote an empty digest" || bad "empty digest missing" 198 199 # one command 200 # more than 64 KiB of older, non-matching events first: the new event must still reach the digest 201 for i in $(seq 800); do printf 'patch other-repo other %040d %040d\n' "$i" "$i"; done >> "$T/data/quiet/events" 202 [ "$(stat -c %s "$T/data/quiet/events")" -gt 65536 ] && ok "events file holds more than 64 KiB before the tool" || bad "events prefill too small" 203 printf 'hello from the tool\n' > "$T/body.txt" 204 printf '#!/bin/sh\npwd > %s/cmd.pwd\nprintf "ran ok\\n"\nexit 0\n' "$T" > "$T/cmd.sh" 205 chmod +x "$T/cmd.sh" 206 CLONE=$T/clone 207 "$T/forge-contribute" "$RID" "$CLONE" "feat-d" "Add a note..." "$T/cmd.sh" tester-one bay24 forge-d-l1008 note.txt "$T/body.txt" "$T/data/" "$HOME" > "$T/tool.out" 2> "$T/tool.err" 208 rc=$? 209 [ "$rc" = 0 ] && ok "forge-contribute exit 0 (title with ..)" || bad "forge-contribute exit $rc $(cat "$T/tool.err" | tail -20)" 210 [ "$(cat "$T/cmd.pwd" 2>/dev/null)" = "$CLONE" ] && ok "CMD ran in the clone" || bad "CMD cwd: $(cat "$T/cmd.pwd" 2>/dev/null)" 211 PAT=$(awk '/^patch /{print $2}' "$T/tool.out") 212 CMT=$(awk '/^commit /{print $2}' "$T/tool.out") 213 [ ${#PAT} = 40 ] && [ ${#CMT} = 40 ] && ok "tool printed patch and commit" || bad "tool output $(cat "$T/tool.out")" 214 # an empty id would make every later grep match: replace it with a word no page contains 215 [ -n "$PAT" ] || PAT=no-patch-id-printed 216 [ -n "$CMT" ] || CMT=no-commit-printed 217 grep -q "$PAT" "$T/data/quiet/out/tester-one" && grep -q 'count=1' "$T/data/quiet/out/tester-one" \ 218 && ok "event rewrote the digest" || bad "digest after contribute: $(cat "$T/data/quiet/out/tester-one" 2>/dev/null)" 219 BEFORE=$(sha256sum "$T/data/quiet/out/tester-one" | cut -d' ' -f1) 220 for base in / /forge/; do 221 P=${base%/} 222 c=$(code GET /notifications -H "$CK" -H "X-Forge-Base: $base") 223 grep -q "$PAT" "$T/body" && grep -q 'bay24' "$T/body" && [ "$c" = 200 ] && ok "[$base] digest page shows the patch" || bad "[$base] digest page" 224 c=$(code GET /notifications.json -H "$CK" -H "X-Forge-Base: $base") 225 grep -q "$PAT" "$T/body" && grep -q '"quiet":false' "$T/body" && [ "$c" = 200 ] && ok "[$base] digest JSON" || bad "[$base] digest JSON" 226 python3 -c 'import json,sys; json.load(open(sys.argv[1]))' "$T/body" 2>/dev/null && ok "[$base] digest JSON parses" || bad "[$base] digest JSON does not parse" 227 c=$(code GET "/drakestapleton/forge-d-l1008" -H "X-Forge-Base: $base") 228 grep -q "Get this repository" "$T/body" && grep -q "forge-contribute $RID DIR BRANCH" "$T/body" && [ "$c" = 200 ] \ 229 && ok "[$base] clone panel names the tool with this RID" || bad "[$base] clone panel $c" 230 c=$(code GET "/drakestapleton/forge-d-l1008/patches/$PAT" -H "X-Forge-Base: $base") 231 grep -q 'Evidence receipt' "$T/body" && grep -q '>PASS<' "$T/body" && grep -q "$CMT" "$T/body" \ 232 && grep -q ".receipt" "$T/body" && [ "$c" = 200 ] && ok "[$base] patch page PASS" || bad "[$base] patch page $c" 233 c=$(code GET "/drakestapleton/forge-d-l1008/patches/$PAT.receipt" -H "X-Forge-Base: $base") 234 grep -q '"verify":"PASS"' "$T/body" && grep -q "\"commit\":\"$CMT\"" "$T/body" && [ "$c" = 200 ] \ 235 && ok "[$base] machine receipt PASS" || bad "[$base] machine receipt $c $(head -c 200 "$T/body")" 236 python3 -c 'import json,sys; json.load(open(sys.argv[1]))' "$T/body" 2>/dev/null && ok "[$base] receipt JSON parses" || bad "[$base] receipt JSON does not parse" 237 done 238 AFTER=$(sha256sum "$T/data/quiet/out/tester-one" | cut -d' ' -f1) 239 [ "$BEFORE" = "$AFTER" ] && ok "NEG page read did not rewrite the digest" || bad "digest changed on read" 240 rm -f "$T/data/quiet/out/tester-one" 241 code GET /notifications -H "$CK" >/dev/null 242 [ ! -e "$T/data/quiet/out/tester-one" ] && ok "NEG deleted digest was not rebuilt on read" || bad "read rebuilt the digest" 243 244 # agent filter negative: a different agent does not keep the event 245 c=$(code GET /notifications -H "$CK"); CSRF=$(field csrf) 246 c=$(code POST /notifications -H "$CK" --data-urlencode "csrf=$CSRF" --data-urlencode "agent=other" --data-urlencode "repo=forge-d-l1008") 247 grep -q "$PAT" "$T/data/quiet/out/tester-one" && bad "NEG other-agent filter still lists the patch" || ok "NEG other-agent filter excludes the patch" 248 grep -q 'count=0' "$T/data/quiet/out/tester-one" && ok "NEG filtered digest count 0" || bad "filtered count" 249 250 # tampered receipt: flip rc, keep the bind 251 code GET "/drakestapleton/forge-d-l1008/patches/$PAT.receipt" >/dev/null 252 python3 - "$T/body" "$T/bad-bind.txt" "$T/bad-commit.txt" <<'PY' 253 import json, sys, hashlib 254 raw = open(sys.argv[1]).read() 255 j = json.loads(raw) 256 lines = [ 257 f"commit={j['commit']}", 258 f"tree={j['tree']}", 259 f"cmd={j['cmd']}", 260 f"rc={j['rc']+1}", 261 f"out={j['out']}", 262 f"agent={j['agent']}", 263 ] 264 canon = "".join(x+"\n" for x in lines) 265 # stale bind from the original 266 stale = j["bind"] if "bind" in j else "" 267 open(sys.argv[2],"w").write("FORGE-EVIDENCE v1\n"+canon+f"bind={stale}\n") 268 lines[0] = "commit=" + "0"*40 269 canon = "".join(x+"\n" for x in lines) 270 bind = hashlib.sha256(canon.encode()).hexdigest() 271 open(sys.argv[3],"w").write("FORGE-EVIDENCE v1\n"+canon+f"bind={bind}\n") 272 print(stale[:12], bind[:12]) 273 PY 274 # the JSON may not include bind. If not, compute the original bind from the good lines. 275 if ! grep -q '"bind"' "$T/body"; then 276 python3 - "$T/body" "$T/bad-bind.txt" <<'PY' 277 import json, sys, hashlib 278 j = json.loads(open(sys.argv[1]).read()) 279 lines = [f"commit={j['commit']}", f"tree={j['tree']}", f"cmd={j['cmd']}", f"rc={j['rc']}", f"out={j['out']}", f"agent={j['agent']}"] 280 canon = "".join(x+"\n" for x in lines) 281 bind = hashlib.sha256(canon.encode()).hexdigest() 282 lines[3] = f"rc={j['rc']+1}" 283 open(sys.argv[2],"w").write("FORGE-EVIDENCE v1\n"+"".join(x+"\n" for x in lines)+f"bind={bind}\n") 284 PY 285 fi 286 287 # second and third patches, planted by the oracle, not by the tool 288 git -C "$CLONE" checkout -q -b feat-bad 289 printf 'bad\n' > "$CLONE/bad.txt" 290 git -C "$CLONE" add bad.txt 291 git -C "$CLONE" -c commit.gpgsign=false -c user.name=forge-d -c user.email=forge@localhost commit -qm bad 292 git -C "$CLONE" push -o patch.message=Bad rad HEAD:refs/patches > "$T/push2.out" 2>&1 || { echo "push2 failed"; cat "$T/push2.out"; bad "push tampered patch"; } 293 PAT2=$(grep -o 'Patch [0-9a-f]\{40\}' "$T/push2.out" | awk '{print $2}') 294 rad patch edit "$PAT2" --repo "rad:$RID" --no-announce --message Bad --message "$(cat "$T/bad-bind.txt")" > "$T/edit2.out" 2>&1 \ 295 && ok "planted stale-bind receipt" || bad "rad patch edit bind $(cat "$T/edit2.out")" 296 c=$(code GET "/drakestapleton/forge-d-l1008/patches/$PAT2.receipt") 297 grep -q '"verify":"REFUSED"' "$T/body" && grep -q '"reason":"bind"' "$T/body" && [ "$c" = 200 ] \ 298 && ok "NEG tampered receipt refused (bind)" || bad "NEG bind $(head -c 240 "$T/body")" 299 300 git -C "$CLONE" checkout -q -b feat-commit 301 printf 'worse\n' > "$CLONE/worse.txt" 302 git -C "$CLONE" add worse.txt 303 git -C "$CLONE" -c commit.gpgsign=false -c user.name=forge-d -c user.email=forge@localhost commit -qm worse 304 git -C "$CLONE" push -o patch.message=Worse rad HEAD:refs/patches > "$T/push3.out" 2>&1 || bad "push commit-mismatch" 305 PAT3=$(grep -o 'Patch [0-9a-f]\{40\}' "$T/push3.out" | awk '{print $2}') 306 rad patch edit "$PAT3" --repo "rad:$RID" --no-announce --message Worse --message "$(cat "$T/bad-commit.txt")" > "$T/edit3.out" 2>&1 \ 307 && ok "planted wrong-commit receipt" || bad "rad patch edit commit" 308 c=$(code GET "/drakestapleton/forge-d-l1008/patches/$PAT3.receipt") 309 grep -q '"verify":"REFUSED"' "$T/body" && grep -q '"reason":"commit"' "$T/body" && [ "$c" = 200 ] \ 310 && ok "NEG wrong commit refused" || bad "NEG commit $(head -c 240 "$T/body")" 311 312 # tool refuses a bad argument 313 "$T/forge-contribute" "not-a-rid" "$T/nope" br title "$T/cmd.sh" tester-one bay24 forge-d-l1008 note.txt "$T/body.txt" "$T/data/" "$HOME" > "$T/neg.out" 2>"$T/neg.err" 314 [ $? = 2 ] && ok "NEG bad rid refused" || bad "NEG bad rid exit $?" 315 "$T/forge-contribute" "$RID" "$T/x/../dots" br title "$T/cmd.sh" tester-one bay24 forge-d-l1008 note.txt "$T/body.txt" "$T/data/" "$HOME" > "$T/neg.out" 2>"$T/neg.err" 316 rc=$? 317 [ "$rc" = 2 ] && [ ! -e "$T/dots" ] && ok "NEG .. segment in DIR refused" || bad "NEG .. segment exit $rc" 318 mkdir "$T/empty" 319 "$T/forge-contribute" "$RID" "$T/empty" br title "$T/cmd.sh" tester-one bay24 forge-d-l1008 note.txt "$T/body.txt" "$T/data/" "$HOME" > "$T/neg.out" 2>"$T/neg.err" 320 rc=$? 321 [ "$rc" = 2 ] && [ -z "$(ls -A "$T/empty")" ] && ok "NEG existing DIR refused" || bad "NEG existing DIR exit $rc" 322 # ---- command lengths at and past the old 64-pass bound of qncanh (review of `486f1cd8`, finding F2). 323 # A receipt may carry 200 bytes of cmd (qncopy); the binder must take all of them, in the tool and 324 # on the patch page and the .receipt route. 325 mkcmd() { # mkcmd LEN: an executable whose absolute path is exactly LEN bytes; prints the path 326 local pad=$(( $1 - ${#T} - 5 )) p 327 p="$T/c$(printf '%*s' "$pad" '' | tr ' ' c).sh" 328 printf '#!/bin/sh\nprintf "ran ok\\n"\nexit 0\n' > "$p"; chmod +x "$p"; printf '%s' "$p" 329 } 330 for L in 64 65 200; do 331 CMDP=$(mkcmd $L) 332 [ ${#CMDP} = $L ] && ok "fixture: CMD path of $L bytes" || bad "fixture: CMD path is ${#CMDP} bytes, want $L" 333 "$T/forge-contribute" "$RID" "$T/clone$L" "feat-l$L" "Cmd of $L bytes" "$CMDP" tester-one bay24 forge-d-l1008 "note$L.txt" "$T/body.txt" "$T/data/" "$HOME" > "$T/tool$L.out" 2> "$T/tool$L.err" 334 rc=$? 335 [ "$rc" = 0 ] && ok "forge-contribute exit 0 with a $L-byte CMD" || bad "forge-contribute with a $L-byte CMD: exit $rc" 336 PL=$(awk '/^patch /{print $2}' "$T/tool$L.out"); [ -n "$PL" ] || PL=no-patch-id-printed 337 c=$(code GET "/drakestapleton/forge-d-l1008/patches/$PL") 338 grep -q '>PASS<' "$T/body" && [ "$c" = 200 ] && ok "patch page PASS with a $L-byte cmd" || bad "patch page with a $L-byte cmd: $c" 339 c=$(code GET "/drakestapleton/forge-d-l1008/patches/$PL.receipt") 340 n=$(python3 -c 'import json,sys; j=json.load(open(sys.argv[1])); print(len(j["cmd"]) if j["verify"]=="PASS" else -1)' "$T/body" 2>/dev/null) 341 [ "$c" = 200 ] && [ "$n" = "$L" ] && ok "machine receipt PASS, cmd is $L bytes" || bad "machine receipt with a $L-byte cmd: $c cmd=$n" 342 alive "after the pages of the $L-byte CMD" 343 done 344 # The same lengths in a receipt the oracle wrote (python sha256, not the tool), with a commit of 345 # zeros: the server's binder must accept the bind, so the refusal names the commit. 201 bytes is over 346 # the format: a parse refusal. 347 for L in 65 200 201; do 348 git -C "$CLONE" checkout -q -b "plant$L" 349 printf 'p%s\n' "$L" > "$CLONE/plant$L.txt" 350 git -C "$CLONE" add "plant$L.txt" 351 git -C "$CLONE" -c commit.gpgsign=false -c user.name=forge-d -c user.email=forge@localhost commit -qm "plant $L" 352 git -C "$CLONE" push -o "patch.message=Planted$L" rad HEAD:refs/patches > "$T/pushp$L.out" 2>&1 || bad "push planted $L" 353 PP=$(grep -o 'Patch [0-9a-f]\{40\}' "$T/pushp$L.out" | awk '{print $2}'); [ -n "$PP" ] || PP=no-patch-id-printed 354 python3 - "$L" > "$T/plant$L.rcpt" <<'PY' 355 import sys, hashlib 356 n = int(sys.argv[1]) 357 canon = "commit=%s\ntree=%s\ncmd=%s\nrc=0\nout=%s\nagent=bay24\n" % ("0" * 40, "0" * 40, "x" * n, "0" * 64) 358 print("FORGE-EVIDENCE v1\n" + canon + "bind=" + hashlib.sha256(canon.encode()).hexdigest()) 359 PY 360 rad patch edit "$PP" --repo "rad:$RID" --no-announce --message "Planted$L" --message "$(cat "$T/plant$L.rcpt")" > "$T/editp$L.out" 2>&1 \ 361 && ok "planted a receipt with a $L-byte cmd (bind by python sha256)" || bad "rad patch edit planted $L $(cat "$T/editp$L.out")" 362 want=commit; [ "$L" = 201 ] && want=parse 363 c=$(code GET "/drakestapleton/forge-d-l1008/patches/$PP.receipt") 364 grep -q '"verify":"REFUSED"' "$T/body" && grep -q "\"reason\":\"$want\"" "$T/body" && [ "$c" = 200 ] \ 365 && ok "planted $L-byte cmd: .receipt refused for $want" || bad "planted $L-byte cmd .receipt: $c $(head -c 200 "$T/body")" 366 alive "after the .receipt of the planted $L-byte cmd" 367 c=$(code GET "/drakestapleton/forge-d-l1008/patches/$PP") 368 grep -q 'Evidence receipt' "$T/body" && grep -q 'REFUSED' "$T/body" && [ "$c" = 200 ] \ 369 && ok "planted $L-byte cmd: patch page shows the refusal" || bad "planted $L-byte cmd patch page: $c" 370 alive "after the patch page of the planted $L-byte cmd" 371 done 372 373 # ---- filter field lengths at the edge of the 40-byte buffers qnba and qnbr (finding F1): 39 bytes 374 # are saved, 40 and 41 are refused before anything is copied, an absent field is refused, and the 375 # server still answers after each 376 savef() { # savef AGENT REPO: POST the filter with a fresh CSRF token; prints the status 377 code GET /notifications -H "$CK" > /dev/null; CSRF=$(field csrf) 378 code POST /notifications -H "$CK" --data-urlencode "csrf=$CSRF" --data-urlencode "agent=$1" --data-urlencode "repo=$2" 379 } 380 saved() { [ "$c" = 303 ] && hdr location | grep -q 'notifications$'; } 381 for f in agent repo; do 382 for L in 39 40 41; do 383 v=$(printf '%*s' "$L" '' | tr ' ' a) 384 if [ "$f" = agent ]; then c=$(savef "$v" forge-d-l1008); line="tester-one $v forge-d-l1008"; else c=$(savef bay24 "$v"); line="tester-one bay24 $v"; fi 385 if [ "$L" = 39 ]; then 386 saved && grep -q -x "$line" "$T/data/quiet/subs" && ok "$f of 39 bytes is saved (303)" || bad "$f of 39 bytes: $c" 387 else 388 [ "$c" = 400 ] && ok "NEG $f of $L bytes refused (400)" || bad "NEG $f of $L bytes: $c, want 400" 389 grep -q "$v" "$T/data/quiet/subs" && bad "NEG $f of $L bytes reached quiet/subs" || ok "NEG $f of $L bytes is not in quiet/subs" 390 fi 391 alive "after $f of $L bytes" 392 done 393 done 394 code GET /notifications -H "$CK" > /dev/null; CSRF=$(field csrf) 395 c=$(code POST /notifications -H "$CK" --data-urlencode "csrf=$CSRF" --data-urlencode "repo=forge-d-l1008") 396 [ "$c" = 400 ] && ok "NEG absent agent field refused (400)" || bad "NEG absent agent: $c" 397 code GET /notifications -H "$CK" > /dev/null; CSRF=$(field csrf) 398 c=$(code POST /notifications -H "$CK" --data-urlencode "csrf=$CSRF" --data-urlencode "agent=bay24") 399 [ "$c" = 400 ] && ok "NEG absent repo field refused (400)" || bad "NEG absent repo: $c" 400 alive "after the absent fields" 401 402 # ---- a subscription file this server did not write (hand-edited or damaged). forged and the tool 403 # write lines of at most 119 bytes with words of at most 39; a longer line is kept as it is and a 404 # longer filter word is refused, and neither ends the server. Not reachable from a request. 405 LONG=$(printf '%*s' 300 '' | tr ' ' b) 406 printf '%s\n' "$LONG" >> "$T/data/quiet/subs" 407 c=$(savef bay24 forge-d-l1008) 408 saved && ok "filter saved with a 300-byte line in quiet/subs" || bad "save with a 300-byte line in quiet/subs: $c" 409 [ "$(grep -c -x "$LONG" "$T/data/quiet/subs")" = 1 ] && ok "the 300-byte line is kept whole" || bad "the 300-byte line was cut or dropped" 410 alive "after the 300-byte subscription line" 411 printf 'zz-user %s forge-d-l1008\n' "$(printf '%*s' 100 '' | tr ' ' a)" >> "$T/data/quiet/subs" 412 c=$(savef bay24 forge-d-l1008) 413 [ "$c" = 500 ] && ok "NEG a 100-byte filter word in quiet/subs is refused (500), as other malformed lines are" || bad "NEG 100-byte filter word: $c, want 500" 414 alive "after the 100-byte filter word" 415 416 grep -q 'Connected to' "$T/node.log" && bad "node dialed out" || ok "NEG node made no outbound connection" 417 stopnode 418 [ -z "$(mynodes)" ] && ok "no radicle-node of this test is left running" || bad "radicle-node of this test still runs: $(mynodes | tr '\n' ' ')" 419 echo "quiet: $PASS passed, $FAIL failed" 420 echo "RID rad:$RID" 421 [ "$FAIL" = 0 ]