#!/usr/bin/env bash # Smoke test for the egress-restricted setup (docker-compose.yml + # egress-proxy/). Confirms three things: # 1. The app's landing page still works normally. # 2. The app container has NO direct route to the internet. # 3. The app container CAN reach api.anthropic.com, but nothing else, # through the egress-proxy container. # # Run this from the repo root, with Docker running: # bash smoke-test-egress.sh # # Needs a real ANTHROPIC_API_KEY in .env for step 3's second check to be # meaningful (a bad/missing key still proves the tunnel works, since you'll # get a real 401 from Anthropic instead of a connection failure - but a # real key confirms the whole path end to end). set -uo pipefail PASS=0 FAIL=0 pass() { echo " PASS: $1"; PASS=$((PASS+1)); } fail() { echo " FAIL: $1"; FAIL=$((FAIL+1)); } echo "== Building and starting the stack ==" docker compose up -d --build echo "Waiting for the app to come up..." sleep 3 echo echo "== Check 1: landing page loads ==" CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:5173/) if [ "$CODE" = "200" ]; then pass "landing page returned 200" else fail "landing page returned $CODE (expected 200)" fi echo echo "== Check 2: app container has no direct internet route ==" # example.com is not api.anthropic.com and not reachable at all from this # container now - not even DNS should resolve, since it's off "default". if docker compose exec -T sde-meeting-toolkit wget -T 5 -qO- http://example.com/ >/dev/null 2>&1; then fail "app container reached example.com directly - it should have no route out at all" else pass "app container could NOT reach example.com directly (expected)" fi echo echo "== Check 3: egress-proxy blocks an unrelated domain ==" if docker compose exec -T sde-meeting-toolkit wget -T 5 -qO- \ -e use_proxy=yes -e https_proxy=http://egress-proxy:8888 \ https://example.com/ >/dev/null 2>&1; then fail "egress-proxy allowed a request to example.com - filter is not restricting properly" else pass "egress-proxy refused example.com (expected - not on the allow-list)" fi echo echo "== Check 4: egress-proxy allows api.anthropic.com ==" # We don't care about the HTTP status Anthropic itself returns here - just # that the CONNECT tunnel succeeds instead of being refused by the proxy. # wget still exits non-zero on a 4xx from the far end, so check for the # specific "403 Forbidden" tinyproxy itself returns when IT refuses, # versus any other outcome (which means the tunnel to Anthropic opened). OUT=$(docker compose exec -T sde-meeting-toolkit wget -T 5 -S -O /dev/null \ -e use_proxy=yes -e https_proxy=http://egress-proxy:8888 \ https://api.anthropic.com/v1/messages 2>&1) if echo "$OUT" | grep -q "403 Forbidden"; then fail "egress-proxy refused api.anthropic.com - filter regex may not match, check egress-proxy/filter" else pass "egress-proxy allowed the tunnel to api.anthropic.com (got a response instead of a proxy-level refusal)" fi echo echo "== Check 5: the AI draft endpoint works end to end through the proxy ==" # Uses whatever ANTHROPIC_API_KEY and MOCK_AI are set in .env. If MOCK_AI is # true this only proves the server route works, not the egress path - set # MOCK_AI=false with a real key for a full test. RESP=$(curl -s -o /dev/null -w "%{http_code}" -X POST http://localhost:5173/api/claude \ -H "Content-Type: application/json" \ -d '{"model":"claude-sonnet-4-6","max_tokens":16,"messages":[{"role":"user","content":"say hi"}]}') if [ "$RESP" = "200" ]; then pass "/api/claude returned 200 (full round trip through the egress proxy worked)" elif [ "$RESP" = "502" ]; then fail "/api/claude returned 502 - egress path is broken, check EGRESS_PROXY_URL and egress-proxy logs" else echo " INFO: /api/claude returned $RESP - check whether this is expected (e.g. 401 for a bad key, 429 for rate limit)" fi echo echo "== Results: $PASS passed, $FAIL failed ==" if [ "$FAIL" -gt 0 ]; then echo "Check container logs for detail:" echo " docker compose logs sde-meeting-toolkit" echo " docker compose logs egress-proxy" exit 1 fi