Refactor session_store_test.go
This commit is contained in:
parent
b965f25c10
commit
1c2ee715b3
@ -27,6 +27,7 @@ var _ = Describe("NewSessionStore", func() {
|
|||||||
var request *http.Request
|
var request *http.Request
|
||||||
var response *httptest.ResponseRecorder
|
var response *httptest.ResponseRecorder
|
||||||
var session *sessionsapi.SessionState
|
var session *sessionsapi.SessionState
|
||||||
|
var ss sessionsapi.SessionStore
|
||||||
|
|
||||||
CheckCookieOptions := func() {
|
CheckCookieOptions := func() {
|
||||||
Context("the cookies returned", func() {
|
Context("the cookies returned", func() {
|
||||||
@ -72,71 +73,7 @@ var _ = Describe("NewSessionStore", func() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
RunCookieTests := func() {
|
SessionStoreInterfaceTests := func() {
|
||||||
var ss sessionsapi.SessionStore
|
|
||||||
|
|
||||||
Context("with default options", func() {
|
|
||||||
BeforeEach(func() {
|
|
||||||
var err error
|
|
||||||
ss, err = sessions.NewSessionStore(opts, cookieOpts)
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
})
|
|
||||||
|
|
||||||
Context("when SaveSession is called", func() {
|
|
||||||
BeforeEach(func() {
|
|
||||||
err := ss.SaveSession(response, request, session)
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
})
|
|
||||||
|
|
||||||
It("sets a `set-cookie` header in the response", func() {
|
|
||||||
Expect(response.Header().Get("set-cookie")).ToNot(BeEmpty())
|
|
||||||
})
|
|
||||||
|
|
||||||
CheckCookieOptions()
|
|
||||||
})
|
|
||||||
|
|
||||||
Context("when ClearSession is called", func() {
|
|
||||||
BeforeEach(func() {
|
|
||||||
cookie := cookies.MakeCookie(request,
|
|
||||||
cookieOpts.CookieName,
|
|
||||||
"foo",
|
|
||||||
cookieOpts.CookiePath,
|
|
||||||
cookieOpts.CookieDomain,
|
|
||||||
cookieOpts.CookieHTTPOnly,
|
|
||||||
cookieOpts.CookieSecure,
|
|
||||||
cookieOpts.CookieExpire,
|
|
||||||
time.Now(),
|
|
||||||
)
|
|
||||||
request.AddCookie(cookie)
|
|
||||||
err := ss.ClearSession(response, request)
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
})
|
|
||||||
|
|
||||||
It("sets a `set-cookie` header in the response", func() {
|
|
||||||
Expect(response.Header().Get("set-cookie")).ToNot(BeEmpty())
|
|
||||||
})
|
|
||||||
|
|
||||||
CheckCookieOptions()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
Context("with non-default options", func() {
|
|
||||||
BeforeEach(func() {
|
|
||||||
cookieOpts = &options.CookieOptions{
|
|
||||||
CookieName: "_cookie_name",
|
|
||||||
CookiePath: "/path",
|
|
||||||
CookieExpire: time.Duration(72) * time.Hour,
|
|
||||||
CookieRefresh: time.Duration(3600),
|
|
||||||
CookieSecure: false,
|
|
||||||
CookieHTTPOnly: false,
|
|
||||||
CookieDomain: "example.com",
|
|
||||||
}
|
|
||||||
|
|
||||||
var err error
|
|
||||||
ss, err = sessions.NewSessionStore(opts, cookieOpts)
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
})
|
|
||||||
|
|
||||||
Context("when SaveSession is called", func() {
|
Context("when SaveSession is called", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
err := ss.SaveSession(response, request, session)
|
err := ss.SaveSession(response, request, session)
|
||||||
@ -173,10 +110,43 @@ var _ = Describe("NewSessionStore", func() {
|
|||||||
|
|
||||||
CheckCookieOptions()
|
CheckCookieOptions()
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
RunCookieTests := func() {
|
||||||
|
Context("with default options", func() {
|
||||||
|
BeforeEach(func() {
|
||||||
|
var err error
|
||||||
|
ss, err = sessions.NewSessionStore(opts, cookieOpts)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
})
|
||||||
|
|
||||||
|
SessionStoreInterfaceTests()
|
||||||
|
})
|
||||||
|
|
||||||
|
Context("with non-default options", func() {
|
||||||
|
BeforeEach(func() {
|
||||||
|
cookieOpts = &options.CookieOptions{
|
||||||
|
CookieName: "_cookie_name",
|
||||||
|
CookiePath: "/path",
|
||||||
|
CookieExpire: time.Duration(72) * time.Hour,
|
||||||
|
CookieRefresh: time.Duration(3600),
|
||||||
|
CookieSecure: false,
|
||||||
|
CookieHTTPOnly: false,
|
||||||
|
CookieDomain: "example.com",
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
ss, err = sessions.NewSessionStore(opts, cookieOpts)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
})
|
||||||
|
|
||||||
|
SessionStoreInterfaceTests()
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
|
ss = nil
|
||||||
opts = &options.SessionOptions{}
|
opts = &options.SessionOptions{}
|
||||||
|
|
||||||
// Set default options in CookieOptions
|
// Set default options in CookieOptions
|
||||||
|
Loading…
Reference in New Issue
Block a user