blob: 585503480e25ce8e3499f4127b102570a9970d08 [file] [log] [blame]
Christopher Faulet3f5fbe92022-07-05 14:50:17 +02001varnishtest "H1 authority validation and host normalizarion based on the scheme (rfc3982 6.3.2) or the method (connect)"
2
3feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.6-dev0)'"
4feature ignore_unknown_macro
5
6syslog S1 -level info {
7 # C1
8 recv
9 expect ~ "^.* uri: GET http://toto:poue@hostname/c1 HTTP/1.1; host: {hostname}$"
10
11 # C2
12 recv
13 expect ~ "^.* uri: GET http://hostname:8080/c2 HTTP/1.1; host: {hostname:8080}$"
14
15 # C3
16 recv
17 expect ~ "^.* uri: GET https://hostname/c3 HTTP/1.1; host: {hostname}$"
18
19 # C4
20 recv
21 expect ~ "^.* uri: GET https://hostname:80/c4 HTTP/1.1; host: {hostname:80}$"
22
23 # C5
24 recv
Christopher Faulet1c521212022-11-22 15:39:12 +010025 expect ~ "^.* uri: CONNECT hostname:80 HTTP/1.1; host: {hostname}$"
Christopher Faulet3f5fbe92022-07-05 14:50:17 +020026 recv
Christopher Faulet1c521212022-11-22 15:39:12 +010027 expect ~ "^.* uri: CONNECT hostname:80 HTTP/1.1; host: {hostname}$"
28 recv
29 expect ~ "^.* uri: CONNECT hostname:80 HTTP/1.1; host: {hostname:}$"
Christopher Faulet3f5fbe92022-07-05 14:50:17 +020030
31 # C6
32 recv
33 expect ~ "^.* uri: CONNECT hostname:443 HTTP/1.1; host: {hostname}$"
34 recv
35 expect ~ "^.* uri: CONNECT hostname:443 HTTP/1.1; host: {hostname}$"
Christopher Faulet1c521212022-11-22 15:39:12 +010036 recv
37 expect ~ "^.* uri: CONNECT hostname:443 HTTP/1.1; host: {hostname:}$"
Christopher Faulet3f5fbe92022-07-05 14:50:17 +020038
Christopher Faulet1c521212022-11-22 15:39:12 +010039 # C7
Christopher Faulet3f5fbe92022-07-05 14:50:17 +020040 recv
41 expect ~ "^.* uri: CONNECT hostname:8443 HTTP/1.1; host: {hostname:8443}$"
Christopher Faulet1c521212022-11-22 15:39:12 +010042
43 # C8
44 recv
45 expect ~ "^.* uri: <BADREQ>; host: $"
46
47 # C9
48 recv
49 expect ~ "^.* uri: <BADREQ>; host: $"
50
51 # C10
52 recv
53 expect ~ "^.* uri: <BADREQ>; host: $"
54
55 # C11
56 recv
57 expect ~ "^.* uri: <BADREQ>; host: $"
58
59 # C12
60 recv
61 expect ~ "^.* uri: <BADREQ>; host: $"
62
63 # C13
64 recv
65 expect ~ "^.* uri: <BADREQ>; host: $"
66
67 # C14
68 recv
69 expect ~ "^.* uri: <BADREQ>; host: $"
70
71 # C15
72 recv
73 expect ~ "^.* uri: <BADREQ>; host: $"
74
75 # C16
76 recv
77 expect ~ "^.* uri: <BADREQ>; host: $"
78
79 # C17
80 recv
81 expect ~ "^.* uri: <BADREQ>; host: $"
82
83 # C18
84 recv
85 expect ~ "^.* uri: <BADREQ>; host: $"
86
87 # C19
88 recv
89 expect ~ "^.* uri: <BADREQ>; host: $"
90
91 # C20
92 recv
93 expect ~ "^.* uri: GET http://hostname/c20 HTTP/1.1; host: {hostname}$"
94
95 # C21
96 recv
97 expect ~ "^.* uri: GET https://hostname/c21 HTTP/1.1; host: {hostname}$"
98
99 # C22
100 recv
101 expect ~ "^.* uri: GET http://hostname/c22 HTTP/1.1; host: {hostname:80}$"
102
103 # C23
104 recv
105 expect ~ "^.* uri: GET https://hostname/c23 HTTP/1.1; host: {hostname:443}$"
106
107 # C24
108 recv
109 expect ~ "^.* uri: GET http://hostname/c24 HTTP/1.1; host: {hostname}$"
110
111 # C25
112 recv
113 expect ~ "^.* uri: GET https://hostname/c25 HTTP/1.1; host: {hostname}$"
114
115 # C26
116 recv
117 expect ~ "^.* uri: GET http://hostname/c26 HTTP/1.1; host: {hostname:}$"
118
119 # C27
120 recv
121 expect ~ "^.* uri: GET https://hostname/c27 HTTP/1.1; host: {hostname:}$"
122
123 # C28
124 recv
125 expect ~ "^.* uri: GET http://hostname/c28 HTTP/1.1; host: {hostname}$"
126
127 # C29
128 recv
129 expect ~ "^.* uri: GET http://hostname/c29 HTTP/1.1; host: {hostname}$"
130
131 # C30
132 recv
133 expect ~ "^.* uri: GET https://hostname/c30 HTTP/1.1; host: {hostname}$"
134
135 # C31
136 recv
137 expect ~ "^.* uri: GET https://hostname/c31 HTTP/1.1; host: {hostname}$"
138
139 # C32
140 recv
141 expect ~ "^.* uri: GET http:// HTTP/1.1; host: {}$"
142
143 # C33
144 recv
145 expect ~ "^.* uri: GET https:// HTTP/1.1; host: {}$"
146
147 # C34
148 recv
149 expect ~ "^.* uri: GET http:// HTTP/1.1; host: {}$"
150
151 # C35
152 recv
153 expect ~ "^.* uri: GET https:// HTTP/1.1; host: {}$"
Christopher Faulet3f5fbe92022-07-05 14:50:17 +0200154} -start
155
156haproxy h1 -conf {
157 defaults
158 mode http
159 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
160 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
161 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
162
163 frontend fe
164 bind "fd@${fe}"
165
166 http-request capture req.hdr(host) len 512
167 log-format "uri: %r; host: %hr"
168 log ${S1_addr}:${S1_port} len 2048 local0 debug err
169
170 http-request return status 200
171} -start
172
173# default port 80 with http scheme => should be normalized
174# Be sure userinfo are skipped
175client c1 -connect ${h1_fe_sock} {
176 txreq \
177 -req "GET" \
178 -url "http://toto:poue@hostname:80/c1" \
179 -hdr "host: hostname:80"
180
181 rxresp
182 expect resp.status == 200
183} -run
184
185# port 8080 with http scheme => no normalization
186client c2 -connect ${h1_fe_sock} {
187 txreq \
188 -req "GET" \
189 -url "http://hostname:8080/c2" \
190 -hdr "host: hostname:8080"
191
192 rxresp
193 expect resp.status == 200
194} -run
195
196# default port 443 with https scheme => should be normalized
197client c3 -connect ${h1_fe_sock} {
198 txreq \
199 -req "GET" \
200 -url "https://hostname:443/c3" \
201 -hdr "host: hostname:443"
202
203 rxresp
204 expect resp.status == 200
205} -run
206
207# port 80 with https scheme => no normalization
208client c4 -connect ${h1_fe_sock} {
209 txreq \
210 -req "GET" \
211 -url "https://hostname:80/c4" \
212 -hdr "host: hostname:80"
213
214 rxresp
215 expect resp.status == 200
216} -run
217
218# CONNECT on port 80 => should be normalized
Christopher Faulet3f5fbe92022-07-05 14:50:17 +0200219client c5 -connect ${h1_fe_sock} {
220 txreq \
221 -req "CONNECT" \
Christopher Faulet1c521212022-11-22 15:39:12 +0100222 -url "hostname:80" \
Christopher Faulet3f5fbe92022-07-05 14:50:17 +0200223 -hdr "host: hostname:80"
224
225 rxresp
226 expect resp.status == 200
227} -run
228client c5 -connect ${h1_fe_sock} {
229
230 txreq \
231 -req "CONNECT" \
Christopher Faulet1c521212022-11-22 15:39:12 +0100232 -url "hostname:80" \
Christopher Faulet3f5fbe92022-07-05 14:50:17 +0200233 -hdr "host: hostname"
234
235 rxresp
236 expect resp.status == 200
237} -run
Christopher Faulet1c521212022-11-22 15:39:12 +0100238client c5 -connect ${h1_fe_sock} {
239
240 txreq \
241 -req "CONNECT" \
242 -url "hostname:80" \
243 -hdr "host: hostname:"
244
245 rxresp
246 expect resp.status == 200
247} -run
Christopher Faulet3f5fbe92022-07-05 14:50:17 +0200248
249# CONNECT on port 443 => should be normalized
250client c6 -connect ${h1_fe_sock} {
251 txreq \
252 -req "CONNECT" \
253 -url "hostname:443" \
254 -hdr "host: hostname:443"
255
256 rxresp
257 expect resp.status == 200
258} -run
259client c6 -connect ${h1_fe_sock} {
260 txreq \
261 -req "CONNECT" \
262 -url "hostname:443" \
263 -hdr "host: hostname"
264
265 rxresp
266 expect resp.status == 200
267} -run
Christopher Faulet1c521212022-11-22 15:39:12 +0100268client c6 -connect ${h1_fe_sock} {
269 txreq \
270 -req "CONNECT" \
271 -url "hostname:443" \
272 -hdr "host: hostname:"
273
274 rxresp
275 expect resp.status == 200
276} -run
Christopher Faulet3f5fbe92022-07-05 14:50:17 +0200277
278# CONNECT on port non-default port => no normalization
279client c7 -connect ${h1_fe_sock} {
280 txreq \
281 -req "CONNECT" \
282 -url "hostname:8443" \
283 -hdr "host: hostname:8443"
284
285 rxresp
286 expect resp.status == 200
287} -run
288
289# host miss-match => error
290client c8 -connect ${h1_fe_sock} {
291 txreq \
292 -req "GET" \
293 -url "http://hostname1/" \
294 -hdr "host: hostname2"
295
296 rxresp
297 expect resp.status == 400
298} -run
299
300# port miss-match => error
301client c9 -connect ${h1_fe_sock} {
302 txreq \
303 -req "GET" \
304 -url "http://hostname:80/" \
305 -hdr "host: hostname:81"
306
307 rxresp
308 expect resp.status == 400
309} -run
310
311# no host port with a non-default port in abs-uri => error
312client c10 -connect ${h1_fe_sock} {
313 txreq \
314 -req "GET" \
315 -url "http://hostname:8080/" \
316 -hdr "host: hostname"
317
318 rxresp
319 expect resp.status == 400
320} -run
321
322# non-default host port with a default in abs-uri => error
323client c11 -connect ${h1_fe_sock} {
324 txreq \
325 -req "GET" \
326 -url "http://hostname/" \
327 -hdr "host: hostname:81"
328
329 rxresp
330 expect resp.status == 400
331} -run
332
333# miss-match between host headers => error
334client c12 -connect ${h1_fe_sock} {
335 txreq \
336 -req "GET" \
337 -url "http://hostname1/" \
338 -hdr "host: hostname1" \
339 -hdr "host: hostname2"
340
341 rxresp
342 expect resp.status == 400
343} -run
344
345# miss-match between host headers but with a normalization => error
346client c13 -connect ${h1_fe_sock} {
347 txreq \
348 -req "GET" \
349 -url "http://hostname1/" \
350 -hdr "host: hostname1:80" \
351 -hdr "host: hostname1"
352
353 rxresp
354 expect resp.status == 400
355} -run
356
357# CONNECT authoriy without port => error
358client c14 -connect ${h1_fe_sock} {
359 txreq \
360 -req "CONNECT" \
361 -url "hostname" \
362 -hdr "host: hostname"
363
364 rxresp
365 expect resp.status == 400
366} -run
367
368# host miss-match with CONNECT => error
369client c15 -connect ${h1_fe_sock} {
370 txreq \
371 -req "CONNECT" \
372 -url "hostname1:80" \
373 -hdr "host: hostname2:80"
374
375 rxresp
376 expect resp.status == 400
377} -run
378
379# port miss-match with CONNECT => error
380client c16 -connect ${h1_fe_sock} {
381 txreq \
382 -req "CONNECT" \
383 -url "hostname:80" \
384 -hdr "host: hostname:443"
385
386 rxresp
387 expect resp.status == 400
388} -run
389
390# no host port with non-default port in CONNECT authority => error
391client c17 -connect ${h1_fe_sock} {
392 txreq \
393 -req "CONNECT" \
394 -url "hostname:8080" \
395 -hdr "host: hostname"
396
397 rxresp
398 expect resp.status == 400
399} -run
400
401# no authority => error
402client c18 -connect ${h1_fe_sock} {
403 txreq \
404 -req "CONNECT" \
405 -url "/" \
406 -hdr "host: hostname"
407
408 rxresp
409 expect resp.status == 400
410} -run
411
Christopher Faulet1c521212022-11-22 15:39:12 +0100412# no authority => error
413client c19 -connect ${h1_fe_sock} {
414 txreq \
415 -req "CONNECT" \
416 -url "hostname:" \
417 -hdr "host: hostname"
418
419 rxresp
420 expect resp.status == 400
421} -run
422
423
424# default port 80 with http scheme but no port for host value => should be normalized
425client c20 -connect ${h1_fe_sock} {
426 txreq \
427 -req "GET" \
428 -url "http://hostname:80/c20" \
429 -hdr "host: hostname"
430
431 rxresp
432 expect resp.status == 200
433} -run
434
435
436# default port 443 with https scheme but no port for host value => should be normalized
437client c21 -connect ${h1_fe_sock} {
438 txreq \
439 -req "GET" \
440 -url "https://hostname:443/c21" \
441 -hdr "host: hostname"
442
443 rxresp
444 expect resp.status == 200
445} -run
446
447
448# http scheme, no port for the authority but default port for host value => no normalization
449client c22 -connect ${h1_fe_sock} {
450 txreq \
451 -req "GET" \
452 -url "http://hostname/c22" \
453 -hdr "host: hostname:80"
454
455 rxresp
456 expect resp.status == 200
457} -run
458
459# https scheme, no port for the authority but default port for host value => no normalization
460client c23 -connect ${h1_fe_sock} {
461 txreq \
462 -req "GET" \
463 -url "https://hostname/c23" \
464 -hdr "host: hostname:443"
465
466 rxresp
467 expect resp.status == 200
468} -run
469
470
471# http scheme, empty port for the authority and no port for host value => should be normalized
472client c24 -connect ${h1_fe_sock} {
473 txreq \
474 -req "GET" \
475 -url "http://hostname:/c24" \
476 -hdr "host: hostname"
477
478 rxresp
479 expect resp.status == 200
480} -run
481
482# https scheme, empty port for the authority and no port for host value => should be normalized
483client c25 -connect ${h1_fe_sock} {
484 txreq \
485 -req "GET" \
486 -url "https://hostname:/c25" \
487 -hdr "host: hostname"
488
489 rxresp
490 expect resp.status == 200
491} -run
492
493# http scheme, no port for the authority and empty port for host value => no normalization
494client c26 -connect ${h1_fe_sock} {
495 txreq \
496 -req "GET" \
497 -url "http://hostname/c26" \
498 -hdr "host: hostname:"
499
500 rxresp
501 expect resp.status == 200
502} -run
503
504# https scheme, no port for the authority and empty port for host value => no normalization
505client c27 -connect ${h1_fe_sock} {
506 txreq \
507 -req "GET" \
508 -url "https://hostname/c27" \
509 -hdr "host: hostname:"
510
511 rxresp
512 expect resp.status == 200
513} -run
514
515# http scheme, default port for the authority and empty port for host value => should be normalized
516client c28 -connect ${h1_fe_sock} {
517 txreq \
518 -req "GET" \
519 -url "http://hostname:80/c28" \
520 -hdr "host: hostname:"
521
522 rxresp
523 expect resp.status == 200
524} -run
525
526# http scheme, empty port for the authority and default port for host value => should be normalized
527client c29 -connect ${h1_fe_sock} {
528 txreq \
529 -req "GET" \
530 -url "http://hostname:/c29" \
531 -hdr "host: hostname:80"
532
533 rxresp
534 expect resp.status == 200
535} -run
536
537# https scheme, default port for the authority and empty port for host value => should be normalized
538client c30 -connect ${h1_fe_sock} {
539 txreq \
540 -req "GET" \
541 -url "https://hostname:443/c30" \
542 -hdr "host: hostname:"
543
544 rxresp
545 expect resp.status == 200
546} -run
547
548# https scheme, empty port for the authority and default port for host value => should be normalized
549client c31 -connect ${h1_fe_sock} {
550 txreq \
551 -req "GET" \
552 -url "https://hostname:/c31" \
553 -hdr "host: hostname:443"
554
555 rxresp
556 expect resp.status == 200
557} -run
558
559# Strange cases
560client c32 -connect ${h1_fe_sock} {
561 txreq \
562 -req "GET" \
563 -url "http://:" \
564 -hdr "host: :80"
565
566 rxresp
567 expect resp.status == 200
568} -run
569
570
571client c33 -connect ${h1_fe_sock} {
572 txreq \
573 -req "GET" \
574 -url "https://:" \
575 -hdr "host: :443"
576
577 rxresp
578 expect resp.status == 200
579} -run
580
581# Strange cases
582client c34 -connect ${h1_fe_sock} {
583 txreq \
584 -req "GET" \
585 -url "http://:" \
586 -hdr "host: :"
587
588 rxresp
589 expect resp.status == 200
590} -run
591
592
593client c35 -connect ${h1_fe_sock} {
594 txreq \
595 -req "GET" \
596 -url "https://:" \
597 -hdr "host: :"
598
599 rxresp
600 expect resp.status == 200
601} -run
602
Christopher Faulet3f5fbe92022-07-05 14:50:17 +0200603syslog S1 -wait