Build the middleware test cookie stores with the production constructor (closes #154)
check / check (push) Successful in 3m30s
check / check (push) Successful in 3m30s
The middleware tests built their cookie stores by setting store.Options by hand, which left the securecookie codecs at the library's 30-day default instead of the 7-day cap production sets, an invisible divergence that would outlive the next change to store construction. The test store constructor moves from internal/session/export_test.go into internal/session/testing.go so other packages can reach it, and the two middleware test helpers build their stores through it. No test in the repo builds a cookie store by hand any more, and no assertion changes. Model: opus-5-5
This commit was merged in pull request #434.
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/sessions"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"sneak.berlin/go/webhooker/internal/config"
|
"sneak.berlin/go/webhooker/internal/config"
|
||||||
@@ -78,14 +77,7 @@ func newTestSessionManager(
|
|||||||
key[i] = byte(i)
|
key[i] = byte(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
store := sessions.NewCookieStore(key)
|
store := session.NewStore(key)
|
||||||
store.Options = &sessions.Options{
|
|
||||||
Path: "/",
|
|
||||||
MaxAge: 86400 * 7,
|
|
||||||
HttpOnly: true,
|
|
||||||
Secure: false,
|
|
||||||
SameSite: http.SameSiteLaxMode,
|
|
||||||
}
|
|
||||||
|
|
||||||
var now func() time.Time
|
var now func() time.Time
|
||||||
|
|
||||||
@@ -931,8 +923,7 @@ func metricsAuthMiddleware(
|
|||||||
}
|
}
|
||||||
|
|
||||||
key := make([]byte, testKeySize)
|
key := make([]byte, testKeySize)
|
||||||
store := sessions.NewCookieStore(key)
|
store := session.NewStore(key)
|
||||||
store.Options = &sessions.Options{Path: "/", MaxAge: 86400}
|
|
||||||
|
|
||||||
sessManager := session.NewForTest(store, cfg, log, key, nil)
|
sessManager := session.NewForTest(store, cfg, log, key, nil)
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
package session
|
|
||||||
|
|
||||||
import "github.com/gorilla/sessions"
|
|
||||||
|
|
||||||
// NewStore exposes the production cookie-store constructor so tests
|
|
||||||
// exercise the store the application actually runs with, rather than a
|
|
||||||
// lookalike assembled in the test.
|
|
||||||
func NewStore(key []byte) *sessions.CookieStore {
|
|
||||||
return newStore(key)
|
|
||||||
}
|
|
||||||
@@ -8,6 +8,13 @@ import (
|
|||||||
"sneak.berlin/go/webhooker/internal/config"
|
"sneak.berlin/go/webhooker/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewStore exposes the production cookie-store constructor so tests
|
||||||
|
// exercise the store the application actually runs with, rather than a
|
||||||
|
// lookalike assembled in the test.
|
||||||
|
func NewStore(key []byte) *sessions.CookieStore {
|
||||||
|
return newStore(key)
|
||||||
|
}
|
||||||
|
|
||||||
// NewForTest creates a Session with a pre-configured cookie store for use
|
// NewForTest creates a Session with a pre-configured cookie store for use
|
||||||
// in tests. This bypasses the fx lifecycle and database dependency, allowing
|
// in tests. This bypasses the fx lifecycle and database dependency, allowing
|
||||||
// middleware and handler tests to use real session functionality. The key
|
// middleware and handler tests to use real session functionality. The key
|
||||||
|
|||||||
Reference in New Issue
Block a user