diff --git a/src/redis.c b/src/redis.c index 658d24867aa975d43810d911beade5db0a79aac3..83aa3a824aa84f667bf9cb302a9f55f7da80bbe8 100644 --- a/src/redis.c +++ b/src/redis.c @@ -1249,7 +1249,9 @@ int prepareForShutdown() { /*================================== Commands =============================== */ void authCommand(redisClient *c) { - if (!server.requirepass || !strcmp(c->argv[1]->ptr, server.requirepass)) { + if (!server.requirepass) { + addReplyError(c,"Client sent AUTH, but no password is set"); + } else if (!strcmp(c->argv[1]->ptr, server.requirepass)) { c->authenticated = 1; addReply(c,shared.ok); } else { diff --git a/tests/unit/auth.tcl b/tests/unit/auth.tcl index 8ccda95dffceb4b6b6ce24ffd3bdce9b581d580d..bd4b8dca06f2455a9e9de6710c4d3b228bcb8f3b 100644 --- a/tests/unit/auth.tcl +++ b/tests/unit/auth.tcl @@ -1,15 +1,27 @@ +start_server {tags {"auth"}} { + test {AUTH fails if there is no password configured server side} { + catch {r auth foo} err + set _ $err + } {ERR*no password*} +} + start_server {tags {"auth"} overrides {requirepass foobar}} { test {AUTH fails when a wrong password is given} { catch {r auth wrong!} err - format $err + set _ $err } {ERR*invalid password} test {Arbitrary command gives an error when AUTH is required} { catch {r set foo bar} err - format $err + set _ $err } {ERR*operation not permitted} test {AUTH succeeds when the right password is given} { r auth foobar } {OK} + + test {Once AUTH succeeded we can actually send commands to the server} { + r set foo 100 + r incr foo + } {101} }