package session import ( "log/slog" "time" "github.com/gorilla/sessions" "sneak.berlin/go/webhooker/internal/config" ) // NewForTest creates a Session with a pre-configured cookie store for use // in tests. This bypasses the fx lifecycle and database dependency, allowing // middleware and handler tests to use real session functionality. The key // parameter is the raw 32-byte authentication key used for session encryption // and CSRF cookie signing. // // The idle timeout is taken from cfg.SessionIdleTimeout, exactly as in // production. The now parameter supplies the clock used for expiry // checks so tests can advance time without sleeping; pass nil for the // real clock. func NewForTest( store *sessions.CookieStore, cfg *config.Config, log *slog.Logger, key []byte, now func() time.Time, ) *Session { if now == nil { now = time.Now } return &Session{ store: store, key: key, config: cfg, log: log, idleTimeout: cfg.SessionIdleTimeout, now: now, } }