Skip to content

Commit ebbb014

Browse files
author
Ruben Bridgewater
committed
Fix auth emitting the error even though a callback is present
Fix auth manipulating the returned error And this is also removing some dead code
1 parent 1a06cfb commit ebbb014

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,20 +206,20 @@ RedisClient.prototype.do_auth = function () {
206206
debug("Warning: Redis server does not require a password, but a password was supplied.");
207207
err = null;
208208
res = "OK";
209+
} else if (self.auth_callback) {
210+
self.auth_callback(err);
211+
self.auth_callback = null;
209212
} else {
210-
return self.emit("error", new Error("Auth error: " + err.message));
213+
self.emit("error", err);
214+
return;
211215
}
212216
}
213217

214218
res = res.toString();
215-
if (res !== "OK") {
216-
return self.emit("error", new Error("Auth failed: " + res));
217-
}
218-
219219
debug("Auth succeeded " + self.address + " id " + self.connection_id);
220220

221221
if (self.auth_callback) {
222-
self.auth_callback(err, res);
222+
self.auth_callback(null, res);
223223
self.auth_callback = null;
224224
}
225225

test/auth.spec.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("client authentication", function () {
3434
});
3535
});
3636

37-
it("raises error when auth is bad", function (done) {
37+
it("emits error when auth is bad without callback", function (done) {
3838
if (helper.redisProcess().spawnFailed()) this.skip();
3939

4040
client = redis.createClient.apply(redis.createClient, args);
@@ -48,6 +48,18 @@ describe("client authentication", function () {
4848
client.auth(auth + 'bad');
4949
});
5050

51+
it("returns an error when auth is bad with a callback", function (done) {
52+
if (helper.redisProcess().spawnFailed()) this.skip();
53+
54+
client = redis.createClient.apply(redis.createClient, args);
55+
56+
client.auth(auth + 'bad', function (err, res) {
57+
assert.strictEqual(err.command_used, 'AUTH');
58+
assert.ok(/ERR invalid password/.test(err.message));
59+
done();
60+
});
61+
});
62+
5163
if (ip === 'IPv4') {
5264
it('allows auth to be provided as part of redis url', function (done) {
5365
if (helper.redisProcess().spawnFailed()) this.skip();
@@ -71,6 +83,19 @@ describe("client authentication", function () {
7183
});
7284
});
7385

86+
it('allows auth and no_ready_check to be provided as config option for client', function (done) {
87+
if (helper.redisProcess().spawnFailed()) this.skip();
88+
89+
var args = config.configureClient(parser, ip, {
90+
auth_pass: auth,
91+
no_ready_check: true
92+
});
93+
client = redis.createClient.apply(redis.createClient, args);
94+
client.on("ready", function () {
95+
done();
96+
});
97+
});
98+
7499
it('allows auth to be provided post-hoc with auth method', function (done) {
75100
if (helper.redisProcess().spawnFailed()) this.skip();
76101

0 commit comments

Comments
 (0)