Check SaveSession works when an existing session is present
(cherry picked from commit 9dc1a96d81
)
This commit is contained in:
parent
ae0258a203
commit
2e2327af6c
@ -195,7 +195,14 @@ func (store *SessionStore) storeValue(value string, expiresOn time.Time, request
|
|||||||
var ticket *TicketData
|
var ticket *TicketData
|
||||||
if requestCookie != nil {
|
if requestCookie != nil {
|
||||||
var err error
|
var err error
|
||||||
ticket, err = decodeTicket(store.CookieOptions.CookieName, requestCookie.Value)
|
val, _, ok := cookie.Validate(requestCookie, store.CookieOptions.CookieSecret, store.CookieOptions.CookieExpire)
|
||||||
|
if !ok {
|
||||||
|
ticket, err = newTicket()
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error creating new ticket: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ticket, err = decodeTicket(store.CookieOptions.CookieName, val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -137,6 +137,7 @@ var _ = Describe("NewSessionStore", func() {
|
|||||||
|
|
||||||
SessionStoreInterfaceTests := func(persistent bool) {
|
SessionStoreInterfaceTests := func(persistent bool) {
|
||||||
Context("when Save is called", func() {
|
Context("when Save is called", func() {
|
||||||
|
Context("with no existing session", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
err := ss.Save(response, request, session)
|
err := ss.Save(response, request, session)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
@ -149,6 +150,33 @@ var _ = Describe("NewSessionStore", func() {
|
|||||||
It("Ensures the session CreatedAt is not zero", func() {
|
It("Ensures the session CreatedAt is not zero", func() {
|
||||||
Expect(session.CreatedAt.IsZero()).To(BeFalse())
|
Expect(session.CreatedAt.IsZero()).To(BeFalse())
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
Context("with an expired saved session", func() {
|
||||||
|
var err error
|
||||||
|
BeforeEach(func() {
|
||||||
|
By("saving a session")
|
||||||
|
req := httptest.NewRequest("GET", "http://example.com/", nil)
|
||||||
|
saveResp := httptest.NewRecorder()
|
||||||
|
err = ss.Save(saveResp, req, session)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
By("and clearing the session")
|
||||||
|
for _, c := range saveResp.Result().Cookies() {
|
||||||
|
request.AddCookie(c)
|
||||||
|
}
|
||||||
|
clearResp := httptest.NewRecorder()
|
||||||
|
err = ss.Clear(clearResp, request)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
By("then saving a request with the cleared session")
|
||||||
|
err = ss.Save(response, request, session)
|
||||||
|
})
|
||||||
|
|
||||||
|
It("no error should occur", func() {
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
CheckCookieOptions()
|
CheckCookieOptions()
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user