Tim Duesterhus | 488ee7f | 2020-03-05 22:55:20 +0100 | [diff] [blame] | 1 | varnishtest "Check that the TLVs are properly validated" |
| 2 | |
Christopher Faulet | 6ade861 | 2020-10-20 09:10:25 +0200 | [diff] [blame] | 3 | #REQUIRE_VERSION=2.4 |
Willy Tarreau | 1d52c7b | 2020-03-31 16:36:20 +0200 | [diff] [blame] | 4 | |
Tim Duesterhus | 488ee7f | 2020-03-05 22:55:20 +0100 | [diff] [blame] | 5 | feature 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 | |
| 10 | haproxy h1 -conf { |
| 11 | defaults |
| 12 | mode http |
Willy Tarreau | f673923 | 2021-11-18 17:46:22 +0100 | [diff] [blame] | 13 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
| 14 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 15 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
Tim Duesterhus | 488ee7f | 2020-03-05 22:55:20 +0100 | [diff] [blame] | 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 |
| 24 | client 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 | |
| 43 | haproxy h2 -conf { |
| 44 | defaults |
| 45 | mode http |
Willy Tarreau | f673923 | 2021-11-18 17:46:22 +0100 | [diff] [blame] | 46 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
| 47 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 48 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
Tim Duesterhus | 488ee7f | 2020-03-05 22:55:20 +0100 | [diff] [blame] | 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 Faulet | 6ade861 | 2020-10-20 09:10:25 +0200 | [diff] [blame] | 56 | # 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 Duesterhus | 488ee7f | 2020-03-05 22:55:20 +0100 | [diff] [blame] | 58 | client 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 Faulet | 6ade861 | 2020-10-20 09:10:25 +0200 | [diff] [blame] | 76 | expect resp.status == 400 |
| 77 | expect resp.http.echo == <undef> |
Tim Duesterhus | 488ee7f | 2020-03-05 22:55:20 +0100 | [diff] [blame] | 78 | } -run |
| 79 | |
| 80 | haproxy h3 -conf { |
| 81 | defaults |
| 82 | mode http |
Willy Tarreau | f673923 | 2021-11-18 17:46:22 +0100 | [diff] [blame] | 83 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
| 84 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 85 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
Tim Duesterhus | 488ee7f | 2020-03-05 22:55:20 +0100 | [diff] [blame] | 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 |
| 94 | client 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 | |
| 112 | haproxy h4 -conf { |
| 113 | defaults |
| 114 | mode http |
Willy Tarreau | f673923 | 2021-11-18 17:46:22 +0100 | [diff] [blame] | 115 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
| 116 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 117 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
Tim Duesterhus | 488ee7f | 2020-03-05 22:55:20 +0100 | [diff] [blame] | 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 |
| 126 | client 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 |