#!/bin/sh # Verifica della rete su pagine vere. Non fa parte della CI predefinita: esce in # internet e dipende da servizi di terzi. Si lancia a mano o con MOSAIC_NET=1. set -eu RADICE=$(cd "$(dirname "$0")/.." && pwd) RENDER="$RADICE/target/release/render" FONT=${FONT:-/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf} USCITA=${TMPDIR:-/tmp} if [ ! -x "$RENDER" ]; then echo "serve prima: cargo build --release" exit 1 fi fallisci=0 prova() { descrizione=$1 url=$2 atteso=$3 if "$RENDER" --url "$url" --font "$FONT" --out "$USCITA/net-check.png" \ --size 640x480 --scale 1 >"$USCITA/net-check.json" 2>"$USCITA/net-check.err"; then righe=$(sed -n 's/.*"lines":\([0-9]*\).*/\1/p' "$USCITA/net-check.json") nodi=$(sed -n 's/.*"nodes":\([0-9]*\).*/\1/p' "$USCITA/net-check.json") if [ "${nodi:-0}" -ge "$atteso" ]; then echo "ok $descrizione (nodi $nodi, righe ${righe:-0})" else echo "FAIL $descrizione: nodi $nodi, attesi almeno $atteso" fallisci=1 fi else echo "FAIL $descrizione: $(tail -1 "$USCITA/net-check.err")" fallisci=1 fi } # HTTPS con certificato valido, corpo con Content-Length prova "https example.com" "https://example.com/" 3 # il server di prova locale serve in chunked; qui si controlla che un 404 non blocchi prova "http con reindirizzamento a https" "http://example.com/" 3 # un errore di rete deve uscire con codice 1 e un messaggio, non con una pagina vuota if "$RENDER" --url "http://127.0.0.1:1/" --font "$FONT" --out "$USCITA/net-check.png" \ --size 320x200 >/dev/null 2>"$USCITA/net-check.err"; then echo "FAIL connessione rifiutata: doveva fallire" fallisci=1 else if grep -q "connessione" "$USCITA/net-check.err"; then echo "ok connessione rifiutata: messaggio esplicito" else echo "FAIL connessione rifiutata: messaggio inatteso" fallisci=1 fi fi # 4. HTTP/2: il server deve negoziare h2 e la pagina deve arrivare if MOSAIC_DEBUG=1 "$RENDER" --url https://example.com/ --font "$FONT" \ --out "$USCITA/h2.png" --size 320x240 > "$USCITA/h2.out" 2> "$USCITA/h2.err"; then if grep -q "richiesta in HTTP/2" "$USCITA/h2.err"; then echo "ok HTTP/2: negoziato con example.com" else echo "warn HTTP/2 non negoziato (il server può non offrirlo)" fi else echo "FAIL HTTP/2: la pagina non è arrivata" fallisci=1 fi exit $fallisci