Merge pull request #4 from jcbwlkr/copy_options

Make a copy of Options for each new session
This commit is contained in:
Anton Lindström 2015-05-07 14:29:52 +02:00
commit 794392bd2e
2 changed files with 30 additions and 1 deletions

View File

@ -74,7 +74,8 @@ func (db *PGStore) New(r *http.Request, name string) (*sessions.Session, error)
if session == nil {
return session, nil
}
session.Options = &(*db.Options)
opts := *db.Options
session.Options = &(opts)
session.IsNew = true
var err error

View File

@ -99,3 +99,31 @@ func TestPGStore(t *testing.T) {
}
}
func TestSessionOptionsAreUniquePerSession(t *testing.T) {
ss := NewPGStore(os.Getenv("PGSTORE_TEST_CONN"), []byte(secret))
if ss == nil {
t.Fatal("This test requires a real database")
}
defer ss.Close()
ss.Options.MaxAge = 900
req, err := http.NewRequest("GET", "http://www.example.com", nil)
if err != nil {
t.Fatal("Failed to create request", err)
}
session, err := ss.Get(req, "newsess")
if err != nil {
t.Fatal("Failed to create session", err)
}
session.Options.MaxAge = -1
if ss.Options.MaxAge != 900 {
t.Fatalf("PGStore.Options.MaxAge: expected %d, got %d", 900, ss.Options.MaxAge)
}
}