From ecf92afdb33059a953c6eb3166be2a4abe83a1b1 Mon Sep 17 00:00:00 2001 From: Harmen Date: Wed, 9 Jun 2021 07:56:15 +0200 Subject: [PATCH] update to redis 6.2 And update code for changed error messages. --- cmd_connection.go | 38 +++++++++++++++++++--------------- cmd_connection_test.go | 2 +- cmd_string_test.go | 4 ++-- integration/connection_test.go | 11 ++++++---- integration/get_redis.sh | 2 +- 5 files changed, 32 insertions(+), 25 deletions(-) diff --git a/cmd_connection.go b/cmd_connection.go index 176c1510..1bf98012 100644 --- a/cmd_connection.go +++ b/cmd_connection.go @@ -108,22 +108,26 @@ func (m *Miniredis) cmdHello(c *server.Peer, cmd string, args []string) { return } + var opts struct { + version int + username, password string + } + versionArg, args := args[0], args[1:] - var version int - switch versionArg { - case "2": - version = 2 - case "3": - version = 3 + var err error + opts.version, err = strconv.Atoi(versionArg) + if err != nil { + c.WriteError("ERR Protocol version is not an integer or out of range") + return + } + switch opts.version { + case 2, 3: default: c.WriteError("NOPROTO unsupported protocol version") return } - var ( - checkAuth bool - username, password string - ) + var checkAuth bool for len(args) > 0 { switch strings.ToUpper(args[0]) { case "AUTH": @@ -131,7 +135,7 @@ func (m *Miniredis) cmdHello(c *server.Peer, cmd string, args []string) { c.WriteError(fmt.Sprintf("ERR Syntax error in HELLO option '%s'", args[0])) return } - username, password, args = args[1], args[2], args[3:] + opts.username, opts.password, args = args[1], args[2], args[3:] checkAuth = true case "SETNAME": if len(args) < 2 { @@ -145,24 +149,24 @@ func (m *Miniredis) cmdHello(c *server.Peer, cmd string, args []string) { } } - if len(m.passwords) == 0 && username == "default" { + if len(m.passwords) == 0 && opts.username == "default" { // redis ignores legacy "AUTH" if it's not enabled. checkAuth = false } if checkAuth { - setPW, ok := m.passwords[username] + setPW, ok := m.passwords[opts.username] if !ok { c.WriteError("WRONGPASS invalid username-password pair") return } - if setPW != password { + if setPW != opts.password { c.WriteError("WRONGPASS invalid username-password pair") return } getCtx(c).authenticated = true } - c.Resp3 = version == 3 + c.Resp3 = opts.version == 3 c.WriteMapLen(7) c.WriteBulk("server") @@ -170,7 +174,7 @@ func (m *Miniredis) cmdHello(c *server.Peer, cmd string, args []string) { c.WriteBulk("version") c.WriteBulk("6.0.5") c.WriteBulk("proto") - c.WriteInt(version) + c.WriteInt(opts.version) c.WriteBulk("id") c.WriteInt(42) c.WriteBulk("mode") @@ -218,7 +222,7 @@ func (m *Miniredis) cmdSelect(c *server.Peer, cmd string, args []string) { withTx(m, c, func(c *server.Peer, ctx *connCtx) { id, err := strconv.Atoi(args[0]) if err != nil { - c.WriteError("ERR invalid DB index") + c.WriteError(msgInvalidInt) setDirty(c) return } diff --git a/cmd_connection_test.go b/cmd_connection_test.go index b0038c74..bc79c657 100644 --- a/cmd_connection_test.go +++ b/cmd_connection_test.go @@ -323,7 +323,7 @@ func TestHello(t *testing.T) { ) mustDo(t, c, "HELLO", "foo", - proto.Error("NOPROTO unsupported protocol version"), + proto.Error("ERR Protocol version is not an integer or out of range"), ) mustDo(t, c, "HELLO", "3", "AUTH", "foo", diff --git a/cmd_string_test.go b/cmd_string_test.go index ee43873e..0789f030 100644 --- a/cmd_string_test.go +++ b/cmd_string_test.go @@ -502,7 +502,7 @@ func TestIncrBy(t *testing.T) { ) } - // Amount not an interger + // Amount not an integer mustDo(t, c, "INCRBY", "key", "noint", proto.Error(msgInvalidInt), @@ -643,7 +643,7 @@ func TestDecrBy(t *testing.T) { ) } - // Amount not an interger + // Amount not an integer mustDo(t, c, "DECRBY", "key", "noint", proto.Error(msgInvalidInt), diff --git a/integration/connection_test.go b/integration/connection_test.go index 78568118..15378271 100644 --- a/integration/connection_test.go +++ b/integration/connection_test.go @@ -60,7 +60,7 @@ func TestSelect(t *testing.T) { c.Error("wrong number", "SELECT") c.Error("out of range", "SELECT", "-1") - c.Error("invalid DB", "SELECT", "aap") + c.Error("not an integer", "SELECT", "aap") c.Error("wrong number", "SELECT", "1", "2") }) @@ -153,7 +153,7 @@ func TestHello(t *testing.T) { c.DoLoosely("HELLO", "2") c.Do("SMEMBERS", "s") - c.Error("unsupported", "HELLO", "twoandahalf") + c.Error("not an integer", "HELLO", "twoandahalf") c.DoLoosely("HELLO", "3", "AUTH", "default", "foo") c.DoLoosely("HELLO", "3", "AUTH", "default", "foo", "SETNAME", "foo") @@ -161,9 +161,12 @@ func TestHello(t *testing.T) { // errors c.Error("Syntax error", "HELLO", "3", "default", "foo") - c.Error("unsupported", "HELLO", "three", "AUTH", "default", "foo") + c.Error("not an integer", "HELLO", "three", "AUTH", "default", "foo") c.Error("Syntax error", "HELLO", "3", "AUTH", "default") - c.Error("unsupported", "HELLO", "default", "foo") + c.Error("unsupported", "HELLO", "-1", "foo") + c.Error("unsupported", "HELLO", "0", "foo") + c.Error("unsupported", "HELLO", "1", "foo") + c.Error("unsupported", "HELLO", "4", "foo") c.Error("Syntax error", "HELLO", "3", "default", "foo", "SETNAME") c.Error("Syntax error", "HELLO", "3", "SETNAME") diff --git a/integration/get_redis.sh b/integration/get_redis.sh index ccbaa49b..629b5d18 100755 --- a/integration/get_redis.sh +++ b/integration/get_redis.sh @@ -2,7 +2,7 @@ set -eu -VERSION=6.0.10 +VERSION=6.2.4 rm -rf ./redis_src/ mkdir -p ./redis_src/