blob: 9f7e6b180d7f30041153559f770e3b3d305659be [file] [log] [blame]
Christopher Faulet32186472020-10-30 17:46:00 +01001varnishtest "mqtt converters Test"
Christopher Faulet85a81362020-12-15 17:13:39 +01002#REQUIRE_VERSION=2.4
Christopher Faulet32186472020-10-30 17:46:00 +01003
4feature ignore_unknown_macro
5
6server s1 {
Christopher Fauletedf94cb2021-06-28 15:26:00 +02007 # MQTT 3.1.1 CONNECT packet (id: test_subaaaaaa... [len = 200])
8 recv 215
Christopher Faulet32186472020-10-30 17:46:00 +01009 sendhex "20020000"
10 close
11
Christopher Fauletf333e3e2021-06-28 15:37:59 +020012 # MQTT 3.1.1 CONNECT packet (id: <empty> - username: test - passwd: passwd)
Christopher Faulet32186472020-10-30 17:46:00 +010013 accept
Christopher Fauletf333e3e2021-06-28 15:37:59 +020014 recv 28
Christopher Faulet32186472020-10-30 17:46:00 +010015 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 Jain08381c42022-03-21 20:04:00 +053045
46 # MQTT 3.1 CONNECT packet (id: test_sub - username: test - passwd: passwd)
47 accept
48 recv 38
49 sendhex "20020000"
Christopher Faulet32186472020-10-30 17:46:00 +010050} -start
51
52server s2 {
53 # MQTT 5.0 complex CONNECT packet
54 recv 128
55 sendhex "20250000221100000078217fff24012501270000ffff22000a2600016100016226000163000164"
56} -start
57
58haproxy h1 -conf {
59 defaults
60 mode tcp
61 timeout connect 1s
62 timeout client 1s
63 timeout server 1s
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)
87 tcp-request content reject if ! { var(req.protoname) "MQTT" } || ! { var(req.protovsn) "5" }
88 tcp-request content reject if ! { var(req.flags) "238" } || ! { var(req.clientid) "test_sub" }
89 tcp-request content reject if ! { var(req.user) "test" } || ! { var(req.pass) "passwd" }
90 tcp-request content reject if ! { var(req.willtopic) "willtopic" } || ! { var(req.willbody) "willpayload" }
91 tcp-request content reject if ! { var(req.maxpktsz) "20" } || ! { var(req.reqpbinfo) "1" }
92 tcp-request content reject if ! { var(req.ctype) "text/plain" } || ! { var(req.willrsptopic) "willrsptopic" }
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)
113 tcp-response content reject if ! { var(res.protovsn) "5" } || ! { var(res.flags) "0" }
114 tcp-response content reject if ! { var(res.rcode) "0" } || ! { var(res.sessexpint) "120" }
115 tcp-response content reject if ! { var(res.recvmax) "32767" } || ! { var(res.maxqos) "1" }
116 tcp-response content reject if ! { var(res.retainavail) "1" } || ! { var(res.maxpktsz) "65535" }
117 tcp-response content reject if ! { var(res.topicaliasmax) "10" }
118} -start
119
120client c1_311_1 -connect ${h1_fe1_sock} {
121 # Valid MQTT 3.1.1 CONNECT packet (id: test_sub)
Christopher Fauletedf94cb2021-06-28 15:26:00 +0200122 sendhex "10d40100044d5154540402003c00c8746573745f737562616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161"
Christopher Faulet32186472020-10-30 17:46:00 +0100123 recv 4
124 expect_close
125} -run
126
127client c1_311_2 -connect ${h1_fe1_sock} {
Christopher Fauletf333e3e2021-06-28 15:37:59 +0200128 # Valid MQTT 3.1.1 CONNECT packet (id: <empty> - username: test - passwd: passwd)
129 sendhex "101a00044d51545404c2003c00000004746573740006706173737764"
Christopher Faulet32186472020-10-30 17:46:00 +0100130 recv 4
131 expect_close
132} -run
133
134client 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
141client 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
148client 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
155client 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
162client c2_311_1 -connect ${h1_fe1_sock} {
163 # Invalid MQTT 3.1.1 PINREQ
164 sendhex "d000"
165 expect_close
166} -run
167
168client 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
174client 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
180client 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
186client 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
192client 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
199client 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 Jain08381c42022-03-21 20:04:00 +0530233
234client 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