Ilya Shipitsin | 77e3b4a | 2020-03-10 12:06:11 +0500 | [diff] [blame] | 1 | varnishtest "Test the custom errors for HTTP deny rules" |
Christopher Faulet | a5afb0b | 2020-01-20 13:49:48 +0100 | [diff] [blame] | 2 | #REQUIRE_VERSION=2.2 |
| 3 | |
| 4 | # This config tests the custom errors for HTTP deny rules. |
| 5 | |
| 6 | feature ignore_unknown_macro |
| 7 | |
| 8 | |
| 9 | haproxy h1 -conf { |
| 10 | http-errors errors-1 |
| 11 | errorfile 400 ${testdir}/errors/400-1.http |
| 12 | errorfile 403 ${testdir}/errors/403-1.http |
| 13 | errorfile 404 ${testdir}/errors/404-1.http |
| 14 | errorfile 500 /dev/null |
| 15 | |
| 16 | defaults |
| 17 | mode http |
| 18 | timeout connect 1s |
| 19 | timeout client 1s |
| 20 | timeout server 1s |
| 21 | |
| 22 | frontend fe1 |
| 23 | bind "fd@${fe1}" |
| 24 | http-request deny deny_status 400 if { path /400 } |
| 25 | http-request deny deny_status 403 errorfile ${testdir}/errors/403.http if { path /403 } |
| 26 | http-request deny deny_status 404 errorfiles errors-1 if { path /404 } |
| 27 | http-request deny deny_status 500 errorfile /dev/null if { path /500-1 } |
| 28 | http-request deny deny_status 500 errorfiles errors-1 if { path /500-2 } |
| 29 | |
Christopher Faulet | 5cb513a | 2020-05-13 17:56:56 +0200 | [diff] [blame] | 30 | http-request deny status 500 hdr x-err-info "path=%[path]" content-type "text/plain" string "Internal Error" if { path /int-err } |
| 31 | http-request deny status 403 hdr x-err-info "path=%[path]" content-type "text/plain" lf-file ${testdir}/errors/lf-403.txt if { path /forbidden } |
| 32 | |
Christopher Faulet | a5afb0b | 2020-01-20 13:49:48 +0100 | [diff] [blame] | 33 | } -start |
| 34 | |
| 35 | client c1r1 -connect ${h1_fe1_sock} { |
| 36 | txreq -req GET -url /400 |
| 37 | rxresp |
| 38 | expect resp.status == 400 |
| 39 | expect resp.http.x-err-type == <undef> |
| 40 | } -run |
| 41 | client c1r2 -connect ${h1_fe1_sock} { |
| 42 | txreq -req GET -url /403 |
| 43 | rxresp |
| 44 | expect resp.status == 403 |
| 45 | expect resp.http.x-err-type == "default" |
| 46 | } -run |
| 47 | client c1r3 -connect ${h1_fe1_sock} { |
| 48 | txreq -req GET -url /404 |
| 49 | rxresp |
| 50 | expect resp.status == 404 |
| 51 | expect resp.http.x-err-type == "errors-1" |
| 52 | } -run |
| 53 | client c1r4 -connect ${h1_fe1_sock} { |
| 54 | txreq -req GET -url /500-1 |
| 55 | expect_close |
| 56 | } -run |
| 57 | client c1r5 -connect ${h1_fe1_sock} { |
| 58 | txreq -req GET -url /500-2 |
| 59 | expect_close |
| 60 | } -run |
Christopher Faulet | 5cb513a | 2020-05-13 17:56:56 +0200 | [diff] [blame] | 61 | client c1r6 -connect ${h1_fe1_sock} { |
| 62 | txreq -req GET -url /int-err |
| 63 | rxresp |
| 64 | expect resp.status == 500 |
| 65 | expect resp.http.x-err-info == "path=/int-err" |
| 66 | expect resp.http.content-type == "text/plain" |
| 67 | expect resp.http.content-length == 14 |
| 68 | expect resp.body == "Internal Error" |
| 69 | } -run |
| 70 | client c1r7 -connect ${h1_fe1_sock} { |
| 71 | txreq -req GET -url /forbidden |
| 72 | rxresp |
| 73 | expect resp.status == 403 |
| 74 | expect resp.http.x-err-info == "path=/forbidden" |
| 75 | expect resp.http.content-type == "text/plain" |
| 76 | expect resp.body == "The path \"/forbidden\" is forbidden\n" |
| 77 | } -run |