Skip to content

Commit

Permalink
fix: missed messageId 0 (#652)
Browse files Browse the repository at this point in the history
  • Loading branch information
ae94 authored Jul 16, 2021
1 parent 8ee88f7 commit ac54f2e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/handlers/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ function completeSubscribe (err) {
const packet = this.packet
const client = this.client

if (packet.messageId) {
if (packet.messageId !== undefined) {
// [MQTT-3.9.3-1]
write(client,
new SubAck(packet, this.subState.map(obj => obj.granted)),
Expand Down Expand Up @@ -234,6 +234,6 @@ function completeSubscribe (err) {
}))
}

function noop () {}
function noop () { }

module.exports = handleSubscribe
6 changes: 3 additions & 3 deletions lib/handlers/unsubscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function handleUnsubscribe (client, packet, done) {
}
}

if (packet.messageId) {
if (packet.messageId !== undefined) {
if (client.clean) {
return actualUnsubscribe(client, packet, done)
}
Expand Down Expand Up @@ -80,7 +80,7 @@ function completeUnsubscribe (err) {
const packet = this.packet
const done = this.finish

if (packet.messageId) {
if (packet.messageId !== undefined) {
write(client, new UnSubAck(packet),
done)
} else {
Expand All @@ -99,6 +99,6 @@ function completeUnsubscribe (err) {
}
}

function noop () {}
function noop () { }

module.exports = handleUnsubscribe
29 changes: 29 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,35 @@ test('subscribe should have messageId', function (t) {
})
})

test('subscribe with messageId 0 should return suback', function (t) {
t.plan(1)

const s = connect(setup())
t.teardown(s.broker.close.bind(s.broker))

s.inStream.write({
cmd: 'subscribe',
subscriptions: [{
topic: 'hello',
qos: 0
}],
messageId: 0
})
s.outStream.once('data', function (packet) {
t.same(packet, {
cmd: 'suback',
messageId: 0,
dup: false,
length: 3,
qos: 0,
retain: false,
granted: [
0
]
}, 'packet matches')
})
})

test('unsubscribe', function (t) {
t.plan(5)

Expand Down

0 comments on commit ac54f2e

Please sign in to comment.