@@ -10,14 +10,74 @@ import (
10
10
)
11
11
12
12
var TestUserName string = "goredis"
13
+ var _ = Describe ("ACL" , func () {
14
+ var client * redis.Client
15
+ var ctx context.Context
16
+
17
+ BeforeEach (func () {
18
+ ctx = context .Background ()
19
+ opt := redisOptions ()
20
+ client = redis .NewClient (opt )
21
+ })
22
+
23
+ It ("should ACL LOG" , Label ("NonRedisEnterprise" ), func () {
24
+ Expect (client .ACLLogReset (ctx ).Err ()).NotTo (HaveOccurred ())
25
+ err := client .Do (ctx , "acl" , "setuser" , "test" , ">test" , "on" , "allkeys" , "+get" ).Err ()
26
+ Expect (err ).NotTo (HaveOccurred ())
27
+
28
+ clientAcl := redis .NewClient (redisOptions ())
29
+ clientAcl .Options ().Username = "test"
30
+ clientAcl .Options ().Password = "test"
31
+ clientAcl .Options ().DB = 0
32
+ _ = clientAcl .Set (ctx , "mystring" , "foo" , 0 ).Err ()
33
+ _ = clientAcl .HSet (ctx , "myhash" , "foo" , "bar" ).Err ()
34
+ _ = clientAcl .SAdd (ctx , "myset" , "foo" , "bar" ).Err ()
35
+
36
+ logEntries , err := client .ACLLog (ctx , 10 ).Result ()
37
+ Expect (err ).NotTo (HaveOccurred ())
38
+ Expect (len (logEntries )).To (Equal (4 ))
39
+
40
+ for _ , entry := range logEntries {
41
+ Expect (entry .Reason ).To (Equal ("command" ))
42
+ Expect (entry .Context ).To (Equal ("toplevel" ))
43
+ Expect (entry .Object ).NotTo (BeEmpty ())
44
+ Expect (entry .Username ).To (Equal ("test" ))
45
+ Expect (entry .AgeSeconds ).To (BeNumerically (">=" , 0 ))
46
+ Expect (entry .ClientInfo ).NotTo (BeNil ())
47
+ Expect (entry .EntryID ).To (BeNumerically (">=" , 0 ))
48
+ Expect (entry .TimestampCreated ).To (BeNumerically (">=" , 0 ))
49
+ Expect (entry .TimestampLastUpdated ).To (BeNumerically (">=" , 0 ))
50
+ }
51
+
52
+ limitedLogEntries , err := client .ACLLog (ctx , 2 ).Result ()
53
+ Expect (err ).NotTo (HaveOccurred ())
54
+ Expect (len (limitedLogEntries )).To (Equal (2 ))
55
+
56
+ // cleanup after creating the user
57
+ err = client .Do (ctx , "acl" , "deluser" , "test" ).Err ()
58
+ Expect (err ).NotTo (HaveOccurred ())
59
+ })
60
+
61
+ It ("should ACL LOG RESET" , Label ("NonRedisEnterprise" ), func () {
62
+ // Call ACL LOG RESET
63
+ resetCmd := client .ACLLogReset (ctx )
64
+ Expect (resetCmd .Err ()).NotTo (HaveOccurred ())
65
+ Expect (resetCmd .Val ()).To (Equal ("OK" ))
66
+
67
+ // Verify that the log is empty after the reset
68
+ logEntries , err := client .ACLLog (ctx , 10 ).Result ()
69
+ Expect (err ).NotTo (HaveOccurred ())
70
+ Expect (len (logEntries )).To (Equal (0 ))
71
+ })
72
+
73
+ })
13
74
var _ = Describe ("ACL user commands" , Label ("NonRedisEnterprise" ), func () {
14
75
var client * redis.Client
15
76
var ctx context.Context
16
77
17
78
BeforeEach (func () {
18
79
ctx = context .Background ()
19
80
opt := redisOptions ()
20
- opt .UnstableResp3 = true
21
81
client = redis .NewClient (opt )
22
82
})
23
83
@@ -58,6 +118,12 @@ var _ = Describe("ACL user commands", Label("NonRedisEnterprise"), func() {
58
118
Expect (resAfterDeletion ).To (HaveLen (1 ))
59
119
Expect (resAfterDeletion [0 ]).To (BeEquivalentTo (res [0 ]))
60
120
})
121
+
122
+ It ("should acl dryrun" , func () {
123
+ dryRun := client .ACLDryRun (ctx , "default" , "get" , "randomKey" )
124
+ Expect (dryRun .Err ()).NotTo (HaveOccurred ())
125
+ Expect (dryRun .Val ()).To (Equal ("OK" ))
126
+ })
61
127
})
62
128
63
129
var _ = Describe ("ACL permissions" , Label ("NonRedisEnterprise" ), func () {
@@ -324,7 +390,6 @@ var _ = Describe("ACL Categories", func() {
324
390
BeforeEach (func () {
325
391
ctx = context .Background ()
326
392
opt := redisOptions ()
327
- opt .UnstableResp3 = true
328
393
client = redis .NewClient (opt )
329
394
})
330
395
0 commit comments