Christopher Faulet | 3218647 | 2020-10-30 17:46:00 +0100 | [diff] [blame] | 1 | varnishtest "mqtt converters Test" |
Christopher Faulet | 85a8136 | 2020-12-15 17:13:39 +0100 | [diff] [blame] | 2 | #REQUIRE_VERSION=2.4 |
Christopher Faulet | 3218647 | 2020-10-30 17:46:00 +0100 | [diff] [blame] | 3 | |
| 4 | feature ignore_unknown_macro |
| 5 | |
| 6 | server s1 { |
Christopher Faulet | ca925c9 | 2021-06-28 15:26:00 +0200 | [diff] [blame] | 7 | # MQTT 3.1.1 CONNECT packet (id: test_subaaaaaa... [len = 200]) |
| 8 | recv 215 |
Christopher Faulet | 3218647 | 2020-10-30 17:46:00 +0100 | [diff] [blame] | 9 | sendhex "20020000" |
| 10 | close |
| 11 | |
Christopher Faulet | 0de0bec | 2021-06-28 15:37:59 +0200 | [diff] [blame] | 12 | # MQTT 3.1.1 CONNECT packet (id: <empty> - username: test - passwd: passwd) |
Christopher Faulet | 3218647 | 2020-10-30 17:46:00 +0100 | [diff] [blame] | 13 | accept |
Christopher Faulet | 0de0bec | 2021-06-28 15:37:59 +0200 | [diff] [blame] | 14 | recv 28 |
Christopher Faulet | 3218647 | 2020-10-30 17:46:00 +0100 | [diff] [blame] | 15 | sendhex "20020000" |
| 16 | close |
| 17 | |
| 18 | # MQTT 3.1.1 CONNECT packet (id: test_sub - username: test - passwd: passwd - will_topic: willtopic - will_payload: willpayload) |
| 19 | accept |
| 20 | recv 60 |
| 21 | sendhex "20020000" |
| 22 | close |
| 23 | |
| 24 | # MQTT 5.0 CONNECT packet (id: test_sub) |
| 25 | accept |
| 26 | recv 26 |
| 27 | sendhex "200600000322000a" |
| 28 | |
| 29 | # MQTT 5.0 CONNECT packet (id: test_sub - username: test - passwd: passwd) |
| 30 | accept |
| 31 | recv 40 |
| 32 | sendhex "200600000322000a" |
| 33 | |
| 34 | # MQTT 5.0 complex CONNECT/CONNACK packet |
| 35 | accept |
| 36 | recv 128 |
| 37 | sendhex "20250000221100000078217fff24012501270000ffff22000a2600016100016226000163000164" |
| 38 | close |
| 39 | |
| 40 | # Invalid MQTT 3.1.1 CONNACK packet with invalid flags (!= 0x00) |
| 41 | accept |
| 42 | recv 22 |
| 43 | sendhex "21020000" |
| 44 | expect_close |
Dhruv Jain | 1295798 | 2022-03-21 20:04:00 +0530 | [diff] [blame] | 45 | |
| 46 | # MQTT 3.1 CONNECT packet (id: test_sub - username: test - passwd: passwd) |
| 47 | accept |
| 48 | recv 38 |
| 49 | sendhex "20020000" |
Christopher Faulet | 3218647 | 2020-10-30 17:46:00 +0100 | [diff] [blame] | 50 | } -start |
| 51 | |
| 52 | server s2 { |
| 53 | # MQTT 5.0 complex CONNECT packet |
| 54 | recv 128 |
| 55 | sendhex "20250000221100000078217fff24012501270000ffff22000a2600016100016226000163000164" |
| 56 | } -start |
| 57 | |
| 58 | haproxy h1 -conf { |
| 59 | defaults |
| 60 | mode tcp |
Willy Tarreau | f673923 | 2021-11-18 17:46:22 +0100 | [diff] [blame] | 61 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
| 62 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 63 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
Christopher Faulet | 3218647 | 2020-10-30 17:46:00 +0100 | [diff] [blame] | 64 | |
| 65 | frontend fe1 |
| 66 | bind "fd@${fe1}" |
| 67 | tcp-request inspect-delay 1s |
| 68 | tcp-request content reject unless { req.payload(0,0),mqtt_is_valid } |
| 69 | default_backend be1 |
| 70 | |
| 71 | frontend fe2 |
| 72 | bind "fd@${fe2}" |
| 73 | tcp-request inspect-delay 1s |
| 74 | tcp-request content reject unless { req.payload(0,0),mqtt_is_valid } |
| 75 | tcp-request content set-var(req.flags) req.payload(0,0),mqtt_field_value(connect,flags) |
| 76 | tcp-request content set-var(req.protoname) req.payload(0,0),mqtt_field_value(connect,protocol_name) |
| 77 | tcp-request content set-var(req.protovsn) req.payload(0,0),mqtt_field_value(connect,protocol_version) |
| 78 | tcp-request content set-var(req.clientid) req.payload(0,0),mqtt_field_value(connect,client_identifier) |
| 79 | tcp-request content set-var(req.willtopic) req.payload(0,0),mqtt_field_value(connect,will_topic) |
| 80 | tcp-request content set-var(req.willbody) req.payload(0,0),mqtt_field_value(connect,will_payload) |
| 81 | tcp-request content set-var(req.user) req.payload(0,0),mqtt_field_value(connect,username) |
| 82 | tcp-request content set-var(req.pass) req.payload(0,0),mqtt_field_value(connect,password) |
| 83 | tcp-request content set-var(req.maxpktsz) req.payload(0,0),mqtt_field_value(connect,39) |
| 84 | tcp-request content set-var(req.reqpbinfo) req.payload(0,0),mqtt_field_value(connect,23) |
| 85 | tcp-request content set-var(req.ctype) req.payload(0,0),mqtt_field_value(connect,3) |
| 86 | tcp-request content set-var(req.willrsptopic) req.payload(0,0),mqtt_field_value(connect,8) |
Willy Tarreau | 44c5ff6 | 2021-11-02 17:08:15 +0100 | [diff] [blame] | 87 | tcp-request content reject if ! { var(req.protoname) -m str "MQTT" } || ! { var(req.protovsn) -m str "5" } |
| 88 | tcp-request content reject if ! { var(req.flags) -m str "238" } || ! { var(req.clientid) -m str "test_sub" } |
| 89 | tcp-request content reject if ! { var(req.user) -m str "test" } || ! { var(req.pass) -m str "passwd" } |
| 90 | tcp-request content reject if ! { var(req.willtopic) -m str "willtopic" } || ! { var(req.willbody) -m str "willpayload" } |
| 91 | tcp-request content reject if ! { var(req.maxpktsz) -m str "20" } || ! { var(req.reqpbinfo) -m str "1" } |
| 92 | tcp-request content reject if ! { var(req.ctype) -m str "text/plain" } || ! { var(req.willrsptopic) -m str "willrsptopic" } |
Christopher Faulet | 3218647 | 2020-10-30 17:46:00 +0100 | [diff] [blame] | 93 | default_backend be2 |
| 94 | |
| 95 | backend be1 |
| 96 | server s1 ${s1_addr}:${s1_port} |
| 97 | tcp-response inspect-delay 1s |
| 98 | tcp-response content reject unless { res.payload(0,0),mqtt_is_valid } |
| 99 | |
| 100 | backend be2 |
| 101 | server s2 ${s2_addr}:${s2_port} |
| 102 | tcp-response inspect-delay 1s |
| 103 | tcp-response content reject unless { res.payload(0,0),mqtt_is_valid } |
| 104 | tcp-response content set-var(res.flags) res.payload(0,0),mqtt_field_value(connack,flags) |
| 105 | tcp-response content set-var(res.protovsn) res.payload(0,0),mqtt_field_value(connack,protocol_version) |
| 106 | tcp-response content set-var(res.rcode) res.payload(0,0),mqtt_field_value(connack,reason_code) |
| 107 | tcp-response content set-var(res.sessexpint) res.payload(0,0),mqtt_field_value(connack,17) |
| 108 | tcp-response content set-var(res.recvmax) res.payload(0,0),mqtt_field_value(connack,33) |
| 109 | tcp-response content set-var(res.maxqos) res.payload(0,0),mqtt_field_value(connack,36) |
| 110 | tcp-response content set-var(res.retainavail) res.payload(0,0),mqtt_field_value(connack,37) |
| 111 | tcp-response content set-var(res.maxpktsz) res.payload(0,0),mqtt_field_value(connack,39) |
| 112 | tcp-response content set-var(res.topicaliasmax) res.payload(0,0),mqtt_field_value(connack,34) |
Willy Tarreau | 44c5ff6 | 2021-11-02 17:08:15 +0100 | [diff] [blame] | 113 | tcp-response content reject if ! { var(res.protovsn) -m str "5" } || ! { var(res.flags) -m str "0" } |
| 114 | tcp-response content reject if ! { var(res.rcode) -m str "0" } || ! { var(res.sessexpint) -m str "120" } |
| 115 | tcp-response content reject if ! { var(res.recvmax) -m str "32767" } || ! { var(res.maxqos) -m str "1" } |
| 116 | tcp-response content reject if ! { var(res.retainavail) -m str "1" } || ! { var(res.maxpktsz) -m str "65535" } |
| 117 | tcp-response content reject if ! { var(res.topicaliasmax) -m str "10" } |
Christopher Faulet | 3218647 | 2020-10-30 17:46:00 +0100 | [diff] [blame] | 118 | } -start |
| 119 | |
| 120 | client c1_311_1 -connect ${h1_fe1_sock} { |
| 121 | # Valid MQTT 3.1.1 CONNECT packet (id: test_sub) |
Christopher Faulet | ca925c9 | 2021-06-28 15:26:00 +0200 | [diff] [blame] | 122 | sendhex "10d40100044d5154540402003c00c8746573745f737562616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161" |
Christopher Faulet | 3218647 | 2020-10-30 17:46:00 +0100 | [diff] [blame] | 123 | recv 4 |
| 124 | expect_close |
| 125 | } -run |
| 126 | |
| 127 | client c1_311_2 -connect ${h1_fe1_sock} { |
Christopher Faulet | 0de0bec | 2021-06-28 15:37:59 +0200 | [diff] [blame] | 128 | # Valid MQTT 3.1.1 CONNECT packet (id: <empty> - username: test - passwd: passwd) |
| 129 | sendhex "101a00044d51545404c2003c00000004746573740006706173737764" |
Christopher Faulet | 3218647 | 2020-10-30 17:46:00 +0100 | [diff] [blame] | 130 | recv 4 |
| 131 | expect_close |
| 132 | } -run |
| 133 | |
| 134 | client c1_311_3 -connect ${h1_fe1_sock} { |
| 135 | # Valid MQTT 3.1.1 CONNECT packet (id: test_sub - username: test - passwd: passwd - will_topic: willtopic - will_payload: willpayload) |
| 136 | sendhex "103a00044d51545404ee003c0008746573745f737562000977696c6c746f706963000b77696c6c7061796c6f61640004746573740006706173737764" |
| 137 | recv 4 |
| 138 | expect_close |
| 139 | } -run |
| 140 | |
| 141 | client c1_50_1 -connect ${h1_fe1_sock} { |
| 142 | # Valid MQTT 5.0 CONNECT packet (id: test_sub) |
| 143 | sendhex "101800044d5154540502003c032100140008746573745f737562" |
| 144 | recv 8 |
| 145 | expect_close |
| 146 | } -run |
| 147 | |
| 148 | client c1_50_2 -connect ${h1_fe1_sock} { |
| 149 | # Valid MQTT 5.0 CONNECT packet (id: test_sub - username: test - passwd: passwd) |
| 150 | sendhex "102600044d51545405c2003c032100140008746573745f7375620004746573740006706173737764" |
| 151 | recv 8 |
| 152 | expect_close |
| 153 | } -run |
| 154 | |
| 155 | client c1_50_3 -connect ${h1_fe1_sock} { |
| 156 | # Valid MQTT 5.0 complex CONNECT/CONNACK packet |
| 157 | sendhex "107e00044d51545405ee003c182700000014170126000161000162260001630001642100140008746573745f7375622a03000a746578742f706c61696e08000c77696c6c727370746f7069632600016500016626000167000168000977696c6c746f706963000b77696c6c7061796c6f61640004746573740006706173737764" |
| 158 | recv 39 |
| 159 | expect_close |
| 160 | } -run |
| 161 | |
| 162 | client c2_311_1 -connect ${h1_fe1_sock} { |
| 163 | # Invalid MQTT 3.1.1 PINREQ |
| 164 | sendhex "d000" |
| 165 | expect_close |
| 166 | } -run |
| 167 | |
| 168 | client c2_311_2 -connect ${h1_fe1_sock} { |
| 169 | # Invalid MQTT 3.1.1 CONNECT packet with invalid flags (!= 0x00) |
| 170 | sendhex "111400044d5154540402003c0008746573745f737562" |
| 171 | expect_close |
| 172 | } -run |
| 173 | |
| 174 | client c2_311_3 -connect ${h1_fe1_sock} { |
| 175 | # Invalid MQTT 3.1.1 CONNACK packet with invalid flags (!= 0x00) |
| 176 | sendhex "101400044d5154540402003c0008746573745f737562" |
| 177 | expect_close |
| 178 | } -run |
| 179 | |
| 180 | client c2_311_4 -connect ${h1_fe1_sock} { |
| 181 | # Invalid MQTT 3.1.1 CONNECT with too long remaing_length ( > 4 bytes) |
| 182 | sendhex "10ffffffff1400044d5154540402003c0008746573745f737562" |
| 183 | expect_close |
| 184 | } -run |
| 185 | |
| 186 | client c2_311_4 -connect ${h1_fe1_sock} { |
| 187 | # Invalid MQTT 3.1.1 CONNECT with not matching ( 0x13 != 0x14) |
| 188 | sendhex "101300044d5154540402003c000874657374a5f737562" |
| 189 | expect_close |
| 190 | } -run |
| 191 | |
| 192 | client c2_311_4 -connect ${h1_fe1_sock} { |
| 193 | # Invalid MQTT 3.1.1 CONNECT with not matching ( 0x18 != 0x14) |
| 194 | sendhex "101800044d5154540402003c000874657374a5f737562ffffffff" |
| 195 | expect_close |
| 196 | } -run |
| 197 | |
| 198 | |
| 199 | client c2_50_1 -connect ${h1_fe2_sock} { |
| 200 | # complex MQTT 5.0 CONNECT/CONNACK packet |
| 201 | # - CONNECT : |
| 202 | # client-id : test_sub |
| 203 | # username : test |
| 204 | # password : passwd |
| 205 | # will-topic : willtopic |
| 206 | # will-payload: willpayload |
| 207 | # connect props: |
| 208 | # maximum-packet-size : 20 |
| 209 | # request-problem-information: 1 |
| 210 | # user-property : name=a value=b |
| 211 | # user-property : name=c value=d |
| 212 | # will props: |
| 213 | # content-type : text/plain |
| 214 | # response-topic: willrsptopic |
| 215 | # user-property : name=e value=f |
| 216 | # user-property : name=g value=h |
| 217 | # - CONNACK : |
| 218 | # flags : 0x00 |
| 219 | # reason-code: 0x00 |
| 220 | # connack props: |
| 221 | # session-Expiry-interval: 120 |
| 222 | # receive-maximum : 32767 |
| 223 | # maximum-qos : 1 |
| 224 | # retain-available : 1 |
| 225 | # maximum-packet-size : 65535 |
| 226 | # topic-alias-maximum : 10 |
| 227 | # user-property : name=a value=b |
| 228 | # user-property : name=c value=d |
| 229 | sendhex "107e00044d51545405ee003c182700000014170126000161000162260001630001642100140008746573745f7375622a03000a746578742f706c61696e08000c77696c6c727370746f7069632600016500016626000167000168000977696c6c746f706963000b77696c6c7061796c6f61640004746573740006706173737764" |
| 230 | recv 39 |
| 231 | expect_close |
| 232 | } -run |
Dhruv Jain | 1295798 | 2022-03-21 20:04:00 +0530 | [diff] [blame] | 233 | |
| 234 | client c3_31_1 -connect ${h1_fe1_sock} { |
| 235 | # Valid MQTT 3.1 CONNECT packet (id: test_sub - username: test - passwd: passwd) |
| 236 | sendhex "102400064d514973647003c200000008746573745f7375620004746573740006706173737764" |
| 237 | recv 4 |
| 238 | } -run |