@@ -214,14 +214,31 @@ var _ = Describe("NewFailoverClusterClient", func() {
214214})
215215
216216var _ = Describe ("SentinelAclAuth" , func () {
217+ const (
218+ aclSentinelUsername = "sentinel-user"
219+ aclSentinelPassword = "sentinel-pass"
220+ )
221+
217222 var client * redis.Client
218- var server * redis.Client
219223 var sentinel * redis.SentinelClient
224+ var sentinels = func () []* redisProcess {
225+ return []* redisProcess { sentinel1 , sentinel2 , sentinel3 }
226+ }
220227
221228 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+
222239 client = redis .NewFailoverClient (& redis.FailoverOptions {
223- MasterName : aclSentinelName ,
224- SentinelAddrs : aclSentinelAddrs ,
240+ MasterName : sentinelName ,
241+ SentinelAddrs : sentinelAddrs ,
225242 MaxRetries : - 1 ,
226243 SentinelUsername : aclSentinelUsername ,
227244 SentinelPassword : aclSentinelPassword ,
@@ -230,35 +247,32 @@ var _ = Describe("SentinelAclAuth", func() {
230247 Expect (client .FlushDB (ctx ).Err ()).NotTo (HaveOccurred ())
231248
232249 sentinel = redis .NewSentinelClient (& redis.Options {
233- Addr : aclSentinelAddrs [0 ],
250+ Addr : sentinelAddrs [0 ],
234251 MaxRetries : - 1 ,
235252 Username : aclSentinelUsername ,
236253 Password : aclSentinelPassword ,
237254 })
238255
239- addr , err := sentinel .GetMasterAddrByName (ctx , aclSentinelName ).Result ()
256+ _ , err := sentinel .GetMasterAddrByName (ctx , sentinelName ).Result ()
240257 Expect (err ).NotTo (HaveOccurred ())
241258
242- server = redis .NewClient (& redis.Options {
243- Addr : net .JoinHostPort (addr [0 ], addr [1 ]),
244- MaxRetries : - 1 ,
245- })
246-
247259 // 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+ }
257265 })
258266
259267 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+
260275 _ = client .Close ()
261- _ = server .Close ()
262276 _ = sentinel .Close ()
263277 })
264278
0 commit comments