interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / collab / tests / verdict.sh

65 lines · 4527 bytes Raw Blame History
1#!/bin/bash
2# collab/tests/verdict.sh: HOST test of the patch page's verdict line (sec review forge-web-13102b54
3# P3-1) and build commit (corr P1). Two test forgeds on PORT (default 18495) read the real store and
4# allow-list (read-only); sed points the review folder (text tcrevd) at a temp dir of fixture verdict
5# files and writes the build commit (text tcbldc). Only a first line that is exactly
6# VERDICT (MERGE|MERGE_AFTER_FIX|REJECT) head=<the revision head> may appear, nothing else of the file,
7# and no folder or file name. Usage: collab/tests/verdict.sh (CORES default 14; KEEP=1 keeps temp)
8# untr FILE: forged adds translation hints while it sends an HTML page (server/tr.om); the checks here
9# read pages without them (server/tests/translate.sh gates the hints). Other bodies are left as sent.
10untr() { 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; }
11set -u
12H=$(cd "$(dirname "$0")" && pwd)
13export PORT=${VERDICT_PORT:-18495} CORES=${CORES:-14}
14T=$(mktemp -d /tmp/cpverd.XXXXXX)
15PASS=0; FAIL=0; PID=
16ok() { PASS=$((PASS+1)); echo "PASS $*"; }
17bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; }
18trap '[ -n "$PID" ] && kill $PID 2>/dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT
19U="http://127.0.0.1:$PORT/drakestapleton/omega-mv/patches"
20start() { # binary
21 FORGE_SOCIAL_DIR=$T/data/ taskset -c "$CORES" nice -n 10 "$1" 2>> "$T/forged.err" &
22 PID=$!
23 for i in $(seq 50); do curl -s -o /dev/null "$U" && break; sleep 0.1; done
24 kill -0 $PID 2> /dev/null || { echo "test forged did not start: $(cat "$T/forged.err")"; exit 1; }
25}
26stop() { kill $PID 2>/dev/null; wait $PID 2>/dev/null; PID=; }
27get() { curl -s -o "$T/b" "$U/$1"; untr "$T/b"; }
28has() { grep -qF -- "$1" "$T/b"; }
29A=215ea39afdc0cf1914cfadf43bbb6d23ce68c920 # head of 4dd099df's revision
30B=3743d642cf034299009936eb8d458ba96a0a8589 # head of 88050ef7's revision
31mkdir -p "$T/rev" "$T/data"
32printf 'VERDICT MERGE_AFTER_FIX head=%s\nsecret second line <b>x</b>\n' "$A" > "$T/rev/omega-mv-${A:0:8}.verdict.txt"
33printf 'VERDICT MERGE head=%s <script>alert(1)</script>\n' "$B" > "$T/rev/omega-mv-${B:0:8}.verdict.txt"
34STAMP=0123456789abcdef0123456789abcdef01234567
35DATA=$T/data/ SEDX="s|^text tcrevd \".*\"\$|text tcrevd \"$T/rev/\"|;s/^text tcbldc \"unrecorded\"\$/text tcbldc \"$STAMP\"/" \
36 "$H/tbuild.sh" "$T/f1" > /dev/null || exit 1
37grep -q "^text tcrevd \"$T/rev/\"\$" "$T/f1.om" && grep -q "^text tcbldc \"$STAMP\"\$" "$T/f1.om" && ok "fixture folder and stamp compiled in" || { bad "sed did not apply"; exit 1; }
38start "$T/f1"
39get 4dd099df
40has "<b>VERDICT MERGE_AFTER_FIX head=$A</b>" && ok "well-formed verdict line shown" || bad "verdict line: $(grep -o '<b>VERDICT[^<]*' "$T/b")"
41! has 'secret second line' && ok "NEG nothing after line 1 shown" || bad "second line leaked"
42! has 'verdict.txt' && ! has 'review folder' && ! has 'handoffs' && ok "NEG no folder or file name on the page" || bad "layout disclosed"
43has "built from commit <code>$STAMP</code>" && ok "page names the build commit" || bad "build commit missing"
44get 88050ef7
45! has '<b>VERDICT' && ! has 'alert(1)' && has 'No review verdict names a head' && ok "NEG line with trailing text not shown" || bad "trailing-text line shown"
46# a verdict for another head with the same sha8, and a malformed word
47printf 'VERDICT MERGE head=%s\n' "${A:0:8}ffffffffffffffffffffffffffffffff" > "$T/rev/omega-mv-${A:0:8}.verdict.txt"
48get 4dd099df
49! has '<b>VERDICT' && ok "NEG head of another commit (same sha8) not shown" || bad "foreign head shown"
50printf 'VERDICT: MERGE head=%s\n' "$A" > "$T/rev/omega-mv-${A:0:8}.verdict.txt"
51get 4dd099df
52! has '<b>VERDICT' && ok "NEG malformed verdict word not shown" || bad "malformed line shown"
53printf 'VERDICT REJECT head=%s\r\n' "$A" > "$T/rev/omega-mv-${A:0:8}.verdict.txt"
54get 4dd099df
55has "<b>VERDICT REJECT head=$A</b>" && ok "REJECT with CRLF shown" || bad "REJECT line"
56stop
57# negative control for the stamp: a value that is not 40 hex is not printed
58DATA=$T/data/ SEDX="s/^text tcbldc \"unrecorded\"\$/text tcbldc \"<b>dirty<\/b>$STAMP\"/" "$H/tbuild.sh" "$T/f2" > /dev/null || exit 1
59start "$T/f2"
60get 4dd099df
61has 'commit was not recorded' && ! has 'dirty' && ok "NEG non-hex build stamp not printed" || bad "bad stamp printed"
62has "<b>VERDICT MERGE head=$A</b>" && ok "real review folder still read" || bad "real verdict missing: $(grep -o '<b>VERDICT[^<]*' "$T/b")"
63stop
64echo "collab verdict: $PASS passed, $FAIL failed"
65[ "$FAIL" = 0 ]