Return a specific NOAUTH error if authentication is required.

This commit is contained in:
antirez 2013-02-12 16:25:41 +01:00
parent 24f258360b
commit dc24a6b132
4 changed files with 7 additions and 5 deletions

View File

@ -1083,6 +1083,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(
@ -1650,7 +1652,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;
}

View File

@ -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,

View File

@ -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

View File

@ -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