@@ -100,14 +100,22 @@ if ! docker compose logs mock 2>/dev/null | grep -F "/files/275a021bbfb6489e54d4
100100 exit 1
101101fi
102102
103- # A clean file must pass through (mock returns 404 = not found on VT = clean)
104- echo " ℹ️ Testing that a clean file passes ..."
103+ # A clean file must NOT be denied (mock returns 404 = not found on VT = clean).
104+ # The hello upstream only accepts GET, so the clean multipart POST reaches it and
105+ # comes back 405 (method). Accept any 2xx or non-403 4xx, but fail on 403 (denied)
106+ # and on 5xx/000 (a crash or fail-closed regression must not hide behind "not 403").
107+ echo " ℹ️ Testing that a clean file is not blocked ..."
105108printf ' just a clean file\n' > /tmp/bunkerweb-plugins/virustotal/clean.txt
106109code=" $( curl -s -o /dev/null -w " %{http_code}" -X POST -H " Host: www.example.com" -F " file=@/tmp/bunkerweb-plugins/virustotal/clean.txt" http://localhost) "
107- if [ " $code " != " 200" ] ; then
110+ case " $code " in
111+ 403) clean_err=" should not be denied by VirusTotal" ;;
112+ 000 | 5?? ) clean_err=" caused an upstream error/crash" ;;
113+ * ) clean_err=" " ;;
114+ esac
115+ if [ -n " $clean_err " ] ; then
108116 docker compose logs
109117 docker compose down -v
110- echo " ❌ Error: clean file should pass (got $code , expected 200 )"
118+ echo " ❌ Error: clean file $clean_err (got $code )"
111119 exit 1
112120fi
113121
@@ -121,6 +129,20 @@ if [ "$code" != "403" ] ; then
121129 exit 1
122130fi
123131
132+ # Error paths: a VT API failure must FAIL OPEN — the request is allowed through,
133+ # never denied (403) and never leaked as a server error (5xx) to the client.
134+ # 5.5.5.5 -> mock returns 500 ; 6.6.6.6 -> mock returns unparsable JSON.
135+ for bad_ip in 5.5.5.5 6.6.6.6 ; do
136+ echo " ℹ️ Testing fail-open when VT API errors for $bad_ip ..."
137+ code=" $( curl -s -o /dev/null -w " %{http_code}" -H " Host: www.example.com" -H " X-Forwarded-For: $bad_ip " http://localhost/) "
138+ if [ " $code " != " 200" ] ; then
139+ docker compose logs
140+ docker compose down -v
141+ echo " ❌ Error: VT API failure for $bad_ip should fail open (got $code , expected 200)"
142+ exit 1
143+ fi
144+ done
145+
124146if [ " $1 " = " verbose" ] ; then
125147 docker compose logs
126148fi
0 commit comments