Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug while client subscribing to an Array of topics. #240

Merged
merged 6 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/handlers/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function SubscribeState (client, packet, finish, granted) {
this.packet = packet
this.finish = finish
this.granted = granted
this.subsIndex = 0
}

function handleSubscribe (client, packet, done) {
Expand Down Expand Up @@ -67,12 +68,10 @@ function storeSubscriptions (sub, done) {

if (!sub) {
this.granted.push(128)
return done(null, sub)
}

if (sub && packet.subscriptions[0].topic !== sub.topic) {
// don't call addSubscriptions per topic,
// TODO change aedes subscribe handle, but this is a fast & dirty fix for now
if (packet.subscriptions.length > 0 && ++this.subsIndex < packet.subscriptions.length) {
// TODO change aedes subscribe handle, but this fix bugs for now.
return done(null, sub)
}

Expand Down
34 changes: 34 additions & 0 deletions test/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,40 @@ test('negate multiple subscriptions', function (t) {
})
})

test('negate subscription with correct persistence', function (t) {
t.plan(7)

var broker = aedes()
broker.authorizeSubscribe = function (client, sub, cb) {
t.ok(client, 'client exists')
if (sub.topic === 'hello') {
sub = null
}
cb(null, sub)
}

var s = connect(setup(broker), { clean: false, clientId: 'abcde' })
s.outStream.once('data', function (packet) {
t.equal(packet.cmd, 'suback')
t.deepEqual(packet.granted, [128, 0])
t.notEqual(broker.persistence._subscriptions.get('abcde'), undefined)
t.deepEqual(broker.persistence._subscriptions.get('abcde').size, 2)
t.equal(packet.messageId, 24)
})

s.inStream.write({
cmd: 'subscribe',
messageId: 24,
subscriptions: [{
topic: 'hello',
qos: 0
}, {
topic: 'world',
qos: 0
}]
})
})

test('negate multiple subscriptions random times', function (t) {
t.plan(5)

Expand Down