Skip to content

Commit

Permalink
Fix MaxAge check.
Browse files Browse the repository at this point in the history
[Resolves gorilla#96]
  • Loading branch information
jmcarp committed Jan 14, 2017
1 parent 83c8db3 commit 962c139
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 12 additions & 0 deletions store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/base64"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
)

Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}

0 comments on commit 962c139

Please sign in to comment.