67 lines
2.7 KiB
Bash
Executable File
67 lines
2.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Smoke: WebSocket upgrade to Phoenix GraphQL WS (graphql-transport-ws) end-to-end through TLS.
|
|
# Uses curl --http1.1 (HTTP/2 cannot complete WS upgrade on many edges). Expects HTTP 101.
|
|
# Each successful probe waits up to PHOENIX_WSS_CURL_MAXTIME seconds (default 8): curl has no EOF on WS.
|
|
#
|
|
# Usage:
|
|
# bash scripts/verify/smoke-phoenix-graphql-wss-public.sh
|
|
# PHOENIX_GRAPHQL_WSS_URL=wss://phoenix.example/graphql-ws bash scripts/verify/smoke-phoenix-graphql-wss-public.sh
|
|
# Optional LAN hub (no TLS):
|
|
# PHOENIX_GRAPHQL_WS_LAN=http://192.168.11.50:8080/graphql-ws PHOENIX_WS_HOST_HEADER=phoenix.sankofa.nexus \
|
|
# bash scripts/verify/smoke-phoenix-graphql-wss-public.sh
|
|
set -euo pipefail
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
# shellcheck source=/dev/null
|
|
source "${PROJECT_ROOT}/scripts/lib/load-project-env.sh" 2>/dev/null || true
|
|
|
|
PUBLIC_WSS="${PHOENIX_GRAPHQL_WSS_URL:-https://phoenix.sankofa.nexus/graphql-ws}"
|
|
LAN_WS="${PHOENIX_GRAPHQL_WS_LAN:-}"
|
|
LAN_HOST="${PHOENIX_WS_HOST_HEADER:-phoenix.sankofa.nexus}"
|
|
# After HTTP 101, curl waits for the WebSocket stream until --max-time (no clean EOF). Keep this
|
|
# modest so LAN+public probes do not sit for minutes (override with PHOENIX_WSS_CURL_MAXTIME if needed).
|
|
CURL_MAXTIME="${PHOENIX_WSS_CURL_MAXTIME:-8}"
|
|
# Opt-in LAN hub probe (same CT, HTTP): PHOENIX_WSS_INCLUDE_LAN=1 with load-project-env / ip-addresses
|
|
if [[ "${PHOENIX_WSS_INCLUDE_LAN:-0}" == "1" && -z "$LAN_WS" && -n "${IP_SANKOFA_PHOENIX_API:-}" ]]; then
|
|
LAN_WS="http://${IP_SANKOFA_PHOENIX_API}:8080/graphql-ws"
|
|
fi
|
|
|
|
probe_upgrade() {
|
|
local name="$1"
|
|
local url="$2"
|
|
shift 2
|
|
echo "--- ${name}"
|
|
echo " URL: ${url}"
|
|
local first
|
|
first="$(curl --http1.1 -sS --connect-timeout 10 -m "${CURL_MAXTIME}" -D- -o /dev/null \
|
|
"$@" \
|
|
-H 'Connection: Upgrade' \
|
|
-H 'Upgrade: websocket' \
|
|
-H 'Sec-WebSocket-Version: 13' \
|
|
-H 'Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==' \
|
|
-H 'Sec-WebSocket-Protocol: graphql-transport-ws' \
|
|
"$url" 2>&1 | head -1 | tr -d '\r')"
|
|
if [[ "$first" == *"101"* ]]; then
|
|
echo " OK (${first})"
|
|
return 0
|
|
fi
|
|
echo " FAIL (expected HTTP/1.1 101; first line: ${first})"
|
|
return 1
|
|
}
|
|
|
|
echo "=== smoke-phoenix-graphql-wss-public (curl WS upgrade) ==="
|
|
fail=0
|
|
probe_upgrade "Public WSS (NPM → hub → Apollo)" "$PUBLIC_WSS" || fail=1
|
|
|
|
if [[ -n "$LAN_WS" ]]; then
|
|
probe_upgrade "LAN hub (optional)" "$LAN_WS" -H "Host: ${LAN_HOST}" || fail=1
|
|
fi
|
|
|
|
if [[ "$fail" -ne 0 ]]; then
|
|
echo ""
|
|
echo "RESULT: one or more upgrade probes failed."
|
|
exit 1
|
|
fi
|
|
echo ""
|
|
echo "RESULT: WebSocket upgrade path OK (HTTP 101). Full handshake: pnpm run verify:phoenix-graphql-ws-subscription"
|