Skip to content

Commit

Permalink
Merge 2471534 into 1eada99
Browse files Browse the repository at this point in the history
  • Loading branch information
seeLuck committed Dec 19, 2019
2 parents 1eada99 + 2471534 commit 7c561eb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function Client (broker, conn, req) {
this.parser = mqtt.parser()
this.connected = false
this.connackSent = false
this.authorized = false
this.errored = false
this.clean = true
this._handling = 0
Expand Down Expand Up @@ -291,7 +292,7 @@ Client.prototype.close = function (done) {
that.connected = false
that.disconnected = true

if (that.broker.clients[that.id]) {
if (that.broker.clients[that.id] && that.authorized) {
that.broker.unregisterClient(that)
}

Expand Down
1 change: 1 addition & 0 deletions lib/handlers/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ function authenticate (arg, done) {
return
}
if (!err && successful) {
client.authorized = true
return done()
}

Expand Down
30 changes: 30 additions & 0 deletions test/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -924,3 +924,33 @@ test('prevent publish in QoS0 mode', function (t) {
t.fail('Should have not recieved this packet')
})
})

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

var broker = aedes({
authenticate: function (client, username, password, callback) {
if (username === 'correct') {
callback(null, true)
} else {
const error = new Error()
error.returnCode = 1
callback(error, false)
}
}
})

connect(setup(broker), {
clientId: 'my-client',
username: 'correct'
}, function () {
t.equal(broker.connectedClients, 1, 'my-client connected')
connect(setup(broker), {
clientId: 'my-client',
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')
})
})
})

0 comments on commit 7c561eb

Please sign in to comment.