AvanzaCast/scripts/verify_backend_after_update.sh
Cesar Mendivil 8b458a3ddf feat: add initial LiveKit Meet integration with utility scripts, configs, and core components
- Add Next.js app structure with base configs, linting, and formatting
- Implement LiveKit Meet page, types, and utility functions
- Add Docker, Compose, and deployment scripts for backend and token server
- Provide E2E and smoke test scaffolding with Puppeteer and Playwright helpers
- Include CSS modules and global styles for UI
- Add postMessage and studio integration utilities
- Update package.json with dependencies and scripts for development and testing
2025-11-20 12:50:38 -07:00

87 lines
2.4 KiB
Bash

#!/usr/bin/env bash
# scripts/verify_backend_after_update.sh
# Verify backend-api can create sessions and that LiveKit accepts the generated token via backend validate proxy.
# Usage:
# ./scripts/verify_backend_after_update.sh --backend-url http://localhost:4000 --session-room testroom --session-user tester
set -euo pipefail
BACKEND_URL="http://localhost:4000"
ROOM="e2e_room"
USER="e2e_user"
while [[ $# -gt 0 ]]; do
case $1 in
--backend-url) BACKEND_URL="$2"; shift 2;;
--session-room) ROOM="$2"; shift 2;;
--session-user) USER="$2"; shift 2;;
-h|--help) echo "Usage: $0 --backend-url <url> --session-room <room> --session-user <user>"; exit 0;;
*) echo "Unknown arg $1"; exit 2;;
esac
done
echo "Verifying backend at $BACKEND_URL (room=$ROOM user=$USER)"
set -o pipefail
RESP=$(curl -s -w '\n__STATUS__%{http_code}\n' -X POST "$BACKEND_URL/api/session" -H 'Content-Type: application/json' -d "{\"room\":\"$ROOM\",\"username\":\"$USER\"}") || true
if [[ -z "$RESP" ]]; then
echo "No response from backend when creating session" >&2
exit 2
fi
# split body and status
STATUS=$(echo "$RESP" | sed -n 's/.*__STATUS__\([0-9][0-9][0-9]\)/\1/p' | tail -n1)
BODY=$(echo "$RESP" | sed 's/__STATUS__.*//g')
echo "POST /api/session status=$STATUS"
echo "$BODY" | jq || echo "$BODY"
if [[ "$STATUS" != "200" && "$STATUS" != "201" ]]; then
echo "Session creation failed with status $STATUS" >&2
exit 2
fi
ID=$(echo "$BODY" | jq -r '.id // empty')
if [[ -z "$ID" ]]; then
echo "No id returned by backend. Response above." >&2
exit 2
fi
echo "Created session id=$ID"
TOKRESP=$(curl -s "$BACKEND_URL/api/session/$ID/token")
if [[ -z "$TOKRESP" ]]; then
echo "No token response for session $ID" >&2
exit 2
fi
echo "Token response:"
echo "$TOKRESP" | jq || echo "$TOKRESP"
TOKEN=$(echo "$TOKRESP" | jq -r '.token // empty')
if [[ -z "$TOKEN" ]]; then
echo "No token field in token response" >&2
exit 2
fi
# Validate token via backend proxy
VAL=$(curl -s "$BACKEND_URL/api/session/validate?token=$TOKEN")
echo "Validate result:"
echo "$VAL" | jq || echo "$VAL"
# print decoded payload
echo "Decoded token payload (unverified):"
python3 - <<PY
import sys,base64,json
t='''$TOKEN'''
try:
p=t.split('.')[1]
p += '=' * ((4 - len(p) % 4) % 4)
print(json.dumps(json.loads(base64.urlsafe_b64decode(p).decode()), indent=2))
except Exception as e:
print('decode failed', e)
PY
# success
echo "Verification finished"
exit 0