Copy store options to sessions instead of referencing them.

Fixes GH-8
This commit is contained in:
Kamil Kisiel 2013-07-08 16:08:57 -07:00
parent c044c93603
commit ee375ad9ef
2 changed files with 52 additions and 2 deletions

View file

@ -73,7 +73,8 @@ func (s *CookieStore) Get(r *http.Request, name string) (*Session, error) {
// decoded session after the first call.
func (s *CookieStore) New(r *http.Request, name string) (*Session, error) {
session := NewSession(s, name)
session.Options = &(*s.Options)
opts := *s.Options
session.Options = &opts
session.IsNew = true
var err error
if c, errCookie := r.Cookie(name); errCookie == nil {
@ -148,7 +149,8 @@ func (s *FilesystemStore) Get(r *http.Request, name string) (*Session, error) {
// See CookieStore.New().
func (s *FilesystemStore) New(r *http.Request, name string) (*Session, error) {
session := NewSession(s, name)
session.Options = &(*s.Options)
opts := *s.Options
session.Options = &opts
session.IsNew = true
var err error
if c, errCookie := r.Cookie(name); errCookie == nil {

48
store_test.go Normal file
View file

@ -0,0 +1,48 @@
package sessions
import (
"net/http"
"testing"
)
// Test for GH-8 for CookieStore
func TestGH8CookieStore(t *testing.T) {
originalPath := "/"
store := NewCookieStore()
store.Options.Path = originalPath
req, err := http.NewRequest("GET", "http://www.example.com", nil)
if err != nil {
t.Fatal("failed to create request", err)
}
session, err := store.New(req, "hello")
if err != nil {
t.Fatal("failed to create session", err)
}
store.Options.Path = "/foo"
if session.Options.Path != originalPath {
t.Fatalf("bad session path: got %q, want %q", session.Options.Path, originalPath)
}
}
// Test for GH-8 for FilesystemStore
func TestGH8FilesystemStore(t *testing.T) {
originalPath := "/"
store := NewFilesystemStore("")
store.Options.Path = originalPath
req, err := http.NewRequest("GET", "http://www.example.com", nil)
if err != nil {
t.Fatal("failed to create request", err)
}
session, err := store.New(req, "hello")
if err != nil {
t.Fatal("failed to create session", err)
}
store.Options.Path = "/foo"
if session.Options.Path != originalPath {
t.Fatalf("bad session path: got %q, want %q", session.Options.Path, originalPath)
}
}