1
1
package db
2
2
3
3
import (
4
+ "github.com/hdt3213/godis/config"
4
5
"github.com/hdt3213/godis/lib/utils"
6
+ "github.com/hdt3213/godis/redis/connection"
5
7
"github.com/hdt3213/godis/redis/reply/asserts"
6
8
"testing"
7
9
)
@@ -15,3 +17,22 @@ func TestPing(t *testing.T) {
15
17
actual = Ping (testDB , utils .ToBytesList (val , val ))
16
18
asserts .AssertErrReply (t , actual , "ERR wrong number of arguments for 'ping' command" )
17
19
}
20
+
21
+ func TestAuth (t * testing.T ) {
22
+ passwd := utils .RandString (10 )
23
+ c := & connection.FakeConn {}
24
+ ret := Auth (testDB , c , utils .ToBytesList ())
25
+ asserts .AssertErrReply (t , ret , "ERR wrong number of arguments for 'auth' command" )
26
+ ret = Auth (testDB , c , utils .ToBytesList (passwd ))
27
+ asserts .AssertErrReply (t , ret , "ERR Client sent AUTH, but no password is set" )
28
+
29
+ config .Properties .RequirePass = passwd
30
+ defer func () {
31
+ config .Properties .RequirePass = ""
32
+ }()
33
+ ret = Auth (testDB , c , utils .ToBytesList (passwd + passwd ))
34
+ asserts .AssertErrReply (t , ret , "ERR invalid password" )
35
+ ret = Auth (testDB , c , utils .ToBytesList (passwd ))
36
+ asserts .AssertStatusReply (t , ret , "OK" )
37
+
38
+ }
0 commit comments