blob: 4b26e33c67ee17c5d33bb5f5fcbb8330638aa4ec [file] [log] [blame]
Christopher Faulet18c13d32022-05-16 11:43:10 +02001varnishtest "http-restrict-req-hdr-names option tests"
Christopher Fauletfdf69342022-06-07 08:21:18 +02002feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.0-dev0)'"
Christopher Faulet18c13d32022-05-16 11:43:10 +02003
4# This config tests "http-restrict-req-hdr-names" option
5
6feature ignore_unknown_macro
7
8server s1 {
9 rxreq
10 expect req.http.x-my_hdr == on
11 txresp
12} -start
13
14server s2 {
15 rxreq
16 expect req.http.x-my_hdr == <undef>
17 txresp
18} -start
19
20server s3 {
21 rxreq
22 expect req.http.x-my_hdr == on
23 txresp
24} -start
25
26server s4 {
27 rxreq
28 expect req.http.x-my_hdr == <undef>
29 txresp
30} -start
31
32server s5 {
33 rxreq
34 expect req.http.x-my_hdr == on
35 txresp
36} -start
37
Mateusz Malek4b85a962022-08-17 14:22:09 +020038server s6 {
39 rxreq
40 expect req.http.x_my_hdr_with_lots_of_underscores == <undef>
41 txresp
42} -start
43
44server s7 {
45 rxreq
46 expect req.http.x_my_hdr-1 == <undef>
47 expect req.http.x-my-hdr-2 == on
48 txresp
49} -start
50
51server s8 {
52 rxreq
53 expect req.http.x-my_hdr-1 == <undef>
54 expect req.http.x-my_hdr-2 == <undef>
55 txresp
56} -start
57
58server s9 {
59 rxreq
60 expect req.http.x-my-hdr-with-trailing-underscore_ == <undef>
61 txresp
62} -start
63
Christopher Faulet18c13d32022-05-16 11:43:10 +020064haproxy h1 -conf {
65 defaults
66 mode http
67 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
68 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
69 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
70
71 frontend fe1
72 bind "fd@${fe1}"
73 use_backend be-http1 if { path /req1 }
74 use_backend be-http2 if { path /req2 }
75 use_backend be-http3 if { path /req3 }
76 use_backend be-fcgi1 if { path /req4 }
77 use_backend be-fcgi2 if { path /req5 }
78 use_backend be-fcgi3 if { path /req6 }
Mateusz Malek4b85a962022-08-17 14:22:09 +020079 use_backend be-http4 if { path /req7 }
80 use_backend be-http5 if { path /req8 }
81 use_backend be-http6 if { path /req9 }
82 use_backend be-http7 if { path /req10 }
Christopher Faulet18c13d32022-05-16 11:43:10 +020083
84 backend be-http1
85 server s1 ${s1_addr}:${s1_port}
86
87 backend be-http2
88 option http-restrict-req-hdr-names delete
89 server s2 ${s2_addr}:${s2_port}
90
91 backend be-http3
92 option http-restrict-req-hdr-names reject
93
94 backend be-fcgi1
95 option http-restrict-req-hdr-names preserve
96 server s3 ${s3_addr}:${s3_port}
97
98 backend be-fcgi2
99 option http-restrict-req-hdr-names delete
100 server s4 ${s4_addr}:${s4_port}
101
102 backend be-fcgi3
103 option http-restrict-req-hdr-names reject
104
Mateusz Malek4b85a962022-08-17 14:22:09 +0200105 backend be-http4
106 option http-restrict-req-hdr-names delete
107 server s6 ${s6_addr}:${s6_port}
108
109 backend be-http5
110 option http-restrict-req-hdr-names delete
111 server s7 ${s7_addr}:${s7_port}
112
113 backend be-http6
114 option http-restrict-req-hdr-names delete
115 server s8 ${s8_addr}:${s8_port}
116
117 backend be-http7
118 option http-restrict-req-hdr-names delete
119 server s9 ${s9_addr}:${s9_port}
120
Christopher Faulet18c13d32022-05-16 11:43:10 +0200121 defaults
122 mode http
123 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
124 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
125 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
126 option http-restrict-req-hdr-names preserve
127
128 frontend fe2
129 bind "fd@${fe2}"
130 default_backend be-fcgi4
131
132 backend be-fcgi4
133 server s5 ${s5_addr}:${s5_port}
134
135 fcgi-app my-fcgi-app
136 docroot ${testdir}
137} -start
138
139client c1 -connect ${h1_fe1_sock} {
140 txreq -req GET -url /req1 -hdr "X-my_hdr: on"
141 rxresp
142 expect resp.status == 200
143
144 txreq -req GET -url /req2 -hdr "X-my_hdr: on"
145 rxresp
146 expect resp.status == 200
147
148 txreq -req GET -url /req3 -hdr "X-my_hdr: on"
149 rxresp
150 expect resp.status == 403
151
152 txreq -req GET -url /req4 -hdr "X-my_hdr: on"
153 rxresp
154 expect resp.status == 200
155
156 txreq -req GET -url /req5 -hdr "X-my_hdr: on"
157 rxresp
158 expect resp.status == 200
159
160 txreq -req GET -url /req6 -hdr "X-my_hdr: on"
161 rxresp
162 expect resp.status == 403
Mateusz Malek4b85a962022-08-17 14:22:09 +0200163
164 txreq -req GET -url /req7 -hdr "X_my_hdr_with_lots_of_underscores: on"
165 rxresp
166 expect resp.status == 200
167
168 txreq -req GET -url /req8 -hdr "X_my_hdr-1: on" -hdr "X-my-hdr-2: on"
169 rxresp
170 expect resp.status == 200
171
172 txreq -req GET -url /req9 -hdr "X-my_hdr-1: on" -hdr "X-my_hdr-2: on"
173 rxresp
174 expect resp.status == 200
175
176 txreq -req GET -url /req10 -hdr "X-my-hdr-with-trailing-underscore_: on"
177 rxresp
178 expect resp.status == 200
Christopher Faulet18c13d32022-05-16 11:43:10 +0200179} -run
180
181client c2 -connect ${h1_fe2_sock} {
182 txreq -req GET -url /req1 -hdr "X-my_hdr: on"
183 rxresp
184 expect resp.status == 200
185} -run