@@ -1,7 +1,10 @@
1package redis
1package redis
@@ -15,6 +18,7 @@ import (
15 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/logger"
18 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/logger"
16 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/sessions/persistence"
19 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/sessions/persistence"
17 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/sessions/tests"
20 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/sessions/tests"
21+ "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/util"
18 . "github.com/onsi/ginkgo"
22 . "github.com/onsi/ginkgo"
19 . "github.com/onsi/gomega"
23 . "github.com/onsi/gomega"
@@ -224,4 +228,104 @@ var _ = Describe("Redis SessionStore Tests", func() {
232+ Context("with custom CA path", func() {
236+ certBytes, keyBytes, err := util.GenerateCert()
237+ Expect(err).ToNot(HaveOccurred())
238+ certOut := new(bytes.Buffer)
239+ Expect(pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: certBytes})).To(Succeed())
240+ certData := certOut.Bytes()
241+ keyOut := new(bytes.Buffer)
242+ Expect(pem.Encode(keyOut, &pem.Block{Type: "PRIVATE KEY", Bytes: keyBytes})).To(Succeed())
243+ cert, err := tls.X509KeyPair(certData, keyOut.Bytes())
244+ Expect(err).ToNot(HaveOccurred())
246+ certFile, err := os.CreateTemp("", "cert.*.pem")
247+ Expect(err).ToNot(HaveOccurred())
248+ caPath = certFile.Name()
249+ _, err = certFile.Write(certData)
250+ defer certFile.Close()
251+ Expect(err).ToNot(HaveOccurred())
255+ mr, err = miniredis.RunTLS(&tls.Config{Certificates: []tls.Certificate{cert}})
256+ Expect(err).ToNot(HaveOccurred())
260+ Expect(os.Remove(caPath)).ToNot(HaveOccurred())
265+ mr, err = miniredis.Run()
266+ Expect(err).ToNot(HaveOccurred())
269+ tests.RunSessionStoreTests(
270+ func(opts *options.SessionOptions, cookieOpts *options.Cookie) (sessionsapi.SessionStore, error) {
271+ // Set the connection URL
272+ opts.Type = options.RedisSessionStoreType
273+ opts.Redis.ConnectionURL = "redis://" + mr.Addr()
274+ opts.Redis.CAPath = caPath
276+ // Capture the session store so that we can close the client
278+ ss, err = NewRedisSessionStore(opts, cookieOpts)
281+ func(d time.Duration) error {
288+ Context("with insecure TLS connection", func() {
290+ certBytes, keyBytes, err := util.GenerateCert()
291+ Expect(err).ToNot(HaveOccurred())
292+ certOut := new(bytes.Buffer)
293+ Expect(pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: certBytes})).To(Succeed())
294+ keyOut := new(bytes.Buffer)
295+ Expect(pem.Encode(keyOut, &pem.Block{Type: "PRIVATE KEY", Bytes: keyBytes})).To(Succeed())
296+ cert, err := tls.X509KeyPair(certOut.Bytes(), keyOut.Bytes())
297+ Expect(err).ToNot(HaveOccurred())
301+ mr, err = miniredis.RunTLS(&tls.Config{Certificates: []tls.Certificate{cert}})
302+ Expect(err).ToNot(HaveOccurred())
309+ mr, err = miniredis.Run()
310+ Expect(err).ToNot(HaveOccurred())
313+ tests.RunSessionStoreTests(
314+ func(opts *options.SessionOptions, cookieOpts *options.Cookie) (sessionsapi.SessionStore, error) {
315+ // Set the connection URL
316+ opts.Type = options.RedisSessionStoreType
317+ opts.Redis.ConnectionURL = "redis://127.0.0.1:" + mr.Port() // func (*Miniredis) StartTLS listens on 127.0.0.1
318+ opts.Redis.InsecureSkipTLSVerify = true
320+ // Capture the session store so that we can close the client
322+ ss, err = NewRedisSessionStore(opts, cookieOpts)
325+ func(d time.Duration) error {