Skip to content

Commit

Permalink
feat: emit authentication related errors with "error" event
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

Authentication related errors are emited with "error" event,
instead of "authError" event
  • Loading branch information
luin committed Apr 30, 2016
1 parent 4e4f5e2 commit 9dc25b4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,6 @@ Besides the above connection events, there are several other custom events:

Event | Description
:------------- | :-------------
authError | emits when the password specified in the options is wrong or the server doesn't require a password.
select | emits when the database changed. The argument is the new db number.

## Offline Queue
Expand Down
4 changes: 2 additions & 2 deletions lib/redis/event_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports.connectHandler = function (self) {
if (self.condition.auth) {
self.auth(self.condition.auth, function (err) {
if (err) {
self.emit('authError', err);
self.silentEmit('error', err);
}
});
}
Expand All @@ -34,7 +34,7 @@ exports.connectHandler = function (self) {
if (err) {
self.flushQueue(new Error('Ready check failed: ' + err.message));
if (!self.condition.auth && err.message.split(' ')[0] === 'NOAUTH') {
self.emit('authError', err);
self.silentEmit('error', err);
}
} else {
self.serverInfo = info;
Expand Down
12 changes: 6 additions & 6 deletions test/functional/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,44 +41,44 @@ describe('auth', function () {
});
});

it('should emit "authError" when the server doesn\'t need auth', function (done) {
it('should emit "error" when the server doesn\'t need auth', function (done) {
var server = new MockServer(17379, function (argv) {
if (argv[0] === 'auth' && argv[1] === 'pass') {
return new Error('ERR Client sent AUTH, but no password is set');
}
});
var redis = new Redis({ port: 17379, password: 'pass' });
redis.on('authError', function (error) {
redis.on('error', function (error) {
expect(error).to.have.property('message', 'ERR Client sent AUTH, but no password is set');
redis.disconnect();
server.disconnect();
done();
});
});

it('should emit "authError" when the password is wrong', function (done) {
it('should emit "error" when the password is wrong', function (done) {
var server = new MockServer(17379, function (argv) {
if (argv[0] === 'auth' && argv[1] === 'pass') {
return new Error('ERR invalid password');
}
});
var redis = new Redis({ port: 17379, password: 'pass' });
redis.on('authError', function (error) {
redis.on('error', function (error) {
expect(error).to.have.property('message', 'ERR invalid password');
redis.disconnect();
server.disconnect();
done();
});
});

it('should emit "authError" when password is not provided', function (done) {
it('should emit "error" 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) {
redis.on('error', function (error) {
expect(error).to.have.property('message', 'NOAUTH Authentication required.');
redis.disconnect();
server.disconnect();
Expand Down

0 comments on commit 9dc25b4

Please sign in to comment.