From 553cf89579d0c5aada6885f040792a32c331acbc Mon Sep 17 00:00:00 2001 From: Joel Speed Date: Tue, 7 May 2019 13:42:43 +0100 Subject: [PATCH] Add tests for saving and loading a session in SessionStore --- pkg/sessions/session_store_test.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/pkg/sessions/session_store_test.go b/pkg/sessions/session_store_test.go index 5bc6594..eb8ad2f 100644 --- a/pkg/sessions/session_store_test.go +++ b/pkg/sessions/session_store_test.go @@ -110,6 +110,33 @@ var _ = Describe("NewSessionStore", func() { CheckCookieOptions() }) + + Context("when LoadSession is called", func() { + var loadedSession *sessionsapi.SessionState + BeforeEach(func() { + req := httptest.NewRequest("GET", "http://example.com/", nil) + resp := httptest.NewRecorder() + err := ss.SaveSession(resp, req, session) + Expect(err).ToNot(HaveOccurred()) + + for _, cookie := range resp.Result().Cookies() { + request.AddCookie(cookie) + } + loadedSession, err = ss.LoadSession(request) + Expect(err).ToNot(HaveOccurred()) + }) + + It("loads a session equal to the original session", func() { + if cookieOpts.CookieSecret == "" { + // Only Email and User stored in session when encrypted + Expect(loadedSession.Email).To(Equal(session.Email)) + Expect(loadedSession.User).To(Equal(session.User)) + } else { + // All fields stored in session if encrypted + Expect(loadedSession).To(Equal(session)) + } + }) + }) } RunCookieTests := func() { @@ -141,7 +168,6 @@ var _ = Describe("NewSessionStore", func() { }) SessionStoreInterfaceTests() - }) }