@@ -47,6 +47,35 @@ func TestSessionStore(t *testing.T) {
4747 RunSpecs(t, "Redis SessionStore")
4848}
4949
50+var (
51+ cert tls.Certificate
52+ caPath string
53+)
54+
55+var _ = BeforeSuite(func() {
56+ var err error
57+ certBytes, keyBytes, err := util.GenerateCert()
58+ Expect(err).ToNot(HaveOccurred())
59+ certOut := new(bytes.Buffer)
60+ Expect(pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: certBytes})).To(Succeed())
61+ certData := certOut.Bytes()
62+ keyOut := new(bytes.Buffer)
63+ Expect(pem.Encode(keyOut, &pem.Block{Type: "PRIVATE KEY", Bytes: keyBytes})).To(Succeed())
64+ cert, err = tls.X509KeyPair(certData, keyOut.Bytes())
65+ Expect(err).ToNot(HaveOccurred())
66+
67+ certFile, err := os.CreateTemp("", "cert.*.pem")
68+ Expect(err).ToNot(HaveOccurred())
69+ caPath = certFile.Name()
70+ _, err = certFile.Write(certData)
71+ defer certFile.Close()
72+ Expect(err).ToNot(HaveOccurred())
73+})
74+
75+var _ = AfterSuite(func() {
76+ Expect(os.Remove(caPath)).ToNot(HaveOccurred())
77+})
78+
5079var _ = Describe("Redis SessionStore Tests", func() {
5180 // helper interface to allow us to close client connections
5281 // All non-nil redis clients should implement this
@@ -229,36 +258,130 @@ var _ = Describe("Redis SessionStore Tests", func() {
229258 })
230259 })
231260
232− Context("with custom CA path", func() {
233− var caPath string
234−
261+ Context("with TLS connection", func() {
235262 BeforeEach(func() {
236− certBytes, keyBytes, err := util.GenerateCert()
263+ mr.Close()
264+
265+ var err error
266+ mr, err = miniredis.RunTLS(&tls.Config{Certificates: []tls.Certificate{cert}})
237267 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())
268+ })
269+ AfterEach(func() {
270+ mr.Close()
271+
272+ var err error
273+ mr, err = miniredis.Run()
244274 Expect(err).ToNot(HaveOccurred())
275+ })
276+
277+ Context("with standalone", func() {
278+ tests.RunSessionStoreTests(
279+ func(opts *options.SessionOptions, cookieOpts *options.Cookie) (sessionsapi.SessionStore, error) {
280+ // Set the connection URL
281+ opts.Type = options.RedisSessionStoreType
282+ opts.Redis.ConnectionURL = "rediss://" + mr.Addr()
283+ opts.Redis.CAPath = caPath
284+
285+ // Capture the session store so that we can close the client
286+ ss, err := NewRedisSessionStore(opts, cookieOpts)
287+ return ss, err
288+ },
289+ func(d time.Duration) error {
290+ mr.FastForward(d)
291+ return nil
292+ },
293+ )
294+ })
295+
296+ Context("with cluster", func() {
297+ tests.RunSessionStoreTests(
298+ func(opts *options.SessionOptions, cookieOpts *options.Cookie) (sessionsapi.SessionStore, error) {
299+ clusterAddr := "rediss://" + mr.Addr()
300+ opts.Type = options.RedisSessionStoreType
301+ opts.Redis.ClusterConnectionURLs = []string{clusterAddr}
302+ opts.Redis.UseCluster = true
303+ opts.Redis.CAPath = caPath
304+
305+ // Capture the session store so that we can close the client
306+ var err error
307+ ss, err = NewRedisSessionStore(opts, cookieOpts)
308+ return ss, err
309+ },
310+ func(d time.Duration) error {
311+ mr.FastForward(d)
312+ return nil
313+ },
314+ )
315+ })
316+ })
317+
318+ Context("with insecure TLS connection", func() {
319+ BeforeEach(func() {
320+ mr.Close()
245321
246− certFile, err := os.CreateTemp("", "cert.*.pem")
322+ var err error
323+ mr, err = miniredis.RunTLS(&tls.Config{Certificates: []tls.Certificate{cert}})
247324 Expect(err).ToNot(HaveOccurred())
248− caPath = certFile.Name()
249− _, err = certFile.Write(certData)
250− defer certFile.Close()
325+ })
326+ AfterEach(func() {
327+ mr.Close()
328+
329+ var err error
330+ mr, err = miniredis.Run()
251331 Expect(err).ToNot(HaveOccurred())
332+ })
333+
334+ Context("with standalone", func() {
335+ tests.RunSessionStoreTests(
336+ func(opts *options.SessionOptions, cookieOpts *options.Cookie) (sessionsapi.SessionStore, error) {
337+ // Set the connection URL
338+ opts.Type = options.RedisSessionStoreType
339+ opts.Redis.ConnectionURL = "rediss://" + mr.Addr()
340+ opts.Redis.InsecureSkipTLSVerify = true
341+
342+ // Capture the session store so that we can close the client
343+ ss, err := NewRedisSessionStore(opts, cookieOpts)
344+ return ss, err
345+ },
346+ func(d time.Duration) error {
347+ mr.FastForward(d)
348+ return nil
349+ },
350+ )
351+ })
352+
353+ Context("with cluster", func() {
354+ tests.RunSessionStoreTests(
355+ func(opts *options.SessionOptions, cookieOpts *options.Cookie) (sessionsapi.SessionStore, error) {
356+ clusterAddr := "rediss://" + mr.Addr()
357+ opts.Type = options.RedisSessionStoreType
358+ opts.Redis.ClusterConnectionURLs = []string{clusterAddr}
359+ opts.Redis.UseCluster = true
360+ opts.Redis.InsecureSkipTLSVerify = true
252361
362+ // Capture the session store so that we can close the client
363+ var err error
364+ ss, err = NewRedisSessionStore(opts, cookieOpts)
365+ return ss, err
366+ },
367+ func(d time.Duration) error {
368+ mr.FastForward(d)
369+ return nil
370+ },
371+ )
372+ })
373+ })
374+
375+ Context("with custom CA path", func() {
376+ BeforeEach(func() {
253377 mr.Close()
254378
379+ var err error
255380 mr, err = miniredis.RunTLS(&tls.Config{Certificates: []tls.Certificate{cert}})
256381 Expect(err).ToNot(HaveOccurred())
257382 })
258383
259384 AfterEach(func() {
260− Expect(os.Remove(caPath)).ToNot(HaveOccurred())
261−
262385 mr.Close()
263386
264387 var err error
@@ -287,17 +410,9 @@ var _ = Describe("Redis SessionStore Tests", func() {
287410
288411 Context("with insecure TLS connection", func() {
289412 BeforeEach(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())
298−
299413 mr.Close()
300414
415+ var err error
301416 mr, err = miniredis.RunTLS(&tls.Config{Certificates: []tls.Certificate{cert}})
302417 Expect(err).ToNot(HaveOccurred())
303418 })