Skip to content

Commit c5ca754

Browse files
committed
fix(auth): emit authError when the server requiring a password
Issue: #258
1 parent 9b10251 commit c5ca754

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/redis/event_handler.js

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ exports.connectHandler = function (self) {
2929
self._readyCheck(function (err, info) {
3030
if (err) {
3131
self.flushQueue(new Error('Ready check failed: ' + err.message));
32+
if (!self.condition.auth && err.message.split(' ')[0] === 'NOAUTH') {
33+
self.emit('authError', err);
34+
}
3235
} else {
3336
self.serverInfo = info;
3437
if (self.connector.check(info)) {

test/functional/auth.js

+15
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,19 @@ describe('auth', function () {
7070
done();
7171
});
7272
});
73+
74+
it('should emit "authError" when password is not provided', function (done) {
75+
var server = new MockServer(17379, function (argv) {
76+
if (argv[0] === 'info') {
77+
return new Error('NOAUTH Authentication required.');
78+
}
79+
});
80+
var redis = new Redis({ port: 17379 });
81+
redis.on('authError', function (error) {
82+
expect(error).to.have.property('message', 'NOAUTH Authentication required.');
83+
redis.disconnect();
84+
server.disconnect();
85+
done();
86+
});
87+
});
7388
});

0 commit comments

Comments
 (0)