Files
ianitor/scripts/conformance.sh

93 lines
4.6 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# SPDX-License-Identifier: CPAL-1.0
# Copyright (c) 2026 Marek Novák. Part of Ianitor, under the Common Public Attribution
# License 1.0: see LICENSE (its Exhibit A is this file's notice).
#
# ROADMAP §5 layer 2: protocol conformance, Ianitor and Caddy side by side on the same routes
# (tests/diff/src/bin/pair.rs): h2spec (HTTP/2, RFC 9113 and HPACK) and testssl.sh (TLS) against
# each. Raw outputs go to bench/conformance/<engine>-*.{txt,json}; the summary table to stdout.
#
# scripts/conformance.sh # needs caddy, h2spec, testssl.sh, jq on PATH
# nix shell nixpkgs#caddy nixpkgs#h2spec nixpkgs#testssl nixpkgs#jq -c scripts/conformance.sh
#
# Exit status: 1 if Ianitor fails an h2spec case Caddy passes, or testssl.sh rates Ianitor's
# TLS below Caddy's (a regression against the fallback); the rest is reported, not enforced.
# Everything listens on 127.0.0.1.
set -euo pipefail
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
out="$root/bench/conformance"
mkdir -p "$out"
for tool in caddy h2spec jq; do # and python3 for the slow-client probes, when present
command -v "$tool" >/dev/null || { echo "missing: $tool" >&2; exit 2; }
done
testssl=$(command -v testssl.sh || command -v testssl || true)
[ -n "$testssl" ] || { echo "missing: testssl.sh" >&2; exit 2; }
profile=${BUILD:-release}
flag=--release
[ "$profile" = debug ] && flag=
cargo build $flag -q -p ianitor-diff --bin ianitor-pair
bin="${CARGO_TARGET_DIR:-$root/target}/$profile/ianitor-pair"
info=$(mktemp)
"$bin" --caddy "$(command -v caddy)" >"$info" &
pair=$!
trap 'kill $pair 2>/dev/null; wait $pair 2>/dev/null; rm -f "$info"' EXIT
for _ in $(seq 1 100); do
[ -s "$info" ] && break
sleep 0.2
done
[ -s "$info" ] || { echo "ianitor-pair did not start" >&2; exit 1; }
port() { jq -r ".$1.https" "$info" | sed 's/.*://'; }
status=0
printf '%-10s %-8s %s\n' engine tool result
for engine in ianitor caddy; do
p=$(port "$engine")
# h2spec names the host for SNI; `localhost` is the pair's only host.
h2spec -h localhost -p "$p" -t -k -o 5 >"$out/$engine-h2spec.txt" 2>&1 || true
summary=$(grep -Eo '[0-9]+ tests, [0-9]+ passed, [0-9]+ skipped, [0-9]+ failed' "$out/$engine-h2spec.txt" | tail -1)
printf '%-10s %-8s %s\n' "$engine" h2spec "${summary:-no summary (see $out/$engine-h2spec.txt)}"
# The failed cases, by id, for the comparison below.
# (only the "Failures:" section: h2spec redraws progress lines with carriage returns above it)
sed -n '/^Failures:/,$p' "$out/$engine-h2spec.txt" | grep '×' | sed -E 's/^[[:space:]]*× //' | sort >"$out/$engine-h2spec-failed.txt" || true
"$testssl" --quiet --color 0 --warnings off --ip 127.0.0.1 --add-ca "$(jq -r .ca "$info")" \
--jsonfile "$out/$engine-testssl.json" --overwrite "https://localhost:$p" \
>"$out/$engine-testssl.txt" 2>&1 || true
grade=$(jq -r '[.[] | select(.id=="overall_grade")][0].finding // "n/a"' "$out/$engine-testssl.json" 2>/dev/null || echo n/a)
bad=$(jq -r '[.[] | select(.severity=="HIGH" or .severity=="CRITICAL")] | length' "$out/$engine-testssl.json" 2>/dev/null || echo "?")
printf '%-10s %-8s %s\n' "$engine" testssl "grade $grade, $bad findings HIGH or CRITICAL"
# Slow clients (QC phase 4, tests/support/probes): a TLS handshake that never starts, and an
# HTTP/2 header block that never ends; how long each engine keeps them open (75 s at most).
if command -v python3 >/dev/null; then
probes="$root/tests/support/probes"
python3 "$probes/slow.py" 127.0.0.1 "$p" idle 75 localhost >"$out/$engine-slow-idle.txt" 2>&1 &
a=$!
python3 "$probes/h2slow.py" 127.0.0.1 "$p" 75 localhost >"$out/$engine-slow-h2.txt" 2>&1 &
b=$!
wait $a $b || true
printf '%-10s %-8s %s\n' "$engine" slow "$(cut -d';' -f1 "$out/$engine-slow-idle.txt" | head -1); $(cut -d';' -f1 "$out/$engine-slow-h2.txt" | head -1)"
fi
done
# A case Caddy passes and Ianitor fails is a regression against the fallback.
regressions=$(comm -23 "$out/ianitor-h2spec-failed.txt" "$out/caddy-h2spec-failed.txt" || true)
if [ -n "$regressions" ]; then
echo "h2spec cases Ianitor fails and Caddy passes:" >&2
echo "$regressions" >&2
status=1
fi
rank() { case "$1" in A+) echo 7;; A) echo 6;; A-) echo 5;; B) echo 4;; C) echo 3;; D) echo 2;; E) echo 1;; *) echo 0;; esac; }
gi=$(jq -r '[.[] | select(.id=="overall_grade")][0].finding // ""' "$out/ianitor-testssl.json" 2>/dev/null || true)
gc=$(jq -r '[.[] | select(.id=="overall_grade")][0].finding // ""' "$out/caddy-testssl.json" 2>/dev/null || true)
if [ "$(rank "$gi")" -lt "$(rank "$gc")" ]; then
echo "testssl.sh grades Ianitor ($gi) below Caddy ($gc)" >&2
status=1
fi
jq -c '{build, caddy_version, edge_threads}' "$info" >"$out/run.json"
exit $status