From: Willy Tarreau Date: Mon, 21 Sep 2026 20:40:32 +0000 (+0000) Subject: REGTESTS: http-errorfiles: test the errorloc directives X-Git-Tag: v3.5-dev8~55 X-Git-Url: https://git.kaiwu.me/$%7BISSUES%7D/static/gitweb.js?a=commitdiff_plain;h=e79a2f9b22e381a511330ba65efbe78403741185;p=haproxy.git REGTESTS: http-errorfiles: test the errorloc directives The errorloc, errorloc302 and errorloc303 directives had no coverage while errorfile and http-error do. The test checks the three forms on a 503 caused by an unreachable server and on a 403 returned by a deny rule, verifies that "errorloc" is an alias for "errorloc302", that a relative location is accepted, and that a status code for which no errorloc was declared still gets the default error page. --- diff --git a/reg-tests/http-errorfiles/errorloc.vtc b/reg-tests/http-errorfiles/errorloc.vtc new file mode 100644 index 000000000..7cf9bb201 --- /dev/null +++ b/reg-tests/http-errorfiles/errorloc.vtc @@ -0,0 +1,83 @@ +varnishtest "Test the errorloc, errorloc302 and errorloc303 directives" + +# The errorloc family was not covered at all while errorfile and +# http-error are. The three forms are checked on a 503 caused by an +# unreachable server and on a 403 returned by a deny rule, including the +# fact that "errorloc" is an alias for "errorloc302" and that the +# redirect only replaces the status codes it was declared for. + +feature ignore_unknown_macro + +haproxy h1 -conf { + global + .if feature(THREAD) + thread-groups 1 + .endif + chroot / + + defaults + mode http + retries 0 + timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" + timeout client "${HAPROXY_TEST_TIMEOUT-5s}" + timeout server "${HAPROXY_TEST_TIMEOUT-5s}" + + frontend fe1 + bind "fd@${fe1}" + errorloc 503 http://www.example.com/oops503 + http-request deny deny_status 403 if { path /denied } + default_backend dead + + frontend fe2 + bind "fd@${fe2}" + errorloc302 503 http://www.example.com/oops503 + errorloc302 403 /local403 + http-request deny deny_status 403 if { path /denied } + default_backend dead + + frontend fe3 + bind "fd@${fe3}" + errorloc303 503 http://www.example.com/oops503 + http-request deny deny_status 403 if { path /denied } + default_backend dead + + backend dead + server s1 ${bad_backend} +} -start + +client c1 -connect ${h1_fe1_sock} { + # "errorloc" behaves like "errorloc302" + txreq -url "/gone" + rxresp + expect resp.status == 302 + expect resp.http.location == "http://www.example.com/oops503" + # no errorloc was declared for 403, the default error page is used + txreq -url "/denied" + rxresp + expect resp.status == 403 + expect resp.http.location == "" +} -run + +client c2 -connect ${h1_fe2_sock} { + txreq -url "/gone" + rxresp + expect resp.status == 302 + expect resp.http.location == "http://www.example.com/oops503" + + # a relative location is accepted too + txreq -url "/denied" + rxresp + expect resp.status == 302 + expect resp.http.location == "/local403" +} -run + +client c3 -connect ${h1_fe3_sock} { + txreq -url "/gone" + rxresp + expect resp.status == 303 + expect resp.http.location == "http://www.example.com/oops503" + + txreq -url "/denied" + rxresp + expect resp.status == 403 +} -run