interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / infra / spark / edge-http-checks.sh

41 lines · 2758 bytes Raw Blame History
1#!/usr/bin/env bash
2# Live checks for the Spark plain-http redirect (spark/edge-http-apply.sh). Run as the Spark user:
3# bash infra/spark/edge-http-checks.sh
4# curl runs on the hub Pi, a house-LAN machine, so the packets arrive on enP7s7 exactly as the
5# router's port-80 forward delivers them. EDGE_LAN_NETNS=<netns> runs them in a network namespace
6# instead (test/http80-netns.sh). Exit 0 only when every check passes.
7set -u
8ADDR=${EDGE_ADDR:-192.168.1.108}
9pass=0; fail=0
10ok() { pass=$((pass+1)); echo "PASS [http80] $*"; }
11bad() { fail=$((fail+1)); echo "FAIL [http80] $*"; }
12lan() { # run argv on the LAN vantage, print its stdout; rc of the remote command
13 if [ -n "${EDGE_LAN_NETNS:-}" ]; then ip netns exec "$EDGE_LAN_NETNS" "$@"
14 else ssh -o BatchMode=yes -o ConnectTimeout=10 hub "$(printf '%q ' "$@")"; fi
15}
16
17for n in interplane.io www.interplane.io www.aienos.com aienos.com; do
18 got=$(lan curl -sS -o /dev/null -m 10 -w '%{http_code} %{redirect_url}' -H "Host: $n" "http://$ADDR/quick-start/?q=1" 2>&1)
19 want="301 https://$n/quick-start/?q=1"
20 [ "$got" = "$want" ] && ok "http://$n/quick-start/?q=1 -> $got" || bad "http://$n/quick-start/?q=1 -> '$got' (want '$want')"
21done
22# unknown name: closed without an answer (curl 52 = empty reply)
23lan curl -sS -o /dev/null -m 10 -H 'Host: unknown.example' "http://$ADDR/" > /dev/null 2>&1; rc=$?
24[ "$rc" = 52 ] && ok "unknown Host closed without an answer (curl rc 52)" || bad "unknown Host: curl rc $rc (want 52)"
25# no Host at all (HTTP/1.0): closed too
26lan curl -sS -0 -o /dev/null -m 10 -H 'Host:' "http://$ADDR/" > /dev/null 2>&1; rc=$?
27[ "$rc" = 52 ] && ok "missing Host closed without an answer (curl rc 52)" || bad "missing Host: curl rc $rc (want 52)"
28# 4480 is reachable only as the redirect target of :80, never directly
29lan curl -sS -o /dev/null -m 5 -H 'Host: interplane.io' "http://$ADDR:4480/" > /dev/null 2>&1; rc=$?
30[ "$rc" = 28 ] && ok "direct :4480 from the LAN dropped (curl rc 28, timeout)" || bad "direct :4480 from the LAN: curl rc $rc (want 28)"
31# https is unchanged (EDGE_SKIP_HTTPS=1: the netns rehearsal has no :443)
32if [ "${EDGE_SKIP_HTTPS:-0}" != 1 ]; then
33 got=$(lan curl -sS -o /dev/null -m 15 -w '%{http_code}' --resolve "interplane.io:443:$ADDR" https://interplane.io/ 2>&1)
34 [ "$got" = 200 ] && ok "https://interplane.io/ via $ADDR:443 = 200" || bad "https://interplane.io/ via $ADDR:443 = '$got' (want 200)"
35fi
36# whatever holds *:80 on this host (apache2 on the Spark) still answers on loopback, untouched
37got=$(curl -sS -o /dev/null -m 5 -w '%{http_code}' http://127.0.0.1/ 2>&1)
38[ "$got" = 200 ] && ok "loopback :80 (apache2) unchanged = 200" || bad "loopback :80 = '$got' (want 200)"
39
40echo "edge-http-checks: $pass passed, $fail failed"
41[ "$fail" = 0 ]