@@ -205,9 +205,14 @@ test('disabled numbers cache', t => {
205
205
testGenerateError ( 'Unknown command' , { } )
206
206
207
207
testParseError ( 'Not supported' , Buffer . from ( [ 0 , 1 , 0 ] ) , { } )
208
+
209
+ // Length header field
208
210
testParseError ( 'Invalid length' , Buffer . from (
209
211
[ 16 , 255 , 255 , 255 , 255 ]
210
212
) , { } )
213
+ testParseError ( 'Invalid length' , Buffer . from (
214
+ [ 16 , 255 , 255 , 255 , 128 ]
215
+ ) , { } )
211
216
212
217
testParseGenerate ( 'minimal connect' , {
213
218
cmd : 'connect' ,
@@ -1134,6 +1139,31 @@ testParseGenerate('publish MQTT 5 properties with 0-4 byte varbyte', {
1134
1139
116 , 101 , 115 , 116 // Payload (test)
1135
1140
] ) , { protocolVersion : 5 } )
1136
1141
1142
+ testParseGenerate ( 'publish MQTT 5 properties with max value varbyte' , {
1143
+ cmd : 'publish' ,
1144
+ retain : true ,
1145
+ qos : 2 ,
1146
+ dup : true ,
1147
+ length : 22 ,
1148
+ topic : 'test' ,
1149
+ payload : Buffer . from ( 'test' ) ,
1150
+ messageId : 10 ,
1151
+ properties : {
1152
+ payloadFormatIndicator : false ,
1153
+ subscriptionIdentifier : [ 1 , 268435455 ]
1154
+ }
1155
+ } , Buffer . from ( [
1156
+ 61 , 22 , // Header
1157
+ 0 , 4 , // Topic length
1158
+ 116 , 101 , 115 , 116 , // Topic (test)
1159
+ 0 , 10 , // Message ID
1160
+ 9 , // properties length
1161
+ 1 , 0 , // payloadFormatIndicator
1162
+ 11 , 1 , // subscriptionIdentifier
1163
+ 11 , 255 , 255 , 255 , 127 , // subscriptionIdentifier (max value)
1164
+ 116 , 101 , 115 , 116 // Payload (test)
1165
+ ] ) , { protocolVersion : 5 } )
1166
+
1137
1167
; ( ( ) => {
1138
1168
const buffer = Buffer . alloc ( 2048 )
1139
1169
testParseGenerate ( '2KB publish packet' , {
@@ -1149,18 +1179,21 @@ testParseGenerate('publish MQTT 5 properties with 0-4 byte varbyte', {
1149
1179
0 , 4 , // Topic length
1150
1180
116 , 101 , 115 , 116 // Topic (test)
1151
1181
] ) , buffer ] ) )
1152
- } ) ( ) ; ( ( ) => {
1153
- const buffer = Buffer . alloc ( 2 * 1024 * 1024 )
1154
- testParseGenerate ( '2MB publish packet' , {
1182
+ } ) ( )
1183
+
1184
+ ; ( ( ) => {
1185
+ const maxLength = 268435455
1186
+ const buffer = Buffer . alloc ( maxLength - 6 )
1187
+ testParseGenerate ( 'Max payload publish packet' , {
1155
1188
cmd : 'publish' ,
1156
1189
retain : false ,
1157
1190
qos : 0 ,
1158
1191
dup : false ,
1159
- length : 6 + 2 * 1024 * 1024 ,
1192
+ length : maxLength ,
1160
1193
topic : 'test' ,
1161
1194
payload : buffer
1162
1195
} , Buffer . concat ( [ Buffer . from ( [
1163
- 48 , 134 , 128 , 128 , 1 , // Header
1196
+ 48 , 255 , 255 , 255 , 127 , // Header
1164
1197
0 , 4 , // Topic length
1165
1198
116 , 101 , 115 , 116 // Topic (test)
1166
1199
] ) , buffer ] ) )
0 commit comments