blob: 284bc915139be882921a7f0216afe03a06a42ba2 [file] [log] [blame]
Tim Duesterhus488ee7f2020-03-05 22:55:20 +01001varnishtest "Check that the TLVs are properly validated"
2
Christopher Faulet6ade8612020-10-20 09:10:25 +02003#REQUIRE_VERSION=2.4
Willy Tarreau1d52c7b2020-03-31 16:36:20 +02004
Tim Duesterhus488ee7f2020-03-05 22:55:20 +01005feature ignore_unknown_macro
6
7# We need one HAProxy for each test, because apparently the connection by
8# the client is reused, leading to connection resets.
9
10haproxy h1 -conf {
11 defaults
12 mode http
13 timeout connect 1s
14 timeout client 1s
15 timeout server 1s
16
17 frontend a
18 bind "fd@${fe1}" accept-proxy
19 http-after-response set-header echo %[fc_pp_authority,hex]
20 http-request return status 200
21} -start
22
23# Validate that a correct header passes
24client c1 -connect ${h1_fe1_sock} {
25 # PROXY v2 signature
26 sendhex "0d 0a 0d 0a 00 0d 0a 51 55 49 54 0a"
27 # version + PROXY
28 sendhex "21"
29 # TCP4
30 sendhex "11"
31 # length of the address (12) + length of the TLV (8)
32 sendhex "00 14"
33 # 127.0.0.1 42 127.0.0.1 1337
34 sendhex "7F 00 00 01 7F 00 00 01 00 2A 05 39"
35 # PP2_TYPE_AUTHORITY + length of the value + "12345"
36 sendhex "02 00 05 31 32 33 34 35"
37
38 txreq -url "/"
39 rxresp
40 expect resp.http.echo == "3132333435"
41} -run
42
43haproxy h2 -conf {
44 defaults
45 mode http
46 timeout connect 1s
47 timeout client 1s
48 timeout server 1s
49
50 frontend a
51 bind "fd@${fe1}" accept-proxy
52 http-after-response set-header echo %[fc_pp_authority,hex]
53 http-request return status 200
54} -start
55
Christopher Faulet6ade8612020-10-20 09:10:25 +020056# Validate that a TLV after the end of the PROXYv2 header is not parsed
57# and handle by the HTTP parser, leading to a 400 bad request error
Tim Duesterhus488ee7f2020-03-05 22:55:20 +010058client c2 -connect ${h2_fe1_sock} {
59 # PROXY v2 signature
60 sendhex "0d 0a 0d 0a 00 0d 0a 51 55 49 54 0a"
61 # version + PROXY
62 sendhex "21"
63 # TCP4
64 sendhex "11"
65 # length of the address (12) + length of the TLV (8)
66 sendhex "00 14"
67 # 127.0.0.1 42 127.0.0.1 1337
68 sendhex "7F 00 00 01 7F 00 00 01 00 2A 05 39"
69 # PP2_TYPE_AUTHORITY + length of the value + "12345"
70 sendhex "02 00 05 31 32 33 34 35"
71 # after the end of the PROXYv2 header: PP2_TYPE_AUTHORITY + length of the value + "54321"
72 sendhex "02 00 05 35 34 33 32 31"
73
74 txreq -url "/"
75 rxresp
Christopher Faulet6ade8612020-10-20 09:10:25 +020076 expect resp.status == 400
77 expect resp.http.echo == <undef>
Tim Duesterhus488ee7f2020-03-05 22:55:20 +010078} -run
79
80haproxy h3 -conf {
81 defaults
82 mode http
83 timeout connect 1s
84 timeout client 1s
85 timeout server 1s
86
87 frontend a
88 bind "fd@${fe1}" accept-proxy
89 http-after-response set-header echo %[fc_pp_authority,hex]
90 http-request return status 200
91} -start
92
93# Validate that a TLV length exceeding the PROXYv2 length fails
94client c3 -connect ${h3_fe1_sock} {
95 # PROXY v2 signature
96 sendhex "0d 0a 0d 0a 00 0d 0a 51 55 49 54 0a"
97 # version + PROXY
98 sendhex "21"
99 # TCP4
100 sendhex "11"
101 # length of the address (12) + too small length of the TLV (8)
102 sendhex "00 14"
103 # 127.0.0.1 42 127.0.0.1 1337
104 sendhex "7F 00 00 01 7F 00 00 01 00 2A 05 39"
105 # PP2_TYPE_AUTHORITY + length of the value + "1234512345"
106 sendhex "02 00 0A 31 32 33 34 35 31 32 33 34 35"
107
108 txreq -url "/"
109 expect_close
110} -run
111
112haproxy h4 -conf {
113 defaults
114 mode http
115 timeout connect 1s
116 timeout client 1s
117 timeout server 1s
118
119 frontend a
120 bind "fd@${fe1}" accept-proxy
121 http-after-response set-header echo %[fc_pp_authority,hex]
122 http-request return status 200
123} -start
124
125# Validate that TLVs not ending with the PROXYv2 header fail
126client c4 -connect ${h4_fe1_sock} {
127 # PROXY v2 signature
128 sendhex "0d 0a 0d 0a 00 0d 0a 51 55 49 54 0a"
129 # version + PROXY
130 sendhex "21"
131 # TCP4
132 sendhex "11"
133 # length of the address (12) + too big length of the TLV (8)
134 sendhex "00 14"
135 # 127.0.0.1 42 127.0.0.1 1337
136 sendhex "7F 00 00 01 7F 00 00 01 00 2A 05 39"
137 # PP2_TYPE_AUTHORITY + length of the value + "1234"
138 sendhex "02 00 04 31 32 33 34"
139
140 txreq -url "/"
141 expect_close
142} -run