Christopher Faulet | 7950715 | 2022-05-16 11:43:10 +0200 | [diff] [blame] | 1 | varnishtest "http-restrict-req-hdr-names option tests" |
Christopher Faulet | b8bb9a8 | 2022-06-07 08:21:18 +0200 | [diff] [blame] | 2 | feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.0-dev0)'" |
Christopher Faulet | 7950715 | 2022-05-16 11:43:10 +0200 | [diff] [blame] | 3 | |
| 4 | # This config tests "http-restrict-req-hdr-names" option |
| 5 | |
| 6 | feature ignore_unknown_macro |
| 7 | |
| 8 | server s1 { |
| 9 | rxreq |
| 10 | expect req.http.x-my_hdr == on |
| 11 | txresp |
| 12 | } -start |
| 13 | |
| 14 | server s2 { |
| 15 | rxreq |
| 16 | expect req.http.x-my_hdr == <undef> |
| 17 | txresp |
| 18 | } -start |
| 19 | |
| 20 | server s3 { |
| 21 | rxreq |
| 22 | expect req.http.x-my_hdr == on |
| 23 | txresp |
| 24 | } -start |
| 25 | |
| 26 | server s4 { |
| 27 | rxreq |
| 28 | expect req.http.x-my_hdr == <undef> |
| 29 | txresp |
| 30 | } -start |
| 31 | |
| 32 | server s5 { |
| 33 | rxreq |
| 34 | expect req.http.x-my_hdr == on |
| 35 | txresp |
| 36 | } -start |
| 37 | |
| 38 | haproxy h1 -conf { |
| 39 | defaults |
| 40 | mode http |
| 41 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
| 42 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 43 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
| 44 | |
| 45 | frontend fe1 |
| 46 | bind "fd@${fe1}" |
| 47 | use_backend be-http1 if { path /req1 } |
| 48 | use_backend be-http2 if { path /req2 } |
| 49 | use_backend be-http3 if { path /req3 } |
| 50 | use_backend be-fcgi1 if { path /req4 } |
| 51 | use_backend be-fcgi2 if { path /req5 } |
| 52 | use_backend be-fcgi3 if { path /req6 } |
| 53 | |
| 54 | backend be-http1 |
| 55 | server s1 ${s1_addr}:${s1_port} |
| 56 | |
| 57 | backend be-http2 |
| 58 | option http-restrict-req-hdr-names delete |
| 59 | server s2 ${s2_addr}:${s2_port} |
| 60 | |
| 61 | backend be-http3 |
| 62 | option http-restrict-req-hdr-names reject |
| 63 | |
| 64 | backend be-fcgi1 |
| 65 | option http-restrict-req-hdr-names preserve |
| 66 | server s3 ${s3_addr}:${s3_port} |
| 67 | |
| 68 | backend be-fcgi2 |
| 69 | option http-restrict-req-hdr-names delete |
| 70 | server s4 ${s4_addr}:${s4_port} |
| 71 | |
| 72 | backend be-fcgi3 |
| 73 | option http-restrict-req-hdr-names reject |
| 74 | |
| 75 | defaults |
| 76 | mode http |
| 77 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
| 78 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 79 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
| 80 | option http-restrict-req-hdr-names preserve |
| 81 | |
| 82 | frontend fe2 |
| 83 | bind "fd@${fe2}" |
| 84 | default_backend be-fcgi4 |
| 85 | |
| 86 | backend be-fcgi4 |
| 87 | server s5 ${s5_addr}:${s5_port} |
| 88 | |
| 89 | fcgi-app my-fcgi-app |
| 90 | docroot ${testdir} |
| 91 | } -start |
| 92 | |
| 93 | client c1 -connect ${h1_fe1_sock} { |
| 94 | txreq -req GET -url /req1 -hdr "X-my_hdr: on" |
| 95 | rxresp |
| 96 | expect resp.status == 200 |
| 97 | |
| 98 | txreq -req GET -url /req2 -hdr "X-my_hdr: on" |
| 99 | rxresp |
| 100 | expect resp.status == 200 |
| 101 | |
| 102 | txreq -req GET -url /req3 -hdr "X-my_hdr: on" |
| 103 | rxresp |
| 104 | expect resp.status == 403 |
| 105 | |
| 106 | txreq -req GET -url /req4 -hdr "X-my_hdr: on" |
| 107 | rxresp |
| 108 | expect resp.status == 200 |
| 109 | |
| 110 | txreq -req GET -url /req5 -hdr "X-my_hdr: on" |
| 111 | rxresp |
| 112 | expect resp.status == 200 |
| 113 | |
| 114 | txreq -req GET -url /req6 -hdr "X-my_hdr: on" |
| 115 | rxresp |
| 116 | expect resp.status == 403 |
| 117 | } -run |
| 118 | |
| 119 | client c2 -connect ${h1_fe2_sock} { |
| 120 | txreq -req GET -url /req1 -hdr "X-my_hdr: on" |
| 121 | rxresp |
| 122 | expect resp.status == 200 |
| 123 | } -run |