Skip to content

Commit

Permalink
fix(auth): emit authError when the server requiring a password
Browse files Browse the repository at this point in the history
Issue: #258
  • Loading branch information
luin committed Mar 6, 2016
1 parent 9b10251 commit c5ca754
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/redis/event_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
15 changes: 15 additions & 0 deletions test/functional/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});

1 comment on commit c5ca754

@mkozjak
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Niiice! 👍

Please sign in to comment.