diff options
| author | James Elliott <james-d-elliott@users.noreply.github.com> | 2023-10-08 09:06:01 +1100 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-08 08:06:01 +1000 | 
| commit | 381a4a95bb4ad1020ef173609fa67bdb70d80b2e (patch) | |
| tree | 59d13d91dc29d9f0af71734df4f55565cf070d5d | |
| parent | b1255c2b17314b88c11da8843930c18ce91abf39 (diff) | |
refactor: clock newups (#6101)
Signed-off-by: James Elliott <james-d-elliott@users.noreply.github.com>
| -rw-r--r-- | internal/authentication/ldap_user_provider.go | 2 | ||||
| -rw-r--r-- | internal/authentication/ldap_user_provider_test.go | 8 | ||||
| -rw-r--r-- | internal/authentication/ldap_util.go | 2 | ||||
| -rw-r--r-- | internal/commands/context.go | 2 | ||||
| -rw-r--r-- | internal/middlewares/authelia_context.go | 2 | ||||
| -rw-r--r-- | internal/oidc/client_credentials_test.go | 6 | ||||
| -rw-r--r-- | internal/oidc/types_test.go | 14 | 
7 files changed, 12 insertions, 24 deletions
diff --git a/internal/authentication/ldap_user_provider.go b/internal/authentication/ldap_user_provider.go index 009f49e62..f889ca739 100644 --- a/internal/authentication/ldap_user_provider.go +++ b/internal/authentication/ldap_user_provider.go @@ -84,7 +84,7 @@ func NewLDAPUserProviderWithFactory(config schema.AuthenticationBackendLDAP, dis  		log:                  logging.Logger(),  		factory:              factory,  		disableResetPassword: disableResetPassword, -		clock:                &clock.Real{}, +		clock:                clock.New(),  	}  	provider.parseDynamicUsersConfiguration() diff --git a/internal/authentication/ldap_user_provider_test.go b/internal/authentication/ldap_user_provider_test.go index 39ba0b84e..96c06b31f 100644 --- a/internal/authentication/ldap_user_provider_test.go +++ b/internal/authentication/ldap_user_provider_test.go @@ -6,7 +6,7 @@ import (  	"testing"  	"time" -	ldap "github.com/go-ldap/ldap/v3" +	"github.com/go-ldap/ldap/v3"  	"github.com/golang/mock/gomock"  	"github.com/stretchr/testify/assert"  	"github.com/stretchr/testify/require" @@ -5259,11 +5259,7 @@ func TestShouldParseDynamicConfiguration(t *testing.T) {  		nil,  		mockFactory) -	clk := &clock.Fixed{} - -	provider.clock = clk - -	clk.Set(time.Unix(1670250519, 0)) +	provider.clock = clock.NewFixed(time.Unix(1670250519, 0))  	assert.True(t, provider.groupsFilterReplacementInput)  	assert.True(t, provider.groupsFilterReplacementUsername) diff --git a/internal/authentication/ldap_util.go b/internal/authentication/ldap_util.go index c19be6203..942aba619 100644 --- a/internal/authentication/ldap_util.go +++ b/internal/authentication/ldap_util.go @@ -5,7 +5,7 @@ import (  	"strings"  	ber "github.com/go-asn1-ber/asn1-ber" -	ldap "github.com/go-ldap/ldap/v3" +	"github.com/go-ldap/ldap/v3"  )  func ldapEntriesContainsEntry(needle *ldap.Entry, haystack []*ldap.Entry) bool { diff --git a/internal/commands/context.go b/internal/commands/context.go index 3022c331b..c4a1a90b4 100644 --- a/internal/commands/context.go +++ b/internal/commands/context.go @@ -143,7 +143,7 @@ func (ctx *CmdCtx) LoadProviders() (warns, errs []error) {  	ctx.providers.Authorizer = authorization.NewAuthorizer(ctx.config)  	ctx.providers.NTP = ntp.NewProvider(&ctx.config.NTP)  	ctx.providers.PasswordPolicy = middlewares.NewPasswordPolicyProvider(ctx.config.PasswordPolicy) -	ctx.providers.Regulator = regulation.NewRegulator(ctx.config.Regulation, ctx.providers.StorageProvider, &clock.Real{}) +	ctx.providers.Regulator = regulation.NewRegulator(ctx.config.Regulation, ctx.providers.StorageProvider, clock.New())  	ctx.providers.SessionProvider = session.NewProvider(ctx.config.Session, ctx.trusted)  	ctx.providers.TOTP = totp.NewTimeBasedProvider(ctx.config.TOTP) diff --git a/internal/middlewares/authelia_context.go b/internal/middlewares/authelia_context.go index 504c0445a..0e1f31c25 100644 --- a/internal/middlewares/authelia_context.go +++ b/internal/middlewares/authelia_context.go @@ -37,7 +37,7 @@ func NewAutheliaCtx(requestCTX *fasthttp.RequestCtx, configuration schema.Config  	ctx.Providers = providers  	ctx.Configuration = configuration  	ctx.Logger = NewRequestLogger(ctx) -	ctx.Clock = &clock.Real{} +	ctx.Clock = clock.New()  	return ctx  } diff --git a/internal/oidc/client_credentials_test.go b/internal/oidc/client_credentials_test.go index 1713a6c5c..2d7ce4dbc 100644 --- a/internal/oidc/client_credentials_test.go +++ b/internal/oidc/client_credentials_test.go @@ -14,7 +14,7 @@ import (  	"testing"  	"time" -	jwt "github.com/golang-jwt/jwt/v5" +	"github.com/golang-jwt/jwt/v5"  	"github.com/golang/mock/gomock"  	"github.com/google/uuid"  	"github.com/ory/fosite" @@ -23,7 +23,7 @@ import (  	"github.com/stretchr/testify/require"  	"github.com/stretchr/testify/suite"  	"github.com/valyala/fasthttp" -	jose "gopkg.in/square/go-jose.v2" +	"gopkg.in/square/go-jose.v2"  	"github.com/authelia/authelia/v4/internal/authorization"  	"github.com/authelia/authelia/v4/internal/clock" @@ -192,7 +192,7 @@ func (s *ClientAuthenticationStrategySuite) GetCtx() oidc.Context {  	return &TestContext{  		Context:       context.TODO(),  		MockIssuerURL: s.GetIssuerURL(), -		Clock:         &clock.Real{}, +		Clock:         clock.New(),  	}  } diff --git a/internal/oidc/types_test.go b/internal/oidc/types_test.go index c7f2d3695..0de1c682f 100644 --- a/internal/oidc/types_test.go +++ b/internal/oidc/types_test.go @@ -68,11 +68,7 @@ func TestNewSessionWithAuthorizeRequest(t *testing.T) {  	ctx := &TestContext{} -	clk := &clock.Fixed{} - -	clk.Set(time.Unix(10000000000, 0)) - -	ctx.Clock = clk +	ctx.Clock = clock.NewFixed(time.Unix(10000000000, 0))  	session := oidc.NewSessionWithAuthorizeRequest(ctx, MustParseRequestURI(issuer), "primary", "john", amr, extra, authAt, consent, request) @@ -153,11 +149,7 @@ func TestPopulateClientCredentialsFlowSessionWithAccessRequest(t *testing.T) {  			func(ctx oidc.Context) {  				c := ctx.(*TestContext) -				clk := &clock.Fixed{} - -				clk.Set(time.Unix(10000000000, 0)) - -				c.Clock = clk +				c.Clock = clock.NewFixed(time.Unix(10000000000, 0))  			},  			&TestContext{  				IssuerURLFunc: func() (issuerURL *url.URL, err error) { @@ -247,7 +239,7 @@ func (m *TestContext) GetClock() clock.Provider {  		return m.Clock  	} -	return &clock.Real{} +	return clock.New()  }  func (m *TestContext) GetJWTWithTimeFuncOption() jwt.ParserOption {  | 
