@@ -21,8 +21,8 @@ var _ = Describe("ACL Users Commands", Label("NonRedisEnterprise"), func() {
2121
2222 AfterEach (func () {
2323 _ , err := client .ACLDelUser (context .Background (), TestUserName ).Result ()
24- Expect (client .Close ()).NotTo (HaveOccurred ())
2524 Expect (err ).NotTo (HaveOccurred ())
25+ Expect (client .Close ()).NotTo (HaveOccurred ())
2626 })
2727
2828 It ("list only default user" , func () {
@@ -69,40 +69,106 @@ var _ = Describe("ACL Permissions", Label("NonRedisEnterprise"), func() {
6969
7070 AfterEach (func () {
7171 _ , err := client .ACLDelUser (context .Background (), TestUserName ).Result ()
72- Expect (client .Close ()).NotTo (HaveOccurred ())
7372 Expect (err ).NotTo (HaveOccurred ())
73+ Expect (client .Close ()).NotTo (HaveOccurred ())
7474 })
7575
76- It ("list only default user" , func () {
77- res , err := client .ACLList (ctx ).Result ()
76+ It ("reset permissions" , func () {
77+ add , err := client .ACLSetUser (ctx ,
78+ TestUserName ,
79+ "reset" ,
80+ "nopass" ,
81+ "on" ,
82+ ).Result ()
7883 Expect (err ).NotTo (HaveOccurred ())
79- Expect (res ).To (HaveLen (1 ))
80- Expect (res [0 ]).To (ContainSubstring ("default" ))
84+ Expect (add ).To (Equal ("OK" ))
85+
86+ connection := client .Conn ()
87+ authed , err := connection .AuthACL (ctx , TestUserName , "" ).Result ()
88+ Expect (err ).NotTo (HaveOccurred ())
89+ Expect (authed ).To (Equal ("OK" ))
90+
91+ _ , err = connection .Get (ctx , "anykey" ).Result ()
92+ Expect (err ).To (HaveOccurred ())
8193 })
8294
83- It ("setuser and deluser" , func () {
84- res , err := client .ACLList (ctx ).Result ()
95+ It ("add write permissions" , func () {
96+ add , err := client .ACLSetUser (ctx ,
97+ TestUserName ,
98+ "reset" ,
99+ "nopass" ,
100+ "on" ,
101+ "~*" ,
102+ "+SET" ,
103+ ).Result ()
85104 Expect (err ).NotTo (HaveOccurred ())
86- Expect (res ).To (HaveLen (1 ))
87- Expect (res [0 ]).To (ContainSubstring ("default" ))
105+ Expect (add ).To (Equal ("OK" ))
88106
89- add , err := client .ACLSetUser (ctx , TestUserName , "nopass" , "on" , "allkeys" , "+set" , "+get" ).Result ()
107+ connection := client .Conn ()
108+ authed , err := connection .AuthACL (ctx , TestUserName , "" ).Result ()
109+ Expect (err ).NotTo (HaveOccurred ())
110+ Expect (authed ).To (Equal ("OK" ))
111+
112+ // can write
113+ v , err := connection .Set (ctx , "anykey" , "anyvalue" , 0 ).Result ()
114+ Expect (err ).ToNot (HaveOccurred ())
115+ Expect (v ).To (Equal ("OK" ))
116+
117+ // but can't read
118+ value , err := connection .Get (ctx , "anykey" ).Result ()
119+ Expect (err ).To (HaveOccurred ())
120+ Expect (value ).To (BeEmpty ())
121+ })
122+
123+ It ("add read permissions" , func () {
124+ add , err := client .ACLSetUser (ctx ,
125+ TestUserName ,
126+ "reset" ,
127+ "nopass" ,
128+ "on" ,
129+ "~*" ,
130+ "+GET" ,
131+ ).Result ()
90132 Expect (err ).NotTo (HaveOccurred ())
91133 Expect (add ).To (Equal ("OK" ))
92134
93- resAfter , err := client .ACLList (ctx ).Result ()
135+ connection := client .Conn ()
136+ authed , err := connection .AuthACL (ctx , TestUserName , "" ).Result ()
94137 Expect (err ).NotTo (HaveOccurred ())
95- Expect (resAfter ).To (HaveLen (2 ))
96- Expect (resAfter [1 ]).To (ContainSubstring (TestUserName ))
138+ Expect (authed ).To (Equal ("OK" ))
97139
98- deletedN , err := client .ACLDelUser (ctx , TestUserName ).Result ()
140+ // can read
141+ value , err := connection .Get (ctx , "anykey" ).Result ()
142+ Expect (err ).ToNot (HaveOccurred ())
143+ Expect (value ).To (Equal ("anyvalue" ))
144+
145+ // but can't delete
146+ del , err := connection .Del (ctx , "anykey" ).Result ()
147+ Expect (err ).To (HaveOccurred ())
148+ Expect (del ).ToNot (Equal (1 ))
149+ })
150+
151+ It ("add del permissions" , func () {
152+ add , err := client .ACLSetUser (ctx ,
153+ TestUserName ,
154+ "reset" ,
155+ "nopass" ,
156+ "on" ,
157+ "~*" ,
158+ "+DEL" ,
159+ ).Result ()
99160 Expect (err ).NotTo (HaveOccurred ())
100- Expect (deletedN ).To (BeNumerically ( "==" , 1 ))
161+ Expect (add ).To (Equal ( "OK" ))
101162
102- resAfterDeletion , err := client .ACLList (ctx ).Result ()
163+ connection := client .Conn ()
164+ authed , err := connection .AuthACL (ctx , TestUserName , "" ).Result ()
103165 Expect (err ).NotTo (HaveOccurred ())
104- Expect (resAfterDeletion ).To (HaveLen (1 ))
105- Expect (resAfterDeletion [0 ]).To (BeEquivalentTo (res [0 ]))
166+ Expect (authed ).To (Equal ("OK" ))
167+
168+ // can read
169+ del , err := connection .Del (ctx , "anykey" ).Result ()
170+ Expect (err ).ToNot (HaveOccurred ())
171+ Expect (del ).To (BeEquivalentTo (1 ))
106172 })
107173})
108174
0 commit comments