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/galaxy/tests/route.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 / galaxy / tests / route.sh` 148 lines ยท 8562 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # galaxy/tests/route.sh: gate for the galaxy routes in server/route.om. 3 # bash galaxy/tests/route.sh (spark; FORGED_CPUS default 4,5; FORGE_TEST_PORT default 18489) 4 # A trial forged with its port, RIDS.md, storage, data dir and count sources redirected into a temp dir (the 5 # server/tests/check.sh pattern). Checks: on base "/" /galaxy streams the page file byte for byte 6 # with the site's no-script policy, the root stays the explore page whether or not the page file 7 # exists, /assets/galaxy.css and /assets/tokens.css stream their files, POST is refused, a missing 8 # page file is 404 at /galaxy, and the /forge/ base never serves the galaxy. Negative controls: the 9 # route.om of the base commit must not serve the page at /galaxy, and a route.om whose root serves 10 # the galaxy file must be seen by the root check. 11 # Read-only on real storage; never touches 18480, ~/forge-data or port 18091. 12 set -u 13 cd "$(dirname "$0")/../.." 14 CORES=${FORGED_CPUS:-4,5} 15 PORT=${FORGE_TEST_PORT:-18489} 16 OMC=$HOME/work/flux/omega-mv/seed/out/omc 17 STORE=$HOME/.radicle/storage 18 OK_RID=z631r2JJiVT8it4tST7RK24hpowi # cuda-crack 19 BASE=${GALAXY_BASE:-edge/spark-front-door} 20 T=$(mktemp -d) 21 pid= 22 pass=0; fail=0 23 ok() { pass=$((pass+1)); echo "PASS $*"; } 24 bad() { fail=$((fail+1)); echo "FAIL $*"; } 25 cleanup() { [ -n "$pid" ] && kill "$pid" 2>/dev/null; wait 2>/dev/null; rm -rf "$T"; } 26 trap cleanup EXIT 27 if ss -ltn | grep -q "127.0.0.1:$PORT "; then echo "NOT_RUN: port $PORT busy"; exit 3; fi 28 run() { taskset -c "$CORES" nice -n 10 "$@"; } 29 want() { [ "$2" = "$3" ] && ok "$1 = $2" || bad "$1 = $2 (want $3)"; } 30 31 compose() { # compose OUT [route.om] 32 local route=${2:-server/route.om} 33 { printf 'om2\n'; for u in $(./run.sh units); do 34 [ "$u" = server/route.om ] && cat "$route" || cat "$u"; done; } > "$1" 35 } 36 redirect() { 37 sed -i -e "s|haddr4 a `2130706433` 18480|haddr4 a `2130706433` $PORT|" \ 38 -e "s|/home/drakestapleton/handoffs/radicle/RIDS.md|$T/RIDS.md|" \ 39 -e "s|/home/drakestapleton/.radicle/storage/|$T/storage/|g" \ 40 -e "s|/home/drakestapleton/forge-data/|$T/data/|g" \ 41 -e "s|^text tfzp0 \".*\"|text tfzp0 \"$T/ng/dl.log\"|" \ 42 -e "s|^text tfzp1 \".*\"|text tfzp1 \"$T/ng/access.log\"|" \ 43 -e "s|^text tfzwal \".*\"|text tfzwal \"$T/ng/wal\"|" \ 44 -e "s|^text tfzrad \".*\"|text tfzrad \"$T/bin/rad\"|" \ 45 -e "s|^text tfzspth \".*\"|text tfzspth \"$T/counts.snapshot\"|" \ 46 -e "s|^text tfzgent \".*\"|text tfzgent \"$T/bin/getent\"|" "$1" 47 if grep -q '`2130706433` 18480\|/home/drakestapleton/forge-data\|/home/drakestapleton/.radicle\|/home/drakestapleton/handoffs/radicle' "$1"; then bad "redirect: a live path or port remains"; exit 1; fi 48 } 49 start() { 50 run "$OMC" < "$1" > "$1.bin" 2> "$T/build.err" || { bad "build $1: $(cat "$T/build.err")"; exit 1; } 51 chmod 755 "$1.bin" 52 taskset -c "$CORES" nice -n 10 "$1.bin" > "$1.log" 2>&1 & 53 pid=$! 54 for _ in $(seq 50); do curl -s -o /dev/null "http://127.0.0.1:$PORT/explore" && return; sleep 0.2; done 55 bad "trial forged did not listen on $PORT"; exit 1 56 } 57 stop() { 58 kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid= 59 for _ in $(seq 50); do ss -ltn | grep -q "127.0.0.1:$PORT " || return; sleep 0.2; done 60 bad "trial forged still listening on $PORT"; exit 1 61 } 62 get() { # get PATH [BASE] 63 curl -s -o "$T/b" -D "$T/h" -w '%{http_code}' -H "X-Forge-Base: ${2:-/}" -H 'X-Real-IP: 10.9.9.9' "http://127.0.0.1:$PORT/$1" 64 } 65 hdr() { grep -i "^$1:" "$T/h" | tr -d '\r' | cut -d' ' -f2-; } 66 67 mkdir -p "$T/storage" "$T/data/logs" "$T/data/galaxy" "$T/ng" "$T/bin" 68 # the count sources of server/counts.om (json-counts) are moved too, as server/tests/check.sh does 69 cp server/tests/fake/rad server/tests/fake/getent "$T/bin/" 70 chmod 755 "$T/bin/rad" "$T/bin/getent" 71 : > "$T/ng/dl.log"; : > "$T/ng/access.log" 72 ln -s "$STORE/$OK_RID" "$T/storage/$OK_RID" 73 printf '# test table\n\n| repo | RID | default branch | head sha | source dir | UTC |\n|---|---|---|---|---|---|\n| cuda-crack | rad:%s | main | - | - | - |\n' "$OK_RID" > "$T/RIDS.md" 74 75 # the page files, made by the filter from the fixture 76 { cat galaxy/page.om galaxy/cli.om; } | run "$OMC" > "$T/cli" 2> "$T/cli.err" || { bad "filter build: $(cat "$T/cli.err")"; exit 1; } 77 chmod 755 "$T/cli" 78 "$T/cli" < galaxy/tests/feed.tsv > "$T/data/galaxy/index.html" 79 printf 'css\n' | "$T/cli" > "$T/data/galaxy/galaxy.css" 80 cp galaxy/tokens.css "$T/data/galaxy/tokens.css" 81 82 compose "$T/f.om"; redirect "$T/f.om" 83 start "$T/f.om" 84 want "GET / on base /" "$(get '')" 200 85 grep -q 'Explore repositories' "$T/b" && ok "root on base / stays the explore page with the galaxy file present" || bad "root on base / stays the explore page with the galaxy file present" 86 cmp -s "$T/b" "$T/data/galaxy/index.html" && bad "root body is not the galaxy file" || ok "root body is not the galaxy file" 87 want "GET /galaxy" "$(get galaxy)" 200 88 cmp -s "$T/b" "$T/data/galaxy/index.html" && ok "/galaxy body is the page file, byte for byte" || bad "/galaxy body is the page file, byte for byte" 89 want "/galaxy content type" "$(hdr content-type)" "text/html; charset=utf-8" 90 case "$(hdr content-security-policy)" in *"script-src 'none'"*"style-src 'self'"*|*"style-src 'self'"*"script-src 'none'"*) ok "/galaxy policy: no scripts, own stylesheets only" ;; *) bad "/galaxy policy: $(hdr content-security-policy)" ;; esac 91 want "GET /galaxy/ (trailing slash)" "$(get galaxy/)" 200 92 cmp -s "$T/b" "$T/data/galaxy/index.html" && ok "/galaxy/ body is the page file" || bad "/galaxy/ body is the page file" 93 want "GET /assets/galaxy.css" "$(get assets/galaxy.css)" 200 94 cmp -s "$T/b" "$T/data/galaxy/galaxy.css" && ok "stylesheet body" || bad "stylesheet body" 95 want "stylesheet content type" "$(hdr content-type)" "text/css; charset=utf-8" 96 want "GET /assets/tokens.css" "$(get assets/tokens.css)" 200 97 cmp -s "$T/b" "$T/data/galaxy/tokens.css" && ok "tokens body" || bad "tokens body" 98 want "GET /assets/forge.css still served" "$(get assets/forge.css)" 200 99 want "POST / refused" "$(curl -s -o /dev/null -w '%{http_code}' -X POST -H 'X-Forge-Base: /' -H 'Origin: https://interplane.io' --data x=1 "http://127.0.0.1:$PORT/")" 405 100 want "GET / on base /forge/" "$(get '' /forge/)" 200 101 grep -q 'Explore repositories' "$T/b" && ok "/forge/ base root stays the explore page" || bad "/forge/ base root stays the explore page" 102 want "GET /assets/galaxy.css on base /forge/" "$(get assets/galaxy.css /forge/)" 404 103 want "GET /explore still served" "$(get explore)" 200 104 want "GET drakestapleton/cuda-crack still served" "$(get drakestapleton/cuda-crack)" 200 105 mv "$T/data/galaxy/index.html" "$T/data/galaxy/index.html.off" 106 want "GET /galaxy without the page file" "$(get galaxy)" 404 107 want "GET / without the page file" "$(get '')" 200 108 grep -q 'Explore repositories' "$T/b" && ok "without the page file the root is the explore page" || bad "without the page file the root is the explore page" 109 want "GET /assets/galaxy.css without tokens touched" "$(get assets/galaxy.css)" 200 110 mv "$T/data/galaxy/galaxy.css" "$T/data/galaxy/galaxy.css.off" 111 want "GET a missing stylesheet" "$(get assets/galaxy.css)" 404 112 mv "$T/data/galaxy/index.html.off" "$T/data/galaxy/index.html" 113 stop 114 115 # negative control 1: the base commit's route.om has no galaxy; /galaxy must not be the page there 116 git show "$BASE:server/route.om" > "$T/oldroute.om" 117 if grep -q 'tfgxi' "$T/oldroute.om"; then 118 bad "negative control: base route.om already has the galaxy routes" 119 else 120 compose "$T/n.om" "$T/oldroute.om"; redirect "$T/n.om" 121 start "$T/n.om" 122 code=$(get galaxy) 123 if [ "$code" != 200 ] || ! cmp -s "$T/b" "$T/data/galaxy/index.html"; then 124 ok "negative control: base route.om does not serve the page at /galaxy ($code)" 125 else 126 bad "negative control: base route.om served the page at /galaxy" 127 fi 128 stop 129 fi 130 # negative control 2: a route.om whose root serves the galaxy file (forge/galaxy-live `8f81e8fc` did) 131 # must fail the "root stays the explore page" check 132 sed 's|^note the root stays the explore page; the galaxy is its own page at /galaxy (fpgone), the map$|if fgxhas\nret fgxsend tfgxi tfgxhtm\nend|' server/route.om > "$T/rootgx.om" 133 if cmp -s server/route.om "$T/rootgx.om"; then 134 bad "negative control 2: the mutant equals route.om" 135 else 136 compose "$T/m.om" "$T/rootgx.om"; redirect "$T/m.om" 137 start "$T/m.om" 138 code=$(get '') 139 if [ "$code" = 200 ] && cmp -s "$T/b" "$T/data/galaxy/index.html"; then 140 ok "negative control 2: a root that serves the galaxy is seen (the root check would fail)" 141 else 142 bad "negative control 2: mutant root gave $code and not the galaxy file" 143 fi 144 stop 145 fi 146 147 echo "RESULT pass=$pass fail=$fail" 148 [ "$fail" -eq 0 ]