diff --git a/store.go b/store.go index 4ff6b6c..2d9ba21 100644 --- a/store.go +++ b/store.go @@ -206,14 +206,14 @@ func (s *FilesystemStore) New(r *http.Request, name string) (*Session, error) { // Save adds a single session to the response. // -// If the Options.MaxAge of the session is <= 0 then the session file will be +// If the Options.MaxAge of the session is < 0 then the session file will be // deleted from the store path. With this process it enforces the properly // session cookie handling so no need to trust in the cookie management in the // web browser. func (s *FilesystemStore) Save(r *http.Request, w http.ResponseWriter, session *Session) error { - // Delete if max-age is <= 0 - if session.Options.MaxAge <= 0 { + // Delete if max-age is < 0 + if session.Options.MaxAge < 0 { if err := s.erase(session); err != nil { return err } diff --git a/store_test.go b/store_test.go index bfc53fa..5d1c588 100644 --- a/store_test.go +++ b/store_test.go @@ -4,6 +4,8 @@ import ( "encoding/base64" "net/http" "net/http/httptest" + "os" + "path/filepath" "testing" ) @@ -96,6 +98,11 @@ func TestGH8FilesystemStoreDelete(t *testing.T) { if err != nil { t.Fatal("failed to delete session", err) } + + path := filepath.Join(os.TempDir(), "session_"+session.ID) + if _, err := os.Stat(path); !os.IsNotExist(err) { + t.Fatalf("failed to delete file: %s", path) + } } // Test delete filesystem store with max-age: 0 @@ -122,4 +129,9 @@ func TestGH8FilesystemStoreDelete2(t *testing.T) { if err != nil { t.Fatal("failed to delete session", err) } + + path := filepath.Join(os.TempDir(), "session_"+session.ID) + if _, err := os.Stat(path); os.IsNotExist(err) { + t.Fatalf("failed to preserve file: %s", path) + } }