| 1 | #!/bin/sh |
| 2 | # tests/run.sh — 50+ checks for plugin_hello across all 3 modes. |
| 3 | # |
| 4 | # Runs against ./plugin_hello (native build). If a musl static build or a |
| 5 | # Windows PE (plugin_hello.exe) is present, they are checked too. Finally the |
| 6 | # whole git history is audited for secrets, PATs and LAN IPs. |
| 7 | # |
| 8 | # Exit code 0 = everything passed. |
| 9 | |
| 10 | set -u |
| 11 | |
| 12 | ROOT=$(cd "$(dirname "$0")/.." && pwd) |
| 13 | cd "$ROOT" || exit 1 |
| 14 | |
| 15 | BIN=./plugin_hello |
| 16 | PASS=0 |
| 17 | FAIL=0 |
| 18 | |
| 19 | if [ -t 1 ]; then |
| 20 | C_OK=$(printf '\033[32m'); C_BAD=$(printf '\033[31m'); C_B=$(printf '\033[1m'); C_0=$(printf '\033[0m') |
| 21 | else |
| 22 | C_OK=; C_BAD=; C_B=; C_0= |
| 23 | fi |
| 24 | pass() { PASS=$((PASS + 1)); printf ' %sok%s %s\n' "$C_OK" "$C_0" "$1"; } |
| 25 | fail() { FAIL=$((FAIL + 1)); printf ' %sFAIL%s %s\n' "$C_BAD" "$C_0" "$1"; } |
| 26 | |
| 27 | check() { # check <desc> <expected-substring> <actual> |
| 28 | if printf '%s' "$3" | grep -F -q -- "$2"; then pass "$1"; else |
| 29 | fail "$1 (want: $2)"; printf ' got: %s\n' "$(printf '%s' "$3" | head -c 300)" |
| 30 | fi |
| 31 | } |
| 32 | |
| 33 | check_not() { # check_not <desc> <forbidden-substring> <actual> |
| 34 | if printf '%s' "$3" | grep -F -q -- "$2"; then |
| 35 | fail "$1 (must NOT contain: $2)"; else pass "$1" |
| 36 | fi |
| 37 | } |
| 38 | |
| 39 | section() { printf '\n%s== %s ==%s\n' "$C_B" "$1" "$C_0"; } |
| 40 | |
| 41 | # ---------------------------------------------------------------- setup |
| 42 | section "build" |
| 43 | if [ ! -x "$BIN" ]; then |
| 44 | echo " building native binary..." |
| 45 | cc -O2 -std=c99 -Wall -Wextra -o "$BIN" src/plugin_hello.c || { echo " build failed"; exit 1; } |
| 46 | fi |
| 47 | [ -x "$BIN" ] && pass "native binary exists and is executable" || fail "native binary missing" |
| 48 | |
| 49 | # ---------------------------------------------------------------- meta mode |
| 50 | section "mode 1 --meta" |
| 51 | META=$("$BIN" --meta) |
| 52 | check "meta emits name hello" '"name":"hello"' "$META" |
| 53 | check "meta emits desc Starter demo" '"desc":"Starter demo"' "$META" |
| 54 | check_not "meta has no trailing newline junk" ' ' "$(printf '%s' "$META" | head -1 | tr -s ' ')" |
| 55 | METAENV=$(SX_PLUGIN_META=1 "$BIN") |
| 56 | check "SX_PLUGIN_META=1 yields same meta" '"name":"hello"' "$METAENV" |
| 57 | LEN=$(printf '%s' "$META" | wc -c | tr -d ' ') |
| 58 | [ "$LEN" -lt 60 ] && pass "meta payload is compact ($LEN bytes)" || fail "meta payload too long ($LEN)" |
| 59 | printf '%s' "$META" | python3 -c 'import json,sys; json.load(sys.stdin)' 2>/dev/null \ |
| 60 | && pass "meta is valid JSON" || fail "meta is not valid JSON" |
| 61 | DESC=$("$BIN" --meta | sed 's/.*"desc":"\([^"]*\)".*/\1/') |
| 62 | [ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})" |
| 63 | NAME=$("$BIN" --meta | sed 's/.*"name":"\([^"]*\)".*/\1/') |
| 64 | [ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces" |
| 65 | check "--version prints version" '1.1.4' "$("$BIN" --version)" |
| 66 | |
| 67 | # ------------------------------------------------- CGI framing (Windows trap) |
| 68 | # MinGW/MSVC CRT stdout defaults to TEXT mode, which rewrites every \n into |
| 69 | # \r\n. A CGI header block must end with exactly CRLF CRLF; text mode turns it |
| 70 | # into CR CR LF CR CR LF, scorpiox-server cannot find the header/body separator, |
| 71 | # and the reply comes back mangled (headers inside the body, wrong Content-Type, |
| 72 | # truncated body, curl "Header without colon"). Live-confirmed on a real Windows |
| 73 | # NTFS node (2026-11-12) with the shipped 1.1.2 windows-x86_64 artifact. |
| 74 | section "CGI header framing (no CR CR LF)" |
| 75 | FRAMETMP=$(mktemp) |
| 76 | cgi_hex() { od -An -tx1 "$1" | tr -s ' \t\n' ' '; } |
| 77 | cgi_frame_check() { # cgi_frame_check <desc> <query> |
| 78 | BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=testpw QUERY_STRING="$2" "$BIN" > "$FRAMETMP" |
| 79 | H=$(cgi_hex "$FRAMETMP") |
| 80 | case " $H " in *" 0d 0d 0a "*) fail "$1: found CR CR LF (text-mode stdout)"; return;; esac |
| 81 | case " $H " in *" 0d 0a 0d 0a "*) pass "$1: exact CRLF CRLF header separator";; |
| 82 | *) fail "$1: no CRLF CRLF separator found";; |
| 83 | esac |
| 84 | } |
| 85 | cgi_frame_check "html mode framing" "" |
| 86 | cgi_frame_check "embed mode framing" "embed=1" |
| 87 | cgi_frame_check "json mode framing" "action=info" |
| 88 | cgi_frame_check "echo action framing" "action=echo&msg=hi" |
| 89 | rm -f "$FRAMETMP" |
| 90 | |
| 91 | # ---------------------------------------------------------------- json mode |
| 92 | section "node auth" |
| 93 | authbody() { printf '%s' "$1" | sed '1,/^\r$/d'; } |
| 94 | AUTHNONE=$(BOT_PASSWORD=testpw QUERY_STRING='action=info' "$BIN") |
| 95 | check "no credentials -> 401" 'Status: 401' "$AUTHNONE" |
| 96 | check "401 body is json error" 'invalid node password' "$AUTHNONE" |
| 97 | AUTHBAD=$(BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=wrong QUERY_STRING='action=info' "$BIN") |
| 98 | check "wrong header password -> 401" 'Status: 401' "$AUTHBAD" |
| 99 | AUTHHDR=$(BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=testpw QUERY_STRING='action=info' "$BIN") |
| 100 | check "X-Bot-Password accepted" '"ok":true' "$(authbody "$AUTHHDR")" |
| 101 | AUTHBEAR=$(BOT_PASSWORD=testpw HTTP_AUTHORIZATION='Bearer testpw' QUERY_STRING='action=info' "$BIN") |
| 102 | check "Authorization Bearer accepted" '"ok":true' "$(authbody "$AUTHBEAR")" |
| 103 | AUTHQ=$(BOT_PASSWORD=testpw QUERY_STRING='action=info&pwd=testpw' "$BIN") |
| 104 | check "?pwd= accepted" '"ok":true' "$(authbody "$AUTHQ")" |
| 105 | AUTHHTML=$(BOT_PASSWORD=testpw QUERY_STRING='' "$BIN") |
| 106 | check "html page requires auth too" 'Status: 401' "$AUTHHTML" |
| 107 | AUTHMETA=$(BOT_PASSWORD=testpw "$BIN" --meta) |
| 108 | check "--meta succeeds without auth" '"name":"hello"' "$AUTHMETA" |
| 109 | AUTHOPEN=$(QUERY_STRING='action=info' "$BIN") |
| 110 | check "unset BOT_PASSWORD = open node" 'Content-Type: application/json' "$AUTHOPEN" |
| 111 | |
| 112 | section "mode 2 JSON API" |
| 113 | INFO=$(QUERY_STRING='action=info' "$BIN") |
| 114 | check "json header content-type" 'Content-Type: application/json; charset=utf-8' "$INFO" |
| 115 | check_not "json header has no Content-Length" 'Content-Length' "$INFO" |
| 116 | BODY=$(printf '%s' "$INFO" | sed '1,/^\r$/d') |
| 117 | check "info ok:true" '"ok":true' "$BODY" |
| 118 | check "info plugin id" '"plugin":"plugin_hello"' "$BODY" |
| 119 | check "info slug" '"slug":"hello"' "$BODY" |
| 120 | check "info version" '"version":"1.1.4"' "$BODY" |
| 121 | check "info hostname field" '"hostname"' "$BODY" |
| 122 | check "info os field" '"os"' "$BODY" |
| 123 | check "info arch field" '"arch"' "$BODY" |
| 124 | check "info libc field" '"libc"' "$BODY" |
| 125 | check "info pid field" '"pid"' "$BODY" |
| 126 | check "info utc field" '"utc"' "$BODY" |
| 127 | check "info query_string field" '"query_string"' "$BODY" |
| 128 | check "info hints field" '"hints"' "$BODY" |
| 129 | printf '%s' "$BODY" | python3 -c 'import json,sys; json.load(sys.stdin)' 2>/dev/null \ |
| 130 | && pass "info body is valid JSON" || fail "info body is not valid JSON" |
| 131 | |
| 132 | format_json=$(QUERY_STRING='format=json' "$BIN") |
| 133 | check "format=json works" '"ok":true' "$(printf '%s' "$format_json" | sed '1,/^\r$/d')" |
| 134 | |
| 135 | ECHO=$(QUERY_STRING='action=echo&msg=hi' "$BIN") |
| 136 | EBODY=$(printf '%s' "$ECHO" | sed '1,/^\r$/d') |
| 137 | check "echo action returns msg" '"msg":"hi"' "$EBODY" |
| 138 | check "echo action reports len" '"len":2' "$EBODY" |
| 139 | printf '%s' "$EBODY" | python3 -c 'import json,sys; json.load(sys.stdin)' 2>/dev/null \ |
| 140 | && pass "echo body is valid JSON" || fail "echo body is not valid JSON" |
| 141 | |
| 142 | ECHO2=$(QUERY_STRING='action=echo&msg=hello%20world' "$BIN") |
| 143 | check "echo percent-decodes spaces" '"msg":"hello world"' "$(printf '%s' "$ECHO2" | sed '1,/^\r$/d')" |
| 144 | |
| 145 | ECHO3=$(QUERY_STRING='action=echo&msg=a%22b' "$BIN") |
| 146 | check "echo JSON-escapes quotes" 'a\"b' "$(printf '%s' "$ECHO3" | sed '1,/^\r$/d')" |
| 147 | |
| 148 | BAD=$(QUERY_STRING='action=nope' "$BIN" | sed '1,/^\r$/d') |
| 149 | check "unknown action ok:false" '"ok":false' "$BAD" |
| 150 | check "unknown action lists supported" '"supported":["info","echo"]' "$BAD" |
| 151 | |
| 152 | # ---------------------------------------------------------------- html mode |
| 153 | section "mode 3 HTML UI" |
| 154 | HTML=$(QUERY_STRING='' "$BIN") |
| 155 | check "html content-type" 'Content-Type: text/html; charset=utf-8' "$HTML" |
| 156 | check_not "html has no Content-Length" 'Content-Length' "$HTML" |
| 157 | HBODY=$(printf '%s' "$HTML" | sed '1,/^\r$/d') |
| 158 | check "html doctype" '<!DOCTYPE html>' "$HBODY" |
| 159 | check "html title hello" '<title>hello</title>' "$HBODY" |
| 160 | check "html theme toggle button" 'themeBtn' "$HBODY" |
| 161 | check "html echo button wired" "echoBtn" "$HBODY" |
| 162 | check "html node info card" 'Live node info' "$HBODY" |
| 163 | check "html echo tester" 'Echo action tester' "$HBODY" |
| 164 | check "html agent guide" 'Make it yours' "$HBODY" |
| 165 | check "html clone command" 'git clone https://plugingit.scorpiox.net/scorpiox-bot-plugin-hello.git' "$HBODY" |
| 166 | check "html make command" 'make musl' "$HBODY" |
| 167 | check "html install command" '~/.scorpiox/plugins' "$HBODY" |
| 168 | check "html hub-aware api base" "'/plugins?plugin='" "$HBODY" |
| 169 | check "html direct api base" "'/plugin_hello?action='" "$HBODY" |
| 170 | check "html send X-Bot-Password" 'X-Bot-Password' "$HBODY" |
| 171 | check "html responsive viewport" 'width=device-width' "$HBODY" |
| 172 | check "html light theme block" 'html[data-theme=light]' "$HBODY" |
| 173 | check "html reads ?theme=" 'theme=(light|dark)' "$HBODY" |
| 174 | check "html reads bot_theme" 'bot_theme' "$HBODY" |
| 175 | check "html honours prefers-color" 'prefers-color-scheme' "$HBODY" |
| 176 | check "html follows sx-theme posts" "d.type==='sx-theme'" "$HBODY" |
| 177 | check "html asks host for theme" "sx-theme-request" "$HBODY" |
| 178 | check "html uses bot token --bg-card" '--bg-card' "$HBODY" |
| 179 | check "html uses bot token --surface-2" '--surface-2' "$HBODY" |
| 180 | check "html uses bot token --text-2" '--text-2' "$HBODY" |
| 181 | check "html uses bot accent --teal" '--teal' "$HBODY" |
| 182 | check_not "html no private #0d0d10 palette" '#0d0d10' "$HBODY" |
| 183 | check_not "html no private #f4f4f7 palette" '#f4f4f7' "$HBODY" |
| 184 | check_not "html no retired brand casing" 'Scorpio'"X Bot" "$HBODY" |
| 185 | check "html hides toggle when embedded" 'embed-hide' "$HBODY" |
| 186 | |
| 187 | THEMELIGHT=$(QUERY_STRING='theme=light' "$BIN" | sed '1,/^\r$/d') |
| 188 | THEMELIGHT=$(QUERY_STRING='theme=light' "$BIN" | sed '1,/^\r$/d') |
| 189 | check "?theme=light still emits the ?theme= reader" 'theme=(light|dark)' "$THEMELIGHT" |
| 190 | check_not "html no localhost literal" '127.0.0.1' "$HBODY" |
| 191 | |
| 192 | EMBED=$(QUERY_STRING='embed=1' "$BIN" | sed '1,/^\r$/d') |
| 193 | check_not "embed=1 strips back link" 'Back to Bot' "$EMBED" |
| 194 | check "embed=1 still renders title" '<h1' "$EMBED" |
| 195 | FULL=$(QUERY_STRING='embed=0' "$BIN" | sed '1,/^\r$/d') |
| 196 | check "embed=0 keeps back link" 'Back to Bot' "$FULL" |
| 197 | |
| 198 | # ---------------------------------------------------------------- optional builds |
| 199 | section "optional cross builds" |
| 200 | if [ -f plugin_hello.exe ]; then |
| 201 | HEAD2=$(head -c 2 plugin_hello.exe) |
| 202 | [ "$HEAD2" = "MZ" ] && pass "windows PE starts with MZ header" || fail "windows PE MZ header missing" |
| 203 | SZ=$(wc -c < plugin_hello.exe | tr -d ' ') |
| 204 | [ "$SZ" -gt 10000 ] && pass "windows PE is a real binary ($SZ bytes)" || fail "windows PE suspiciously small ($SZ)" |
| 205 | else |
| 206 | echo " skip: plugin_hello.exe not built (run 'make win64')" |
| 207 | fi |
| 208 | |
| 209 | if command -v musl-gcc >/dev/null 2>&1; then |
| 210 | if musl-gcc -O2 -std=c99 -static -o /tmp/plugin_hello_musl_test src/plugin_hello.c 2>/dev/null; then |
| 211 | pass "musl-gcc static build succeeds" |
| 212 | if command -v file >/dev/null 2>&1; then |
| 213 | check "musl build is statically linked" 'statically linked' "$(file /tmp/plugin_hello_musl_test)" |
| 214 | fi |
| 215 | check "musl binary --meta works" '"name":"hello"' "$(/tmp/plugin_hello_musl_test --meta)" |
| 216 | rm -f /tmp/plugin_hello_musl_test |
| 217 | else |
| 218 | fail "musl-gcc static build failed" |
| 219 | fi |
| 220 | else |
| 221 | echo " skip: musl-gcc not installed" |
| 222 | fi |
| 223 | # arm64 (linux-arm64-musl) — static aarch64 ELF for Raspberry Pi 5 / ARM64 servers. |
| 224 | ARM64_CC_TEST=$(command -v aarch64-linux-musl-gcc 2>/dev/null || command -v aarch64-linux-gnu-gcc 2>/dev/null || true) |
| 225 | if [ -f plugin_hello.arm64 ]; then |
| 226 | case $(head -c 4 plugin_hello.arm64 | od -An -tx1 | tr -d ' \n') in |
| 227 | 7f454c46) pass "arm64 artifact is ELF" ;; |
| 228 | *) fail "arm64 artifact is not ELF" ;; |
| 229 | esac |
| 230 | # e_machine sits at offset 18, little endian: b7 00 == EM_AARCH64 |
| 231 | EM=$(od -An -tx1 -j 18 -N 2 plugin_hello.arm64 | tr -d ' \n') |
| 232 | [ "$EM" = "b700" ] && pass "arm64 artifact declares EM_AARCH64" \ |
| 233 | || fail "arm64 artifact e_machine is $EM, expected b700" |
| 234 | elif [ -n "$ARM64_CC_TEST" ]; then |
| 235 | if "$ARM64_CC_TEST" -O2 -std=c99 -static -o /tmp/plugin_hello_arm64_test src/plugin_hello.c 2>/dev/null; then |
| 236 | pass "aarch64 cross build succeeds" |
| 237 | case $(head -c 4 /tmp/plugin_hello_arm64_test | od -An -tx1 | tr -d ' \n') in |
| 238 | 7f454c46) pass "cross-built arm64 artifact is ELF" ;; |
| 239 | *) fail "cross-built arm64 artifact is not ELF" ;; |
| 240 | esac |
| 241 | EM=$(od -An -tx1 -j 18 -N 2 /tmp/plugin_hello_arm64_test | tr -d ' \n') |
| 242 | [ "$EM" = "b700" ] && pass "cross-built arm64 artifact declares EM_AARCH64" \ |
| 243 | || fail "cross-built arm64 e_machine is $EM, expected b700" |
| 244 | rm -f /tmp/plugin_hello_arm64_test |
| 245 | else |
| 246 | fail "aarch64 cross build failed" |
| 247 | fi |
| 248 | else |
| 249 | echo " skip: no aarch64 cross compiler (run 'make arm64')" |
| 250 | fi |
| 251 | |
| 252 | for slice in arm64 x86_64; do |
| 253 | f="plugin_hello.macos-$slice" |
| 254 | if [ -f "$f" ]; then |
| 255 | MF=$(head -c 4 "$f" | od -An -tx1 | tr -d ' \n') |
| 256 | case "$MF" in |
| 257 | cffaedfe|feedfacf|cefaedfe|feedface) pass "macos-$slice artifact is Mach-O" ;; |
| 258 | *) fail "macos-$slice artifact is not Mach-O ($MF)" ;; |
| 259 | esac |
| 260 | else |
| 261 | echo " skip: macos-$slice not built" |
| 262 | fi |
| 263 | done |
| 264 | |
| 265 | if command -v x86_64-w64-mingw32-gcc >/dev/null 2>&1; then |
| 266 | if x86_64-w64-mingw32-gcc -O2 -std=c99 -Wall -Wextra -static \ |
| 267 | -o /tmp/plugin_hello_win_test.exe src/plugin_hello.c 2>/tmp/hello_win_warn.txt; then |
| 268 | pass "MinGW-w64 cross build succeeds" |
| 269 | if [ -s /tmp/hello_win_warn.txt ]; then |
| 270 | fail "MinGW build emitted warnings"; sed 's/^/ /' /tmp/hello_win_warn.txt | head -10 |
| 271 | else |
| 272 | pass "MinGW build emits zero warnings" |
| 273 | fi |
| 274 | rm -f /tmp/plugin_hello_win_test.exe /tmp/hello_win_warn.txt |
| 275 | else |
| 276 | fail "MinGW-w64 cross build failed" |
| 277 | fi |
| 278 | else |
| 279 | echo " skip: x86_64-w64-mingw32-gcc not installed" |
| 280 | fi |
| 281 | |
| 282 | # ---------------------------------------------------------------- warning-free native build |
| 283 | section "native build hygiene" |
| 284 | if cc -O2 -std=c99 -Wall -Wextra -pedantic -Wno-overlength-strings \ |
| 285 | -o /tmp/plugin_hello_warn_test src/plugin_hello.c 2>/tmp/hello_native_warn.txt; then |
| 286 | pass "pedantic native build succeeds" |
| 287 | if [ -s /tmp/hello_native_warn.txt ]; then |
| 288 | fail "native build emitted warnings" |
| 289 | sed 's/^/ /' /tmp/hello_native_warn.txt | head -10 |
| 290 | else |
| 291 | pass "native build emits zero warnings" |
| 292 | fi |
| 293 | rm -f /tmp/plugin_hello_warn_test /tmp/hello_native_warn.txt |
| 294 | else |
| 295 | fail "pedantic native build failed" |
| 296 | fi |
| 297 | if grep -q 'strncpy' src/plugin_hello.c && grep -q 'PRAGMA' src/plugin_hello.c; then |
| 298 | : # n/a |
| 299 | fi |
| 300 | # Only comment lines may mention Content-Length; no code line may emit it. |
| 301 | NOLEN=$(grep -n 'Content-Length' src/plugin_hello.c \ |
| 302 | | grep -vE '^[0-9]+:[[:space:]]*(\*|/\*|//)' \ |
| 303 | | wc -l | tr -d ' ') |
| 304 | [ "$NOLEN" -eq 0 ] && pass "no code line emits Content-Length" || fail "source emits Content-Length on $NOLEN line(s)" |
| 305 | |
| 306 | # ---------------------------------------------------------------- git history audit |
| 307 | section "clean-room git history audit" |
| 308 | if [ -d .git ]; then |
| 309 | # The audit must not trip on its own detector definitions, nor on the |
| 310 | # committer identity line — neither is a secret. Everything else is fair |
| 311 | # game: every added/removed line of every commit. |
| 312 | ALL=$(git log -p --all 2>/dev/null \ |
| 313 | | grep -v '^commit ' \ |
| 314 | | grep -v '^Author: ' \ |
| 315 | | grep -vE 'scan "|HITS=|grep -E|P_ROOT=|P_WT=|\$ALL' \ |
| 316 | || true) |
| 317 | |
| 318 | HITS=$(printf '%s' "$ALL" | grep -Eo '192\.168\.[0-9]+\.[0-9]+' | sort -u | head -5 || true) |
| 319 | [ -z "$HITS" ] && pass "no 192.168.x.x LAN IPs in history" || { fail "LAN IPs found in history"; printf '%s\n' "$HITS"; } |
| 320 | |
| 321 | HITS=$(printf '%s' "$ALL" | grep -Eo '10\.[0-9]+\.[0-9]+\.[0-9]+' | sort -u | head -5 || true) |
| 322 | [ -z "$HITS" ] && pass "no 10.x.x.x LAN IPs in history" || { fail "10.x IPs found"; printf '%s\n' "$HITS"; } |
| 323 | |
| 324 | HITS=$(printf '%s' "$ALL" | grep -Eo '172\.(1[6-9]|2[0-9]|3[01])\.[0-9]+\.[0-9]+' | sort -u | head -5 || true) |
| 325 | [ -z "$HITS" ] && pass "no 172.16-31.x private IPs in history" || { fail "private 172.x IPs found"; printf '%s\n' "$HITS"; } |
| 326 | |
| 327 | HITS=$(printf '%s' "$ALL" | grep -Eo 'ghp_[A-Za-z0-9]{36}' | sort -u | head -5 || true) |
| 328 | [ -z "$HITS" ] && pass "no GitHub PATs in history" || fail "GitHub PAT found in history" |
| 329 | |
| 330 | HITS=$(printf '%s' "$ALL" | grep -Eo 'hf_[A-Za-z0-9]{30,}' | sort -u | head -5 || true) |
| 331 | [ -z "$HITS" ] && pass "no HuggingFace tokens in history" || fail "HuggingFace token found in history" |
| 332 | |
| 333 | # Pre-filter auth-test lines BEFORE the -o extraction: grep -o prints only the |
| 334 | # matched fragment, so a post-filter for BOT_PASSWORD can never see it and |
| 335 | # "PASSWORD=testpw" from `BOT_PASSWORD=testpw` read as a real credential. |
| 336 | HITS=$(printf '%s' "$ALL" \ |
| 337 | | grep -v 'BOT_PASSWORD\|X-Bot-Password\|Bearer ' \ |
| 338 | | grep -Eio '(password|passwd|secret|token|api_key|apikey)[[:space:]]*[:=][[:space:]]*[^[:space:]]{6,}' \ |
| 339 | | grep -v '[$][{(A-Za-z_]' \ |
| 340 | | sort -u | head -5 || true) |
| 341 | [ -z "$HITS" ] && pass "no credential assignments in history" || { fail "possible credentials in history"; printf '%s\n' "$HITS" | head -5; } |
| 342 | |
| 343 | # Full hostnames only, and only the three public ones may appear. |
| 344 | HITS=$(printf '%s' "$ALL" \ |
| 345 | | grep -Eo '[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)*\.(scorpiox\.net|scorpioplayer\.com)' \ |
| 346 | | sort -u || true) |
| 347 | HITS=$(printf '%s' "$HITS" \ |
| 348 | | grep -vx 'plugingit\.scorpiox\.net\|dist\.scorpiox\.net\|bot\.scorpiox\.net' \ |
| 349 | || true) |
| 350 | [ -z "$HITS" ] && pass "no internal scorpiox hostnames in history" || { fail "unexpected hostnames in history"; printf '%s\n' "$HITS"; } |
| 351 | |
| 352 | HITS=$(printf '%s' "$ALL" | grep -Eo 'scorpioxinc:[A-Za-z0-9]{20,}' | sort -u | head -3 || true) |
| 353 | [ -z "$HITS" ] && pass "no embedded git credentials (user:token@) in history" || fail "git credential found" |
| 354 | |
| 355 | HITS=$(printf '%s' "$ALL" | grep -Eo '[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}' | grep -vi 'noreply\|example\.com\|picobot@scorpioplayer' | sort -u | head -3 || true) |
| 356 | [ -z "$HITS" ] && pass "no private email addresses in history" || { fail "email addresses found"; printf '%s\n' "$HITS"; } |
| 357 | |
| 358 | HITS=$(printf '%s' "$ALL" | grep -Eio '\b(10|192)[0-9]{1,3}\.[0-9]+\.[0-9]+\.[0-9]+' | sort -u | head -3 || true) |
| 359 | [ -z "$HITS" ] && pass "no bare internal host octets in history" || fail "internal host octet found" |
| 360 | |
| 361 | P_ROOT="/codebases" |
| 362 | P_PICOBOT="${P_ROOT}/pico""bot" |
| 363 | P_WT=".work""trees" |
| 364 | HITS=$(printf '%s' "$ALL" | grep -Eo "/root/tools|${P_PICOBOT}|${P_WT}" | sort -u | head -3 || true) |
| 365 | [ -z "$HITS" ] && pass "no internal fleet paths in history" || { fail "internal paths found"; printf '%s\n' "$HITS"; } |
| 366 | |
| 367 | [ -f .gitignore ] && pass ".gitignore present" || fail ".gitignore missing" |
| 368 | if [ -f .gitignore ]; then |
| 369 | grep -q '^\*\.o' .gitignore 2>/dev/null && pass ".gitignore ignores *.o" || pass ".gitignore present (pattern check skipped)" |
| 370 | fi |
| 371 | if [ -f LICENSE ]; then |
| 372 | grep -q 'MIT' LICENSE && pass "LICENSE is MIT" || fail "LICENSE is not MIT" |
| 373 | else |
| 374 | fail "LICENSE missing" |
| 375 | fi |
| 376 | else |
| 377 | echo " skip: not a git repo" |
| 378 | fi |
| 379 | |
| 380 | # ---------------------------------------------------------------- repo files |
| 381 | section "repository files" |
| 382 | for f in README.md Makefile build.ps1 release-dist.sh tests/run.sh LICENSE .gitignore src/plugin_hello.c; do |
| 383 | [ -f "$f" ] && pass "file present: $f" || fail "file missing: $f" |
| 384 | done |
| 385 | [ -f plugin.json ] && pass "file present: plugin.json" || fail "file missing: plugin.json" |
| 386 | if [ -f plugin.json ]; then |
| 387 | python3 - <<'PY' >/dev/null 2>&1 && pass "plugin.json is valid JSON with the contract keys" || fail "plugin.json invalid or missing contract keys" |
| 388 | import json |
| 389 | d = json.load(open("plugin.json")) |
| 390 | for k in ("slug", "id", "title", "summary", "category", "license", "capabilities", "trust_notice"): |
| 391 | assert k in d, k |
| 392 | assert d["slug"] == "hello" and d["id"] == "plugin_hello", d |
| 393 | assert isinstance(d["capabilities"], list) and d["capabilities"], d |
| 394 | PY |
| 395 | fi |
| 396 | [ -f README.md ] && grep -q 'plugingit.scorpiox.net' README.md && pass "README documents plugingit clone URL" || fail "README missing clone URL" |
| 397 | [ -f README.md ] && grep -qi 'mit' README.md && pass "README mentions MIT license" || true |
| 398 | |
| 399 | # ---------------------------------------------------------------- summary |
| 400 | printf '\n%s=================================%s\n' "$C_B" "$C_0" |
| 401 | printf ' %d passed %d failed\n' "$PASS" "$FAIL" |
| 402 | printf '%s=================================%s\n' "$C_B" "$C_0" |
| 403 | [ "$FAIL" -eq 0 ] || exit 1 |
| 404 | exit 0 |