From c5ca754171326ee07dafbbb0299efadb28fe7510 Mon Sep 17 00:00:00 2001 From: luin Date: Sun, 6 Mar 2016 13:23:54 +0800 Subject: [PATCH] fix(auth): emit authError when the server requiring a password Issue: #258 --- lib/redis/event_handler.js | 3 +++ test/functional/auth.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/redis/event_handler.js b/lib/redis/event_handler.js index 6f905925..273a1541 100644 --- a/lib/redis/event_handler.js +++ b/lib/redis/event_handler.js @@ -29,6 +29,9 @@ exports.connectHandler = function (self) { self._readyCheck(function (err, info) { if (err) { self.flushQueue(new Error('Ready check failed: ' + err.message)); + if (!self.condition.auth && err.message.split(' ')[0] === 'NOAUTH') { + self.emit('authError', err); + } } else { self.serverInfo = info; if (self.connector.check(info)) { diff --git a/test/functional/auth.js b/test/functional/auth.js index a76b246c..49fc8d93 100644 --- a/test/functional/auth.js +++ b/test/functional/auth.js @@ -70,4 +70,19 @@ describe('auth', function () { done(); }); }); + + it('should emit "authError" when password is not provided', function (done) { + var server = new MockServer(17379, function (argv) { + if (argv[0] === 'info') { + return new Error('NOAUTH Authentication required.'); + } + }); + var redis = new Redis({ port: 17379 }); + redis.on('authError', function (error) { + expect(error).to.have.property('message', 'NOAUTH Authentication required.'); + redis.disconnect(); + server.disconnect(); + done(); + }); + }); });