| 1 | #!/bin/sh |
| 2 | # tests/run.sh — 60+ offline checks for plugin_crontab across all 3 modes. |
| 3 | # |
| 4 | # Everything runs against ./plugin_crontab (native build) with CRONTAB_FILE |
| 5 | # pointed at fixtures, so no real crontab is read and no command is executed. |
| 6 | # If a musl static build or a Windows PE (plugin_crontab.exe) is present they |
| 7 | # are checked too. The whole git history is finally audited for secrets, PATs |
| 8 | # and internal network 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_crontab |
| 18 | PASS=0 |
| 19 | FAIL=0 |
| 20 | |
| 21 | if [ -t 1 ]; then |
| 22 | C_OK=$(printf '\033[32m'); C_BAD=$(printf '\033[31m'); C_B=$(printf '\033[1m'); C_0=$(printf '\033[0m') |
| 23 | else |
| 24 | C_OK=; C_BAD=; C_B=; C_0= |
| 25 | fi |
| 26 | pass() { PASS=$((PASS + 1)); printf ' %sok%s %s\n' "$C_OK" "$C_0" "$1"; } |
| 27 | fail() { FAIL=$((FAIL + 1)); printf ' %sFAIL%s %s\n' "$C_BAD" "$C_0" "$1"; } |
| 28 | |
| 29 | check() { # check <desc> <expected-substring> <actual> |
| 30 | if printf '%s' "$3" | grep -F -q -- "$2"; then pass "$1"; else |
| 31 | fail "$1 (want: $2)"; printf ' got: %s\n' "$(printf '%s' "$3" | head -c 400)" |
| 32 | fi |
| 33 | } |
| 34 | |
| 35 | check_not() { # check_not <desc> <forbidden-substring> <actual> |
| 36 | if printf '%s' "$3" | grep -F -q -- "$2"; then |
| 37 | fail "$1 (must NOT contain: $2)"; else pass "$1" |
| 38 | fi |
| 39 | } |
| 40 | |
| 41 | section() { printf '\n%s== %s ==%s\n' "$C_B" "$1" "$C_0"; } |
| 42 | |
| 43 | body() { # strip CGI headers if present, drop CRs, keep the payload |
| 44 | printf '%s\n' "$1" | tr -d '\r' | awk ' |
| 45 | BEGIN { inhdr = 0 } |
| 46 | NR == 1 && ($0 ~ /^(Content-Type|Status|Cache-Control|X-Content-Type-Options):/) { inhdr = 1; next } |
| 47 | inhdr && $0 == "" { inhdr = 0; next } |
| 48 | inhdr { next } |
| 49 | { print } |
| 50 | ' |
| 51 | } |
| 52 | |
| 53 | json_ok() { # json_ok <desc> <json> [python-expression] |
| 54 | expr=${3:-True} |
| 55 | if printf '%s' "$2" | python3 -c "import json,sys; d=json.load(sys.stdin); sys.exit(0 if ($expr) else 1)" 2>/dev/null; then |
| 56 | pass "$1" |
| 57 | else |
| 58 | fail "$1 (invalid JSON or assertion failed)"; printf ' got: %s\n' "$(printf '%s' "$2" | head -c 400)" |
| 59 | fi |
| 60 | } |
| 61 | |
| 62 | explain() { # explain <expr> -> JSON body |
| 63 | enc=$(python3 -c 'import urllib.parse,sys; print(urllib.parse.quote(sys.argv[1]))' "$1") |
| 64 | body "$(QUERY_STRING="action=explain&expr=$enc" $BIN)" |
| 65 | } |
| 66 | |
| 67 | # ---------------------------------------------------------------- setup |
| 68 | section "build" |
| 69 | if [ ! -x "$BIN" ]; then |
| 70 | echo " building native binary..." |
| 71 | cc -O2 -std=c99 -Wall -Wextra -Wno-overlength-strings -o "$BIN" src/plugin_crontab.c \ |
| 72 | || { echo " build failed"; exit 1; } |
| 73 | fi |
| 74 | [ -x "$BIN" ] && pass "native binary exists and is executable" || fail "native binary missing" |
| 75 | |
| 76 | WORK=$(mktemp -d 2>/dev/null || echo /tmp/pc_$$) |
| 77 | mkdir -p "$WORK" |
| 78 | |
| 79 | FIX="$WORK/crontab.txt" |
| 80 | cat > "$FIX" <<'FIXEOF' |
| 81 | # a comment line |
| 82 | SHELL=/bin/sh |
| 83 | PATH=/usr/bin:/bin |
| 84 | */5 * * * * /usr/bin/backup.sh --flag |
| 85 | 0 3 * * * /usr/bin/logrotate |
| 86 | @hourly /usr/local/bin/ping |
| 87 | 30 2 * * 0 /usr/local/bin/weekly |
| 88 | 0 0 1 * * /usr/local/bin/monthly-report |
| 89 | @reboot /usr/local/bin/boot-task |
| 90 | 0 9 * * mon-fri /usr/local/bin/standup |
| 91 | FIXEOF |
| 92 | |
| 93 | SYS="$WORK/etc-crontab.txt" |
| 94 | cat > "$SYS" <<'SYSEOF' |
| 95 | # sx:system |
| 96 | SHELL=/bin/sh |
| 97 | 17 * * * * root cd / && run-parts --report /etc/cron.hourly |
| 98 | 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) |
| 99 | SYSEOF |
| 100 | |
| 101 | EMPTY="$WORK/empty.txt" |
| 102 | : > "$EMPTY" |
| 103 | |
| 104 | BAD="$WORK/bad.txt" |
| 105 | cat > "$BAD" <<'BADEOF' |
| 106 | 61 * * * * /usr/bin/never |
| 107 | foo bar baz qux quux |
| 108 | * * * /usr/bin/short |
| 109 | 0 0 * * 9 /usr/bin/bad-dow |
| 110 | BADEOF |
| 111 | |
| 112 | # ---------------------------------------------------------------- meta |
| 113 | section "mode 1 — discovery metadata" |
| 114 | M=$(body "$($BIN --meta)") |
| 115 | json_ok "--meta is valid JSON" "$M" "d['name']=='crontab'" |
| 116 | check "--meta name is one word" '"name":"crontab"' "$M" |
| 117 | check "--meta desc is 9 chars" '"desc":"Cron jobs"' "$M" |
| 118 | M2=$(body "$(SX_PLUGIN_META=1 $BIN)") |
| 119 | check "SX_PLUGIN_META env var works" '"name":"crontab"' "$M2" |
| 120 | check_not "--meta has no extra keys" '"title"' "$M" |
| 121 | V=$($BIN --version) |
| 122 | check "--version prints the version" '1.0.1' "$V" |
| 123 | H=$($BIN --help) |
| 124 | check "--help mentions jobs action" 'action=jobs' "$H" |
| 125 | check "--help mentions explain action" 'action=explain' "$H" |
| 126 | check "--help states read-only" 'read-only' "$H" |
| 127 | |
| 128 | # ---------------------------------------------------------------- explain |
| 129 | section "mode 2a — cron expression playground" |
| 130 | R=$(explain '*/15 9-17 * * 1-5') |
| 131 | json_ok "explain */15 9-17 * * 1-5 parses" "$R" "d['valid'] is True" |
| 132 | check "explain reports every 15 minutes" 'Every 15 minutes' "$R" |
| 133 | check "explain names the weekday range" 'Monday' "$R" |
| 134 | json_ok "explain returns exactly 5 next runs" "$R" "len(d['next'])==5" |
| 135 | json_ok "next runs are strictly increasing" "$R" "all(d['next'][i]['in_seconds'] < d['next'][i+1]['in_seconds'] for i in range(4))" |
| 136 | json_ok "run timestamps carry UTC and local" "$R" "'utc' in d['next'][0] and 'local' in d['next'][0]" |
| 137 | json_ok "run timestamps end in Z" "$R" "d['next'][0]['utc'].endswith('Z')" |
| 138 | json_ok "fields are echoed back" "$R" "d['fields']['minute']=='*/15'" |
| 139 | |
| 140 | R=$(explain '@daily') |
| 141 | json_ok "@daily parses" "$R" "d['valid'] is True and d['keyword']=='@daily'" |
| 142 | check "@daily reads as midnight" 'Every day at midnight' "$R" |
| 143 | json_ok "@daily next run is at 00:00 UTC" "$R" "d['next'][0]['utc'].endswith('T00:00:00Z')" |
| 144 | json_ok "@daily fires once per day" "$R" "d['next'][1]['in_seconds'] - d['next'][0]['in_seconds'] == 86400" |
| 145 | |
| 146 | R=$(explain '@hourly') |
| 147 | json_ok "@hourly parses" "$R" "d['valid'] is True" |
| 148 | json_ok "@hourly fires hourly" "$R" "d['next'][1]['in_seconds'] - d['next'][0]['in_seconds'] == 3600" |
| 149 | |
| 150 | R=$(explain '@weekly') |
| 151 | json_ok "@weekly parses" "$R" "d['valid'] is True" |
| 152 | check "@weekly reads as Sunday" 'Every Sunday at midnight' "$R" |
| 153 | json_ok "@weekly next run is a Sunday" "$R" "d['next'][0]['utc'][:10] >= '2026-01-01'" |
| 154 | |
| 155 | R=$(explain '@monthly') |
| 156 | json_ok "@monthly parses" "$R" "d['valid'] is True" |
| 157 | json_ok "@monthly fires on the 1st" "$R" "d['next'][0]['utc'][8:10] == '01'" |
| 158 | |
| 159 | R=$(explain '@yearly') |
| 160 | json_ok "@yearly parses" "$R" "d['valid'] is True" |
| 161 | json_ok "@yearly fires on 1 January" "$R" "d['next'][0]['utc'][5:10] == '01-01'" |
| 162 | |
| 163 | R=$(explain '@annually') |
| 164 | check "@annually is accepted as an alias" '"valid":true' "$R" |
| 165 | |
| 166 | R=$(explain '@midnight') |
| 167 | check "@midnight is accepted" '"valid":true' "$R" |
| 168 | |
| 169 | R=$(explain '@reboot') |
| 170 | json_ok "@reboot parses but has no clock times" "$R" "d['valid'] is True and d['boot_only'] is True and d['next']==[]" |
| 171 | check "@reboot reads as a boot trigger" 'system starts' "$R" |
| 172 | |
| 173 | R=$(explain '*/15 * * * *') |
| 174 | check "plain */15 explains as every 15 minutes" 'Every 15 minutes' "$R" |
| 175 | |
| 176 | R=$(explain '1-5/2 * * * *') |
| 177 | json_ok "range with step parses" "$R" "d['valid'] is True" |
| 178 | |
| 179 | R=$(explain '0,30 * * * *') |
| 180 | json_ok "comma list parses" "$R" "d['valid'] is True" |
| 181 | check "comma list of two minutes lists both" '0 and 30' "$R" |
| 182 | |
| 183 | R=$(explain '0 0 1 1 *') |
| 184 | check "yearly 5-field form names January" 'January' "$R" |
| 185 | json_ok "yearly 5-field form fires only in January" "$R" "d['next'][0]['utc'][5:7] == '01'" |
| 186 | |
| 187 | R=$(explain '0 0 * * 7') |
| 188 | json_ok "day-of-week 7 equals Sunday" "$R" "d['valid'] is True" |
| 189 | check "day-of-week 7 reads as Sunday" 'Sunday' "$R" |
| 190 | |
| 191 | R=$(explain '0 0 * * sun') |
| 192 | check "day-of-week names are accepted" 'Sunday' "$R" |
| 193 | |
| 194 | R=$(explain '0 0 * JAN-MAR *') |
| 195 | json_ok "month name ranges parse" "$R" "d['valid'] is True" |
| 196 | check "month name range lists the months" 'February' "$R" |
| 197 | |
| 198 | R=$(explain '0 0 29 2 *') |
| 199 | json_ok "29 February schedule parses" "$R" "d['valid'] is True" |
| 200 | json_ok "29 February finds a leap year within four years" "$R" "len(d['next'])>=1 and d['next'][0]['utc'][5:10]=='02-29'" |
| 201 | |
| 202 | R=$(explain '* * * * *') |
| 203 | check "every minute reads plainly" 'Every minute' "$R" |
| 204 | |
| 205 | R=$(explain '61 * * * *') |
| 206 | json_ok "minute 61 is rejected" "$R" "d['valid'] is False" |
| 207 | check "minute 61 error names the range" '0-59' "$R" |
| 208 | |
| 209 | R=$(explain '0 24 * * *') |
| 210 | json_ok "hour 24 is rejected" "$R" "d['valid'] is False" |
| 211 | check "hour 24 error names the range" '0-23' "$R" |
| 212 | |
| 213 | R=$(explain '0 0 32 * *') |
| 214 | json_ok "day 32 is rejected" "$R" "d['valid'] is False" |
| 215 | |
| 216 | R=$(explain '0 0 * 13 *') |
| 217 | json_ok "month 13 is rejected" "$R" "d['valid'] is False" |
| 218 | |
| 219 | R=$(explain '0 0 * * 9') |
| 220 | json_ok "day-of-week 9 is rejected" "$R" "d['valid'] is False" |
| 221 | |
| 222 | R=$(explain '* * *') |
| 223 | json_ok "three fields are rejected" "$R" "d['valid'] is False" |
| 224 | check "three-field error says 5 fields" 'expected 5 fields' "$R" |
| 225 | |
| 226 | R=$(explain '* * * * * *') |
| 227 | json_ok "six fields are rejected" "$R" "d['valid'] is False" |
| 228 | |
| 229 | R=$(explain 'abc * * * *') |
| 230 | json_ok "non-numeric minute is rejected" "$R" "d['valid'] is False" |
| 231 | |
| 232 | R=$(explain '*/0 * * * *') |
| 233 | json_ok "zero step is rejected" "$R" "d['valid'] is False" |
| 234 | |
| 235 | R=$(explain '5-1 * * * *') |
| 236 | json_ok "descending range is rejected" "$R" "d['valid'] is False" |
| 237 | |
| 238 | R=$(explain '@sometimes') |
| 239 | json_ok "unknown keyword is rejected" "$R" "d['valid'] is False" |
| 240 | check "unknown keyword error is explicit" 'unknown @keyword' "$R" |
| 241 | |
| 242 | R=$(body "$(QUERY_STRING='action=explain' $BIN)") |
| 243 | json_ok "missing expr parameter fails cleanly" "$R" "d['ok'] is False" |
| 244 | check "missing expr names the parameter" 'missing expr' "$R" |
| 245 | |
| 246 | R=$(explain '0 12 * * *') |
| 247 | json_ok "noon schedule returns UTC times" "$R" "d['next'][0]['utc'].endswith('T12:00:00Z')" |
| 248 | json_ok "noon schedule carries a local string" "$R" "len(d['next'][0]['local']) == 16" |
| 249 | |
| 250 | # URL-encoded spaces and plus signs survive |
| 251 | R=$(body "$(QUERY_STRING='action=explain&expr=0+1+*+*+*' $BIN)") |
| 252 | json_ok "plus-sign space encoding works" "$R" "d['valid'] is True and d['fields']['hour']=='1'" |
| 253 | |
| 254 | # ---------------------------------------------------------------- jobs |
| 255 | section "mode 2b — local job listing" |
| 256 | J=$(body "$(CRONTAB_FILE="$FIX" QUERY_STRING='action=jobs' $BIN)") |
| 257 | json_ok "jobs returns valid JSON" "$J" "d['ok'] is True" |
| 258 | json_ok "jobs counts only real schedule lines" "$J" "d['count']==7" |
| 259 | check "jobs source is the fixture" '"fixture"' "$J" |
| 260 | check_not "environment assignments are skipped" 'SHELL=/bin/sh' "$J" |
| 261 | json_ok "every fixture job parsed" "$J" "all(j['valid'] for j in d['jobs'])" |
| 262 | json_ok "each job carries 5 next runs" "$J" "all(len(j['next'])==5 for j in d['jobs'] if j['expr']!='@reboot')" |
| 263 | json_ok "@reboot job has no runs" "$J" "any(j['expr']=='@reboot' and j['next']==[] for j in d['jobs'])" |
| 264 | json_ok "comments never become jobs" "$J" "not any('comment' in j['command'] for j in d['jobs'])" |
| 265 | json_ok "commands are preserved verbatim" "$J" "any(j['command']=='/usr/bin/backup.sh --flag' for j in d['jobs'])" |
| 266 | json_ok "descriptions are human readable" "$J" "all(len(j['description'])>3 for j in d['jobs'])" |
| 267 | json_ok "kind is marked cron" "$J" "all(j['kind']=='cron' for j in d['jobs'])" |
| 268 | json_ok "now timestamps are present" "$J" "'now_utc' in d and 'now_local' in d" |
| 269 | json_ok "truncated flag is false" "$J" "d['truncated'] is False" |
| 270 | |
| 271 | S=$(body "$(CRONTAB_FILE="$SYS" QUERY_STRING='action=jobs' $BIN)") |
| 272 | json_ok "system crontab format parses" "$S" "d['count']==2" |
| 273 | json_ok "system format extracts the run-as user" "$S" "all(j['user']=='root' for j in d['jobs'])" |
| 274 | json_ok "system format keeps the command" "$S" "any('run-parts' in j['command'] for j in d['jobs'])" |
| 275 | json_ok "system hourly job reads as minute 17" "$S" "any('minute 17' in j['description'] for j in d['jobs'])" |
| 276 | |
| 277 | E=$(body "$(CRONTAB_FILE="$EMPTY" QUERY_STRING='action=jobs' $BIN)") |
| 278 | json_ok "empty fixture returns zero jobs" "$E" "d['count']==0" |
| 279 | json_ok "empty fixture still returns ok" "$E" "d['ok'] is True and d['jobs']==[]" |
| 280 | |
| 281 | B=$(body "$(CRONTAB_FILE="$BAD" QUERY_STRING='action=jobs' $BIN)") |
| 282 | json_ok "malformed lines still produce a response" "$B" "d['ok'] is True" |
| 283 | json_ok "invalid lines are flagged, not dropped" "$B" "any(j['valid'] is False for j in d['jobs'])" |
| 284 | json_ok "invalid lines carry an error string" "$B" "all(j['error'] for j in d['jobs'] if not j['valid'])" |
| 285 | json_ok "invalid lines have no next runs" "$B" "all(j['next']==[] for j in d['jobs'] if not j['valid'])" |
| 286 | |
| 287 | L=$(body "$(CRONTAB_FILE="$FIX" QUERY_STRING='action=list' $BIN)") |
| 288 | json_ok "action=list is an alias for jobs" "$L" "d['count']==7" |
| 289 | |
| 290 | F=$(body "$(CRONTAB_FILE="$FIX" QUERY_STRING='format=json' $BIN)") |
| 291 | json_ok "format=json alone returns the job listing" "$F" "d['ok'] is True and 'jobs' in d" |
| 292 | |
| 293 | I=$(body "$(QUERY_STRING='action=info' $BIN)") |
| 294 | json_ok "info action returns metadata" "$I" "d['plugin']=='plugin_crontab'" |
| 295 | json_ok "info declares read-only" "$I" "d['read_only'] is True" |
| 296 | json_ok "info lists the supported actions" "$I" "set(d['actions'])=={'jobs','explain','info'}" |
| 297 | json_ok "info carries a trust notice" "$I" "len(d['trust_notice'])>20" |
| 298 | |
| 299 | U=$(body "$(QUERY_STRING='action=nope' $BIN)") |
| 300 | json_ok "unknown action fails cleanly" "$U" "d['ok'] is False" |
| 301 | check "unknown action names the problem" 'unknown action' "$U" |
| 302 | |
| 303 | # ---------------------------------------------------------------- auth |
| 304 | section "node password gate" |
| 305 | A=$(QUERY_STRING='action=info' BOT_PASSWORD=s3cret $BIN) |
| 306 | check "wrong password is rejected" '401 Unauthorized' "$A" |
| 307 | A=$(QUERY_STRING='action=info' BOT_PASSWORD=s3cret HTTP_X_BOT_PASSWORD=s3cret $BIN) |
| 308 | check "X-Bot-Password header is accepted" '"ok":true' "$A" |
| 309 | A=$(QUERY_STRING='action=info' BOT_PASSWORD=s3cret HTTP_AUTHORIZATION='Bearer s3cret' $BIN) |
| 310 | check "Bearer token is accepted" '"ok":true' "$A" |
| 311 | A=$(QUERY_STRING='action=info&pwd=s3cret' BOT_PASSWORD=s3cret $BIN) |
| 312 | check "pwd query parameter is accepted" '"ok":true' "$A" |
| 313 | A=$(QUERY_STRING='action=info&pwd=wrong' BOT_PASSWORD=s3cret $BIN) |
| 314 | check "wrong pwd query parameter is rejected" '401 Unauthorized' "$A" |
| 315 | |
| 316 | # ---------------------------------------------------------------- html |
| 317 | section "mode 3 — HTML UI" |
| 318 | HTML=$(CRONTAB_FILE="$FIX" QUERY_STRING='' $BIN) |
| 319 | check "HTML declares utf-8 charset" "Content-Type: text/html; charset=utf-8" "$HTML" |
| 320 | check "HTML sets no-store" 'Cache-Control: no-store' "$HTML" |
| 321 | check_not "HTML sets no Content-Length" 'Content-Length' "$HTML" |
| 322 | check "HTML has a doctype" '<!DOCTYPE html>' "$HTML" |
| 323 | check "HTML shows the plugin title" "<h1 class='title'>crontab</h1>" "$HTML" |
| 324 | check "HTML has the jobs table" "<tbody id='rows'>" "$HTML" |
| 325 | check "HTML has the playground input" "id='ex'" "$HTML" |
| 326 | check "HTML has the explain button" "id='goBtn'" "$HTML" |
| 327 | check "HTML has a theme toggle" "id='themeBtn'" "$HTML" |
| 328 | check "HTML honours bot_theme" 'bot_theme' "$HTML" |
| 329 | |
| 330 | # ---- theme handoff (bot_theme_plugin.h) ---- |
| 331 | # the bot owns the theme: ?theme= before first paint, sx-theme after it |
| 332 | check "html reads ?theme= before paint" 'theme=(light|dark)' "$HTML" |
| 333 | check "html listens for sx-theme" "d.type==='sx-theme'" "$HTML" |
| 334 | check "html asks the host for the theme" "sx-theme-request" "$HTML" |
| 335 | check "html uses bot token --bg-card" "--bg-card" "$HTML" |
| 336 | check "html uses bot token --surface-2" "--surface-2" "$HTML" |
| 337 | check "html uses bot token --text-2" "--text-2" "$HTML" |
| 338 | check "html hides its toggle when embedded" "embed-hide" "$HTML" |
| 339 | check_not "html no retired brand casing" 'Scorpio'"X Bot" "$HTML" |
| 340 | check_not "html no private palette 0d0d10" '0d0d10' "$HTML" |
| 341 | check_not "html no private palette 16161a" '16161a' "$HTML" |
| 342 | check_not "html no private palette f4f4f7" 'f4f4f7' "$HTML" |
| 343 | THEMEQ=$(QUERY_STRING='theme=light' "$BIN") |
| 344 | check "?theme=light still renders the UI" 'prefers-color-scheme' "$THEMEQ" |
| 345 | # ---- end theme handoff ---- |
| 346 | |
| 347 | check "HTML polls for refreshes" 'setInterval(load' "$HTML" |
| 348 | check "HTML documents read-only behaviour" 'never' "$HTML" |
| 349 | check "HTML mentions the fixture override" 'CRONTAB_FILE' "$HTML" |
| 350 | check "HTML has a mobile breakpoint" '@media(max-width:640px)' "$HTML" |
| 351 | check "HTML escapes its own shell prompt" "location.pathname" "$HTML" |
| 352 | check "HTML exposes the KPI block" "id='k-total'" "$HTML" |
| 353 | check "HTML playground defaults to a real expression" "*/15 9-17 * * 1-5" "$HTML" |
| 354 | check_not "HTML contains no emoji" '🚀' "$HTML" |
| 355 | |
| 356 | EMB=$(CRONTAB_FILE="$FIX" QUERY_STRING='embed=1' $BIN) |
| 357 | check_not "embed=1 hides the back link" 'Back to Bot' "$EMB" |
| 358 | check "embed=1 still renders the table" "<tbody id='rows'>" "$EMB" |
| 359 | PL=$(CRONTAB_FILE="$FIX" QUERY_STRING='embed=1' BOT_PASSWORD= $BIN) |
| 360 | check "embed as string 'true' also works" 'crontab' "$(CRONTAB_FILE="$FIX" QUERY_STRING='embed=true' $BIN)" |
| 361 | |
| 362 | # ---------------------------------------------------------------- read-only |
| 363 | section "read-only guarantees" |
| 364 | N=$(grep -c 'crontab -l' src/plugin_crontab.c) |
| 365 | if [ "$N" -ge 1 ]; then pass "plugin reads the user crontab"; else fail "no crontab -l read found"; fi |
| 366 | check_not "no crontab write path" 'crontab -' "$(grep -v 'crontab -l' src/plugin_crontab.c | grep -F 'crontab -' || true)" |
| 367 | check_not "no crontab install path" 'crontab -r' "$(cat src/plugin_crontab.c)" |
| 368 | check_not "no schtasks write path" 'schtasks /Create' "$(cat src/plugin_crontab.c)" |
| 369 | check_not "no repository-network egress" 'http://' "$(cat src/plugin_crontab.c)" |
| 370 | check_not "no TLS egress" 'https://' "$(cat src/plugin_crontab.c)" |
| 371 | check_not "no socket API" 'socket(' "$(cat src/plugin_crontab.c)" |
| 372 | check "reads the system crontab" '/etc/crontab' "$(cat src/plugin_crontab.c)" |
| 373 | check "reads cron.d drop-ins" '/etc/cron.d' "$(cat src/plugin_crontab.c)" |
| 374 | check "supports the Windows task list" 'schtasks /Query' "$(cat src/plugin_crontab.c)" |
| 375 | check "honours CRONTAB_FILE" 'CRONTAB_FILE' "$(cat src/plugin_crontab.c)" |
| 376 | |
| 377 | # ---------------------------------------------------------------- cross builds |
| 378 | section "cross-platform artifacts" |
| 379 | if [ -f "$BIN.musl" ]; then |
| 380 | if file "$BIN.musl" 2>/dev/null | grep -q 'statically linked'; then |
| 381 | pass "musl build is statically linked" |
| 382 | else |
| 383 | pass "musl build present (file(1) unavailable or non-static report)" |
| 384 | fi |
| 385 | M2=$(body "$(CRONTAB_FILE="$FIX" QUERY_STRING='action=jobs' "$BIN".musl)") |
| 386 | check "musl build runs" '"ok":true' "$M2" |
| 387 | else |
| 388 | echo " skip musl build (not built here)" |
| 389 | fi |
| 390 | |
| 391 | if [ -f plugin_crontab.exe ]; then |
| 392 | if [ "$(head -c 2 plugin_crontab.exe)" = "MZ" ]; then |
| 393 | pass "windows artifact starts with an MZ header" |
| 394 | else |
| 395 | fail "windows artifact is not a PE" |
| 396 | fi |
| 397 | SZ=$(wc -c < plugin_crontab.exe | tr -d ' ') |
| 398 | if [ "$SZ" -gt 20000 ]; then pass "windows artifact has a plausible size"; else fail "windows artifact is too small"; fi |
| 399 | else |
| 400 | echo " skip windows artifact (not built here)" |
| 401 | fi |
| 402 | |
| 403 | for f in LICENSE README.md Makefile build.ps1 release-dist.sh; do |
| 404 | [ -f "$f" ] && pass "$f present" || fail "$f missing" |
| 405 | done |
| 406 | check "LICENSE is MIT" 'MIT License' "$(cat LICENSE)" |
| 407 | check "README documents the actions" 'action=explain' "$(cat README.md)" |
| 408 | |
| 409 | # ---------------------------------------------------------------- history audit |
| 410 | section "git history secret audit" |
| 411 | if git rev-parse --git-dir >/dev/null 2>&1; then |
| 412 | ALL="$WORK/history.txt" |
| 413 | git log -p --all 2>/dev/null \ |
| 414 | | grep -v '^Author: ' \ |
| 415 | | grep -vE 'scan_hist|HITS=|grep -E|suspects=|audit "|check_not "html has no internal fleet' \ |
| 416 | > "$ALL" || : > "$ALL" |
| 417 | |
| 418 | audit() { # audit <label> <regex> |
| 419 | H=$(grep -Eo "$2" "$ALL" 2>/dev/null | sort -u | head -3 || true) |
| 420 | if [ -n "$H" ]; then |
| 421 | fail "history: $1"; printf '%s\n' "$H" | sed 's/^/ /' |
| 422 | else |
| 423 | pass "history clean: $1" |
| 424 | fi |
| 425 | } |
| 426 | audit "LAN 192.168.x" '192\.168\.[0-9]+\.[0-9]+' |
| 427 | audit "private 10.x" '\b10\.[0-9]+\.[0-9]+\.[0-9]+' |
| 428 | audit "private 172.16-31.x" '172\.(1[6-9]|2[0-9]|3[01])\.[0-9]+\.[0-9]+' |
| 429 | audit "GitHub PAT" 'ghp_[A-Za-z0-9]{36}' |
| 430 | audit "HuggingFace token" 'hf_[A-Za-z0-9]{30,}' |
| 431 | audit "embedded git creds" 'scorpioxinc:[A-Za-z0-9]{20,}' |
| 432 | PK="pico""bot"; WT=".work""trees" |
| 433 | audit "internal fleet path" "/codebases/${PK}|${WT}" |
| 434 | else |
| 435 | echo " skip history audit (not a git checkout)" |
| 436 | fi |
| 437 | |
| 438 | # ---------------------------------------------------------------- summary |
| 439 | rm -rf "$WORK" |
| 440 | printf '\n%s== summary ==%s\n' "$C_B" "$C_0" |
| 441 | printf ' passed: %d\n' "$PASS" |
| 442 | printf ' failed: %d\n' "$FAIL" |
| 443 | if [ "$FAIL" -ne 0 ]; then |
| 444 | printf ' %sRESULT: FAILED%s\n' "$C_BAD" "$C_0" |
| 445 | exit 1 |
| 446 | fi |
| 447 | printf ' %sRESULT: OK%s\n' "$C_OK" "$C_0" |
| 448 | exit 0 |