diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 1b545b7..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,70 +0,0 @@ -version: 2.1 - -jobs: - "test": - parameters: - version: - type: string - default: "latest" - golint: - type: boolean - default: true - modules: - type: boolean - default: true - goproxy: - type: string - default: "" - docker: - - image: "circleci/golang:<< parameters.version >>" - working_directory: /go/src/github.com/gorilla/sessions - environment: - GO111MODULE: "on" - GOPROXY: "<< parameters.goproxy >>" - steps: - - checkout - - run: - name: "Print the Go version" - command: > - go version - - run: - name: "Fetch dependencies" - command: > - if [[ << parameters.modules >> = true ]]; then - go mod download - export GO111MODULE=on - else - go get -v ./... - fi - # Only run gofmt, vet & lint against the latest Go version - - run: - name: "Run golint" - command: > - if [ << parameters.version >> = "latest" ] && [ << parameters.golint >> = true ]; then - go get -u golang.org/x/lint/golint - golint ./... - fi - - run: - name: "Run gofmt" - command: > - if [[ << parameters.version >> = "latest" ]]; then - diff -u <(echo -n) <(gofmt -d -e .) - fi - - run: - name: "Run go vet" - command: > - if [[ << parameters.version >> = "latest" ]]; then - go vet -v ./... - fi - - run: - name: "Run go test (+ race detector)" - command: > - go test -v -race ./... - -workflows: - tests: - jobs: - - test: - matrix: - parameters: - version: ["latest", "1.15", "1.14", "1.13", "1.12", "1.11"] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..1d49e1f --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,64 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + test: + strategy: + matrix: + go-version: ['1.20', '1.19'] + runs-on: ubuntu-latest + env: + GO111MODULE: "on" + GOPROXY: '' + steps: + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + + - name: Check out code + uses: actions/checkout@v2 + + - name: Print the Go version + run: go version + + - name: Install dependencies + run: | + set +e + output=$(go mod download 2>&1) + exit_status=$? + set -e + if [[ $exit_status -ne 0 ]]; then + if [[ $output != "go: no module dependencies to download" ]]; then + echo "$output" >&2 + exit $exit_status + else + echo "No external dependencies found." + fi + else + echo $output + fi + + - name: Run golint + if: matrix.go-version == '1.20' + run: | + go install golang.org/x/lint/golint@latest + golint ./... + + - name: Run gofmt + if: matrix.go-version == '1.20' + run: diff -u <(echo -n) <(gofmt -d -e .) + + - name: Run go vet + if: matrix.go-version == '1.20' + run: go vet -v ./... + + - name: Run go test (+ race detector) + run: go test -v -race ./... diff --git a/AUTHORS b/AUTHORS index 1e3e7ac..e27fbac 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,3 +1,10 @@ +# This is the official list of go-extras/sessions authors for copyright +# purposes. +# +# Please keep the list sorted. + +Denis Voytyuk + # This is the official list of gorilla/sessions authors for copyright purposes. # # Please keep the list sorted. diff --git a/LICENSE b/LICENSE index 6903df6..c3b0bf1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,5 @@ +Copyright (c) 2023 The Go-Extras Sessions Authors. All rights reserved. + Copyright (c) 2012-2018 The Gorilla Authors. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/README.md b/README.md index b2b95ff..b58fbdb 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,9 @@ # sessions -[![GoDoc](https://godoc.org/github.com/gorilla/sessions?status.svg)](https://godoc.org/github.com/gorilla/sessions) [![Build Status](https://travis-ci.org/gorilla/sessions.svg?branch=master)](https://travis-ci.org/gorilla/sessions) -[![Sourcegraph](https://sourcegraph.com/github.com/gorilla/sessions/-/badge.svg)](https://sourcegraph.com/github.com/gorilla/sessions?badge) +[![GoDoc](https://godoc.org/github.com/go-extras/sessions?status.svg)](https://godoc.org/github.com/go-extras/sessions) +[![Build Status](https://github.com/go-extras/sessions/actions/workflows/main.yml/badge.svg)](https://github.com/go-extras/sessions/actions/workflows/main.yml) ---- - -**The Gorilla project has been archived, and is no longer under active maintainenance. You can read more here: https://github.com/gorilla#gorilla-toolkit** - ---- - -gorilla/sessions provides cookie and filesystem sessions and infrastructure for +`go-extras/sessions` provides cookie and filesystem sessions and infrastructure for custom session backends. The key features are: @@ -30,7 +24,7 @@ Let's start with an example that shows the sessions API in a nutshell: ```go import ( "net/http" - "github.com/gorilla/sessions" + "github.com/go-extras/sessions" ) // Note: Don't store your key in your source code. Pass it via an diff --git a/cookie.go b/cookie.go index 6612662..22d9bd8 100644 --- a/cookie.go +++ b/cookie.go @@ -1,6 +1,3 @@ -//go:build !go1.11 -// +build !go1.11 - package sessions import "net/http" @@ -15,6 +12,7 @@ func newCookieFromOptions(name, value string, options *Options) *http.Cookie { MaxAge: options.MaxAge, Secure: options.Secure, HttpOnly: options.HttpOnly, + SameSite: options.SameSite, } } diff --git a/cookie_go111.go b/cookie_go111.go deleted file mode 100644 index 9b58828..0000000 --- a/cookie_go111.go +++ /dev/null @@ -1,21 +0,0 @@ -//go:build go1.11 -// +build go1.11 - -package sessions - -import "net/http" - -// newCookieFromOptions returns an http.Cookie with the options set. -func newCookieFromOptions(name, value string, options *Options) *http.Cookie { - return &http.Cookie{ - Name: name, - Value: value, - Path: options.Path, - Domain: options.Domain, - MaxAge: options.MaxAge, - Secure: options.Secure, - HttpOnly: options.HttpOnly, - SameSite: options.SameSite, - } - -} diff --git a/cookie_go111_test.go b/cookie_go111_test.go deleted file mode 100644 index e6137c7..0000000 --- a/cookie_go111_test.go +++ /dev/null @@ -1,30 +0,0 @@ -//go:build go1.11 -// +build go1.11 - -package sessions - -import ( - "net/http" - "testing" -) - -// Test for setting SameSite field in new http.Cookie from name, value -// and options -func TestNewCookieFromOptionsSameSite(t *testing.T) { - tests := []struct { - sameSite http.SameSite - }{ - {http.SameSiteDefaultMode}, - {http.SameSiteLaxMode}, - {http.SameSiteStrictMode}, - } - for i, v := range tests { - options := &Options{ - SameSite: v.sameSite, - } - cookie := newCookieFromOptions("", "", options) - if cookie.SameSite != v.sameSite { - t.Fatalf("%v: bad cookie sameSite: got %v, want %v", i+1, cookie.SameSite, v.sameSite) - } - } -} diff --git a/cookie_test.go b/cookie_test.go index acb4efb..4149538 100644 --- a/cookie_test.go +++ b/cookie_test.go @@ -1,57 +1,27 @@ package sessions import ( + "net/http" "testing" ) -// Test for creating new http.Cookie from name, value and options -func TestNewCookieFromOptions(t *testing.T) { +// Test for setting SameSite field in new http.Cookie from name, value +// and options +func TestNewCookieFromOptionsSameSite(t *testing.T) { tests := []struct { - name string - value string - path string - domain string - maxAge int - secure bool - httpOnly bool + sameSite http.SameSite }{ - {"", "bar", "/foo/bar", "foo.example.com", 3600, true, true}, - {"foo", "", "/foo/bar", "foo.example.com", 3600, true, true}, - {"foo", "bar", "", "foo.example.com", 3600, true, true}, - {"foo", "bar", "/foo/bar", "", 3600, true, true}, - {"foo", "bar", "/foo/bar", "foo.example.com", 0, true, true}, - {"foo", "bar", "/foo/bar", "foo.example.com", 3600, false, true}, - {"foo", "bar", "/foo/bar", "foo.example.com", 3600, true, false}, + {http.SameSiteDefaultMode}, + {http.SameSiteLaxMode}, + {http.SameSiteStrictMode}, } for i, v := range tests { options := &Options{ - Path: v.path, - Domain: v.domain, - MaxAge: v.maxAge, - Secure: v.secure, - HttpOnly: v.httpOnly, + SameSite: v.sameSite, } - cookie := newCookieFromOptions(v.name, v.value, options) - if cookie.Name != v.name { - t.Fatalf("%v: bad cookie name: got %q, want %q", i+1, cookie.Name, v.name) - } - if cookie.Value != v.value { - t.Fatalf("%v: bad cookie value: got %q, want %q", i+1, cookie.Value, v.value) - } - if cookie.Path != v.path { - t.Fatalf("%v: bad cookie path: got %q, want %q", i+1, cookie.Path, v.path) - } - if cookie.Domain != v.domain { - t.Fatalf("%v: bad cookie domain: got %q, want %q", i+1, cookie.Domain, v.domain) - } - if cookie.MaxAge != v.maxAge { - t.Fatalf("%v: bad cookie maxAge: got %q, want %q", i+1, cookie.MaxAge, v.maxAge) - } - if cookie.Secure != v.secure { - t.Fatalf("%v: bad cookie secure: got %v, want %v", i+1, cookie.Secure, v.secure) - } - if cookie.HttpOnly != v.httpOnly { - t.Fatalf("%v: bad cookie httpOnly: got %v, want %v", i+1, cookie.HttpOnly, v.httpOnly) + cookie := newCookieFromOptions("", "", options) + if cookie.SameSite != v.sameSite { + t.Fatalf("%v: bad cookie sameSite: got %v, want %v", i+1, cookie.SameSite, v.sameSite) } } } diff --git a/doc.go b/doc.go index 946bf5c..981c3b1 100644 --- a/doc.go +++ b/doc.go @@ -8,22 +8,22 @@ infrastructure for custom session backends. The key features are: - * Simple API: use it as an easy way to set signed (and optionally - encrypted) cookies. - * Built-in backends to store sessions in cookies or the filesystem. - * Flash messages: session values that last until read. - * Convenient way to switch session persistency (aka "remember me") and set - other attributes. - * Mechanism to rotate authentication and encryption keys. - * Multiple sessions per request, even using different backends. - * Interfaces and infrastructure for custom session backends: sessions from - different stores can be retrieved and batch-saved using a common API. + - Simple API: use it as an easy way to set signed (and optionally + encrypted) cookies. + - Built-in backends to store sessions in cookies or the filesystem. + - Flash messages: session values that last until read. + - Convenient way to switch session persistency (aka "remember me") and set + other attributes. + - Mechanism to rotate authentication and encryption keys. + - Multiple sessions per request, even using different backends. + - Interfaces and infrastructure for custom session backends: sessions from + different stores can be retrieved and batch-saved using a common API. Let's start with an example that shows the sessions API in a nutshell: import ( "net/http" - "github.com/gorilla/sessions" + "github.com/go-extras/sessions" ) // Note: Don't store your key in your source code. Pass it via an @@ -103,7 +103,7 @@ so it is easy to register new datatypes for storage in sessions: import( "encoding/gob" - "github.com/gorilla/sessions" + "github.com/go-extras/sessions" ) type Person struct { diff --git a/go.mod b/go.mod index 9028bcf..27162b9 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ -module github.com/gorilla/sessions +module github.com/go-extras/sessions -require github.com/gorilla/securecookie v1.1.1 +go 1.20 + +require github.com/go-extras/securecookie v1.0.0 diff --git a/go.sum b/go.sum index e6a7ed5..15c07a7 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,2 @@ -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/go-extras/securecookie v1.0.0 h1:EWUshlZfI5s403oVDoH8coz2YsMCqNheD7mIEQDflW8= +github.com/go-extras/securecookie v1.0.0/go.mod h1:Po3LJtelUIfBsNUFcE6K+S+ZGe4nZ3u57Pogvm/ygFQ= diff --git a/options.go b/options.go index d33d076..658ce95 100644 --- a/options.go +++ b/options.go @@ -1,8 +1,7 @@ -//go:build !go1.11 -// +build !go1.11 - package sessions +import "net/http" + // Options stores configuration for a session or session store. // // Fields are a subset of http.Cookie fields. @@ -16,4 +15,6 @@ type Options struct { MaxAge int Secure bool HttpOnly bool + // Defaults to http.SameSiteDefaultMode + SameSite http.SameSite } diff --git a/options_go111.go b/options_go111.go deleted file mode 100644 index af9cdf0..0000000 --- a/options_go111.go +++ /dev/null @@ -1,23 +0,0 @@ -//go:build go1.11 -// +build go1.11 - -package sessions - -import "net/http" - -// Options stores configuration for a session or session store. -// -// Fields are a subset of http.Cookie fields. -type Options struct { - Path string - Domain string - // MaxAge=0 means no Max-Age attribute specified and the cookie will be - // deleted after the browser session ends. - // MaxAge<0 means delete cookie immediately. - // MaxAge>0 means Max-Age attribute present and given in seconds. - MaxAge int - Secure bool - HttpOnly bool - // Defaults to http.SameSiteDefaultMode - SameSite http.SameSite -} diff --git a/store.go b/store.go index eb45afb..099e8a2 100644 --- a/store.go +++ b/store.go @@ -12,7 +12,7 @@ import ( "path/filepath" "sync" - "github.com/gorilla/securecookie" + "github.com/go-extras/securecookie" ) // Store is an interface for custom session stores.