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

Guarantee granted always come in the right order #140

Merged
merged 2 commits into from
Aug 7, 2017
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
2 changes: 1 addition & 1 deletion lib/handlers/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function handleSubscribe (client, packet, done) {
var subs = packet.subscriptions
var granted = []

broker._parallel(
broker._series(
new SubscribeState(client, packet, done, granted),
doSubscribe,
subs,
Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/unsubscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function handleUnsubscribe (client, packet, done) {

function actualUnsubscribe (client, packet, done) {
var broker = client.broker
broker._parallel(
broker._series(
new UnsubscribeState(client, packet, done, null),
doUnsubscribe,
packet.unsubscriptions,
Expand Down
65 changes: 65 additions & 0 deletions test/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,71 @@ test('negate subscription', function (t) {
})
})

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

var s = connect(setup())

s.broker.authorizeSubscribe = function (client, sub, cb) {
t.ok(client, 'client exists')
cb(null, null)
}

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

s.outStream.once('data', function (packet) {
t.equal(packet.cmd, 'suback')
t.deepEqual(packet.granted, [128, 128])
t.equal(packet.messageId, 24)
})
})

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

var s = connect(setup())

s.broker.authorizeSubscribe = function (client, sub, cb) {
t.ok(client, 'client exists')
if (sub.topic === 'hello') {
setTimeout(function () {
cb(null, sub)
}, 100)
} else {
cb(null, null)
}
}

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

s.outStream.once('data', function (packet) {
t.equal(packet.cmd, 'suback')
t.deepEqual(packet.granted, [0, 128])
t.equal(packet.messageId, 24)
})
})


test('failed authentication does not disconnect other client with same clientId', function (t) {
t.plan(3)

Expand Down