@@ -10,14 +10,74 @@ import (
1010)
1111
1212var  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+ })
1374var  _  =  Describe ("ACL user commands" , Label ("NonRedisEnterprise" ), func () {
1475	var  client  * redis.Client 
1576	var  ctx  context.Context 
1677
1778	BeforeEach (func () {
1879		ctx  =  context .Background ()
1980		opt  :=  redisOptions ()
20- 		opt .UnstableResp3  =  true 
2181		client  =  redis .NewClient (opt )
2282	})
2383
@@ -58,6 +118,12 @@ var _ = Describe("ACL user commands", Label("NonRedisEnterprise"), func() {
58118		Expect (resAfterDeletion ).To (HaveLen (1 ))
59119		Expect (resAfterDeletion [0 ]).To (BeEquivalentTo (res [0 ]))
60120	})
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+ 	})
61127})
62128
63129var  _  =  Describe ("ACL permissions" , Label ("NonRedisEnterprise" ), func () {
@@ -324,7 +390,6 @@ var _ = Describe("ACL Categories", func() {
324390	BeforeEach (func () {
325391		ctx  =  context .Background ()
326392		opt  :=  redisOptions ()
327- 		opt .UnstableResp3  =  true 
328393		client  =  redis .NewClient (opt )
329394	})
330395
0 commit comments