From 5fe2577a19e1ef5ddad08e3a7013685de6ad9950 Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 12 Feb 2013 16:25:41 +0100 Subject: [PATCH] Return a specific NOAUTH error if authentication is required. --- src/redis.c | 4 +++- src/redis.h | 2 +- tests/support/server.tcl | 4 ++-- tests/unit/auth.tcl | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/redis.c b/src/redis.c index d2bfe1b3..e5e6405e 100644 --- a/src/redis.c +++ b/src/redis.c @@ -1050,6 +1050,8 @@ void createSharedObjects(void) { "-MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.\r\n")); shared.roslaveerr = createObject(REDIS_STRING,sdsnew( "-READONLY You can't write against a read only slave.\r\n")); + shared.noautherr = createObject(REDIS_STRING,sdsnew( + "-NOAUTH Authentication required.\r\n")); shared.oomerr = createObject(REDIS_STRING,sdsnew( "-OOM command not allowed when used memory > 'maxmemory'.\r\n")); shared.execaborterr = createObject(REDIS_STRING,sdsnew( @@ -1610,7 +1612,7 @@ int processCommand(redisClient *c) { if (server.requirepass && !c->authenticated && c->cmd->proc != authCommand) { flagTransaction(c); - addReplyError(c,"operation not permitted"); + addReply(c,shared.noautherr); return REDIS_OK; } diff --git a/src/redis.h b/src/redis.h index be27fd72..100896b5 100644 --- a/src/redis.h +++ b/src/redis.h @@ -448,7 +448,7 @@ struct sharedObjectsStruct { *colon, *nullbulk, *nullmultibulk, *queued, *emptymultibulk, *wrongtypeerr, *nokeyerr, *syntaxerr, *sameobjecterr, *outofrangeerr, *noscripterr, *loadingerr, *slowscripterr, *bgsaveerr, - *masterdownerr, *roslaveerr, *execaborterr, + *masterdownerr, *roslaveerr, *execaborterr, *noautherr, *oomerr, *plus, *messagebulk, *pmessagebulk, *subscribebulk, *unsubscribebulk, *psubscribebulk, *punsubscribebulk, *del, *rpop, *lpop, *lpush, diff --git a/tests/support/server.tcl b/tests/support/server.tcl index acbfe73c..e10c350f 100644 --- a/tests/support/server.tcl +++ b/tests/support/server.tcl @@ -84,8 +84,8 @@ proc ping_server {host port} { puts $fd "PING\r\n" flush $fd set reply [gets $fd] - if {[string range $reply 0 4] eq {+PONG} || - [string range $reply 0 3] eq {-ERR}} { + if {[string range $reply 0 0] eq {+} || + [string range $reply 0 0] eq {-}} { set retval 1 } close $fd diff --git a/tests/unit/auth.tcl b/tests/unit/auth.tcl index bd4b8dca..15753e9e 100644 --- a/tests/unit/auth.tcl +++ b/tests/unit/auth.tcl @@ -14,7 +14,7 @@ start_server {tags {"auth"} overrides {requirepass foobar}} { test {Arbitrary command gives an error when AUTH is required} { catch {r set foo bar} err set _ $err - } {ERR*operation not permitted} + } {NOAUTH*} test {AUTH succeeds when the right password is given} { r auth foobar