Add tests for saving and loading a session in SessionStore
This commit is contained in:
		
							parent
							
								
									1c2ee715b3
								
							
						
					
					
						commit
						553cf89579
					
				|  | @ -110,6 +110,33 @@ var _ = Describe("NewSessionStore", func() { | ||||||
| 
 | 
 | ||||||
| 			CheckCookieOptions() | 			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() { | 	RunCookieTests := func() { | ||||||
|  | @ -141,7 +168,6 @@ var _ = Describe("NewSessionStore", func() { | ||||||
| 			}) | 			}) | ||||||
| 
 | 
 | ||||||
| 			SessionStoreInterfaceTests() | 			SessionStoreInterfaceTests() | ||||||
| 
 |  | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue