Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 692d5f1

Browse files
Add more tests relating to maximum allowed variable byte integer
1 parent 2dcc70c commit 692d5f1

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

test.js

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,14 @@ test('disabled numbers cache', t => {
205205
testGenerateError('Unknown command', {})
206206

207207
testParseError('Not supported', Buffer.from([0, 1, 0]), {})
208+
209+
// Length header field
208210
testParseError('Invalid length', Buffer.from(
209211
[16, 255, 255, 255, 255]
210212
), {})
213+
testParseError('Invalid length', Buffer.from(
214+
[16, 255, 255, 255, 128]
215+
), {})
211216

212217
testParseGenerate('minimal connect', {
213218
cmd: 'connect',
@@ -1134,6 +1139,31 @@ testParseGenerate('publish MQTT 5 properties with 0-4 byte varbyte', {
11341139
116, 101, 115, 116 // Payload (test)
11351140
]), { protocolVersion: 5 })
11361141

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+
11371167
; (() => {
11381168
const buffer = Buffer.alloc(2048)
11391169
testParseGenerate('2KB publish packet', {
@@ -1149,18 +1179,21 @@ testParseGenerate('publish MQTT 5 properties with 0-4 byte varbyte', {
11491179
0, 4, // Topic length
11501180
116, 101, 115, 116 // Topic (test)
11511181
]), 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', {
11551188
cmd: 'publish',
11561189
retain: false,
11571190
qos: 0,
11581191
dup: false,
1159-
length: 6 + 2 * 1024 * 1024,
1192+
length: maxLength,
11601193
topic: 'test',
11611194
payload: buffer
11621195
}, Buffer.concat([Buffer.from([
1163-
48, 134, 128, 128, 1, // Header
1196+
48, 255, 255, 255, 127, // Header
11641197
0, 4, // Topic length
11651198
116, 101, 115, 116 // Topic (test)
11661199
]), buffer]))

0 commit comments

Comments
 (0)