diff --git a/pkg/apis/sessions/session_state.go b/pkg/apis/sessions/session_state.go index 752d8afb..08538dae 100644 --- a/pkg/apis/sessions/session_state.go +++ b/pkg/apis/sessions/session_state.go @@ -4,13 +4,14 @@ import ( "bytes" "context" "fmt" + "io" + "io/ioutil" + "time" + "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/clock" "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/encryption" "github.com/pierrec/lz4" "github.com/vmihailenco/msgpack/v4" - "io" - "io/ioutil" - "time" ) // SessionState is used to store information about the currently authenticated user session @@ -29,6 +30,7 @@ type SessionState struct { Groups []string `msgpack:"g,omitempty"` PreferredUsername string `msgpack:"pu,omitempty"` + // Internal helpers, not serialized Clock clock.Clock `msgpack:"-"` Lock Lock `msgpack:"-"` } diff --git a/pkg/clock/clock.go b/pkg/clock/clock.go index 34b7bf23..887bf0aa 100644 --- a/pkg/clock/clock.go +++ b/pkg/clock/clock.go @@ -63,13 +63,10 @@ func Reset() *clockapi.Mock { // package. type Clock struct { mock *clockapi.Mock - sync.Mutex } // Set sets the Clock to a clock.Mock at the given time.Time func (c *Clock) Set(t time.Time) { - c.Lock() - defer c.Unlock() if c.mock == nil { c.mock = clockapi.NewMock() } @@ -79,8 +76,6 @@ func (c *Clock) Set(t time.Time) { // Add moves clock forward time.Duration if it is mocked. It will error // if the clock is not mocked. func (c *Clock) Add(d time.Duration) error { - c.Lock() - defer c.Unlock() if c.mock == nil { return errors.New("clock not mocked") } @@ -91,8 +86,6 @@ func (c *Clock) Add(d time.Duration) error { // Reset removes local clock.Mock. Returns any existing Mock if set in case // lingering time operations are attached to it. func (c *Clock) Reset() *clockapi.Mock { - c.Lock() - defer c.Unlock() existing := c.mock c.mock = nil return existing