diff --git a/lib/client.js b/lib/client.js index ee55884..14178b8 100644 --- a/lib/client.js +++ b/lib/client.js @@ -296,7 +296,7 @@ Client.prototype.handleConnect = function(packet, completeConnection) { logger.info({ username: packet.username }, "authentication error"); client.connack({ returnCode: 4 - }); + }); client.stream.end(); return; } diff --git a/test/abstract_server.js b/test/abstract_server.js index dfbebad..70588ef 100644 --- a/test/abstract_server.js +++ b/test/abstract_server.js @@ -1026,7 +1026,25 @@ module.exports = function(moscaSettings, createConnection) { client.on('connack', function(packet) { expect(packet.returnCode).to.eql(5); - client.disconnect(); + }); + }); + }); + + it("should support authentication (error)", function(done) { + instance.authenticate = function(client, username, password, callback) { + callback(new Error("auth error")); + }; + + buildClient(done, function(client) { + + var options = buildOpts(); + options.username = "matteo"; + options.password = "collina"; + + client.connect(options); + + client.on('connack', function(packet) { + expect(packet.returnCode).to.eql(4); }); }); });