Skip to content

Commit

Permalink
fix: suback fails validation of packets with QoS 128 (#134)
Browse files Browse the repository at this point in the history
* fix: suback fails validation of packets with QoS 128

* fix: tests
  • Loading branch information
robertsLando authored Aug 10, 2022
1 parent f496e89 commit 66a562a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ class Parser extends EventEmitter {
return this._emitError(new Error('Invalid suback code'))
}
} else {
if (code > 2) {
return this._emitError(new Error('Invalid suback QoS, must be <= 2'))
if (code > 2 && code !== 0x80) {
return this._emitError(new Error('Invalid suback QoS, must be 0, 1, 2 or 128'))
}
}
this.packet.granted.push(code)
Expand Down Expand Up @@ -800,7 +800,7 @@ class Parser extends EventEmitter {
}

_emitError (err) {
debug('_emitError')
debug('_emitError', err)
this.error = err
this.emit('error', err)
}
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2266,10 +2266,10 @@ testParseGenerate('suback', {
0, 1, 2, 128 // Granted qos (0, 1, 2) and a rejected being 0x80
]), { protocolVersion: 5 })

testParseError('Invalid suback QoS, must be <= 2', Buffer.from([
testParseError('Invalid suback QoS, must be 0, 1, 2 or 128', Buffer.from([
144, 6, // Header
0, 6, // Message ID
0, 1, 2, 128 // Granted qos (0, 1, 2) and a rejected being 0x80
0, 1, 2, 3 // Granted qos (0, 1, 2)
]))

testParseError('Invalid suback code', Buffer.from([
Expand Down

0 comments on commit 66a562a

Please sign in to comment.