Repository Public
1#!/usr/bin/env bash2# =============================================================================3# SP BOUCHER | SOFTWARE & RESEARCH4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project : SPIDER8# File : scripts/verify.sh9# Module : Scripts10# Repository : https://git.spboucher.ai/spider11# Project Website : Not specified12# Created : 2026-12-0413# Last Modified : 2026-12-0414#15# Author : Simon-Pierre Boucher16# Position : Professor of Finance17# Institution : Université du Québec en Outaouais (UQO)18# Organization : SP Boucher19# Website : https://spboucher.ai20# Git : https://git.spboucher.ai21#22# Preferred Contact: contact@spboucher.ai23# Development : dev@spboucher.ai24# Support : support@spboucher.ai25# Security/Admin : admin@spboucher.ai26#27# Copyright (c) 202628# Simon-Pierre Boucher29# All rights reserved where applicable. This file is governed by the30# applicable project license, copyright notices and relevant law.31# Existing third-party rights and notices remain unaffected.32#33# License : ISC34#35# Do not embed credentials, private keys, access tokens,36# certificates or confidential personal information.37#38# =============================================================================39# END OF SP BOUCHER SOURCE HEADER40# =============================================================================4142# Post-deployment verification from a real client. Read-only unless --scrape URL is given43# (URL must be a source the operator is authorised to collect).44# Usage: SPIDER_URL=… SPIDER_API_KEY=… scripts/verify.sh [--scrape URL]45set -uo pipefail46URL="${SPIDER_URL:-http://127.0.0.1:8900}"; KEY="${SPIDER_API_KEY:?SPIDER_API_KEY is required}"; FAIL=047check() { if [ "$2" = "$3" ]; then echo "ok $1 ($2)"; else echo "FAIL $1: expected $3, got $2"; FAIL=1; fi; }48code() { curl -s -o /dev/null -w '%{http_code}' --max-time 20 "$@"; }49check "health" "$(code "$URL/v1/health")" 20050check "openapi" "$(code "$URL/v1/openapi.json")" 20051check "dashboard" "$(code "$URL/dashboard/")" 20052check "auth required" "$(code "$URL/v1/jobs")" 40153check "auth accepted" "$(code -H "Authorization: Bearer $KEY" "$URL/v1/jobs")" 20054check "internal API not for clients" "$(code -X POST -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{}' "$URL/internal/v1/workers/register")" 40355check "mandatory policy enforced" "$(code -X POST -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"url":"https://example.com","policy":{"respect_robots_txt":false}}' "$URL/v1/scrape")" 42256check "SSRF seed refused" "$(code -X POST -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"url":"http://169.254.169.254/"}' "$URL/v1/scrape")" 42257W="$(curl -s --max-time 20 -H "Authorization: Bearer $KEY" "$URL/v1/workers" | python3 -c 'import json,sys; d=json.load(sys.stdin).get("items",[]); print(sum(1 for w in d if w["state"]=="active"), ",".join(sorted({c for w in d if w["state"]=="active" for c in w["capabilities"]})))' 2>/dev/null)"58echo "info active workers: ${W:-unknown}"59if [ "${1:-}" = "--scrape" ] && [ -n "${2:-}" ]; then60 OUT="$(SPIDER_URL="$URL" SPIDER_API_KEY="$KEY" "$(dirname "$0")/../.venv/bin/spider" scrape "$2" --render http --timeout 120 2>&1)"; RC=$?61 check "scrape $2" "$RC" 062fi63exit $FAIL64