Skip to content

Commit

Permalink
Fixed helper connected callback (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnought committed Feb 2, 2020
1 parent 69e5263 commit 2274802
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions test/auth.js
Expand Up @@ -771,7 +771,7 @@ test('failed authentication does not disconnect other client with same clientId'
})
})

test('unauthorized connection should not unregister the correct one', function (t) {
test('unauthorized connection should not unregister the correct one with same clientId', function (t) {
t.plan(2)

var broker = aedes({
Expand All @@ -780,11 +780,14 @@ test('unauthorized connection should not unregister the correct one', function (
callback(null, true)
} else {
const error = new Error()
error.returnCode = 1
error.returnCode = 4
callback(error, false)
}
}
})
broker.on('clientError', function (client, err) {
t.equal(broker.connectedClients, 1, 'my-client still connected')
})

connect(setup(broker), {
clientId: 'my-client',
Expand All @@ -796,7 +799,7 @@ test('unauthorized connection should not unregister the correct one', function (
username: 'unauthorized'
}, function () {
// other unauthorized connection with the same clientId should not unregister the correct one.
t.equal(broker.connectedClients, 1, 'my-client still connected')
t.fail('unauthorized should not connect')
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/helper.js
Expand Up @@ -60,7 +60,7 @@ function connect (s, opts, connected) {
// setup also needs to return first
if (packet.cmd !== 'connack') {
setImmediate(this.push.bind(this, packet))
} else if (connected) {
} else if (connected && packet.returnCode === 0) {
setImmediate(connected, packet)
}
cb()
Expand Down

0 comments on commit 2274802

Please sign in to comment.