Make a copy of Options for each new session

This commit is contained in:
Jacob Walker 2015-05-06 11:10:11 -05:00
parent 951665cd6d
commit cbe9f2afe4
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 { if session == nil {
return session, nil return session, nil
} }
session.Options = &(*db.Options) opts := *db.Options
session.Options = &(opts)
session.IsNew = true session.IsNew = true
var err error 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)
}
}