interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / collab / tests / compose.sh
| 1 | #!/bin/bash |
| 2 | # collab/tests/compose.sh: end-to-end HOST test of Phase A (docs/collab-write.md): the web composes and |
| 3 | # checks and says publishing is closed (no command shown); the author runs commands this test writes, |
| 4 | # and the result shows on the forge. Everything is private |
| 5 | # to a temp dir: a throwaway Radicle profile (RAD_HOME) with a private repo, a test forged on PORT |
| 6 | # (default 18493) whose store and allow-list point at that profile, throwaway ssh keys for sign-in. |
| 7 | # Nothing touches ~/.radicle, the live forged or the network. Every gate has a negative control. |
| 8 | # Usage: collab/tests/compose.sh (from anywhere; CORES default 14; KEEP=1 keeps the temp dir) |
| 9 | # untr FILE: forged adds translation hints while it sends an HTML page (server/tr.om); the checks here |
| 10 | # read pages without them (server/tests/translate.sh gates the hints). Other bodies are left as sent. |
| 11 | untr() { case "$(head -c 15 "$1" 2>/dev/null)" in '<!doctype html'*) sed -i 's/<span translate="no">\([^<]*\)<\/span>/\1/g; s/ translate="no"//g' "$1" ;; esac; } |
| 12 | set -u |
| 13 | H=$(cd "$(dirname "$0")" && pwd) |
| 14 | export PORT=${COMPOSE_PORT:-18493} CORES=${CORES:-14} |
| 15 | T=$(mktemp -d /tmp/cpcompose.XXXXXX) |
| 16 | W=$T/w |
| 17 | PASS=0; FAIL=0 |
| 18 | ok() { PASS=$((PASS+1)); echo "PASS $*"; } |
| 19 | bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; } |
| 20 | check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want $2, got $1"; fi; } |
| 21 | has() { grep -qF -- "$1" "$T/body"; } |
| 22 | |
| 23 | # ---- throwaway Radicle profile and private repo (the "author's clone") |
| 24 | export RAD_HOME=$T/rad RAD_PASSPHRASE= |
| 25 | rad auth --alias cptest < /dev/null > /dev/null 2>&1 || { echo "rad auth failed"; exit 1; } |
| 26 | git init -q -b main "$W" && cd "$W" && echo hello > a.txt && git add a.txt \ |
| 27 | && git -c user.name=t -c user.email=t@t.invalid commit -qm init \ |
| 28 | && rad init --private --name cpscratch --description "compose test" --default-branch main --no-confirm --no-seed > /dev/null 2>&1 \ |
| 29 | || { echo "rad init failed"; exit 1; } |
| 30 | git config user.name t; git config user.email t@t.invalid |
| 31 | RID=$(rad . | sed 's/^rad://') |
| 32 | echo "scratch repo rad:$RID in $RAD_HOME" |
| 33 | printf '# test allow-list\n\n| repo | RID | default branch |\n|---|---|---|\n| cpscratch | rad:%s | main |\n' "$RID" > "$T/rids.md" |
| 34 | |
| 35 | # ---- test forged |
| 36 | mkdir -p "$T/data" "$T/social" |
| 37 | DATA=$T/data/ STORE=$RAD_HOME/storage/ RIDS=$T/rids.md "$H/tbuild.sh" "$T/forged" || exit 1 |
| 38 | FORGE_SOCIAL_DIR=$T/social/ taskset -c "$CORES" nice -n 10 "$T/forged" 2>> "$T/forged.err" & |
| 39 | PID=$! |
| 40 | trap 'kill $PID 2>/dev/null; wait $PID 2>/dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT |
| 41 | U="http://127.0.0.1:$PORT" |
| 42 | for i in $(seq 50); do curl -s -o /dev/null "$U/" && break; sleep 0.1; done |
| 43 | kill -0 $PID 2> /dev/null || { echo "test forged did not start: $(cat "$T/forged.err")"; exit 1; } |
| 44 | R=/drakestapleton/cpscratch |
| 45 | BASE=/ |
| 46 | IP=10.9.0.1 |
| 47 | |
| 48 | # code METHOD PATH [curl args] -> status; body in $T/body, headers in $T/hdr |
| 49 | code() { m=$1; p=$2; shift 2; c=$(curl -s -o "$T/body" -D "$T/hdr" -X "$m" -H "X-Forge-Base: $BASE" -H "X-Real-IP: $IP" "$@" "$U$p" -w '%{http_code}'); untr "$T/body"; printf %s "$c"; } |
| 50 | hdr() { grep -i "^$1:" "$T/hdr" | head -1 | cut -d' ' -f2- | tr -d '\r'; } |
| 51 | field() { grep -o "name=\"$1\" value=\"[^\"]*\"" "$T/body" | head -1 | sed 's/.*value="//; s/"$//'; } |
| 52 | cmds() { python3 - "$T/body" <<'EOF' |
| 53 | import sys, re, html |
| 54 | for m in re.findall(r'<pre class="so-cmd">(.*?)</pre>', open(sys.argv[1]).read(), re.S): |
| 55 | print(html.unescape(m)) |
| 56 | EOF |
| 57 | } |
| 58 | run_() { [ -n "$1" ] && (cd "$W" && sh -c "$1"); } |
| 59 | # The compose page shows no command: publishing is closed for now. The author's own commands below |
| 60 | # are written by this test (not read from the page) so the fixture repo still gets its COBs. |
| 61 | closed() { has 'Publishing it is closed for now: Interplane does not accept comments, reviews, issues or patches yet.' && [ -z "$(cmds)" ] && ok "$1: publishing closed, no command shown" || bad "$1: closed note missing or a command shown"; } |
| 62 | dl() { curl -s -o "$2" -D "$T/hdr" -H "X-Forge-Base: $BASE" -H "$CK" "$U$1" -w '%{http_code}'; } |
| 63 | cidof() { hdr location | sed -n 's|.*/compose/\([0-9a-f]\{32\}\)$|\1|p'; } |
| 64 | |
| 65 | # ---- sign-in with throwaway ssh keys (the forge accepts any did:key it can verify) |
| 66 | ssh-keygen -q -t ed25519 -N '' -C t1 -f "$T/k1"; ssh-keygen -q -t ed25519 -N '' -C t2 -f "$T/k2" |
| 67 | did() { python3 - "$1" <<'EOF' |
| 68 | import sys, base64 |
| 69 | raw = b'\xed\x01' + base64.b64decode(open(sys.argv[1]).read().split()[1])[-32:] |
| 70 | A = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' |
| 71 | n = int.from_bytes(raw, 'big'); s = '' |
| 72 | while n: n, r = divmod(n, 58); s = A[r] + s |
| 73 | print('did:key:z' + s) |
| 74 | EOF |
| 75 | } |
| 76 | login() { # key -> SES, TOK |
| 77 | code GET /login > /dev/null |
| 78 | local pn=$(hdr set-cookie | sed -n 's/^\([A-Za-z_-]*forge_pre\)=.*/\1/p') |
| 79 | local pre=$(hdr set-cookie | sed -n 's/^[A-Za-z_-]*forge_pre=\([0-9a-f]*\);.*/\1/p') |
| 80 | local cs=$(field csrf) no=$(field nonce) ts=$(field ts) |
| 81 | printf '%s' "interplane-forge-login:$no:$ts" | ssh-keygen -Y sign -f "$1" -n interplane-forge > "$T/sig" 2> /dev/null |
| 82 | code POST /login -H "Cookie: $pn=$pre" --data-urlencode "csrf=$cs" --data-urlencode "nonce=$no" \ |
| 83 | --data-urlencode "ts=$ts" --data-urlencode "did=$(did "$1.pub")" --data-urlencode "sig@$T/sig" > /dev/null |
| 84 | SES=$(grep -i "^set-cookie:" "$T/hdr" | cut -d" " -f2- | tr -d "\r" | sed -n 's/^\([A-Za-z_-]*forge_session=[0-9a-f]*\);.*/\1/p') |
| 85 | code GET /settings -H "Cookie: $SES" > /dev/null |
| 86 | TOK=$(field csrf) |
| 87 | } |
| 88 | login "$T/k2"; SES2=$SES; TOK2=$TOK |
| 89 | login "$T/k1" |
| 90 | [ ${#TOK} = 32 ] && [ ${#TOK2} = 32 ] && [ "$TOK" != "$TOK2" ] && ok "two sessions signed in" || { bad "sign-in failed ($SES / $TOK)"; exit 1; } |
| 91 | CK="Cookie: $SES" |
| 92 | |
| 93 | # ---- forms |
| 94 | c=$(code GET "$R/issues/new"); check "$c" 200 "GET issues/new signed out" |
| 95 | has 'Sign in with your key' && ! has 'name="title"' && ok "NEG signed out: sign-in link, no form" || bad "signed-out new-issue page" |
| 96 | c=$(code GET "$R/issues/new" -H "$CK"); check "$c" 200 "GET issues/new signed in" |
| 97 | has "action=\"$R/issues/new\"" && has 'name="title"' && has "value=\"$TOK\"" && ok "new-issue form with this session's CSRF token" || bad "new-issue form" |
| 98 | c=$(code GET "$R/patches/new" -H "$CK"); has 'name="draft"' && ok "new-patch form has the draft box" || bad "new-patch form ($c)" |
| 99 | c=$(code GET "$R/issues" -H "$CK"); has "href=\"$R/issues/new\"" && ok "issue list links the new-issue form" || bad "issue list link" |
| 100 | |
| 101 | # ---- write gate (contract section 5): signed out, CSRF, then the checks |
| 102 | printf 'Title one\n' > "$T/t" |
| 103 | c=$(code POST "$R/issues/new" --data-urlencode "csrf=$TOK" --data-urlencode "title=x" --data-urlencode "body=y") |
| 104 | check "$c" 303 "NEG signed-out POST redirects"; check "$(hdr location)" "/login" "NEG signed-out POST goes to login" |
| 105 | c=$(code POST "$R/issues/new" -H "$CK" --data-urlencode "csrf=$TOK2" --data-urlencode "title=x"); check "$c" 403 "NEG other session's CSRF token" |
| 106 | c=$(code POST "$R/issues/new" -H "$CK" --data-urlencode "title=x"); check "$c" 403 "NEG missing CSRF token" |
| 107 | c=$(code POST "$R/issues/new" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "title="); check "$c" 400 "NEG empty title" |
| 108 | has 'The title must be one line' && ok "empty title message" || bad "empty title message" |
| 109 | c=$(code POST "$R/issues/new" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "title=a |
| 110 | b"); check "$c" 400 "NEG two-line title" |
| 111 | c=$(code POST "$R/issues/new" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "title=$(printf 'x%.0s' $(seq 257))"); check "$c" 400 "NEG 257-byte title" |
| 112 | c=$(code POST "$R/issues/new" -H "$CK" --data "csrf=$TOK&title=ok&body=%FF%FE"); check "$c" 400 "NEG invalid UTF-8 body" |
| 113 | has 'must be UTF-8' && ok "UTF-8 message" || bad "UTF-8 message" |
| 114 | c=$(code POST "$R/issues/new" -H "$CK" --data "csrf=$TOK&title=ok&body=a%01b"); check "$c" 400 "NEG control byte in body" |
| 115 | c=$(code POST "$R/issues/new" -H "$CK" --data "csrf=$TOK&title=ok&body=%ED%A0%80"); check "$c" 400 "NEG UTF-16 surrogate in body" |
| 116 | head -c 60001 /dev/zero | tr '\0' a > "$T/big" |
| 117 | c=$(code POST "$R/issues/new" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "title=ok" --data-urlencode "body@$T/big"); check "$c" 400 "NEG 60001-byte body" |
| 118 | has 'longer than 60000' && ok "length message" || bad "length message" |
| 119 | head -c 60000 /dev/zero | tr '\0' a > "$T/big" |
| 120 | c=$(code POST "$R/issues/new" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "title=ok" --data-urlencode "body@$T/big"); check "$c" 303 "60000-byte body accepted" |
| 121 | c=$(code POST "$R/issues/0000000000000000000000000000000000000000/compose" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "body=hi"); check "$c" 404 "NEG comment on an unknown issue" |
| 122 | c=$(code POST "$R/issues/new/x" -H "$CK" --data-urlencode "csrf=$TOK"); check "$c" 405 "NEG POST on an unknown route" |
| 123 | |
| 124 | # ---- new issue, with an XSS body; the published issue must render it inert |
| 125 | IP=10.9.0.2 |
| 126 | printf 'Hello <b>there</b>\r\n\r\n<script>alert(1)</script>\n[x](javascript:alert(1)) <img src=x onerror=alert(1)>\n\n**bold** text\n\n\n' > "$T/ib" |
| 127 | TITLE='-Crash on "quotes" & $(id) `uname`' |
| 128 | c=$(code POST "$R/issues/new" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "title=$TITLE" --data-urlencode "body@$T/ib") |
| 129 | check "$c" 303 "POST issues/new" |
| 130 | CID=$(cidof); [ ${#CID} = 32 ] && ok "redirect to compose/<128-bit id>" || bad "location $(hdr location)" |
| 131 | c=$(code GET "$R/compose/$CID" -H "$CK"); check "$c" 200 "compose page" |
| 132 | has '<strong>bold</strong>' && ok "preview renders Markdown" || bad "preview markdown" |
| 133 | ! has '<script>alert' && ! has 'href="javascript:' && ! has '<img src=x' && ok "NEG preview renders the XSS inert" || bad "preview XSS" |
| 134 | has 'Crash on "quotes" & $(id)' && ok "title escaped in preview" || bad "title escape" |
| 135 | closed "new issue"; CMD="rad issue open --repo rad:$RID --title=\"\$(head -n 1 issue.md)\" --description=\"\$(tail -n +3 issue.md)\"" |
| 136 | c=$(dl "$R/compose/$CID/issue.md" "$W/issue.md"); check "$c" 200 "download issue.md" |
| 137 | check "$(hdr content-type)" "text/markdown; charset=utf-8" "issue.md content type" |
| 138 | check "$(hdr content-disposition)" 'attachment; filename="issue.md"' "issue.md is an attachment" |
| 139 | printf '%s\n\nHello <b>there</b>\n\n<script>alert(1)</script>\n[x](javascript:alert(1)) <img src=x onerror=alert(1)>\n\n**bold** text\n' "$TITLE" > "$T/want" |
| 140 | cmp -s "$W/issue.md" "$T/want" && ok "issue.md = title, blank line, body (CRLF folded, trailing blank lines trimmed)" || bad "issue.md content: $(od -c "$W/issue.md" | head -5)" |
| 141 | # NEGATIVE: the compose belongs to this session, this repo, this id |
| 142 | c=$(code GET "$R/compose/$CID"); check "$c" 404 "NEG signed-out compose page" |
| 143 | c=$(code GET "$R/compose/$CID" -H "Cookie: $SES2"); check "$c" 404 "NEG other session's compose page" |
| 144 | c=$(code GET "$R/compose/$CID/issue.md" -H "Cookie: $SES2"); check "$c" 404 "NEG other session's download" |
| 145 | c=$(code GET "$R/compose/${CID%?}0" -H "$CK"); [ "${CID: -1}" = 0 ] && c=404; check "$c" 404 "NEG altered compose id" |
| 146 | c=$(code GET "$R/compose/$CID/patch.md" -H "$CK"); check "$c" 404 "NEG wrong file name" |
| 147 | # run it as the author |
| 148 | run_ "$CMD" > "$T/out" 2>&1 && ok "author ran: rad issue open" || bad "rad issue open: $(cat "$T/out")" |
| 149 | c=$(code GET "$R/issues"); has 'Crash on "quotes"' && ok "new issue listed on the forge" || bad "issue not listed ($c)" |
| 150 | ISS=$(grep -o "$R/issues/[0-9a-f]\{7,40\}" "$T/body" | head -1 | sed 's|.*/||') |
| 151 | ET=$(printf '%s' "$TITLE" | sed 's/&/\&/g; s/"/\"/g') |
| 152 | has "$ET" && ok "title reached rad unchanged (leading -, quotes, \$(...), backticks)" || bad "title changed: $(grep -o '[^>]*Crash[^<]*' "$T/body" | head -1)" |
| 153 | c=$(code GET "$R/issues/$ISS"); check "$c" 200 "issue page" |
| 154 | has '<strong>bold</strong>' && ok "issue body rendered as Markdown" || bad "issue body markdown" |
| 155 | ! has '<script>alert' && ! has 'href="javascript:' && ! has '<img src=x' && ok "NEG published issue renders the XSS inert" || bad "published issue XSS" |
| 156 | has 'id="compose"' && has 'Sign in with your key' && ok "issue page: sign-in prompt when signed out" || bad "issue page prompt" |
| 157 | |
| 158 | # ---- comment on the issue |
| 159 | c=$(code GET "$R/issues/$ISS" -H "$CK"); ISSF=$(grep -o "issues/[0-9a-f]\{40\}/compose" "$T/body" | head -1 | cut -d/ -f2) |
| 160 | [ ${#ISSF} = 40 ] && has "value=\"$TOK\"" && ok "issue page has the comment form" || bad "issue comment form" |
| 161 | c=$(code POST "$R/issues/$ISSF/compose" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "body= "); check "$c" 400 "NEG blank comment" |
| 162 | c=$(code POST "$R/issues/${ISSF:0:8}/compose" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "body=First *comment* from the forge"); check "$c" 303 "POST issue comment (short id)" |
| 163 | CID=$(cidof); code GET "$R/compose/$CID" -H "$CK" > /dev/null; closed "issue comment" |
| 164 | CMD="rad issue comment $ISSF --repo rad:$RID --message=\"\$(cat comment.md)\"" |
| 165 | dl "$R/compose/$CID/comment.md" "$W/comment.md" > /dev/null |
| 166 | check "$(cat "$W/comment.md")" "First *comment* from the forge" "comment.md content" |
| 167 | run_ "$CMD" > "$T/out" 2>&1 && ok "author ran: rad issue comment" || bad "rad issue comment: $(cat "$T/out")" |
| 168 | c=$(code GET "$R/issues/$ISS"); has 'First <em>comment</em> from the forge' && ok "comment shows on the forge" || bad "comment missing" |
| 169 | |
| 170 | # ---- new patch: git push, then rad patch edit for the multi-line description |
| 171 | IP=10.9.0.3 |
| 172 | git -C "$W" checkout -qb feat && echo more > "$W/b.txt" && git -C "$W" add b.txt && git -C "$W" commit -qm "add b" |
| 173 | printf 'Line one of the description.\n\nLine three, `code`.\n' > "$T/pb" |
| 174 | c=$(code POST "$R/patches/new" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "title=Add b.txt" --data-urlencode "body@$T/pb"); check "$c" 303 "POST patches/new" |
| 175 | CID=$(cidof); code GET "$R/compose/$CID" -H "$CK" > /dev/null; closed "new patch" |
| 176 | printf '%s\n' 'git push -o patch.message="$(head -n 1 patch.md)" rad HEAD:refs/patches' "rad patch edit PATCH_ID --repo rad:$RID --message=\"\$(head -n 1 patch.md)\" --message=\"\$(tail -n +3 patch.md)\"" > "$T/cmds" |
| 177 | dl "$R/compose/$CID/patch.md" "$W/patch.md" > /dev/null |
| 178 | run_ "$(sed -n 1p "$T/cmds")" > "$T/out" 2>&1 && ok "author ran: git push" || bad "git push: $(cat "$T/out")" |
| 179 | PAT=$(grep -o '[0-9a-f]\{40\}' "$T/out" | head -1) |
| 180 | E=$(sed -n 2p "$T/cmds"); E=${E/PATCH_ID/$PAT} |
| 181 | run_ "$E" > "$T/out" 2>&1 && ok "author ran: rad patch edit" || bad "rad patch edit: $(cat "$T/out")" |
| 182 | c=$(code GET "$R/patches/$PAT"); check "$c" 200 "patch page" |
| 183 | has 'Add b.txt' && has 'Line three, <code>code</code>.' && ok "patch title and Markdown description on the forge" || bad "patch description" |
| 184 | # single-line description and draft go into the push options |
| 185 | c=$(code POST "$R/patches/new" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "title=T2" --data-urlencode "body=one line" --data-urlencode "draft=1") |
| 186 | CID=$(cidof); code GET "$R/compose/$CID" -H "$CK" > /dev/null |
| 187 | closed "draft patch" |
| 188 | has 'New patch (draft)' && ok "draft named on the compose page" || bad "draft heading" |
| 189 | |
| 190 | # ---- patch comment and reviews |
| 191 | c=$(code GET "$R/patches/$PAT" -H "$CK"); REV=$(field rev) |
| 192 | [ ${#REV} = 40 ] && has 'name="verdict" value="accept"' && ok "patch page has the review form (revision $REV)" || bad "patch form" |
| 193 | c=$(code POST "$R/patches/$PAT/compose" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "body=Looks *fine*"); check "$c" 303 "POST patch comment" |
| 194 | CID=$(cidof); code GET "$R/compose/$CID" -H "$CK" > /dev/null; closed "patch comment" |
| 195 | CMD="rad patch comment $REV --repo rad:$RID --message=\"\$(cat comment.md)\"" |
| 196 | dl "$R/compose/$CID/comment.md" "$W/comment.md" > /dev/null |
| 197 | run_ "$CMD" > "$T/out" 2>&1 && ok "author ran: rad patch comment" || bad "rad patch comment: $(cat "$T/out")" |
| 198 | c=$(code POST "$R/patches/$PAT/compose" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "rev=$REV" --data-urlencode "verdict=accept" --data-urlencode "body=Ship **it**") |
| 199 | check "$c" 303 "POST review accept" |
| 200 | CID=$(cidof); code GET "$R/compose/$CID" -H "$CK" > /dev/null; closed "review accept" |
| 201 | CMD="rad patch review $PAT --repo rad:$RID --revision $REV --accept --message=\"\$(cat review.md)\"" |
| 202 | dl "$R/compose/$CID/review.md" "$W/review.md" > /dev/null |
| 203 | run_ "$CMD" > "$T/out" 2>&1 && ok "author ran: rad patch review --accept" || bad "rad patch review: $(cat "$T/out")" |
| 204 | c=$(code GET "$R/patches/$PAT"); has 'Looks <em>fine</em>' && ok "patch comment shows on the forge" || bad "patch comment missing" |
| 205 | has 'Ship <strong>it</strong>' && ok "review body shows on the forge" || bad "review body missing" |
| 206 | c=$(code POST "$R/patches/$PAT/compose" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "verdict=reject") |
| 207 | check "$c" 303 "POST review reject without text" |
| 208 | CID=$(cidof); code GET "$R/compose/$CID" -H "$CK" > /dev/null |
| 209 | closed "review reject without text" |
| 210 | ! has 'download>' && ok "no download step without text" || bad "download step shown" |
| 211 | c=$(code POST "$R/patches/$PAT/compose" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "verdict=review" --data-urlencode "body=Needs a test") |
| 212 | CID=$(cidof); code GET "$R/compose/$CID" -H "$CK" > /dev/null; closed "review without verdict" |
| 213 | CMD="rad patch review $PAT --repo rad:$RID --revision $REV --message=\"\$(cat review.md)\"" |
| 214 | dl "$R/compose/$CID/review.md" "$W/review.md" > /dev/null |
| 215 | run_ "$CMD" > "$T/out" 2>&1 && ok "author ran: rad patch review (no verdict)" || bad "rad patch review (no verdict): $(cat "$T/out")" |
| 216 | c=$(code GET "$R/patches/$PAT"); has 'Needs a test' && ok "review without verdict shown on the forge" || bad "no-verdict review missing ($c)" |
| 217 | c=$(code POST "$R/patches/$PAT/compose" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "verdict=merge" --data-urlencode "body=x"); check "$c" 400 "NEG unknown verdict" |
| 218 | c=$(code POST "$R/patches/$PAT/compose" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "rev=deadbeef" --data-urlencode "body=x"); check "$c" 400 "NEG revision not of this patch" |
| 219 | c=$(code POST "$R/patches/$PAT/compose" -H "$CK" --data-urlencode "csrf=$TOK"); check "$c" 400 "NEG comment without text" |
| 220 | c=$(code POST "$R/patches/$ISSF/compose" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "body=x"); check "$c" 404 "NEG issue id used as a patch" |
| 221 | |
| 222 | # ---- base path: /forge/ links and redirects |
| 223 | BASE=/forge/ |
| 224 | c=$(code POST "$R/issues/$ISSF/compose" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "body=via aienos"); check "$c" 303 "POST under /forge/" |
| 225 | case "$(hdr location)" in "/forge$R/compose/"*) ok "redirect keeps /forge/";; *) bad "location $(hdr location)";; esac |
| 226 | c=$(code GET "$R/compose/$(cidof)" -H "$CK"); has "href=\"/forge$R/compose/" && has "href=\"/forge$R/issues/$ISSF\"" && ok "compose page links under /forge/" || bad "/forge/ links" |
| 227 | BASE=/ |
| 228 | |
| 229 | # ---- per-IP write limit (30 writes a minute), checked before the text |
| 230 | IP=10.9.0.4; n=0 |
| 231 | for i in $(seq 30); do c=$(code POST "$R/issues/new" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "title="); [ "$c" = 400 ] && n=$((n+1)); done |
| 232 | check "$n" 30 "30 writes from one address pass the limit" |
| 233 | c=$(code POST "$R/issues/new" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "title="); check "$c" 429 "NEG 31st write in a minute" |
| 234 | IP=10.9.0.5 |
| 235 | c=$(code POST "$R/issues/new" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "title="); check "$c" 400 "another address is not limited" |
| 236 | |
| 237 | # ---- the forge wrote nothing itself: every COB above came from the author's commands |
| 238 | c=$(code POST "$R/issues/new" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "title=never published") |
| 239 | code GET "$R/issues" > /dev/null; ! has 'never published' && ok "NEG composed but not run: not on the forge" || bad "forge published by itself" |
| 240 | |
| 241 | echo "collab compose: $PASS passed, $FAIL failed" |
| 242 | [ "$FAIL" = 0 ] |