support auth

This commit is contained in:
hdt3213
2021-05-09 18:37:29 +08:00
parent bf90941b76
commit 65fc1c3e62
10 changed files with 111 additions and 13 deletions

View File

@@ -1,6 +1,9 @@
package cluster
import (
"github.com/hdt3213/godis/config"
"github.com/hdt3213/godis/lib/utils"
"github.com/hdt3213/godis/redis/connection"
"github.com/hdt3213/godis/redis/reply/asserts"
"testing"
)
@@ -16,6 +19,21 @@ func TestExec(t *testing.T) {
}
}
func TestAuth(t *testing.T) {
passwd := utils.RandString(10)
config.Properties.RequirePass = passwd
defer func() {
config.Properties.RequirePass = ""
}()
conn := &connection.FakeConn{}
ret := testCluster.Exec(conn, toArgs("GET", "a"))
asserts.AssertErrReply(t, ret, "NOAUTH Authentication required")
ret = testCluster.Exec(conn, toArgs("AUTH", passwd))
asserts.AssertStatusReply(t, ret, "OK")
ret = testCluster.Exec(conn, toArgs("GET", "a"))
asserts.AssertNotError(t, ret)
}
func TestRelay(t *testing.T) {
testCluster2 := MakeTestCluster([]string{"127.0.0.1:6379"})
key := RandString(4)