@@ -214,14 +214,31 @@ var _ = Describe("NewFailoverClusterClient", func() {
214
214
})
215
215
216
216
var _ = Describe ("SentinelAclAuth" , func () {
217
+ const (
218
+ aclSentinelUsername = "sentinel-user"
219
+ aclSentinelPassword = "sentinel-pass"
220
+ )
221
+
217
222
var client * redis.Client
218
- var server * redis.Client
219
223
var sentinel * redis.SentinelClient
224
+ var sentinels = func () []* redisProcess {
225
+ return []* redisProcess { sentinel1 , sentinel2 , sentinel3 }
226
+ }
220
227
221
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
+
222
239
client = redis .NewFailoverClient (& redis.FailoverOptions {
223
- MasterName : aclSentinelName ,
224
- SentinelAddrs : aclSentinelAddrs ,
240
+ MasterName : sentinelName ,
241
+ SentinelAddrs : sentinelAddrs ,
225
242
MaxRetries : - 1 ,
226
243
SentinelUsername : aclSentinelUsername ,
227
244
SentinelPassword : aclSentinelPassword ,
@@ -230,35 +247,32 @@ var _ = Describe("SentinelAclAuth", func() {
230
247
Expect (client .FlushDB (ctx ).Err ()).NotTo (HaveOccurred ())
231
248
232
249
sentinel = redis .NewSentinelClient (& redis.Options {
233
- Addr : aclSentinelAddrs [0 ],
250
+ Addr : sentinelAddrs [0 ],
234
251
MaxRetries : - 1 ,
235
252
Username : aclSentinelUsername ,
236
253
Password : aclSentinelPassword ,
237
254
})
238
255
239
- addr , err := sentinel .GetMasterAddrByName (ctx , aclSentinelName ).Result ()
256
+ _ , err := sentinel .GetMasterAddrByName (ctx , sentinelName ).Result ()
240
257
Expect (err ).NotTo (HaveOccurred ())
241
258
242
- server = redis .NewClient (& redis.Options {
243
- Addr : net .JoinHostPort (addr [0 ], addr [1 ]),
244
- MaxRetries : - 1 ,
245
- })
246
-
247
259
// Wait until sentinels are picked up by each other.
248
- Eventually (func () string {
249
- return aclSentinel1 .Info (ctx ).Val ()
250
- }, "15s" , "100ms" ).Should (ContainSubstring ("sentinels=3" ))
251
- Eventually (func () string {
252
- return aclSentinel2 .Info (ctx ).Val ()
253
- }, "15s" , "100ms" ).Should (ContainSubstring ("sentinels=3" ))
254
- Eventually (func () string {
255
- return aclSentinel3 .Info (ctx ).Val ()
256
- }, "15s" , "100ms" ).Should (ContainSubstring ("sentinels=3" ))
260
+ for _ , process := range sentinels () {
261
+ Eventually (func () string {
262
+ return process .Info (ctx ).Val ()
263
+ }, "15s" , "100ms" ).Should (ContainSubstring ("sentinels=3" ))
264
+ }
257
265
})
258
266
259
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
+
260
275
_ = client .Close ()
261
- _ = server .Close ()
262
276
_ = sentinel .Close ()
263
277
})
264
278
0 commit comments