From 1d29a0d09458ccc456d9c6d677038786a82592a5 Mon Sep 17 00:00:00 2001 From: Joel Speed Date: Wed, 8 May 2019 16:36:28 +0100 Subject: [PATCH] Drop Session suffix from SessionStore methods --- pkg/apis/sessions/interfaces.go | 6 +++--- pkg/sessions/cookie/session_store.go | 12 ++++++------ pkg/sessions/session_store_test.go | 14 +++++++------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/apis/sessions/interfaces.go b/pkg/apis/sessions/interfaces.go index 254909d..34d945f 100644 --- a/pkg/apis/sessions/interfaces.go +++ b/pkg/apis/sessions/interfaces.go @@ -6,7 +6,7 @@ import ( // SessionStore is an interface to storing user sessions in the proxy type SessionStore interface { - SaveSession(rw http.ResponseWriter, req *http.Request, s *SessionState) error - LoadSession(req *http.Request) (*SessionState, error) - ClearSession(rw http.ResponseWriter, req *http.Request) error + Save(rw http.ResponseWriter, req *http.Request, s *SessionState) error + Load(req *http.Request) (*SessionState, error) + Clear(rw http.ResponseWriter, req *http.Request) error } diff --git a/pkg/sessions/cookie/session_store.go b/pkg/sessions/cookie/session_store.go index b4db9ba..14c0b71 100644 --- a/pkg/sessions/cookie/session_store.go +++ b/pkg/sessions/cookie/session_store.go @@ -37,9 +37,9 @@ type SessionStore struct { CookieSecure bool } -// SaveSession takes a sessions.SessionState and stores the information from it +// Save takes a sessions.SessionState and stores the information from it // within Cookies set on the HTTP response writer -func (s *SessionStore) SaveSession(rw http.ResponseWriter, req *http.Request, ss *sessions.SessionState) error { +func (s *SessionStore) Save(rw http.ResponseWriter, req *http.Request, ss *sessions.SessionState) error { value, err := utils.CookieForSession(ss, s.CookieCipher) if err != nil { return err @@ -48,9 +48,9 @@ func (s *SessionStore) SaveSession(rw http.ResponseWriter, req *http.Request, ss return nil } -// LoadSession reads sessions.SessionState information from Cookies within the +// Load reads sessions.SessionState information from Cookies within the // HTTP request object -func (s *SessionStore) LoadSession(req *http.Request) (*sessions.SessionState, error) { +func (s *SessionStore) Load(req *http.Request) (*sessions.SessionState, error) { c, err := loadCookie(req, s.CookieName) if err != nil { // always http.ErrNoCookie @@ -68,9 +68,9 @@ func (s *SessionStore) LoadSession(req *http.Request) (*sessions.SessionState, e return session, nil } -// ClearSession clears any saved session information by writing a cookie to +// Clear clears any saved session information by writing a cookie to // clear the session -func (s *SessionStore) ClearSession(rw http.ResponseWriter, req *http.Request) error { +func (s *SessionStore) Clear(rw http.ResponseWriter, req *http.Request) error { var cookies []*http.Cookie // matches CookieName, CookieName_ diff --git a/pkg/sessions/session_store_test.go b/pkg/sessions/session_store_test.go index 31b9a14..0ceea66 100644 --- a/pkg/sessions/session_store_test.go +++ b/pkg/sessions/session_store_test.go @@ -76,9 +76,9 @@ var _ = Describe("NewSessionStore", func() { } SessionStoreInterfaceTests := func() { - Context("when SaveSession is called", func() { + Context("when Save is called", func() { BeforeEach(func() { - err := ss.SaveSession(response, request, session) + err := ss.Save(response, request, session) Expect(err).ToNot(HaveOccurred()) }) @@ -89,7 +89,7 @@ var _ = Describe("NewSessionStore", func() { CheckCookieOptions() }) - Context("when ClearSession is called", func() { + Context("when Clear is called", func() { BeforeEach(func() { cookie := cookies.MakeCookie(request, cookieOpts.CookieName, @@ -102,7 +102,7 @@ var _ = Describe("NewSessionStore", func() { time.Now(), ) request.AddCookie(cookie) - err := ss.ClearSession(response, request) + err := ss.Clear(response, request) Expect(err).ToNot(HaveOccurred()) }) @@ -113,18 +113,18 @@ var _ = Describe("NewSessionStore", func() { CheckCookieOptions() }) - Context("when LoadSession is called", func() { + Context("when Load 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) + err := ss.Save(resp, req, session) Expect(err).ToNot(HaveOccurred()) for _, cookie := range resp.Result().Cookies() { request.AddCookie(cookie) } - loadedSession, err = ss.LoadSession(request) + loadedSession, err = ss.Load(request) Expect(err).ToNot(HaveOccurred()) })