git.iko.soy/typeable/oauth2-proxy
on master help sign in
Run persistent tests with multiple option groups
bc3d75aJoel Speed
pkg/sessions/session_store_test.go+49−58
@@ -90,7 +90,46 @@ var _ = Describe("NewSessionStore", func() {
90 })
90 })
91 }
91 }
92
92
93+ // The following should only be for server stores
94+ PersistentSessionStoreTests := func() {
95+ Context("when Clear is called on a persistent store", func() {
96+ var loadedAfterClear *sessionsapi.SessionState
97+ BeforeEach(func() {
98+ req := httptest.NewRequest("GET", "http://example.com/", nil)
99+ saveResp := httptest.NewRecorder()
100+ err := ss.Save(saveResp, req, session)
101+ Expect(err).ToNot(HaveOccurred())
102+
103+ resultCookies := saveResp.Result().Cookies()
104+ for _, c := range resultCookies {
105+ request.AddCookie(c)
106+ }
107+ err = ss.Clear(response, request)
108+ Expect(err).ToNot(HaveOccurred())
109+
110+ loadReq := httptest.NewRequest("GET", "http://example.com/", nil)
111+ for _, c := range resultCookies {
112+ loadReq.AddCookie(c)
113+ }
114+
115+ loadedAfterClear, err = ss.Load(loadReq)
116+ // If we have cleared the session, Load should fail
117+ Expect(err).To(HaveOccurred())
118+ })
119+
120+ It("sets a `set-cookie` header in the response", func() {
121+ Expect(response.Header().Get("Set-Cookie")).ToNot(BeEmpty())
122+ })
123+
124+ It("attempting to Load returns an empty session", func() {
125+ Expect(loadedAfterClear).To(BeNil())
126+ })
127+
128+ CheckCookieOptions()
129+ })
130+ }
131+
93− SessionStoreInterfaceTests := func() {
132+ SessionStoreInterfaceTests := func(persistent bool) {
94 Context("when Save is called", func() {
133 Context("when Save is called", func() {
95 BeforeEach(func() {
134 BeforeEach(func() {
96 err := ss.Save(response, request, session)
135 err := ss.Save(response, request, session)
@@ -167,48 +206,13 @@ var _ = Describe("NewSessionStore", func() {
167 }
206 }
168 })
207 })
169 })
208 })
170− }
171−
172− // The following should only be for server stores
173− PersistentSessionStoreTests := func() {
174− Context("when Clear is called on a persistent store", func() {
175− var loadedAfterClear *sessionsapi.SessionState
176− BeforeEach(func() {
177− req := httptest.NewRequest("GET", "http://example.com/", nil)
178− saveResp := httptest.NewRecorder()
179− err := ss.Save(saveResp, req, session)
180− Expect(err).ToNot(HaveOccurred())
181−
182− resultCookies := saveResp.Result().Cookies()
183− for _, c := range resultCookies {
184− request.AddCookie(c)
185− }
186− err = ss.Clear(response, request)
187− Expect(err).ToNot(HaveOccurred())
188
209
189− loadReq := httptest.NewRequest("GET", "http://example.com/", nil)
210+ if persistent {
190− for _, c := range resultCookies {
211+ PersistentSessionStoreTests()
191− loadReq.AddCookie(c)
192− }
193−
194− loadedAfterClear, err = ss.Load(loadReq)
195− // If we have cleared the session, Load should fail
196− Expect(err).To(HaveOccurred())
197− })
198−
199− It("sets a `set-cookie` header in the response", func() {
200− Expect(response.Header().Get("Set-Cookie")).ToNot(BeEmpty())
201− })
202−
203− It("attempting to Load returns an empty session", func() {
204− Expect(loadedAfterClear).To(BeNil())
205− })
206−
207− CheckCookieOptions()
208− })
212+ }
209 }
213 }
210
214
211− RunSessionTests := func() {
215+ RunSessionTests := func(persistent bool) {
212 Context("with default options", func() {
216 Context("with default options", func() {
213 BeforeEach(func() {
217 BeforeEach(func() {
214 var err error
218 var err error
@@ -216,7 +220,7 @@ var _ = Describe("NewSessionStore", func() {
216 Expect(err).ToNot(HaveOccurred())
220 Expect(err).ToNot(HaveOccurred())
217 })
221 })
218
222
219− SessionStoreInterfaceTests()
223+ SessionStoreInterfaceTests(persistent)
220 })
224 })
221
225
222 Context("with non-default options", func() {
226 Context("with non-default options", func() {
@@ -236,7 +240,7 @@ var _ = Describe("NewSessionStore", func() {
236 Expect(err).ToNot(HaveOccurred())
240 Expect(err).ToNot(HaveOccurred())
237 })
241 })
238
242
239− SessionStoreInterfaceTests()
243+ SessionStoreInterfaceTests(persistent)
240 })
244 })
241
245
242 Context("with a cipher", func() {
246 Context("with a cipher", func() {
@@ -254,19 +258,7 @@ var _ = Describe("NewSessionStore", func() {
254 Expect(err).ToNot(HaveOccurred())
258 Expect(err).ToNot(HaveOccurred())
255 })
259 })
256
260
257− SessionStoreInterfaceTests()
261+ SessionStoreInterfaceTests(persistent)
258− })
259− }
260−
261− RunPersistentSessionStoreTests := func() {
262− Context("with default options", func() {
263− BeforeEach(func() {
264− var err error
265− ss, err = sessions.NewSessionStore(opts, cookieOpts)
266− Expect(err).ToNot(HaveOccurred())
267− })
268−
269− PersistentSessionStoreTests()
270 })
262 })
271 }
263 }
272
264
@@ -309,7 +301,7 @@ var _ = Describe("NewSessionStore", func() {
309 })
301 })
310
302
311 Context("the cookie.SessionStore", func() {
303 Context("the cookie.SessionStore", func() {
312− RunSessionTests()
304+ RunSessionTests(false)
313 })
305 })
314 })
306 })
315
307
@@ -330,8 +322,7 @@ var _ = Describe("NewSessionStore", func() {
330 })
322 })
331
323
332 Context("the redis.SessionStore", func() {
324 Context("the redis.SessionStore", func() {
333− RunSessionTests()
325+ RunSessionTests(true)
334− RunPersistentSessionStoreTests()
335 })
326 })
336 })
327 })
337
328