@@ -47,6 +47,35 @@ func TestSessionStore(t *testing.T) {
47 RunSpecs(t, "Redis SessionStore")
47 RunSpecs(t, "Redis SessionStore")
55+var _ = BeforeSuite(func() {
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())
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())
75+var _ = AfterSuite(func() {
76+ Expect(os.Remove(caPath)).ToNot(HaveOccurred())
50var _ = Describe("Redis SessionStore Tests", func() {
79var _ = Describe("Redis SessionStore Tests", func() {
51 // helper interface to allow us to close client connections
80 // helper interface to allow us to close client connections
52 // All non-nil redis clients should implement this
81 // All non-nil redis clients should implement this
@@ -229,36 +258,130 @@ var _ = Describe("Redis SessionStore Tests", func() {
232− Context("with custom CA path", func() {
261+ Context("with TLS connection", func() {
235 BeforeEach(func() {
262 BeforeEach(func() {
236− certBytes, keyBytes, err := util.GenerateCert()
263+ mr.Close()
266+ mr, err = miniredis.RunTLS(&tls.Config{Certificates: []tls.Certificate{cert}})
237 Expect(err).ToNot(HaveOccurred())
267 Expect(err).ToNot(HaveOccurred())
238− certOut := new(bytes.Buffer)
268+ })
239− Expect(pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: certBytes})).To(Succeed())
269+ AfterEach(func() {
240− certData := certOut.Bytes()
270+ mr.Close()
241− keyOut := new(bytes.Buffer)
271+
242− Expect(pem.Encode(keyOut, &pem.Block{Type: "PRIVATE KEY", Bytes: keyBytes})).To(Succeed())
272+ var err error
243− cert, err := tls.X509KeyPair(certData, keyOut.Bytes())
273+ mr, err = miniredis.Run()
244 Expect(err).ToNot(HaveOccurred())
274 Expect(err).ToNot(HaveOccurred())
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
285+ // Capture the session store so that we can close the client
286+ ss, err := NewRedisSessionStore(opts, cookieOpts)
289+ func(d time.Duration) error {
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
305+ // Capture the session store so that we can close the client
307+ ss, err = NewRedisSessionStore(opts, cookieOpts)
310+ func(d time.Duration) error {
318+ Context("with insecure TLS connection", func() {
246− certFile, err := os.CreateTemp("", "cert.*.pem")
322+ var err error
323+ mr, err = miniredis.RunTLS(&tls.Config{Certificates: []tls.Certificate{cert}})
247 Expect(err).ToNot(HaveOccurred())
324 Expect(err).ToNot(HaveOccurred())
248− caPath = certFile.Name()
325+ })
249− _, err = certFile.Write(certData)
326+ AfterEach(func() {
250− defer certFile.Close()
327+ mr.Close()
330+ mr, err = miniredis.Run()
251 Expect(err).ToNot(HaveOccurred())
331 Expect(err).ToNot(HaveOccurred())
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
342+ // Capture the session store so that we can close the client
343+ ss, err := NewRedisSessionStore(opts, cookieOpts)
346+ func(d time.Duration) error {
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
362+ // Capture the session store so that we can close the client
364+ ss, err = NewRedisSessionStore(opts, cookieOpts)
367+ func(d time.Duration) error {
375+ Context("with custom CA path", func() {
253 mr.Close()
377 mr.Close()
255 mr, err = miniredis.RunTLS(&tls.Config{Certificates: []tls.Certificate{cert}})
380 mr, err = miniredis.RunTLS(&tls.Config{Certificates: []tls.Certificate{cert}})
256 Expect(err).ToNot(HaveOccurred())
381 Expect(err).ToNot(HaveOccurred())
259 AfterEach(func() {
384 AfterEach(func() {
260− Expect(os.Remove(caPath)).ToNot(HaveOccurred())
262 mr.Close()
385 mr.Close()
264 var err error
387 var err error
@@ -287,17 +410,9 @@ var _ = Describe("Redis SessionStore Tests", func() {
288 Context("with insecure TLS connection", func() {
411 Context("with insecure TLS connection", func() {
289 BeforeEach(func() {
412 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())
299 mr.Close()
413 mr.Close()
301 mr, err = miniredis.RunTLS(&tls.Config{Certificates: []tls.Certificate{cert}})
416 mr, err = miniredis.RunTLS(&tls.Config{Certificates: []tls.Certificate{cert}})
302 Expect(err).ToNot(HaveOccurred())
417 Expect(err).ToNot(HaveOccurred())