@@ -212,3 +212,76 @@ var _ = Describe("NewFailoverClusterClient", func() {
212
212
Expect (err ).NotTo (HaveOccurred ())
213
213
})
214
214
})
215
+
216
+ var _ = Describe ("SentinelAclAuth" , func () {
217
+ const (
218
+ aclSentinelUsername = "sentinel-user"
219
+ aclSentinelPassword = "sentinel-pass"
220
+ )
221
+
222
+ var client * redis.Client
223
+ var sentinel * redis.SentinelClient
224
+ var sentinels = func () []* redisProcess {
225
+ return []* redisProcess { sentinel1 , sentinel2 , sentinel3 }
226
+ }
227
+
228
+ BeforeEach (func () {
229
+ authCmd := redis .NewStatusCmd (ctx , "ACL" , "SETUSER" , aclSentinelUsername , "ON" ,
230
+ ">" + aclSentinelPassword , "-@all" , "+auth" , "+client|getname" , "+client|id" , "+client|setname" ,
231
+ "+command" , "+hello" , "+ping" , "+role" , "+sentinel|get-master-addr-by-name" , "+sentinel|master" ,
232
+ "+sentinel|myid" , "+sentinel|replicas" , "+sentinel|sentinels" )
233
+
234
+ for _ , process := range sentinels () {
235
+ err := process .Client .Process (ctx , authCmd )
236
+ Expect (err ).NotTo (HaveOccurred ())
237
+ }
238
+
239
+ client = redis .NewFailoverClient (& redis.FailoverOptions {
240
+ MasterName : sentinelName ,
241
+ SentinelAddrs : sentinelAddrs ,
242
+ MaxRetries : - 1 ,
243
+ SentinelUsername : aclSentinelUsername ,
244
+ SentinelPassword : aclSentinelPassword ,
245
+ })
246
+
247
+ Expect (client .FlushDB (ctx ).Err ()).NotTo (HaveOccurred ())
248
+
249
+ sentinel = redis .NewSentinelClient (& redis.Options {
250
+ Addr : sentinelAddrs [0 ],
251
+ MaxRetries : - 1 ,
252
+ Username : aclSentinelUsername ,
253
+ Password : aclSentinelPassword ,
254
+ })
255
+
256
+ _ , err := sentinel .GetMasterAddrByName (ctx , sentinelName ).Result ()
257
+ Expect (err ).NotTo (HaveOccurred ())
258
+
259
+ // Wait until sentinels are picked up by each other.
260
+ for _ , process := range sentinels () {
261
+ Eventually (func () string {
262
+ return process .Info (ctx ).Val ()
263
+ }, "15s" , "100ms" ).Should (ContainSubstring ("sentinels=3" ))
264
+ }
265
+ })
266
+
267
+ AfterEach (func () {
268
+ unauthCommand := redis .NewStatusCmd (ctx , "ACL" , "DELUSER" , aclSentinelUsername )
269
+
270
+ for _ , process := range sentinels () {
271
+ err := process .Client .Process (ctx , unauthCommand )
272
+ Expect (err ).NotTo (HaveOccurred ())
273
+ }
274
+
275
+ _ = client .Close ()
276
+ _ = sentinel .Close ()
277
+ })
278
+
279
+ It ("should still facilitate operations" , func () {
280
+ err := client .Set (ctx , "wow" , "acl-auth" , 0 ).Err ()
281
+ Expect (err ).NotTo (HaveOccurred ())
282
+
283
+ val , err := client .Get (ctx , "wow" ).Result ()
284
+ Expect (err ).NotTo (HaveOccurred ())
285
+ Expect (val ).To (Equal ("acl-auth" ))
286
+ })
287
+ })
0 commit comments