| 1 | #!/bin/sh |
| 2 | # tests/run.sh — 60+ offline checks for plugin_docker across all 3 modes. |
| 3 | # |
| 4 | # Runs against ./plugin_docker (native build) using a mock DOCKER_BIN script, so |
| 5 | # nothing here needs a real container runtime. If a musl static build or a |
| 6 | # Windows PE (plugin_docker.exe) is present, they are checked too. The whole git |
| 7 | # history is finally audited for secrets, PATs and LAN IPs. |
| 8 | # |
| 9 | # Exit code 0 = everything passed. |
| 10 | |
| 11 | set -u |
| 12 | |
| 13 | ROOT=$(cd "$(dirname "$0")/.." && pwd) |
| 14 | cd "$ROOT" || exit 1 |
| 15 | |
| 16 | BIN=./plugin_docker |
| 17 | PASS=0 |
| 18 | FAIL=0 |
| 19 | |
| 20 | if [ -t 1 ]; then |
| 21 | C_OK=$(printf '\033[32m'); C_BAD=$(printf '\033[31m'); C_B=$(printf '\033[1m'); C_0=$(printf '\033[0m') |
| 22 | else |
| 23 | C_OK=; C_BAD=; C_B=; C_0= |
| 24 | fi |
| 25 | pass() { PASS=$((PASS + 1)); printf ' %sok%s %s\n' "$C_OK" "$C_0" "$1"; } |
| 26 | fail() { FAIL=$((FAIL + 1)); printf ' %sFAIL%s %s\n' "$C_BAD" "$C_0" "$1"; } |
| 27 | |
| 28 | check() { # check <desc> <expected-substring> <actual> |
| 29 | if printf '%s' "$3" | grep -F -q -- "$2"; then pass "$1"; else |
| 30 | fail "$1 (want: $2)"; printf ' got: %s\n' "$(printf '%s' "$3" | head -c 300)" |
| 31 | fi |
| 32 | } |
| 33 | |
| 34 | check_not() { # check_not <desc> <forbidden-substring> <actual> |
| 35 | if printf '%s' "$3" | grep -F -q -- "$2"; then |
| 36 | fail "$1 (must NOT contain: $2)"; else pass "$1" |
| 37 | fi |
| 38 | } |
| 39 | |
| 40 | section() { printf '\n%s== %s ==%s\n' "$C_B" "$1" "$C_0"; } |
| 41 | |
| 42 | body() { printf '%s' "$1" | sed '1,/^\r$/d'; } |
| 43 | |
| 44 | # ---------------------------------------------------------------- setup |
| 45 | section "build" |
| 46 | if [ ! -x "$BIN" ]; then |
| 47 | echo " building native binary..." |
| 48 | cc -O2 -std=c99 -Wall -Wextra -o "$BIN" src/plugin_docker.c || { echo " build failed"; exit 1; } |
| 49 | fi |
| 50 | [ -x "$BIN" ] && pass "native binary exists and is executable" || fail "native binary missing" |
| 51 | |
| 52 | # mock runtime |
| 53 | MOCKDIR=$(mktemp -d 2>/dev/null || echo /tmp/pd_mock_$$) |
| 54 | mkdir -p "$MOCKDIR" |
| 55 | MOCK="$MOCKDIR/mockdocker" |
| 56 | cat > "$MOCK" <<'MOCKEOF' |
| 57 | #!/bin/sh |
| 58 | case "$1" in |
| 59 | ps) |
| 60 | echo "a1b2c3d4e5f6|web|nginx:1.27|running|Up 3 hours|0.0.0.0:8080->80/tcp" |
| 61 | echo "b2c3d4e5f6a1|db|postgres:16|running|Up 3 hours|127.0.0.1:5432->5432/tcp" |
| 62 | echo "c3d4e5f6a1b2|old-job|alpine:3.20|exited|Exited (0) 2 days ago|" |
| 63 | exit 0 ;; |
| 64 | stats) |
| 65 | echo "a1b2c3d4e5f6|1.25%|12.5MiB / 1GiB" |
| 66 | echo "b2c3d4e5f6a1|0.40%|88.1MiB / 1GiB" |
| 67 | exit 0 ;; |
| 68 | logs) |
| 69 | echo "line one" |
| 70 | echo 'line two with "quotes" and a <tab>' |
| 71 | printf 'line three\n' |
| 72 | exit 0 ;; |
| 73 | start|stop|restart) |
| 74 | exit 0 ;; |
| 75 | *) echo "unknown command: $1" >&2; exit 1 ;; |
| 76 | esac |
| 77 | MOCKEOF |
| 78 | chmod +x "$MOCK" |
| 79 | |
| 80 | # a "no runtime" path: empty DOCKER_BIN, PATH with no docker/podman |
| 81 | # (no runtime helper: assignments are inlined at each call site) |
| 82 | |
| 83 | # ---------------------------------------------------------------- meta mode |
| 84 | section "mode 1 --meta (must work without auth — discovery)" |
| 85 | META=$("$BIN" --meta) |
| 86 | check "meta emits name docker" '"name":"docker"' "$META" |
| 87 | check "meta emits desc Containers" '"desc":"Containers"' "$META" |
| 88 | METAENV=$(SX_PLUGIN_META=1 "$BIN") |
| 89 | check "SX_PLUGIN_META=1 yields same meta" '"name":"docker"' "$METAENV" |
| 90 | LEN=$(printf '%s' "$META" | wc -c | tr -d ' ') |
| 91 | [ "$LEN" -lt 60 ] && pass "meta payload is compact ($LEN bytes)" || fail "meta payload too long ($LEN)" |
| 92 | printf '%s' "$META" | python3 -c 'import json,sys; json.load(sys.stdin)' 2>/dev/null \ |
| 93 | && pass "meta is valid JSON" || fail "meta is not valid JSON" |
| 94 | DESC=$(printf '%s' "$META" | sed 's/.*"desc":"\([^"]*\)".*/\1/') |
| 95 | [ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})" |
| 96 | NAME=$(printf '%s' "$META" | sed 's/.*"name":"\([^"]*\)".*/\1/') |
| 97 | [ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces" |
| 98 | check "--version prints version" '1.1.3' "$("$BIN" --version)" |
| 99 | check "--help is available" 'usage:' "$("$BIN" --help)" |
| 100 | |
| 101 | # ---------------------------------------------------------------- list mode |
| 102 | section "node auth" |
| 103 | AUTHNONE=$(BOT_PASSWORD=testpw QUERY_STRING='action=list' "$BIN") |
| 104 | check "no credentials -> 401" 'Status: 401' "$AUTHNONE" |
| 105 | check "401 body is json error" 'invalid node password' "$AUTHNONE" |
| 106 | check_not "401 leaks no container data" '"containers"' "$AUTHNONE" |
| 107 | AUTHBAD=$(BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=wrong QUERY_STRING='action=list' "$BIN") |
| 108 | check "wrong header password -> 401" 'Status: 401' "$AUTHBAD" |
| 109 | AUTHHDR=$(BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=testpw QUERY_STRING='action=list' "$BIN") |
| 110 | check "X-Bot-Password accepted" '"ok":true' "$(body "$AUTHHDR")" |
| 111 | AUTHBEAR=$(BOT_PASSWORD=testpw HTTP_AUTHORIZATION='Bearer testpw' QUERY_STRING='action=list' "$BIN") |
| 112 | check "Authorization Bearer accepted" '"ok":true' "$(body "$AUTHBEAR")" |
| 113 | AUTHQ=$(BOT_PASSWORD=testpw QUERY_STRING='action=list&pwd=testpw' "$BIN") |
| 114 | check "?pwd= accepted" '"ok":true' "$(body "$AUTHQ")" |
| 115 | AUTHHTML=$(BOT_PASSWORD=testpw QUERY_STRING='' "$BIN") |
| 116 | check "html page requires auth too" 'Status: 401' "$AUTHHTML" |
| 117 | AUTHMETA=$(BOT_PASSWORD=testpw "$BIN" --meta) |
| 118 | check "--meta succeeds without auth" '"name":"docker"' "$AUTHMETA" |
| 119 | AUTHOPEN=$(QUERY_STRING='action=list' "$BIN") |
| 120 | check "unset BOT_PASSWORD = open node" 'Content-Type: application/json' "$AUTHOPEN" |
| 121 | |
| 122 | # All remaining checks run with BOT_PASSWORD unset (open mode) so they stay readable. |
| 123 | section "mode 2 JSON list (mock runtime)" |
| 124 | export DOCKER_BIN="$MOCK" |
| 125 | LIST=$(QUERY_STRING='action=list' "$BIN") |
| 126 | LBODY=$(body "$LIST") |
| 127 | check "list header content-type" 'Content-Type: application/json; charset=utf-8' "$LIST" |
| 128 | check_not "list header has no Content-Length" 'Content-Length' "$LIST" |
| 129 | check "list ok:true" '"ok":true' "$LBODY" |
| 130 | check "list plugin id" '"plugin":"plugin_docker"' "$LBODY" |
| 131 | check "list slug docker" '"slug":"docker"' "$LBODY" |
| 132 | check "list version" '"version":"1.1.3"' "$LBODY" |
| 133 | check "list runtime available" '"available":true' "$LBODY" |
| 134 | check "list daemon available" '"daemon_available":true' "$LBODY" |
| 135 | check "list count 3" '"count":3' "$LBODY" |
| 136 | check "summary total 3" '"total":3' "$LBODY" |
| 137 | check "summary running 2" '"running":2' "$LBODY" |
| 138 | check "summary exited 1" '"exited":1' "$LBODY" |
| 139 | check "container web present" '"name":"web"' "$LBODY" |
| 140 | check "container db present" '"name":"db"' "$LBODY" |
| 141 | check "container old-job present" '"name":"old-job"' "$LBODY" |
| 142 | check "image field present" '"image":"nginx:1.27"' "$LBODY" |
| 143 | check "state running present" '"state":"running"' "$LBODY" |
| 144 | check "state exited present" '"state":"exited"' "$LBODY" |
| 145 | check "ports field present" '0.0.0.0:8080->80/tcp' "$LBODY" |
| 146 | check "cpu stat merged" '"cpu":"1.25%"' "$LBODY" |
| 147 | check "mem stat merged" '12.5MiB / 1GiB' "$LBODY" |
| 148 | printf '%s' "$LBODY" | python3 -c 'import json,sys; d=json.load(sys.stdin); assert len(d["containers"])==3' 2>/dev/null \ |
| 149 | && pass "list body is valid JSON with 3 containers" || fail "list body JSON invalid" |
| 150 | |
| 151 | section "mode 2 JSON info" |
| 152 | INFO=$(QUERY_STRING='action=info' "$BIN") |
| 153 | IBODY=$(body "$INFO") |
| 154 | check "info ok:true" '"ok":true' "$IBODY" |
| 155 | check "info action info" '"action":"info"' "$IBODY" |
| 156 | check "info runtime label" '"label":"custom"' "$IBODY" |
| 157 | check "info pid present" '"pid":' "$IBODY" |
| 158 | check "info utc present" '"utc":"20' "$IBODY" |
| 159 | check "info supported list" '"supported":["list","info","logs","control"]' "$IBODY" |
| 160 | printf '%s' "$IBODY" | python3 -c 'import json,sys; json.load(sys.stdin)' 2>/dev/null \ |
| 161 | && pass "info body is valid JSON" || fail "info body JSON invalid" |
| 162 | |
| 163 | section "mode 2 JSON logs" |
| 164 | LOGS=$(QUERY_STRING='action=logs&cid=web' "$BIN") |
| 165 | LOG_BODY=$(body "$LOGS") |
| 166 | check "logs ok:true" '"ok":true' "$LOG_BODY" |
| 167 | check "logs cid echoed" '"cid":"web"' "$LOG_BODY" |
| 168 | check "logs tail 100" '"tail":100' "$LOG_BODY" |
| 169 | check "logs exit_code 0" '"exit_code":0' "$LOG_BODY" |
| 170 | check "logs first line" 'line one' "$LOG_BODY" |
| 171 | check "logs escapes quotes" 'line two with \"quotes\"' "$LOG_BODY" |
| 172 | check_not "logs has no Content-Length" 'Content-Length' "$LOGS" |
| 173 | printf '%s' "$LOG_BODY" | python3 -c 'import json,sys; d=json.load(sys.stdin); assert d["lines"][0]=="line one"' 2>/dev/null \ |
| 174 | && pass "logs body is valid JSON with parsed lines" || fail "logs body JSON invalid" |
| 175 | |
| 176 | section "mode 2 unknown action" |
| 177 | UNK=$(QUERY_STRING='action=bogus' "$BIN") |
| 178 | check "unknown action rejected" 'unknown_action' "$(body "$UNK")" |
| 179 | check "unknown action lists supported" '"supported":["list","info","logs","control"]' "$(body "$UNK")" |
| 180 | |
| 181 | section "mode 2 no runtime" |
| 182 | LIST2=$(DOCKER_BIN= PATH=/nonexistent QUERY_STRING='action=list' "$BIN") |
| 183 | NRT=$(body "$LIST2") |
| 184 | check "no-runtime available false" '"available":false' "$NRT" |
| 185 | check "no-runtime graceful message" 'Neither docker nor podman' "$NRT" |
| 186 | check "no-runtime count 0" '"count":0' "$NRT" |
| 187 | LOGS2=$(DOCKER_BIN= PATH=/nonexistent QUERY_STRING='action=logs&cid=web' "$BIN") |
| 188 | check "no-runtime logs explains why" 'runtime_available' "$(body "$LOGS2")" |
| 189 | |
| 190 | section "podman state normalisation" |
| 191 | PODMOCK="$MOCKDIR/podmock" |
| 192 | cat > "$PODMOCK" <<'PODEOF' |
| 193 | #!/bin/sh |
| 194 | case "$1" in |
| 195 | ps) |
| 196 | echo "8890ba09c621|registry|registry:2|Up 4 months ago|Up 4 months ago|" |
| 197 | echo "aa11bb22cc33|job|alpine:3.20|Exited (1) 2 days ago|Exited (1) 2 days ago|" |
| 198 | echo "dd44ee55ff66|paused-one|redis:7|Paused|Paused|" |
| 199 | exit 0 ;; |
| 200 | stats) exit 0 ;; |
| 201 | *) exit 0 ;; |
| 202 | esac |
| 203 | PODEOF |
| 204 | chmod +x "$PODMOCK" |
| 205 | POD=$(DOCKER_BIN="$PODMOCK" QUERY_STRING='action=list' "$BIN") |
| 206 | PBODY=$(body "$POD") |
| 207 | check "podman: Up becomes running" '"state":"running"' "$PBODY" |
| 208 | check "podman: Exited becomes exited" '"state":"exited"' "$PBODY" |
| 209 | check "podman: Paused becomes paused" '"state":"paused"' "$PBODY" |
| 210 | check "podman: running counted" '"running":1' "$PBODY" |
| 211 | check "podman: exited counted" '"exited":1' "$PBODY" |
| 212 | check "podman: paused counted" '"paused":1' "$PBODY" |
| 213 | check_not "podman: raw status not used as state" '"state":"Up 4 months ago"' "$PBODY" |
| 214 | |
| 215 | section "injection & validation" |
| 216 | section "injection & validation" |
| 217 | INJ1=$(QUERY_STRING='action=logs&cid=a;id' "$BIN") |
| 218 | check "semicolon cid rejected" 'invalid_cid' "$(body "$INJ1")" |
| 219 | INJ2=$(QUERY_STRING='action=logs&cid=--help' "$BIN") |
| 220 | check "leading-dash cid rejected" 'invalid_cid' "$(body "$INJ2")" |
| 221 | INJ3=$(QUERY_STRING='action=logs&cid=a%24(id)' "$BIN") |
| 222 | check "command-substitution cid rejected" 'invalid_cid' "$(body "$INJ3")" |
| 223 | INJ4=$(QUERY_STRING='action=logs&cid=8a7b6c5d4e3f' "$BIN") |
| 224 | check "valid hex cid accepted" '"ok":true' "$(body "$INJ4")" |
| 225 | INJ5=$(QUERY_STRING='action=logs&cid=my_app.v2-x' "$BIN") |
| 226 | check "valid dotted/dashed cid accepted" '"ok":true' "$(body "$INJ5")" |
| 227 | INJ6=$(QUERY_STRING="action=logs&cid=$(printf 'a%.0s' $(seq 1 200))" "$BIN") |
| 228 | check "over-long cid rejected" 'invalid_cid' "$(body "$INJ6")" |
| 229 | |
| 230 | section "control (POST-only, op allowlist)" |
| 231 | CG=$(QUERY_STRING='action=control&op=start&cid=web' "$BIN") |
| 232 | check "control GET refused" 'control_requires_post' "$(body "$CG")" |
| 233 | check "control GET status 405" 'Status: 405' "$CG" |
| 234 | CP=$(REQUEST_METHOD=POST CONTENT_LENGTH=17 QUERY_STRING='action=control' \ |
| 235 | sh -c 'printf "op=start&cid=web" | ./plugin_docker') |
| 236 | check "control POST start ok" '"ok":true' "$(body "$CP")" |
| 237 | check "control POST op echoed" '"op":"start"' "$(body "$CP")" |
| 238 | CP2=$(REQUEST_METHOD=POST CONTENT_LENGTH=17 QUERY_STRING='action=control' \ |
| 239 | sh -c 'printf "op=pwn&cid=web " | ./plugin_docker') |
| 240 | check "invalid op rejected" 'invalid_op' "$(body "$CP2")" |
| 241 | CP3=$(REQUEST_METHOD=POST CONTENT_LENGTH=22 QUERY_STRING='action=control' \ |
| 242 | sh -c 'printf "op=stop&cid=a;id " | ./plugin_docker') |
| 243 | check "control POST injection rejected" 'invalid_cid' "$(body "$CP3")" |
| 244 | CP4=$(printf 'op=start&cid=web' | DOCKER_BIN= PATH=/nonexistent \ |
| 245 | REQUEST_METHOD=POST CONTENT_LENGTH=16 QUERY_STRING='action=control' ./plugin_docker) |
| 246 | check "control POST without runtime degrades" 'runtime_available' "$(body "$CP4")" |
| 247 | |
| 248 | section "mode 3 HTML" |
| 249 | HTML=$(QUERY_STRING='' "$BIN") |
| 250 | check "html content-type" 'Content-Type: text/html; charset=utf-8' "$HTML" |
| 251 | check_not "html has no Content-Length" 'Content-Length' "$HTML" |
| 252 | check "html has viewport meta" 'width=device-width' "$HTML" |
| 253 | check "html title docker" '<title>docker</title>' "$HTML" |
| 254 | check "html back-link present" 'Back to Bot' "$HTML" |
| 255 | check "html KPI total" "k-total" "$HTML" |
| 256 | check "html KPI running" "k-run" "$HTML" |
| 257 | check "html table rows host" "id='rows'" "$HTML" |
| 258 | check "html log viewer card" "logCard" "$HTML" |
| 259 | check "html uses /plugins?plugin= route" "/plugins?plugin=" "$HTML" |
| 260 | check "html uses POST for control" "method:'POST'" "$HTML" |
| 261 | check "html has theme switch" "bot_theme" "$HTML" |
| 262 | |
| 263 | # ---- theme handoff (bot_theme_plugin.h) ---- |
| 264 | # the bot owns the theme: ?theme= before first paint, sx-theme after it |
| 265 | check "html reads ?theme= before paint" 'theme=(light|dark)' "$HTML" |
| 266 | check "html listens for sx-theme" "d.type==='sx-theme'" "$HTML" |
| 267 | check "html asks the host for the theme" "sx-theme-request" "$HTML" |
| 268 | check "html uses bot token --bg-card" "--bg-card" "$HTML" |
| 269 | check "html uses bot token --surface-2" "--surface-2" "$HTML" |
| 270 | check "html uses bot token --text-2" "--text-2" "$HTML" |
| 271 | check "html hides its toggle when embedded" "embed-hide" "$HTML" |
| 272 | check_not "html no retired brand casing" 'Scorpio'"X Bot" "$HTML" |
| 273 | check_not "html no private palette 0d0d10" '0d0d10' "$HTML" |
| 274 | check_not "html no private palette 16161a" '16161a' "$HTML" |
| 275 | check_not "html no private palette f4f4f7" 'f4f4f7' "$HTML" |
| 276 | THEMEQ=$(QUERY_STRING='theme=light' "$BIN") |
| 277 | check "?theme=light still renders the UI" 'prefers-color-scheme' "$THEMEQ" |
| 278 | # ---- end theme handoff ---- |
| 279 | |
| 280 | check "html closes document" '</html>' "$HTML" |
| 281 | EMB=$(QUERY_STRING='embed=1' "$BIN") |
| 282 | check_not "embed=1 strips the back-link" 'Back to Bot' "$EMB" |
| 283 | check "embed=1 still renders UI" "k-total" "$EMB" |
| 284 | ZEROEMOJI=$(printf '%s' "$HTML" | python3 -c ' |
| 285 | import sys |
| 286 | s = sys.stdin.read() |
| 287 | bad = [c for c in s if ord(c) > 0x2600 and ord(c) not in (0x2014, 0x2013, 0x2026)] |
| 288 | print(len(bad)) |
| 289 | ') |
| 290 | [ "$ZEROEMOJI" = "0" ] && pass "HTML contains no emoji glyphs" || fail "HTML has $ZEROEMOJI emoji glyph(s)" |
| 291 | PK="pico""bot" |
| 292 | check_not "html has no internal fleet paths" "$PK" "$HTML" |
| 293 | check_not "html has no private IPs" "192.168." "$HTML" |
| 294 | |
| 295 | section "format=json alias" |
| 296 | FJ=$(QUERY_STRING='format=json' "$BIN") |
| 297 | check "format=json routes to JSON" 'Content-Type: application/json' "$FJ" |
| 298 | |
| 299 | # ---------------------------------------------------------------- optional targets |
| 300 | section "optional cross builds" |
| 301 | if [ -f plugin_docker.musl ]; then |
| 302 | M=$(./plugin_docker.musl --meta) |
| 303 | check "musl build --meta" '"name":"docker"' "$M" |
| 304 | else |
| 305 | echo " skip musl (not built)" |
| 306 | fi |
| 307 | if [ -f plugin_docker.arm64 ]; then |
| 308 | case $(head -c 4 plugin_docker.arm64 | od -An -tx1 | tr -d ' \n') in |
| 309 | 7f454c46) pass "arm64 artifact is ELF" ;; |
| 310 | *) fail "arm64 artifact is not ELF" ;; |
| 311 | esac |
| 312 | # e_machine sits at offset 18, little endian: b7 00 == EM_AARCH64 |
| 313 | EM=$(od -An -tx1 -j 18 -N 2 plugin_docker.arm64 | tr -d ' \n') |
| 314 | [ "$EM" = "b700" ] && pass "arm64 artifact declares EM_AARCH64" \ |
| 315 | || fail "arm64 artifact e_machine is $EM, expected b700" |
| 316 | elif command -v aarch64-linux-musl-gcc >/dev/null 2>&1 || command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then |
| 317 | A64=$(command -v aarch64-linux-musl-gcc 2>/dev/null || command -v aarch64-linux-gnu-gcc) |
| 318 | if "$A64" -O2 -std=c99 -static -o /tmp/plugin_docker_arm64_test src/plugin_docker.c 2>/dev/null; then |
| 319 | pass "aarch64 cross build succeeds" |
| 320 | EM=$(od -An -tx1 -j 18 -N 2 /tmp/plugin_docker_arm64_test | tr -d ' \n') |
| 321 | [ "$EM" = "b700" ] && pass "cross-built arm64 declares EM_AARCH64" \ |
| 322 | || fail "cross-built arm64 e_machine is $EM, expected b700" |
| 323 | rm -f /tmp/plugin_docker_arm64_test |
| 324 | else |
| 325 | fail "aarch64 cross build failed" |
| 326 | fi |
| 327 | else |
| 328 | echo " skip arm64 (no aarch64 cross compiler)" |
| 329 | fi |
| 330 | for slice in arm64 x86_64; do |
| 331 | f="plugin_docker.macos-$slice" |
| 332 | if [ -f "$f" ]; then |
| 333 | MF=$(head -c 4 "$f" | od -An -tx1 | tr -d ' \n') |
| 334 | case "$MF" in |
| 335 | cffaedfe|feedfacf|cefaedfe|feedface) pass "macos-$slice artifact is Mach-O" ;; |
| 336 | *) fail "macos-$slice artifact is not Mach-O ($MF)" ;; |
| 337 | esac |
| 338 | else |
| 339 | echo " skip macos-$slice (not built)" |
| 340 | fi |
| 341 | done |
| 342 | if [ -f plugin_docker.exe ]; then |
| 343 | MAGIC=$(head -c 2 plugin_docker.exe) |
| 344 | [ "$MAGIC" = "MZ" ] && pass "windows artifact has MZ header" || fail "windows artifact missing MZ" |
| 345 | else |
| 346 | echo " skip windows PE (not built)" |
| 347 | fi |
| 348 | |
| 349 | [ -f plugin.json ] && pass "file present: plugin.json" || fail "file missing: plugin.json" |
| 350 | if [ -f plugin.json ]; then |
| 351 | python3 - <<'PY' >/dev/null 2>&1 && pass "plugin.json is valid JSON with the contract keys" || fail "plugin.json invalid or missing contract keys" |
| 352 | import json |
| 353 | d = json.load(open("plugin.json")) |
| 354 | for k in ("slug", "id", "title", "summary", "category", "license", "capabilities", "trust_notice"): |
| 355 | assert k in d, k |
| 356 | assert d["slug"] == "docker" and d["id"] == "plugin_docker", d |
| 357 | assert isinstance(d["capabilities"], list) and d["capabilities"], d |
| 358 | PY |
| 359 | fi |
| 360 | |
| 361 | # ---------------------------------------------------------------- history audit |
| 362 | section "git history secret & LAN audit" |
| 363 | if git rev-parse --git-dir >/dev/null 2>&1; then |
| 364 | ALL="$MOCKDIR/history.txt" |
| 365 | # Bookkeeping lines of this audit are excluded so the detector cannot flag itself. |
| 366 | git log -p --all 2>/dev/null \ |
| 367 | | grep -v '^Author: ' \ |
| 368 | | grep -vE 'scan_hist|HITS=|grep -E|suspects=|audit "|check_not "html has no internal fleet' \ |
| 369 | > "$ALL" || : > "$ALL" |
| 370 | |
| 371 | audit() { # audit <label> <regex> |
| 372 | H=$(grep -Eo "$2" "$ALL" 2>/dev/null | sort -u | head -3 || true) |
| 373 | if [ -n "$H" ]; then |
| 374 | fail "history: $1"; printf '%s\n' "$H" | sed 's/^/ /' |
| 375 | else |
| 376 | pass "history clean: $1" |
| 377 | fi |
| 378 | } |
| 379 | audit "LAN 192.168.x" '192\.168\.[0-9]+\.[0-9]+' |
| 380 | audit "private 10.x" '\b10\.[0-9]+\.[0-9]+\.[0-9]+' |
| 381 | audit "private 172.16-31.x" '172\.(1[6-9]|2[0-9]|3[01])\.[0-9]+\.[0-9]+' |
| 382 | audit "GitHub PAT" 'ghp_[A-Za-z0-9]{36}' |
| 383 | audit "HuggingFace token" 'hf_[A-Za-z0-9]{30,}' |
| 384 | audit "embedded git creds" 'scorpioxinc:[A-Za-z0-9]{20,}' |
| 385 | # the literal is split so this file never contains the string it hunts |
| 386 | audit "bare host password" 'Xbo''xone0909|xbo''xone' |
| 387 | PK="pico""bot"; WT=".work""trees" |
| 388 | audit "fleet path" "/codebases/${PK}|${WT}/" |
| 389 | else |
| 390 | echo " skip history audit (not a git checkout)" |
| 391 | fi |
| 392 | |
| 393 | # ---------------------------------------------------------------- summary |
| 394 | rm -rf "$MOCKDIR" |
| 395 | printf '\n%s== summary ==%s\n' "$C_B" "$C_0" |
| 396 | printf ' passed: %d\n' "$PASS" |
| 397 | printf ' failed: %d\n' "$FAIL" |
| 398 | if [ "$FAIL" -ne 0 ]; then |
| 399 | printf ' %sRESULT: FAILED%s\n' "$C_BAD" "$C_0" |
| 400 | exit 1 |
| 401 | fi |
| 402 | printf ' %sRESULT: ALL PASSED%s\n' "$C_OK" "$C_0" |
| 403 | exit 0 |