#!/bin/bash # The dashboard from scratch, the way docs/dashboard.md says, in clean Debian containers (Docker): # install.sh, every plugin on, then every page and the food search must answer, and a foreign Host is refused. # # tests/clean-install.sh Debian 12 (bookworm) and 13 (trixie) # tests/clean-install.sh debian:trixie just that one set -euo pipefail REPO=$(cd "$(dirname "$0")/.." && pwd) IMAGES=("${@:-debian:bookworm}"); [ $# -gt 0 ] || IMAGES=(debian:bookworm debian:trixie) INSIDE=' set -e cp -r /repo /tmp/repo && cd /tmp/repo/dashboard && rm -rf __pycache__ ./install.sh --headless --no-service --user dash > /tmp/install.log 2>&1 || { tail -30 /tmp/install.log; exit 1; } apt-get install -y -qq curl > /dev/null 2>&1 python3 - < /tmp/dash.log 2>&1 &" for i in $(seq 30); do curl -s -o /dev/null http://127.0.0.1:8080/login && break; sleep 1; done fail=0 for p in / /settings /weather /stations /week /month /health /health/sleep /food /cycle /work /activity /notes /app /login; do code=$(curl -s -o /dev/null -w "%{http_code}" -H "Host: localhost" http://127.0.0.1:8080$p) [ "$code" = 200 ] || { echo "FAIL $p → $code"; fail=1; } done code=$(curl -s -o /dev/null -w "%{http_code}" -H "Host: evil.example" http://127.0.0.1:8080/) [ "$code" = 400 ] || { echo "FAIL a foreign Host got $code (want 400)"; fail=1; } n=$(curl -s -H "Host: localhost" "http://127.0.0.1:8080/food/api/foods?q=apple" | python3 -c "import json,sys; print(len(json.load(sys.stdin)[\"db\"]))") [ "$n" -gt 0 ] || { echo "FAIL the food search found nothing"; fail=1; } grep -q Traceback /tmp/dash.log && { echo "FAIL tracebacks in the log:"; grep -B2 -A12 Traceback /tmp/dash.log | head -60; fail=1; } echo "python $(python3 -c "import sys; print(sys.version.split()[0])") · $(grep -c "plugin .*loaded" /tmp/dash.log) plugins loaded" exit $fail ' status=0 for img in "${IMAGES[@]}"; do echo "== $img" if docker run --rm -v "$REPO":/repo:ro "$img" bash -c "$INSIDE"; then echo "ok"; else echo "FAILED"; status=1; fi done exit $status