blob: ea2cbb4f89243a64e31f103661e7ac634ff4c435 [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
45} -start
46
47server s2 {
48 # MQTT 5.0 complex CONNECT packet
49 recv 128
50 sendhex "20250000221100000078217fff24012501270000ffff22000a2600016100016226000163000164"
51} -start
52
53haproxy h1 -conf {
54 defaults
55 mode tcp
56 timeout connect 1s
57 timeout client 1s
58 timeout server 1s
59
60 frontend fe1
61 bind "fd@${fe1}"
62 tcp-request inspect-delay 1s
63 tcp-request content reject unless { req.payload(0,0),mqtt_is_valid }
64 default_backend be1
65
66 frontend fe2
67 bind "fd@${fe2}"
68 tcp-request inspect-delay 1s
69 tcp-request content reject unless { req.payload(0,0),mqtt_is_valid }
70 tcp-request content set-var(req.flags) req.payload(0,0),mqtt_field_value(connect,flags)
71 tcp-request content set-var(req.protoname) req.payload(0,0),mqtt_field_value(connect,protocol_name)
72 tcp-request content set-var(req.protovsn) req.payload(0,0),mqtt_field_value(connect,protocol_version)
73 tcp-request content set-var(req.clientid) req.payload(0,0),mqtt_field_value(connect,client_identifier)
74 tcp-request content set-var(req.willtopic) req.payload(0,0),mqtt_field_value(connect,will_topic)
75 tcp-request content set-var(req.willbody) req.payload(0,0),mqtt_field_value(connect,will_payload)
76 tcp-request content set-var(req.user) req.payload(0,0),mqtt_field_value(connect,username)
77 tcp-request content set-var(req.pass) req.payload(0,0),mqtt_field_value(connect,password)
78 tcp-request content set-var(req.maxpktsz) req.payload(0,0),mqtt_field_value(connect,39)
79 tcp-request content set-var(req.reqpbinfo) req.payload(0,0),mqtt_field_value(connect,23)
80 tcp-request content set-var(req.ctype) req.payload(0,0),mqtt_field_value(connect,3)
81 tcp-request content set-var(req.willrsptopic) req.payload(0,0),mqtt_field_value(connect,8)
82 tcp-request content reject if ! { var(req.protoname) "MQTT" } || ! { var(req.protovsn) "5" }
83 tcp-request content reject if ! { var(req.flags) "238" } || ! { var(req.clientid) "test_sub" }
84 tcp-request content reject if ! { var(req.user) "test" } || ! { var(req.pass) "passwd" }
85 tcp-request content reject if ! { var(req.willtopic) "willtopic" } || ! { var(req.willbody) "willpayload" }
86 tcp-request content reject if ! { var(req.maxpktsz) "20" } || ! { var(req.reqpbinfo) "1" }
87 tcp-request content reject if ! { var(req.ctype) "text/plain" } || ! { var(req.willrsptopic) "willrsptopic" }
88 default_backend be2
89
90 backend be1
91 server s1 ${s1_addr}:${s1_port}
92 tcp-response inspect-delay 1s
93 tcp-response content reject unless { res.payload(0,0),mqtt_is_valid }
94
95 backend be2
96 server s2 ${s2_addr}:${s2_port}
97 tcp-response inspect-delay 1s
98 tcp-response content reject unless { res.payload(0,0),mqtt_is_valid }
99 tcp-response content set-var(res.flags) res.payload(0,0),mqtt_field_value(connack,flags)
100 tcp-response content set-var(res.protovsn) res.payload(0,0),mqtt_field_value(connack,protocol_version)
101 tcp-response content set-var(res.rcode) res.payload(0,0),mqtt_field_value(connack,reason_code)
102 tcp-response content set-var(res.sessexpint) res.payload(0,0),mqtt_field_value(connack,17)
103 tcp-response content set-var(res.recvmax) res.payload(0,0),mqtt_field_value(connack,33)
104 tcp-response content set-var(res.maxqos) res.payload(0,0),mqtt_field_value(connack,36)
105 tcp-response content set-var(res.retainavail) res.payload(0,0),mqtt_field_value(connack,37)
106 tcp-response content set-var(res.maxpktsz) res.payload(0,0),mqtt_field_value(connack,39)
107 tcp-response content set-var(res.topicaliasmax) res.payload(0,0),mqtt_field_value(connack,34)
108 tcp-response content reject if ! { var(res.protovsn) "5" } || ! { var(res.flags) "0" }
109 tcp-response content reject if ! { var(res.rcode) "0" } || ! { var(res.sessexpint) "120" }
110 tcp-response content reject if ! { var(res.recvmax) "32767" } || ! { var(res.maxqos) "1" }
111 tcp-response content reject if ! { var(res.retainavail) "1" } || ! { var(res.maxpktsz) "65535" }
112 tcp-response content reject if ! { var(res.topicaliasmax) "10" }
113} -start
114
115client c1_311_1 -connect ${h1_fe1_sock} {
116 # Valid MQTT 3.1.1 CONNECT packet (id: test_sub)
Christopher Fauletedf94cb2021-06-28 15:26:00 +0200117 sendhex "10d40100044d5154540402003c00c8746573745f737562616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161"
Christopher Faulet32186472020-10-30 17:46:00 +0100118 recv 4
119 expect_close
120} -run
121
122client c1_311_2 -connect ${h1_fe1_sock} {
Christopher Fauletf333e3e2021-06-28 15:37:59 +0200123 # Valid MQTT 3.1.1 CONNECT packet (id: <empty> - username: test - passwd: passwd)
124 sendhex "101a00044d51545404c2003c00000004746573740006706173737764"
Christopher Faulet32186472020-10-30 17:46:00 +0100125 recv 4
126 expect_close
127} -run
128
129client c1_311_3 -connect ${h1_fe1_sock} {
130 # Valid MQTT 3.1.1 CONNECT packet (id: test_sub - username: test - passwd: passwd - will_topic: willtopic - will_payload: willpayload)
131 sendhex "103a00044d51545404ee003c0008746573745f737562000977696c6c746f706963000b77696c6c7061796c6f61640004746573740006706173737764"
132 recv 4
133 expect_close
134} -run
135
136client c1_50_1 -connect ${h1_fe1_sock} {
137 # Valid MQTT 5.0 CONNECT packet (id: test_sub)
138 sendhex "101800044d5154540502003c032100140008746573745f737562"
139 recv 8
140 expect_close
141} -run
142
143client c1_50_2 -connect ${h1_fe1_sock} {
144 # Valid MQTT 5.0 CONNECT packet (id: test_sub - username: test - passwd: passwd)
145 sendhex "102600044d51545405c2003c032100140008746573745f7375620004746573740006706173737764"
146 recv 8
147 expect_close
148} -run
149
150client c1_50_3 -connect ${h1_fe1_sock} {
151 # Valid MQTT 5.0 complex CONNECT/CONNACK packet
152 sendhex "107e00044d51545405ee003c182700000014170126000161000162260001630001642100140008746573745f7375622a03000a746578742f706c61696e08000c77696c6c727370746f7069632600016500016626000167000168000977696c6c746f706963000b77696c6c7061796c6f61640004746573740006706173737764"
153 recv 39
154 expect_close
155} -run
156
157client c2_311_1 -connect ${h1_fe1_sock} {
158 # Invalid MQTT 3.1.1 PINREQ
159 sendhex "d000"
160 expect_close
161} -run
162
163client c2_311_2 -connect ${h1_fe1_sock} {
164 # Invalid MQTT 3.1.1 CONNECT packet with invalid flags (!= 0x00)
165 sendhex "111400044d5154540402003c0008746573745f737562"
166 expect_close
167} -run
168
169client c2_311_3 -connect ${h1_fe1_sock} {
170 # Invalid MQTT 3.1.1 CONNACK packet with invalid flags (!= 0x00)
171 sendhex "101400044d5154540402003c0008746573745f737562"
172 expect_close
173} -run
174
175client c2_311_4 -connect ${h1_fe1_sock} {
176 # Invalid MQTT 3.1.1 CONNECT with too long remaing_length ( > 4 bytes)
177 sendhex "10ffffffff1400044d5154540402003c0008746573745f737562"
178 expect_close
179} -run
180
181client c2_311_4 -connect ${h1_fe1_sock} {
182 # Invalid MQTT 3.1.1 CONNECT with not matching ( 0x13 != 0x14)
183 sendhex "101300044d5154540402003c000874657374a5f737562"
184 expect_close
185} -run
186
187client c2_311_4 -connect ${h1_fe1_sock} {
188 # Invalid MQTT 3.1.1 CONNECT with not matching ( 0x18 != 0x14)
189 sendhex "101800044d5154540402003c000874657374a5f737562ffffffff"
190 expect_close
191} -run
192
193
194client c2_50_1 -connect ${h1_fe2_sock} {
195 # complex MQTT 5.0 CONNECT/CONNACK packet
196 # - CONNECT :
197 # client-id : test_sub
198 # username : test
199 # password : passwd
200 # will-topic : willtopic
201 # will-payload: willpayload
202 # connect props:
203 # maximum-packet-size : 20
204 # request-problem-information: 1
205 # user-property : name=a value=b
206 # user-property : name=c value=d
207 # will props:
208 # content-type : text/plain
209 # response-topic: willrsptopic
210 # user-property : name=e value=f
211 # user-property : name=g value=h
212 # - CONNACK :
213 # flags : 0x00
214 # reason-code: 0x00
215 # connack props:
216 # session-Expiry-interval: 120
217 # receive-maximum : 32767
218 # maximum-qos : 1
219 # retain-available : 1
220 # maximum-packet-size : 65535
221 # topic-alias-maximum : 10
222 # user-property : name=a value=b
223 # user-property : name=c value=d
224 sendhex "107e00044d51545405ee003c182700000014170126000161000162260001630001642100140008746573745f7375622a03000a746578742f706c61696e08000c77696c6c727370746f7069632600016500016626000167000168000977696c6c746f706963000b77696c6c7061796c6f61640004746573740006706173737764"
225 recv 39
226 expect_close
227} -run