1# Offline, the edge adds the slash a folder's address lacks (/a/b -> /a/b/),2# but never for a path that starts // or /\, where the slash would make3# Location another site's address (//evil.test/x/): those are asked of the4# copy as they are, and get its 404.5. "$(dirname "$0")/../lib.sh"6command -v caddy >/dev/null 2>&1 || { note "caddy is not installed: skipped running it"; exit 0; }7mkdir -p "$T/bucket/dami/greet"8echo '<p>greet</p>' >"$T/bucket/dami/greet/index.html"9mport=$(free_port)10printf '{\n\tadmin off\n\tauto_https off\n\tpersist_config off\n\tdefault_bind 127.0.0.1\n}\n\n:%s {\n\troot * %s\n\tfile_server\n}\n' "$mport" "$T/bucket" >"$T/Caddyfile.bucket"11eport=$(free_port)12dead=$(free_port)13# On 127.0.0.1 only, so no other scenario's server can take the port there.14sed "s/^:8080 {/:$eport {/; s/127\.0\.0\.1:8081/127.0.0.1:$dead/" "$T_HOME/deploy/edge/Caddyfile" |15 awk '{ print } $0 == "\tadmin off" { print "\tdefault_bind 127.0.0.1" }' >"$T/Caddyfile.edge"16for c in bucket edge; do17 FORGE_DOMAIN=src.test FORGE_MIRROR_URL=http://127.0.0.1:$mport XDG_DATA_HOME=$T/xdg XDG_CONFIG_HOME=$T/xdg \18 caddy run --config "$T/Caddyfile.$c" --adapter caddyfile >"$T/caddy.$c.log" 2>&1 &19 T_PIDS="$T_PIDS $!"20done21wait_http "http://127.0.0.1:$mport/"22wait_http "http://127.0.0.1:$eport/"23e=http://127.0.0.1:$eport24eq "$(http -s -o /dev/null -w '%{http_code} %{redirect_url}' -H 'Host: src.test' "$e/dami/greet")" "308 $e/dami/greet/"25for p in //evil.test/x //evil.test /%5Cevil.test/x /%2Fevil.test/x; do26 http -s -i -H 'Host: src.test' "$e$p" | tr -d '\r' >"$T/res"27 lacks "$T/res" '^Location:'28 has "$T/res" '^HTTP/1.1 404 '29done