Build the middleware test cookie stores with the production constructor (closes #154) #434

Merged
clawbot merged 1 commits from issue-154-session-test-store into next 2026-10-02 14:30:52 +02:00
3 changed files with 9 additions and 21 deletions
+2 -11
View File
@@ -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)
-10
View File
@@ -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)
}
+7
View File
@@ -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