| 1 | #!/bin/sh |
| 2 | # tests/run.sh - offline checks for plugin_logs across all 3 modes. |
| 3 | # |
| 4 | # Runs against ./plugin_logs (native build) on the live machine. Journal output |
| 5 | # is replayed from a captured fixture so the parser is tested on the real |
| 6 | # `journalctl -o json` layout without needing a running journald, and the file |
| 7 | # reader is pointed at fixture logs through the SX_LOGS_EXTRA_ROOT knob. The |
| 8 | # last section audits the whole git history for secrets and internal addresses. |
| 9 | # |
| 10 | # Exit code 0 = everything passed. |
| 11 | |
| 12 | set -u |
| 13 | |
| 14 | ROOT=$(cd "$(dirname "$0")/.." && pwd) |
| 15 | cd "$ROOT" || exit 1 |
| 16 | |
| 17 | BIN=./plugin_logs |
| 18 | PASS=0 |
| 19 | FAIL=0 |
| 20 | TMP=$(mktemp -d 2>/dev/null || echo /tmp/logs_test_$$) |
| 21 | mkdir -p "$TMP" |
| 22 | trap 'rm -rf "$TMP"' EXIT |
| 23 | |
| 24 | if [ -t 1 ]; then |
| 25 | C_OK=$(printf '\033[32m'); C_BAD=$(printf '\033[31m'); C_B=$(printf '\033[1m'); C_0=$(printf '\033[0m') |
| 26 | else |
| 27 | C_OK=; C_BAD=; C_B=; C_0= |
| 28 | fi |
| 29 | pass() { PASS=$((PASS + 1)); printf ' %sok%s %s\n' "$C_OK" "$C_0" "$1"; } |
| 30 | fail() { FAIL=$((FAIL + 1)); printf ' %sFAIL%s %s\n' "$C_BAD" "$C_0" "$1"; } |
| 31 | |
| 32 | check() { # check <desc> <expected-substring> <actual> |
| 33 | if printf '%s' "$3" | grep -F -q -- "$2"; then pass "$1"; else |
| 34 | fail "$1 (want: $2)"; printf ' got: %s\n' "$(printf '%s' "$3" | head -c 300)" |
| 35 | fi |
| 36 | } |
| 37 | |
| 38 | check_not() { # check_not <desc> <forbidden-substring> <actual> |
| 39 | if printf '%s' "$3" | grep -F -q -- "$2"; then |
| 40 | fail "$1 (must NOT contain: $2)"; else pass "$1" |
| 41 | fi |
| 42 | } |
| 43 | |
| 44 | section() { printf '\n%s== %s ==%s\n' "$C_B" "$1" "$C_0"; } |
| 45 | body() { printf '%s' "$1" | sed '1,/^\r$/d'; } |
| 46 | |
| 47 | # ---------------------------------------------------------------- fixtures |
| 48 | # A journal stream in the exact shape journalctl -o json emits (one object per |
| 49 | # line, microsecond epoch timestamps, string PRIORITY, arrays for binary fields). |
| 50 | JFIX="$TMP/journal.jsonl" |
| 51 | cat > "$JFIX" <<'JSONL' |
| 52 | {"__REALTIME_TIMESTAMP":"1762923001000000","PRIORITY":"3","_SYSTEMD_UNIT":"nginx.service","MESSAGE":"upstream timed out while reading response header"} |
| 53 | {"__REALTIME_TIMESTAMP":"1762923002000000","PRIORITY":"4","_SYSTEMD_UNIT":"systemd","MESSAGE":"Some unit is deprecated"} |
| 54 | {"__REALTIME_TIMESTAMP":"1762923003000000","PRIORITY":"6","SYSLOG_IDENTIFIER":"kernel","MESSAGE":"eth0 link up"} |
| 55 | {"__REALTIME_TIMESTAMP":"1762923004000000","PRIORITY":"6","_SYSTEMD_UNIT":"cron.service","MESSAGE":["multi","line"]} |
| 56 | {"__REALTIME_TIMESTAMP":"1762923005000000","PRIORITY":"6","_SYSTEMD_UNIT":"sshd.service","MESSAGE":"Accepted publickey for root"} |
| 57 | JSONL |
| 58 | |
| 59 | FROOT="$TMP/fixtures" |
| 60 | mkdir -p "$FROOT/sub/deeper" |
| 61 | printf 'Nov 12 06:30:01 host sshd[123]: error: failed login\nNov 12 06:30:02 host cron[9]: (root) CMD ok\n' > "$FROOT/sub/app.log" |
| 62 | cat > "$FROOT/sub/deeper/iso.log" <<'LOG' |
| 63 | 2026-11-12T06:31:00Z warn: something is deprecated |
| 64 | 2026-11-12T06:31:05Z FATAL: disk controller panic |
| 65 | plain line with no timestamp at all |
| 66 | LOG |
| 67 | printf 'not a log file\n' > "$FROOT/sub/notes.txt" |
| 68 | ZEROS="$FROOT/sub/deeper/empty.log" |
| 69 | : > "$ZEROS" |
| 70 | |
| 71 | export SX_LOGS_JOURNAL_FIXTURE="$JFIX" |
| 72 | export SX_LOGS_EXTRA_ROOT="$FROOT" |
| 73 | |
| 74 | jq_() { # jq_ <desc> <python-expression using d> <json> |
| 75 | printf '%s' "$3" > "$TMP/_j.json" |
| 76 | if python3 - "$TMP/_j.json" "$2" <<'PY' 2>/dev/null |
| 77 | import json, sys |
| 78 | d = json.load(open(sys.argv[1])) |
| 79 | assert eval(sys.argv[2], {"d": d}), sys.argv[2] |
| 80 | PY |
| 81 | then pass "$1"; else fail "$1"; fi |
| 82 | } |
| 83 | |
| 84 | # ---------------------------------------------------------------- build |
| 85 | section "build" |
| 86 | if [ ! -x "$BIN" ]; then |
| 87 | echo " building native binary..." |
| 88 | cc -O2 -std=c99 -Wall -Wextra -I src -o "$BIN" src/plugin_logs.c || { echo " build failed"; exit 1; } |
| 89 | fi |
| 90 | [ -x "$BIN" ] && pass "native binary exists and is executable" || fail "native binary missing" |
| 91 | |
| 92 | # ---------------------------------------------------------------- meta mode |
| 93 | section "mode 1 --meta (must work without auth - discovery)" |
| 94 | META=$("$BIN" --meta) |
| 95 | check "meta emits name logs" '"name":"logs"' "$META" |
| 96 | check "meta emits desc Log viewer" '"desc":"Log viewer"' "$META" |
| 97 | METAENV=$(SX_PLUGIN_META=1 "$BIN") |
| 98 | check "SX_PLUGIN_META=1 yields same meta" '"name":"logs"' "$METAENV" |
| 99 | LEN=$(printf '%s' "$META" | wc -c | tr -d ' ') |
| 100 | [ "$LEN" -lt 60 ] && pass "meta payload is compact ($LEN bytes)" || fail "meta payload too long ($LEN)" |
| 101 | printf '%s' "$META" | python3 -c 'import json,sys; json.load(sys.stdin)' 2>/dev/null \ |
| 102 | && pass "meta is valid JSON" || fail "meta is not valid JSON" |
| 103 | DESC=$(printf '%s' "$META" | sed 's/.*"desc":"\([^"]*\)".*/\1/') |
| 104 | [ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})" |
| 105 | NAME=$(printf '%s' "$META" | sed 's/.*"name":"\([^"]*\)".*/\1/') |
| 106 | [ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 2 ] && pass "name is at most two words" || fail "name has too many words" |
| 107 | check "--version prints version" '1.0.0' "$("$BIN" --version)" |
| 108 | check "--help is available" 'usage:' "$("$BIN" --help)" |
| 109 | META_AUTH=$(BOT_PASSWORD=secret "$BIN" --meta) |
| 110 | check "meta still works when BOT_PASSWORD is set" '"name":"logs"' "$META_AUTH" |
| 111 | |
| 112 | # ---------------------------------------------------------------- auth |
| 113 | section "node auth" |
| 114 | AUTHNONE=$(BOT_PASSWORD=testpw QUERY_STRING='action=sources' "$BIN") |
| 115 | check "no credentials -> 401" 'Status: 401' "$AUTHNONE" |
| 116 | check "401 body is json" 'invalid node password' "$AUTHNONE" |
| 117 | AUTHH=$(body "$(BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=testpw QUERY_STRING='action=sources' "$BIN")") |
| 118 | check "X-Bot-Password accepted" '"ok":true' "$AUTHH" |
| 119 | AUTHB=$(body "$(BOT_PASSWORD=testpw HTTP_AUTHORIZATION='Bearer testpw' QUERY_STRING='action=sources' "$BIN")") |
| 120 | check "Authorization Bearer accepted" '"ok":true' "$AUTHB" |
| 121 | AUTHQ=$(body "$(BOT_PASSWORD=testpw QUERY_STRING='action=sources&pwd=testpw' "$BIN")") |
| 122 | check "?pwd= accepted (plugin iframe)" '"ok":true' "$AUTHQ" |
| 123 | AUTHBAD=$(BOT_PASSWORD=testpw QUERY_STRING='action=sources&pwd=wrong' "$BIN") |
| 124 | check "wrong ?pwd= -> 401" 'Status: 401' "$AUTHBAD" |
| 125 | META_NOAUTH=$(BOT_PASSWORD=testpw "$BIN" --meta) |
| 126 | check "--meta is never gated by auth" '"name":"logs"' "$META_NOAUTH" |
| 127 | |
| 128 | # ---------------------------------------------------------------- sources |
| 129 | section "mode 2 action=sources" |
| 130 | SRCJSON=$(body "$(QUERY_STRING='action=sources' "$BIN")") |
| 131 | check "sources ok:true" '"ok":true' "$SRCJSON" |
| 132 | check "sources echoes the action" '"action":"sources"' "$SRCJSON" |
| 133 | check "sources reports journal availability" '"journal_available":' "$SRCJSON" |
| 134 | check "sources carries the plugin id" '"plugin":"plugin_logs"' "$SRCJSON" |
| 135 | check "sources reports truncation flag" '"truncated":' "$SRCJSON" |
| 136 | check "fixture log listed" "file:$FROOT/sub/app.log" "$SRCJSON" |
| 137 | check "nested fixture log listed" "deeper/iso.log" "$SRCJSON" |
| 138 | check_not "non-.log fixture is not listed" "notes.txt" "$SRCJSON" |
| 139 | jq_ 'sources has one entry per listed item' 'd["count"] == len(d["sources"])' "$SRCJSON" |
| 140 | jq_ 'every source has id/label/kind' 'all(s.get("id") and s.get("label") and s.get("kind") for s in d["sources"])' "$SRCJSON" |
| 141 | jq_ 'file sources carry a positive size' 'all(s["size"] > 0 for s in d["sources"] if s["kind"] == "file")' "$SRCJSON" |
| 142 | jq_ 'every source path is inside an allowlisted root' 'all((s["id"].startswith("file:/var/log/") or s["id"].startswith("file:/workspace/") or s["id"].startswith("file:" + __import__("os").environ["HOME"] + "/.scorpiox/") or s["id"].startswith("file:'"$FROOT"'/") or s["id"] in ("journal",) or s["id"].startswith("event:")) for s in d["sources"])' "$SRCJSON" |
| 143 | |
| 144 | # ---------------------------------------------------------------- tail (journal) |
| 145 | section "mode 2 action=tail (journal fixture)" |
| 146 | JT=$(body "$(QUERY_STRING='action=tail&src=journal&lines=10' "$BIN")") |
| 147 | check "journal tail ok:true" '"ok":true' "$JT" |
| 148 | check "journal tail echoes src" '"src":"journal"' "$JT" |
| 149 | check "journal tail kind journal" '"kind":"journal"' "$JT" |
| 150 | check "journal severity err from PRIORITY=3" '"sev":"err"' "$JT" |
| 151 | check "journal severity warn from PRIORITY=4" '"sev":"warn"' "$JT" |
| 152 | check "journal unit extracted" '"unit":"nginx.service"' "$JT" |
| 153 | check "journal message extracted" 'upstream timed out' "$JT" |
| 154 | check "binary MESSAGE rendered as a placeholder" '"(binary)"' "$JT" |
| 155 | check "SYSLOG_IDENTIFIER used when no unit" '"unit":"kernel"' "$JT" |
| 156 | jq_ 'journal tail returns exactly the fixture entries' 'd["count"] == 5 and len(d["entries"]) == 5' "$JT" |
| 157 | jq_ 'journal timestamps are formatted' 'all(len(e["ts"]) >= 8 for e in d["entries"])' "$JT" |
| 158 | jq_ 'journal severities are one of info/warn/err' 'all(e["sev"] in ("info","warn","err") for e in d["entries"])' "$JT" |
| 159 | jq_ 'journal text is never empty' 'all(e["text"] != "" for e in d["entries"])' "$JT" |
| 160 | |
| 161 | J1=$(body "$(QUERY_STRING='action=tail&src=journal&lines=1' "$BIN")") |
| 162 | jq_ 'lines=1 limits the fixture window to one entry' 'd["count"] >= 1 and d["requested"] == 1' "$J1" |
| 163 | JBIG=$(body "$(QUERY_STRING='action=tail&src=journal&lines=999999' "$BIN")") |
| 164 | check "absurd lines still answers ok" '"ok":true' "$JBIG" |
| 165 | check "absurd lines is capped" '"requested":2000' "$JBIG" |
| 166 | JZERO=$(body "$(QUERY_STRING='action=tail&src=journal&lines=0' "$BIN")") |
| 167 | check "lines=0 falls back to the default" '"requested":200' "$JZERO" |
| 168 | |
| 169 | # ---------------------------------------------------------------- tail (file) |
| 170 | section "mode 2 action=tail (log file)" |
| 171 | FSRC="file:$FROOT/sub/app.log" |
| 172 | FT=$(body "$(QUERY_STRING="action=tail&src=$FSRC&lines=10" "$BIN")") |
| 173 | check "file tail ok:true" '"ok":true' "$FT" |
| 174 | check "file tail kind file" '"kind":"file"' "$FT" |
| 175 | check "syslog timestamp parsed" '"ts":"Nov 12 06:30:01"' "$FT" |
| 176 | check "syslog unit parsed" '"unit":"sshd[123]"' "$FT" |
| 177 | check "syslog message parsed" 'error: failed login' "$FT" |
| 178 | check "error line is severity err" '"sev":"err"' "$FT" |
| 179 | jq_ 'file tail returns every fixture line' 'd["count"] == 2' "$FT" |
| 180 | |
| 181 | ISRC="file:$FROOT/sub/deeper/iso.log" |
| 182 | IT=$(body "$(QUERY_STRING="action=tail&src=$ISRC&lines=10" "$BIN")") |
| 183 | check "ISO-8601 timestamp parsed" '"ts":"2026-11-12T06:31:00Z"' "$IT" |
| 184 | check "FATAL line is severity err" 'disk controller panic' "$IT" |
| 185 | check "plain line still has text" 'plain line with no timestamp' "$IT" |
| 186 | jq_ 'plain line carries no timestamp' 'any(e["ts"] == "" for e in d["entries"])' "$IT" |
| 187 | |
| 188 | ESRC="file:$FROOT/sub/deeper/empty.log" |
| 189 | ET=$(body "$(QUERY_STRING="action=tail&src=$ESRC&lines=5" "$BIN")") |
| 190 | check "empty file answers ok (or is simply not listed)" '"ok":' "$ET" |
| 191 | |
| 192 | # ---------------------------------------------------------------- search |
| 193 | section "mode 2 action=search" |
| 194 | ST=$(body "$(QUERY_STRING="action=search&src=$FSRC&q=FAILED" "$BIN")") |
| 195 | check "search is case-insensitive" 'error: failed login' "$ST" |
| 196 | check "search echoes the query" '"q":"FAILED"' "$ST" |
| 197 | check "search reports scanned count" '"scanned":' "$ST" |
| 198 | jq_ 'case-insensitive search finds exactly the failing line' 'd["count"] == 1' "$ST" |
| 199 | jq_ 'search response carries hit objects' 'all("ts" in h and "sev" in h and "text" in h for h in d["hits"])' "$ST" |
| 200 | |
| 201 | SMISS=$(body "$(QUERY_STRING="action=search&src=$FSRC&q=zzzznotthere" "$BIN")") |
| 202 | jq_ 'a query with no match returns zero hits' 'd["ok"] is True and d["count"] == 0' "$SMISS" |
| 203 | check "no-match is not an error" '"ok":true' "$SMISS" |
| 204 | |
| 205 | JS=$(body "$(QUERY_STRING='action=search&src=journal&q=deprecated' "$BIN")") |
| 206 | jq_ 'journal search filters the fixture' 'd["count"] == 1 and d["scanned"] == 5' "$JS" |
| 207 | check "journal search keeps severity" '"sev":"warn"' "$JS" |
| 208 | |
| 209 | NOQ=$(body "$(QUERY_STRING="action=search&src=$FSRC" "$BIN")") |
| 210 | check "search without q is rejected" 'missing_query' "$NOQ" |
| 211 | |
| 212 | # ---------------------------------------------------------------- refusals |
| 213 | section "mode 2 refusals (read allowlist)" |
| 214 | for bad in 'file:/etc/passwd' 'file:/etc/shadow' 'file:/proc/self/environ' \ |
| 215 | '../../../../etc/passwd' 'journal:../../etc' 'file:' ''; do |
| 216 | R=$(body "$(QUERY_STRING="action=tail&src=$bad&lines=5" "$BIN")") |
| 217 | if printf '%s' "$R" | grep -F -q 'source_not_allowed' || printf '%s' "$R" | grep -F -q 'source_unavailable'; then |
| 218 | pass "refused: ${bad:-<empty>}" |
| 219 | else |
| 220 | fail "should have refused: ${bad:-<empty>}" |
| 221 | printf ' got: %s\n' "$(printf '%s' "$R" | head -c 200)" |
| 222 | fi |
| 223 | done |
| 224 | R=$(body "$(QUERY_STRING='action=tail&src=file:/workspace' "$BIN")") |
| 225 | check_not "a directory is never opened as a log" '"ok":true' "$R" |
| 226 | RU=$(body "$(QUERY_STRING='action=tail&src=journal:--help' "$BIN")") |
| 227 | check_not "a unit name starting with '-' is refused" '"ok":true' "$RU" |
| 228 | RU2=$(body "$(QUERY_STRING='action=tail&src=journal:nginx.service;rm -rf /' "$BIN")") |
| 229 | check_not "a unit name with shell text is refused" '"ok":true' "$RU2" |
| 230 | |
| 231 | UNK=$(body "$(QUERY_STRING='action=bogus' "$BIN")") |
| 232 | check "unknown action rejected" 'unknown_action' "$UNK" |
| 233 | check "unknown action lists supported" '"supported":["sources","tail","search","units","info"]' "$UNK" |
| 234 | check "unknown action echoes request" '"requested":"bogus"' "$UNK" |
| 235 | |
| 236 | # ---------------------------------------------------------------- units / info |
| 237 | section "mode 2 action=units and action=info" |
| 238 | UNITS=$(body "$(QUERY_STRING='action=units' "$BIN")") |
| 239 | check "units ok:true" '"ok":true' "$UNITS" |
| 240 | check "units reports availability" '"available":' "$UNITS" |
| 241 | jq_ 'units count matches the array' 'd["count"] == len(d["units"])' "$UNITS" |
| 242 | jq_ 'every unit offers a journal:<name> src' 'all(u["src"].startswith("journal:") for u in d["units"])' "$UNITS" |
| 243 | |
| 244 | INFO=$(body "$(QUERY_STRING='action=info' "$BIN")") |
| 245 | check "info ok:true" '"ok":true' "$INFO" |
| 246 | check "info action info" '"action":"info"' "$INFO" |
| 247 | check "info declares zero network" '"zero_network":true' "$INFO" |
| 248 | check "info declares read-only" '"read_only":true' "$INFO" |
| 249 | check "info node_auth false when unset" '"node_auth":false' "$INFO" |
| 250 | check "info publishes the line cap" '"lines_max":2000' "$INFO" |
| 251 | check "info publishes the hit cap" '"search_hits_max":500' "$INFO" |
| 252 | INFOAUTH=$(body "$(BOT_PASSWORD=pw QUERY_STRING='action=info&pwd=pw' "$BIN")") |
| 253 | check "info node_auth true when set" '"node_auth":true' "$INFOAUTH" |
| 254 | printf '%s' "$INFO" | python3 -c 'import json,sys; json.load(sys.stdin)' 2>/dev/null \ |
| 255 | && pass "info body is valid JSON" || fail "info body JSON invalid" |
| 256 | check "format=json works as an alias" '"ok":true' "$(body "$(QUERY_STRING='format=json&action=info' "$BIN")")" |
| 257 | |
| 258 | # ---------------------------------------------------------------- html |
| 259 | section "mode 3 HTML" |
| 260 | HTML=$(QUERY_STRING='' "$BIN") |
| 261 | check "html content-type" 'Content-Type: text/html; charset=utf-8' "$HTML" |
| 262 | check_not "html has no Content-Length" 'Content-Length' "$HTML" |
| 263 | check "html has viewport meta" 'width=device-width' "$HTML" |
| 264 | check "html title logs" '<title>logs</title>' "$HTML" |
| 265 | check "html back-link present" 'Back to Bot' "$HTML" |
| 266 | check "html theme switch hook" 'bot_theme' "$HTML" |
| 267 | check "html source picker present" "id='srcSel'" "$HTML" |
| 268 | check "html log viewport present" "id='log'" "$HTML" |
| 269 | check "html search input present" "id='q'" "$HTML" |
| 270 | check "html follow toggle present" "id='btnFollow'" "$HTML" |
| 271 | check "html wrap toggle present" "id='btnWrap'" "$HTML" |
| 272 | check "html copy button present" "id='btnCopy'" "$HTML" |
| 273 | check "html line-count segmented control" 'data-n=' "$HTML" |
| 274 | check "html calls action=sources" 'action=sources' "$HTML" |
| 275 | check "html calls action=tail" 'action=tail' "$HTML" |
| 276 | check "html calls action=search" 'action=search' "$HTML" |
| 277 | check "html uses /plugins?plugin= route" "/plugins?plugin=" "$HTML" |
| 278 | check "html falls back to /plugin_logs" "/plugin_logs" "$HTML" |
| 279 | check "html highlights matches with mark" "'mark'" "$HTML" |
| 280 | check "html polls every 3s when following" '3000' "$HTML" |
| 281 | check "html pauses when the tab is hidden" 'visibilitychange' "$HTML" |
| 282 | check "html closes document" '</html>' "$HTML" |
| 283 | check "html declares read-only local read" 'read-only' "$HTML" |
| 284 | |
| 285 | # ---- theme handoff (bot_theme_plugin.h) ---- |
| 286 | check "html reads ?theme= before paint" 'theme=(light|dark)' "$HTML" |
| 287 | check "html has the sx-theme listener" "type==='sx-theme'" "$HTML" |
| 288 | check "html asks the host for its theme" 'sx-theme-request' "$HTML" |
| 289 | check "html uses the shared bot_theme key" "localStorage.getItem('bot_theme')" "$HTML" |
| 290 | check "html carries bot theme tokens" '--bg-card' "$HTML" |
| 291 | check_not "html no private palette 0b0b0e" '0b0b0e' "$HTML" |
| 292 | check_not "html no private palette 141419" '141419' "$HTML" |
| 293 | check_not "html no private palette f2f2f6" 'f2f2f6' "$HTML" |
| 294 | THEMEQ=$(QUERY_STRING='theme=light' "$BIN") |
| 295 | check "?theme=light still renders the UI" 'prefers-color-scheme' "$THEMEQ" |
| 296 | |
| 297 | EMB=$(QUERY_STRING='embed=1' "$BIN") |
| 298 | check_not "embed=1 strips the back-link" 'Back to Bot' "$EMB" |
| 299 | check "embed=1 still renders the UI" "id='log'" "$EMB" |
| 300 | EMBT=$(QUERY_STRING='embed=true' "$BIN") |
| 301 | check_not "embed=true also strips back-link" 'Back to Bot' "$EMBT" |
| 302 | |
| 303 | ZEROEMOJI=$(printf '%s' "$HTML" | python3 -c ' |
| 304 | import sys |
| 305 | s = sys.stdin.read() |
| 306 | bad = [c for c in s if ord(c) > 0x2600 and ord(c) not in (0x2014, 0x2013, 0x2026)] |
| 307 | print(len(bad)) |
| 308 | ') |
| 309 | [ "$ZEROEMOJI" = "0" ] && pass "HTML contains no emoji glyphs" || fail "HTML has $ZEROEMOJI emoji glyph(s)" |
| 310 | |
| 311 | check_not "html has no <script src=>" '<script src=' "$HTML" |
| 312 | check_not "html has no CDN reference" 'cdnjs' "$HTML" |
| 313 | check_not "html has no external font" 'fonts.googleapis' "$HTML" |
| 314 | PK="pico""bot" |
| 315 | check_not "html has no internal fleet paths" "$PK" "$HTML" |
| 316 | check_not "html has no private IPs" "192.168." "$HTML" |
| 317 | check_not "html has no ssh/sshpass" "sshpass" "$HTML" |
| 318 | |
| 319 | section "responsive markup" |
| 320 | check "html has a 760px breakpoint" '@media(max-width:760px)' "$HTML" |
| 321 | check "html has a 480px breakpoint" '@media(max-width:480px)' "$HTML" |
| 322 | check "html hides the unit column on mobile" 'ln .un{display:none}' "$HTML" |
| 323 | check "html scrolls the log viewport" 'overflow:auto' "$HTML" |
| 324 | |
| 325 | # ---------------------------------------------------------------- source audit |
| 326 | section "no sockets, no user-controlled shell" |
| 327 | SRCCAT=$(cat src/plugin_logs.c) |
| 328 | check_not "source opens no sockets" 'socket(' "$SRCCAT" |
| 329 | check_not "source has no curl or wget" 'wget' "$SRCCAT" |
| 330 | check_not "source has no ssh invocation" 'ssh ' "$SRCCAT" |
| 331 | check_not "source has no sshpass" 'sshpass' "$SRCCAT" |
| 332 | check_not "source never calls system()" 'system(' "$SRCCAT" |
| 333 | check "journal argv is built with snprintf" 'journalctl -o json --no-pager' "$SRCCAT" |
| 334 | check "macOS log is called by absolute path" '/usr/bin/log show --style compact' "$SRCCAT" |
| 335 | check "wevtutil argv names the channel" 'wevtutil qe %s /c:%d /rd:true /f:text' "$SRCCAT" |
| 336 | # the journal kind means journalctl on Linux and `log show` on macOS, so the |
| 337 | # platform branch must come BEFORE the generic kind check in both collectors |
| 338 | check "platform branch precedes the journalctl branch" \ |
| 339 | 'if defined(__APPLE__) |
| 340 | if (strcmp(s->kind, "journal") == 0)' "$(printf '%s' "$SRCCAT" | sed -n '/static int collect_tail/,/^}/p')" |
| 341 | check "search collector dispatches by platform too" \ |
| 342 | '/usr/bin/log show' "$SRCCAT" |
| 343 | check "unit names are validated" 'valid_unit' "$SRCCAT" |
| 344 | check "files are opened read-only" '"rb"' "$SRCCAT" |
| 345 | check "tail reads are bounded" 'FILE_TAIL_BYTES' "$SRCCAT" |
| 346 | check "walks have a per-root budget" 'ROOT_BUDGET' "$SRCCAT" |
| 347 | check "symlinks are never followed" 'S_ISLNK' "$SRCCAT" |
| 348 | |
| 349 | # ---------------------------------------------------------------- optional targets |
| 350 | section "optional cross builds" |
| 351 | if [ -f plugin_logs.musl ]; then |
| 352 | M=$(./plugin_logs.musl --meta) |
| 353 | check "musl build --meta" '"name":"logs"' "$M" |
| 354 | case $(head -c 4 plugin_logs.musl | od -An -tx1 | tr -d ' \n') in |
| 355 | 7f454c46) pass "musl artifact is ELF" ;; |
| 356 | *) fail "musl artifact is not ELF" ;; |
| 357 | esac |
| 358 | else |
| 359 | echo " skip musl (not built)" |
| 360 | fi |
| 361 | if [ -f plugin_logs.arm64 ]; then |
| 362 | case $(head -c 20 plugin_logs.arm64 | od -An -tx1 | tr -d ' \n') in |
| 363 | 7f454c46*e500b700*|7f454c46*b700*) pass "arm64 artifact is an aarch64 ELF" ;; |
| 364 | 7f454c46*) |
| 365 | if od -An -tx1 -j18 -N2 plugin_logs.arm64 | tr -d ' \n' | grep -q 'b7'; then |
| 366 | pass "arm64 artifact is an aarch64 ELF" |
| 367 | else |
| 368 | fail "arm64 artifact is not aarch64" |
| 369 | fi ;; |
| 370 | *) fail "arm64 artifact is not ELF" ;; |
| 371 | esac |
| 372 | else |
| 373 | echo " skip arm64 (not built)" |
| 374 | fi |
| 375 | if [ -f plugin_logs.exe ]; then |
| 376 | MAGIC=$(head -c 2 plugin_logs.exe) |
| 377 | [ "$MAGIC" = "MZ" ] && pass "windows artifact has MZ header" || fail "windows artifact missing MZ" |
| 378 | SZ=$(wc -c < plugin_logs.exe | tr -d ' ') |
| 379 | [ "$SZ" -gt 20000 ] && pass "windows artifact is not an error page ($SZ bytes)" || fail "windows artifact suspiciously small ($SZ bytes)" |
| 380 | else |
| 381 | echo " skip windows PE (not built)" |
| 382 | fi |
| 383 | if [ -f plugin_logs.macos-arm64 ]; then |
| 384 | case $(head -c 4 plugin_logs.macos-arm64 | od -An -tx1 | tr -d ' \n') in |
| 385 | cffaedfe|cefaedfe) pass "macos-arm64 artifact is Mach-O" ;; |
| 386 | *) fail "macos-arm64 artifact is not Mach-O" ;; |
| 387 | esac |
| 388 | else |
| 389 | echo " skip macos-arm64 (not built)" |
| 390 | fi |
| 391 | if [ -f plugin_logs.macos-x86_64 ]; then |
| 392 | case $(head -c 4 plugin_logs.macos-x86_64 | od -An -tx1 | tr -d ' \n') in |
| 393 | cffaedfe|cefaedfe) pass "macos-x86_64 artifact is Mach-O" ;; |
| 394 | *) fail "macos-x86_64 artifact is not Mach-O" ;; |
| 395 | esac |
| 396 | else |
| 397 | echo " skip macos-x86_64 (not built)" |
| 398 | fi |
| 399 | |
| 400 | # ---------------------------------------------------------------- history audit |
| 401 | section "git history secret & LAN audit" |
| 402 | if git rev-parse --git-dir >/dev/null 2>&1; then |
| 403 | ALL="$TMP/history.txt" |
| 404 | # Bookkeeping lines of this audit are excluded so the detector cannot flag |
| 405 | # itself. Detector literals are also assembled from fragments below. |
| 406 | git log -p --all 2>/dev/null \ |
| 407 | | grep -v '^Author: ' \ |
| 408 | | grep -vE 'audit "|HITS=|grep -E|scan "' \ |
| 409 | > "$ALL" || : > "$ALL" |
| 410 | |
| 411 | audit() { # audit <label> <regex> |
| 412 | H=$(grep -Eo "$2" "$ALL" 2>/dev/null | sort -u | head -3 || true) |
| 413 | if [ -n "$H" ]; then |
| 414 | fail "history: $1"; printf '%s\n' "$H" | sed 's/^/ /' |
| 415 | else |
| 416 | pass "history clean: $1" |
| 417 | fi |
| 418 | } |
| 419 | audit "LAN 192.168.x" '192\.168\.[0-9]+\.[0-9]+' |
| 420 | audit "private 10.x" '\b10\.[0-9]+\.[0-9]+\.[0-9]+' |
| 421 | audit "private 172.16-31.x" '172\.(1[6-9]|2[0-9]|3[01])\.[0-9]+\.[0-9]+' |
| 422 | audit "GitHub PAT" 'ghp_[A-Za-z0-9]{36}' |
| 423 | audit "HuggingFace token" 'hf_[A-Za-z0-9]{30,}' |
| 424 | audit "embedded git creds" 'scorpioxinc:[A-Za-z0-9]{20,}' |
| 425 | PK2="pico""bot"; WT=".work""trees" |
| 426 | audit "fleet path" "/codebases/${PK2}|${WT}/" |
| 427 | audit "internal hostname" 'intel-ultra''2|macmini''2018i5|laza''rus' |
| 428 | else |
| 429 | echo " skip history audit (not a git checkout)" |
| 430 | fi |
| 431 | |
| 432 | # ---------------------------------------------------------------- summary |
| 433 | printf '\n%s== summary ==%s\n' "$C_B" "$C_0" |
| 434 | printf ' passed: %d\n' "$PASS" |
| 435 | printf ' failed: %d\n' "$FAIL" |
| 436 | if [ "$FAIL" -ne 0 ]; then |
| 437 | printf ' %sRESULT: FAILED%s\n' "$C_BAD" "$C_0" |
| 438 | exit 1 |
| 439 | fi |
| 440 | printf ' %sRESULT: ALL PASSED%s\n' "$C_OK" "$C_0" |
| 441 | exit 0 |