Merge pull request #654 from oauth2-proxy/redis-test-client-close

Close client connections after each redis test
This commit is contained in:
Joel Speed 2020-07-03 16:43:42 +01:00 committed by GitHub
commit 39c01d5930
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 4 deletions

View File

@ -8,6 +8,7 @@
## Changes since v6.0.0
- [#654](https://github.com/oauth2-proxy/oauth2-proxy/pull/654) Close client connections after each redis test (@JoelSpeed)
- [#542](https://github.com/oauth2-proxy/oauth2-proxy/pull/542) Move SessionStore tests to independent package (@JoelSpeed)
- [#577](https://github.com/oauth2-proxy/oauth2-proxy/pull/577) Move Cipher and Session Store initialisation out of Validation (@JoelSpeed)
- [#635](https://github.com/oauth2-proxy/oauth2-proxy/pull/635) Support specifying alternative provider TLS trust source(s) (@k-wall)

View File

@ -29,7 +29,14 @@ func TestSessionStore(t *testing.T) {
}
var _ = Describe("Redis SessionStore Tests", func() {
// helper interface to allow us to close client connections
// All non-nil redis clients should implement this
type closer interface {
Close() error
}
var mr *miniredis.Miniredis
var ss sessionsapi.SessionStore
BeforeEach(func() {
var err error
@ -41,12 +48,25 @@ var _ = Describe("Redis SessionStore Tests", func() {
mr.Close()
})
JustAfterEach(func() {
// Release any connections immediately after the test ends
if redisStore, ok := ss.(*SessionStore); ok {
if redisStore.Client != nil {
Expect(redisStore.Client.(closer).Close()).To(Succeed())
}
}
})
tests.RunSessionStoreTests(
func(opts *options.SessionOptions, cookieOpts *options.CookieOptions) (sessionsapi.SessionStore, error) {
// Set the connection URL
opts.Type = options.RedisSessionStoreType
opts.Redis.ConnectionURL = "redis://" + mr.Addr()
return NewRedisSessionStore(opts, cookieOpts)
// 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)
@ -63,7 +83,7 @@ var _ = Describe("Redis SessionStore Tests", func() {
})
AfterEach(func() {
go ms.Close()
ms.Close()
})
tests.RunSessionStoreTests(
@ -74,7 +94,11 @@ var _ = Describe("Redis SessionStore Tests", func() {
opts.Redis.SentinelConnectionURLs = []string{sentinelAddr}
opts.Redis.UseSentinel = true
opts.Redis.SentinelMasterName = ms.MasterInfo().Name
return NewRedisSessionStore(opts, cookieOpts)
// 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)
@ -90,7 +114,11 @@ var _ = Describe("Redis SessionStore Tests", func() {
opts.Type = options.RedisSessionStoreType
opts.Redis.ClusterConnectionURLs = []string{clusterAddr}
opts.Redis.UseCluster = true
return NewRedisSessionStore(opts, cookieOpts)
// 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)