From 389ffe9985d674a51cb3b0424ee08bfc74729061 Mon Sep 17 00:00:00 2001 From: Ralf Geschke Date: Mon, 27 Nov 2023 02:20:28 +0100 Subject: [PATCH 1/8] Update go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index f5cffcd..4265391 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/gin-contrib/sessions +module github.com/geschke/gin-contrib-sessions go 1.18 From ceae2ed6370ef49c796df81d150d310e94435940 Mon Sep 17 00:00:00 2001 From: Ralf Geschke Date: Mon, 27 Nov 2023 03:07:14 +0100 Subject: [PATCH 2/8] Update cookie.go --- cookie/cookie.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookie/cookie.go b/cookie/cookie.go index 1f32b97..770fe38 100644 --- a/cookie/cookie.go +++ b/cookie/cookie.go @@ -1,7 +1,7 @@ package cookie import ( - "github.com/gin-contrib/sessions" + "github.com/geschke/gin-contrib-sessions" gsessions "github.com/gorilla/sessions" ) From 234f297f9c978c9713cfd51f8f7d22448179d812 Mon Sep 17 00:00:00 2001 From: Ralf Geschke Date: Mon, 27 Nov 2023 03:38:31 +0100 Subject: [PATCH 3/8] add filesystem store as provided by Gorilla sessions --- filesystem/filesystem.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 filesystem/filesystem.go diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go new file mode 100644 index 0000000..c7e9934 --- /dev/null +++ b/filesystem/filesystem.go @@ -0,0 +1,31 @@ +package filesystem + +import ( + "github.com/geschke/gin-contrib-sessions" + gsessions "github.com/gorilla/sessions" +) + +type Store interface { + sessions.Store +} + +// Keys are defined in pairs to allow key rotation, but the common case is to set a single +// authentication key and optionally an encryption key. +// +// The first key in a pair is used for authentication and the second for encryption. The +// encryption key can be set to nil or omitted in the last pair, but the authentication key +// is required in all pairs. +// +// It is recommended to use an authentication key with 32 or 64 bytes. The encryption key, +// if set, must be either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256 modes. +func NewStore(path string, keyPairs ...[]byte) Store { + return &store{gsessions.NewFilesystemStore(path, keyPairs...)} +} + +type store struct { + *gsessions.FilesystemStore +} + +func (c *store) Options(options sessions.Options) { + c.FilesystemStore.Options = options.ToGorillaOptions() +} From be12f9f767bf32fffd117487432d139d46be0e25 Mon Sep 17 00:00:00 2001 From: Ralf Geschke Date: Mon, 27 Nov 2023 03:46:19 +0100 Subject: [PATCH 4/8] Add filesystem backend example --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index 2e6f708..d27fc00 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ Gin middleware for session management with multi-backend support: - [GoRM](#gorm) - [memstore](#memstore) - [PostgreSQL](#postgresql) +- [Filesystem](#Filesystem) ## Usage @@ -456,3 +457,40 @@ func main() { r.Run(":8000") } ``` + +### Filesystem + +```go +package main + +import ( + "github.com/gin-contrib/sessions" + "github.com/gin-contrib/sessions/filesystem" + "github.com/gin-gonic/gin" +) + +func main() { + r := gin.Default() + + var sessionPath = "/tmp/" // in case of empty string, the system's default tmp folder is used + + store := filesystem.NewStore(sessionPath,[]byte("secret")) + r.Use(sessions.Sessions("mysession", store)) + + r.GET("/incr", func(c *gin.Context) { + session := sessions.Default(c) + var count int + v := session.Get("count") + if v == nil { + count = 0 + } else { + count = v.(int) + count++ + } + session.Set("count", count) + session.Save() + c.JSON(200, gin.H{"count": count}) + }) + r.Run(":8000") +} +``` From 05c1d5e59faee35652a72d3cdb89c3caaefba807 Mon Sep 17 00:00:00 2001 From: Ralf Geschke Date: Mon, 27 Nov 2023 16:32:03 +0100 Subject: [PATCH 5/8] add filesystem tester --- filesystem/filesystem_test.go | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 filesystem/filesystem_test.go diff --git a/filesystem/filesystem_test.go b/filesystem/filesystem_test.go new file mode 100644 index 0000000..5228b32 --- /dev/null +++ b/filesystem/filesystem_test.go @@ -0,0 +1,39 @@ +package filesystem + +import ( + "testing" + + "github.com/geschke/gin-contrib-sessions/filesystem" + "github.com/geschke/gin-contrib-sessions/tester" +) + +const sessionPath = "/tmp/" + +var newStore = func(_ *testing.T) sessions.Store { + store := filesystem.NewStore(sessionPath, []byte("secret")) + return store +} + +func TestFilesystem_SessionGetSet(t *testing.T) { + tester.GetSet(t, newStore) +} + +func TestFilesystem_SessionDeleteKey(t *testing.T) { + tester.DeleteKey(t, newStore) +} + +func TestFilesystem_SessionFlashes(t *testing.T) { + tester.Flashes(t, newStore) +} + +func TestFilesystem_SessionClear(t *testing.T) { + tester.Clear(t, newStore) +} + +func TestFilesystem_SessionOptions(t *testing.T) { + tester.Options(t, newStore) +} + +func TestFilesystem_SessionMany(t *testing.T) { + tester.Many(t, newStore) +} From e46103f1f1b5b179f51c691a27ed358365ec64b7 Mon Sep 17 00:00:00 2001 From: Ralf Geschke Date: Tue, 28 Nov 2023 18:28:37 +0100 Subject: [PATCH 6/8] add example file, add some debug output in tests --- _example/filesystem/main.go | 30 ++++++++++++++++++++++++ cookie/cookie.go | 2 +- cookie/cookie_test.go | 9 ++++--- filesystem/filesystem.go | 2 +- filesystem/filesystem_test.go | 4 +++- go.mod | 9 ++++--- go.sum | 13 ++++++---- tester/tester.go | 12 +++++++++- tester/tester_options_samesite_go1.11.go | 6 ++++- 9 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 _example/filesystem/main.go diff --git a/_example/filesystem/main.go b/_example/filesystem/main.go new file mode 100644 index 0000000..3ea148d --- /dev/null +++ b/_example/filesystem/main.go @@ -0,0 +1,30 @@ +package main + +import ( + sessions "github.com/geschke/gin-contrib-sessions" + "github.com/geschke/gin-contrib-sessions/filesystem" + "github.com/gin-gonic/gin" +) + +func main() { + sessionPath := "/tmp/" + r := gin.Default() + store := filesystem.NewStore(sessionPath, []byte("secret")) + r.Use(sessions.Sessions("mysession", store)) + + r.GET("/incr", func(c *gin.Context) { + session := sessions.Default(c) + var count int + v := session.Get("count") + if v == nil { + count = 0 + } else { + count = v.(int) + count++ + } + session.Set("count", count) + session.Save() + c.JSON(200, gin.H{"count": count}) + }) + r.Run(":8000") +} diff --git a/cookie/cookie.go b/cookie/cookie.go index 770fe38..c250b10 100644 --- a/cookie/cookie.go +++ b/cookie/cookie.go @@ -1,7 +1,7 @@ package cookie import ( - "github.com/geschke/gin-contrib-sessions" + sessions "github.com/geschke/gin-contrib-sessions" gsessions "github.com/gorilla/sessions" ) diff --git a/cookie/cookie_test.go b/cookie/cookie_test.go index 9f2da68..a2e3f7a 100644 --- a/cookie/cookie_test.go +++ b/cookie/cookie_test.go @@ -3,16 +3,18 @@ package cookie import ( "testing" - "github.com/gin-contrib/sessions" - "github.com/gin-contrib/sessions/tester" + sessions "github.com/geschke/gin-contrib-sessions" + "github.com/geschke/gin-contrib-sessions/cookie" + "github.com/geschke/gin-contrib-sessions/tester" ) var newStore = func(_ *testing.T) sessions.Store { - store := NewStore([]byte("secret")) + store := cookie.NewStore([]byte("secret")) return store } func TestCookie_SessionGetSet(t *testing.T) { + t.Logf("in GetSet") tester.GetSet(t, newStore) } @@ -29,6 +31,7 @@ func TestCookie_SessionClear(t *testing.T) { } func TestCookie_SessionOptions(t *testing.T) { + t.Logf("in TestCookieSessionOptions") tester.Options(t, newStore) } diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index c7e9934..bde3bdb 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go @@ -1,7 +1,7 @@ package filesystem import ( - "github.com/geschke/gin-contrib-sessions" + sessions "github.com/geschke/gin-contrib-sessions" gsessions "github.com/gorilla/sessions" ) diff --git a/filesystem/filesystem_test.go b/filesystem/filesystem_test.go index 5228b32..1949931 100644 --- a/filesystem/filesystem_test.go +++ b/filesystem/filesystem_test.go @@ -1,13 +1,15 @@ package filesystem import ( + "os" "testing" + sessions "github.com/geschke/gin-contrib-sessions" "github.com/geschke/gin-contrib-sessions/filesystem" "github.com/geschke/gin-contrib-sessions/tester" ) -const sessionPath = "/tmp/" +var sessionPath = os.TempDir() var newStore = func(_ *testing.T) sessions.Store { store := filesystem.NewStore(sessionPath, []byte("secret")) diff --git a/go.mod b/go.mod index 4265391..eefe2c2 100644 --- a/go.mod +++ b/go.mod @@ -8,11 +8,12 @@ require ( github.com/bos-hieu/mongostore v0.0.3 github.com/bradfitz/gomemcache v0.0.0-20230905024940-24af94b03874 github.com/bradleypeabody/gorilla-sessions-memcache v0.0.0-20181103040241-659414f458e1 + github.com/gin-contrib/sessions v0.0.5 github.com/gin-gonic/gin v1.9.1 github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 github.com/gomodule/redigo v2.0.0+incompatible github.com/gorilla/context v1.1.1 - github.com/gorilla/sessions v1.2.1 + github.com/gorilla/sessions v1.2.2 github.com/kidstuff/mongostore v0.0.0-20181113001930-e650cd85ee4b github.com/memcachier/mc v2.0.1+incompatible github.com/quasoft/memstore v0.0.0-20191010062613-2bce066d2b0b @@ -33,7 +34,7 @@ require ( github.com/go-playground/validator/v10 v10.15.5 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/golang/snappy v0.0.4 // indirect - github.com/gorilla/securecookie v1.1.1 // indirect + github.com/gorilla/securecookie v1.1.2 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/json-iterator/go v1.1.12 // indirect @@ -42,7 +43,7 @@ require ( github.com/leodido/go-urn v1.2.4 // indirect github.com/lib/pq v1.10.9 // indirect github.com/mattn/go-isatty v0.0.19 // indirect - github.com/mattn/go-sqlite3 v1.14.16 // indirect + github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/montanaflynn/stats v0.7.1 // indirect @@ -62,3 +63,5 @@ require ( google.golang.org/protobuf v1.31.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + +//replace github.com/gorilla/sessions => ../gorillasessions diff --git a/go.sum b/go.sum index 6380871..db27970 100644 --- a/go.sum +++ b/go.sum @@ -29,6 +29,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/gin-contrib/sessions v0.0.5 h1:CATtfHmLMQrMNpJRgzjWXD7worTh7g7ritsQfmF+0jE= +github.com/gin-contrib/sessions v0.0.5/go.mod h1:vYAuaUPqie3WUSsft6HUlCjlwwoJQs97miaG2+7neKY= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= @@ -60,14 +62,17 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= -github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= +github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA= +github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo= github.com/gorilla/sessions v1.1.1/go.mod h1:8KCfur6+4Mqcc6S0FEfKuN15Vl5MgXW92AE8ovaJD0w= -github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= +github.com/gorilla/sessions v1.2.2 h1:lqzMYz6bOfvn2WriPUjNByzeXIlVzURcPmgMczkmTjY= +github.com/gorilla/sessions v1.2.2/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ= github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0= github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo= github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= @@ -157,8 +162,8 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= -github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= -github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= +github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U= +github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/memcachier/mc v2.0.1+incompatible h1:s8EDz0xrJLP8goitwZOoq1vA/sm0fPS4X3KAF0nyhWQ= github.com/memcachier/mc v2.0.1+incompatible/go.mod h1:7bkvFE61leUBvXz+yxsOnGBQSZpBSPIMUQSmmSHvuXc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= diff --git a/tester/tester.go b/tester/tester.go index cecc913..31e4704 100644 --- a/tester/tester.go +++ b/tester/tester.go @@ -4,12 +4,13 @@ package tester import ( + "log" "net/http" "net/http/httptest" "strings" "testing" - "github.com/gin-contrib/sessions" + sessions "github.com/geschke/gin-contrib-sessions" "github.com/gin-gonic/gin" ) @@ -24,6 +25,7 @@ func init() { } func GetSet(t *testing.T, newStore storeFactory) { + log.Println("in GetSet") r := gin.Default() r.Use(sessions.Sessions(sessionName, newStore(t))) @@ -49,6 +51,7 @@ func GetSet(t *testing.T, newStore storeFactory) { res2 := httptest.NewRecorder() req2, _ := http.NewRequest("GET", "/get", nil) + t.Logf(strings.Join(res1.Header().Values("Set-Cookie"), ";")) copyCookies(req2, res1) r.ServeHTTP(res2, req2) } @@ -183,6 +186,7 @@ func Clear(t *testing.T, newStore storeFactory) { } func Options(t *testing.T, newStore storeFactory) { + log.Println("in Options in tester") r := gin.Default() store := newStore(t) store.Options(sessions.Options{ @@ -244,12 +248,18 @@ func Options(t *testing.T, newStore storeFactory) { res4 := httptest.NewRecorder() req4, _ := http.NewRequest("GET", "/expire", nil) + t.Logf("test expire") + t.Logf(strings.Join(res4.Header().Values("Set-Cookie"), ";")) r.ServeHTTP(res4, req4) res5 := httptest.NewRecorder() req5, _ := http.NewRequest("GET", "/check", nil) r.ServeHTTP(res5, req5) + t.Logf("vor path und domain") + t.Logf(strings.Join(res1.Header().Values("Set-Cookie"), ";")) + t.Logf(strings.Join(res2.Header().Values("Set-Cookie"), ";")) + for _, c := range res1.Header().Values("Set-Cookie") { s := strings.Split(c, ";") if s[1] != " Path=/foo/bar/bat" { diff --git a/tester/tester_options_samesite_go1.11.go b/tester/tester_options_samesite_go1.11.go index 8379148..7241515 100644 --- a/tester/tester_options_samesite_go1.11.go +++ b/tester/tester_options_samesite_go1.11.go @@ -4,12 +4,13 @@ package tester import ( + "log" "net/http" "net/http/httptest" "strings" "testing" - "github.com/gin-contrib/sessions" + sessions "github.com/geschke/gin-contrib-sessions" "github.com/gin-gonic/gin" ) @@ -28,7 +29,10 @@ func testOptionSameSitego(t *testing.T, r *gin.Engine) { req3, _ := http.NewRequest("GET", "/sameSite", nil) r.ServeHTTP(res3, req3) + log.Println("Here we are!") s := strings.Split(res3.Header().Get("Set-Cookie"), ";") + log.Println(s) + log.Println(res3.Header().Get("Set-Cookie")) if s[1] != " SameSite=Strict" { t.Error("Error writing samesite with options:", s[1]) } From 174a0e2c540cfb35fb50335add0ff5a36a2ef5ef Mon Sep 17 00:00:00 2001 From: Ralf Geschke Date: Tue, 28 Nov 2023 19:00:53 +0100 Subject: [PATCH 7/8] reset package / module paths, so it should ready to merge --- cookie/cookie.go | 2 +- cookie/cookie_test.go | 9 +-- filesystem/filesystem.go | 2 +- filesystem/filesystem_test.go | 82 ++++++++++++------------ go.mod | 4 +- tester/tester.go | 12 +--- tester/tester_options_samesite_go1.11.go | 6 +- 7 files changed, 49 insertions(+), 68 deletions(-) diff --git a/cookie/cookie.go b/cookie/cookie.go index c250b10..1f32b97 100644 --- a/cookie/cookie.go +++ b/cookie/cookie.go @@ -1,7 +1,7 @@ package cookie import ( - sessions "github.com/geschke/gin-contrib-sessions" + "github.com/gin-contrib/sessions" gsessions "github.com/gorilla/sessions" ) diff --git a/cookie/cookie_test.go b/cookie/cookie_test.go index a2e3f7a..9f2da68 100644 --- a/cookie/cookie_test.go +++ b/cookie/cookie_test.go @@ -3,18 +3,16 @@ package cookie import ( "testing" - sessions "github.com/geschke/gin-contrib-sessions" - "github.com/geschke/gin-contrib-sessions/cookie" - "github.com/geschke/gin-contrib-sessions/tester" + "github.com/gin-contrib/sessions" + "github.com/gin-contrib/sessions/tester" ) var newStore = func(_ *testing.T) sessions.Store { - store := cookie.NewStore([]byte("secret")) + store := NewStore([]byte("secret")) return store } func TestCookie_SessionGetSet(t *testing.T) { - t.Logf("in GetSet") tester.GetSet(t, newStore) } @@ -31,7 +29,6 @@ func TestCookie_SessionClear(t *testing.T) { } func TestCookie_SessionOptions(t *testing.T) { - t.Logf("in TestCookieSessionOptions") tester.Options(t, newStore) } diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index bde3bdb..7aa1991 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go @@ -1,7 +1,7 @@ package filesystem import ( - sessions "github.com/geschke/gin-contrib-sessions" + "github.com/gin-contrib/sessions" gsessions "github.com/gorilla/sessions" ) diff --git a/filesystem/filesystem_test.go b/filesystem/filesystem_test.go index 1949931..e2b4c26 100644 --- a/filesystem/filesystem_test.go +++ b/filesystem/filesystem_test.go @@ -1,41 +1,41 @@ -package filesystem - -import ( - "os" - "testing" - - sessions "github.com/geschke/gin-contrib-sessions" - "github.com/geschke/gin-contrib-sessions/filesystem" - "github.com/geschke/gin-contrib-sessions/tester" -) - -var sessionPath = os.TempDir() - -var newStore = func(_ *testing.T) sessions.Store { - store := filesystem.NewStore(sessionPath, []byte("secret")) - return store -} - -func TestFilesystem_SessionGetSet(t *testing.T) { - tester.GetSet(t, newStore) -} - -func TestFilesystem_SessionDeleteKey(t *testing.T) { - tester.DeleteKey(t, newStore) -} - -func TestFilesystem_SessionFlashes(t *testing.T) { - tester.Flashes(t, newStore) -} - -func TestFilesystem_SessionClear(t *testing.T) { - tester.Clear(t, newStore) -} - -func TestFilesystem_SessionOptions(t *testing.T) { - tester.Options(t, newStore) -} - -func TestFilesystem_SessionMany(t *testing.T) { - tester.Many(t, newStore) -} +package filesystem + +import ( + "os" + "testing" + + "github.com/gin-contrib/sessions" + "github.com/gin-contrib/sessions/filesystem" + "github.com/gin-contrib/sessions/tester" +) + +var sessionPath = os.TempDir() + +var newStore = func(_ *testing.T) sessions.Store { + store := filesystem.NewStore(sessionPath, []byte("secret")) + return store +} + +func TestFilesystem_SessionGetSet(t *testing.T) { + tester.GetSet(t, newStore) +} + +func TestFilesystem_SessionDeleteKey(t *testing.T) { + tester.DeleteKey(t, newStore) +} + +func TestFilesystem_SessionFlashes(t *testing.T) { + tester.Flashes(t, newStore) +} + +func TestFilesystem_SessionClear(t *testing.T) { + tester.Clear(t, newStore) +} + +func TestFilesystem_SessionOptions(t *testing.T) { + tester.Options(t, newStore) +} + +func TestFilesystem_SessionMany(t *testing.T) { + tester.Many(t, newStore) +} diff --git a/go.mod b/go.mod index eefe2c2..7b832b2 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/geschke/gin-contrib-sessions +module github.com/gin-contrib/sessions go 1.18 @@ -63,5 +63,3 @@ require ( google.golang.org/protobuf v1.31.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) - -//replace github.com/gorilla/sessions => ../gorillasessions diff --git a/tester/tester.go b/tester/tester.go index 31e4704..cecc913 100644 --- a/tester/tester.go +++ b/tester/tester.go @@ -4,13 +4,12 @@ package tester import ( - "log" "net/http" "net/http/httptest" "strings" "testing" - sessions "github.com/geschke/gin-contrib-sessions" + "github.com/gin-contrib/sessions" "github.com/gin-gonic/gin" ) @@ -25,7 +24,6 @@ func init() { } func GetSet(t *testing.T, newStore storeFactory) { - log.Println("in GetSet") r := gin.Default() r.Use(sessions.Sessions(sessionName, newStore(t))) @@ -51,7 +49,6 @@ func GetSet(t *testing.T, newStore storeFactory) { res2 := httptest.NewRecorder() req2, _ := http.NewRequest("GET", "/get", nil) - t.Logf(strings.Join(res1.Header().Values("Set-Cookie"), ";")) copyCookies(req2, res1) r.ServeHTTP(res2, req2) } @@ -186,7 +183,6 @@ func Clear(t *testing.T, newStore storeFactory) { } func Options(t *testing.T, newStore storeFactory) { - log.Println("in Options in tester") r := gin.Default() store := newStore(t) store.Options(sessions.Options{ @@ -248,18 +244,12 @@ func Options(t *testing.T, newStore storeFactory) { res4 := httptest.NewRecorder() req4, _ := http.NewRequest("GET", "/expire", nil) - t.Logf("test expire") - t.Logf(strings.Join(res4.Header().Values("Set-Cookie"), ";")) r.ServeHTTP(res4, req4) res5 := httptest.NewRecorder() req5, _ := http.NewRequest("GET", "/check", nil) r.ServeHTTP(res5, req5) - t.Logf("vor path und domain") - t.Logf(strings.Join(res1.Header().Values("Set-Cookie"), ";")) - t.Logf(strings.Join(res2.Header().Values("Set-Cookie"), ";")) - for _, c := range res1.Header().Values("Set-Cookie") { s := strings.Split(c, ";") if s[1] != " Path=/foo/bar/bat" { diff --git a/tester/tester_options_samesite_go1.11.go b/tester/tester_options_samesite_go1.11.go index 7241515..8379148 100644 --- a/tester/tester_options_samesite_go1.11.go +++ b/tester/tester_options_samesite_go1.11.go @@ -4,13 +4,12 @@ package tester import ( - "log" "net/http" "net/http/httptest" "strings" "testing" - sessions "github.com/geschke/gin-contrib-sessions" + "github.com/gin-contrib/sessions" "github.com/gin-gonic/gin" ) @@ -29,10 +28,7 @@ func testOptionSameSitego(t *testing.T, r *gin.Engine) { req3, _ := http.NewRequest("GET", "/sameSite", nil) r.ServeHTTP(res3, req3) - log.Println("Here we are!") s := strings.Split(res3.Header().Get("Set-Cookie"), ";") - log.Println(s) - log.Println(res3.Header().Get("Set-Cookie")) if s[1] != " SameSite=Strict" { t.Error("Error writing samesite with options:", s[1]) } From 576e0dd94895e17a78abab45b22c95f3df0c6c08 Mon Sep 17 00:00:00 2001 From: Ralf Geschke Date: Tue, 28 Nov 2023 19:04:19 +0100 Subject: [PATCH 8/8] module cleanup --- go.mod | 1 - go.sum | 2 -- 2 files changed, 3 deletions(-) diff --git a/go.mod b/go.mod index 7b832b2..c7a1ae2 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( github.com/bos-hieu/mongostore v0.0.3 github.com/bradfitz/gomemcache v0.0.0-20230905024940-24af94b03874 github.com/bradleypeabody/gorilla-sessions-memcache v0.0.0-20181103040241-659414f458e1 - github.com/gin-contrib/sessions v0.0.5 github.com/gin-gonic/gin v1.9.1 github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 github.com/gomodule/redigo v2.0.0+incompatible diff --git a/go.sum b/go.sum index db27970..0678eae 100644 --- a/go.sum +++ b/go.sum @@ -29,8 +29,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= -github.com/gin-contrib/sessions v0.0.5 h1:CATtfHmLMQrMNpJRgzjWXD7worTh7g7ritsQfmF+0jE= -github.com/gin-contrib/sessions v0.0.5/go.mod h1:vYAuaUPqie3WUSsft6HUlCjlwwoJQs97miaG2+7neKY= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=