diff --git a/test/isolation.sh b/test/isolation.sh index 44c67b0..e092b62 100755 --- a/test/isolation.sh +++ b/test/isolation.sh @@ -1,15 +1,24 @@ #!/bin/sh -# Untrusted HTML must neither run JavaScript nor fetch anything (CDN scripts/styles, public images, file://). -# Each probe page is rendered next to an identical page without the probe: the PNGs must be byte-identical. +# Untrusted HTML must neither run JavaScript nor fetch anything. +# - Fetches: a probe server on the same Docker network logs every request; each page below points at it, +# and the log must stay empty (a sanity request from the host proves the log works). Works offline. +# - JavaScript and file://: each page is rendered next to an identical page without the probe, +# the PNGs must be byte-identical. # Usage: test/isolation.sh [image] (default dockette/docshot:latest) IMAGE=${1:-dockette/docshot:latest} PORT=39995 -NAME=docshot-isolation -DIR=$(mktemp -d) -trap 'docker rm -f $NAME >/dev/null 2>&1; rm -rf "$DIR"' EXIT +PROBE_PORT=39996 +NET=docshot-isolation +DIR= +cleanup() { docker rm -f $NET-app $NET-probe >/dev/null 2>&1; docker network rm $NET >/dev/null 2>&1; rm -rf "$DIR"; } +trap cleanup EXIT -docker rm -f $NAME >/dev/null 2>&1 -docker run -d --name $NAME -p $PORT:3000 "$IMAGE" >/dev/null || exit 1 +cleanup +DIR=$(mktemp -d) +docker network create $NET >/dev/null || exit 1 +docker run -d --name $NET-probe --network $NET --network-alias probe -p $PROBE_PORT:8080 busybox \ + sh -c 'mkdir /www && exec httpd -f -vv -p 8080 -h /www' >/dev/null || exit 1 +docker run -d --name $NET-app --network $NET -p $PORT:3000 "$IMAGE" >/dev/null || exit 1 i=0 until curl -fsS -m 2 "http://localhost:$PORT/readyz" >/dev/null 2>&1; do i=$((i + 1)); [ $i -gt 60 ] && { echo "isolation: docshot did not become ready"; exit 1; } @@ -20,19 +29,27 @@ page() { printf '
" \ + "
' '' '