mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-06 17:26:52 +08:00
support auth
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package db
|
||||
|
||||
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"
|
||||
)
|
||||
@@ -15,3 +17,22 @@ func TestPing(t *testing.T) {
|
||||
actual = Ping(testDB, utils.ToBytesList(val, val))
|
||||
asserts.AssertErrReply(t, actual, "ERR wrong number of arguments for 'ping' command")
|
||||
}
|
||||
|
||||
func TestAuth(t *testing.T) {
|
||||
passwd := utils.RandString(10)
|
||||
c := &connection.FakeConn{}
|
||||
ret := Auth(testDB, c, utils.ToBytesList())
|
||||
asserts.AssertErrReply(t, ret, "ERR wrong number of arguments for 'auth' command")
|
||||
ret = Auth(testDB, c, utils.ToBytesList(passwd))
|
||||
asserts.AssertErrReply(t, ret, "ERR Client sent AUTH, but no password is set")
|
||||
|
||||
config.Properties.RequirePass = passwd
|
||||
defer func() {
|
||||
config.Properties.RequirePass = ""
|
||||
}()
|
||||
ret = Auth(testDB, c, utils.ToBytesList(passwd+passwd))
|
||||
asserts.AssertErrReply(t, ret, "ERR invalid password")
|
||||
ret = Auth(testDB, c, utils.ToBytesList(passwd))
|
||||
asserts.AssertStatusReply(t, ret, "OK")
|
||||
|
||||
}
|
Reference in New Issue
Block a user