Add ability to configure username for Redis cluster connections (#2381)

* Initial attempt.

* Add CHANGELOG entry.

* Drop commented-out Sentinel test.

---------

Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
This commit is contained in:
Ross Golder
2024-01-20 20:00:02 +00:00
committed by GitHub
co-authored by Joel Speed
parent 4c2bf5a2fe
commit f3dbca600f
5 changed files with 76 additions and 3 deletions
+51
View File
@@ -18,6 +18,7 @@ import (
. "github.com/onsi/gomega"
)
const redisUsername = "testuser"
const redisPassword = "0123456789abcdefghijklmnopqrstuv"
var (
@@ -231,6 +232,56 @@ var _ = Describe("Redis SessionStore Tests", func() {
})
})
Context("with a redis username and password", func() {
BeforeEach(func() {
mr.RequireUserAuth(redisUsername, redisPassword)
})
AfterEach(func() {
mr.RequireUserAuth("", "")
})
tests.RunSessionStoreTests(
func(opts *options.SessionOptions, cookieOpts *options.Cookie) (sessionsapi.SessionStore, error) {
// Set the connection URL
opts.Type = options.RedisSessionStoreType
opts.Redis.ConnectionURL = "redis://" + redisUsername + "@" + mr.Addr()
opts.Redis.Password = redisPassword
// Capture the session store so that we can close the client
var err error
ss, err = NewRedisSessionStore(opts, cookieOpts)
return ss, err
},
func(d time.Duration) error {
mr.FastForward(d)
return nil
},
)
Context("with cluster", func() {
tests.RunSessionStoreTests(
func(opts *options.SessionOptions, cookieOpts *options.Cookie) (sessionsapi.SessionStore, error) {
clusterAddr := "redis://" + redisUsername + "@" + mr.Addr()
opts.Type = options.RedisSessionStoreType
opts.Redis.ClusterConnectionURLs = []string{clusterAddr}
opts.Redis.UseCluster = true
opts.Redis.Username = redisUsername
opts.Redis.Password = redisPassword
// Capture the session store so that we can close the client
var err error
ss, err = NewRedisSessionStore(opts, cookieOpts)
return ss, err
},
func(d time.Duration) error {
mr.FastForward(d)
return nil
},
)
})
})
Context("with TLS connection", func() {
BeforeEach(func() {
mr.Close()