From e8740c3498446dcaeab2990604a317e61dc170df Mon Sep 17 00:00:00 2001 From: Arne Luenser Date: Wed, 24 Jan 2024 12:56:51 +0100 Subject: [PATCH] fix: lint --- hash/hash_comparator.go | 5 +--- .../strategy/code/strategy_recovery_test.go | 4 +-- .../strategy/link/strategy_recovery_test.go | 2 +- .../strategy/password/op_helpers_test.go | 26 +++++++++---------- .../strategy/password/op_login_test.go | 6 ++--- .../strategy/password/op_registration_test.go | 14 ++++------ 6 files changed, 24 insertions(+), 33 deletions(-) diff --git a/hash/hash_comparator.go b/hash/hash_comparator.go index e68c1e663286..524eb9bfba14 100644 --- a/hash/hash_comparator.go +++ b/hash/hash_comparator.go @@ -28,7 +28,7 @@ import ( "golang.org/x/crypto/bcrypt" //nolint:staticcheck - //lint:ignore SA1019 + //lint:ignore SA1019 compatibility for imported passwords "golang.org/x/crypto/md4" //#nosec G501 -- compatibility for imported passwords "golang.org/x/crypto/pbkdf2" "golang.org/x/crypto/scrypt" @@ -211,7 +211,6 @@ func CompareScrypt(_ context.Context, password []byte, hash []byte) error { func CompareSSHA(_ context.Context, password []byte, hash []byte) error { hasher, salt, hash, err := decodeSSHAHash(string(hash)) - if err != nil { return err } @@ -222,7 +221,6 @@ func CompareSSHA(_ context.Context, password []byte, hash []byte) error { } func CompareSHA(_ context.Context, password []byte, hash []byte) error { - hasher, pf, salt, hash, err := decodeSHAHash(string(hash)) if err != nil { return err @@ -485,7 +483,6 @@ func decodeSHAHash(encodedHash string) (hasher string, pf, salt, hash []byte, er // used for CompareSHA and CompareSSHA func compareSHAHelper(hasher string, raw []byte, hash []byte) error { - var sha []byte switch hasher { diff --git a/selfservice/strategy/code/strategy_recovery_test.go b/selfservice/strategy/code/strategy_recovery_test.go index 29a054c28550..a5b4cef8bca5 100644 --- a/selfservice/strategy/code/strategy_recovery_test.go +++ b/selfservice/strategy/code/strategy_recovery_test.go @@ -354,7 +354,7 @@ func TestRecovery(t *testing.T) { expectedAAL: "aal2", }, } { - t.Run(fmt.Sprintf("%s", tc.desc), func(t *testing.T) { + t.Run(tc.desc, func(t *testing.T) { client := testhelpers.NewClientWithCookies(t) email := testhelpers.RandomEmail() i := createIdentityToRecover(t, reg, email) @@ -1191,7 +1191,7 @@ func TestRecovery_WithContinueWith(t *testing.T) { expectedAAL: "aal2", }, } { - t.Run(fmt.Sprintf("%s", tc.desc), func(t *testing.T) { + t.Run(tc.desc, func(t *testing.T) { client := testhelpers.NewClientWithCookies(t) email := testhelpers.RandomEmail() i := createIdentityToRecover(t, reg, email) diff --git a/selfservice/strategy/link/strategy_recovery_test.go b/selfservice/strategy/link/strategy_recovery_test.go index d470d8af6ce3..67e1cd388671 100644 --- a/selfservice/strategy/link/strategy_recovery_test.go +++ b/selfservice/strategy/link/strategy_recovery_test.go @@ -593,7 +593,7 @@ func TestRecovery(t *testing.T) { }, }, } { - t.Run(fmt.Sprintf("%s", tc.desc), func(t *testing.T) { + t.Run(tc.desc, func(t *testing.T) { email := testhelpers.RandomEmail() createIdentityToRecover(t, reg, email) diff --git a/selfservice/strategy/password/op_helpers_test.go b/selfservice/strategy/password/op_helpers_test.go index 824de913be69..17422063207b 100644 --- a/selfservice/strategy/password/op_helpers_test.go +++ b/selfservice/strategy/password/op_helpers_test.go @@ -43,25 +43,25 @@ type callTrace string const ( RegistrationUI callTrace = "registration-ui" - RegistrationWithOAuth2LoginChallenge = "registration-with-oauth2-login-challenge" - RegistrationWithFlowID = "registration-with-flow-id" - LoginUI = "login-ui" - LoginWithOAuth2LoginChallenge = "login-with-oauth2-login-challenge" - LoginWithFlowID = "login-with-flow-id" - Consent = "consent" - ConsentWithChallenge = "consent-with-challenge" - ConsentAccept = "consent-accept" - ConsentSkip = "consent-skip" - ConsentClientSkip = "consent-client-skip" - CodeExchange = "code-exchange" - CodeExchangeWithToken = "code-exchange-with-token" + RegistrationWithOAuth2LoginChallenge callTrace = "registration-with-oauth2-login-challenge" + RegistrationWithFlowID callTrace = "registration-with-flow-id" + LoginUI callTrace = "login-ui" + LoginWithOAuth2LoginChallenge callTrace = "login-with-oauth2-login-challenge" + LoginWithFlowID callTrace = "login-with-flow-id" + Consent callTrace = "consent" + ConsentWithChallenge callTrace = "consent-with-challenge" + ConsentAccept callTrace = "consent-accept" + ConsentSkip callTrace = "consent-skip" + ConsentClientSkip callTrace = "consent-client-skip" + CodeExchange callTrace = "code-exchange" + CodeExchangeWithToken callTrace = "code-exchange-with-token" ) type testContextKey string const ( TestUIConfig testContextKey = "test-ui-config" - TestOAuthClientState = "test-oauth-client-state" + TestOAuthClientState testContextKey = "test-oauth-client-state" ) type testConfig struct { diff --git a/selfservice/strategy/password/op_login_test.go b/selfservice/strategy/password/op_login_test.go index 64232072d736..6d8492a2ff3e 100644 --- a/selfservice/strategy/password/op_login_test.go +++ b/selfservice/strategy/password/op_login_test.go @@ -147,10 +147,8 @@ func TestOAuth2Provider(t *testing.T) { require.NoError(t, err) assert.Equal(t, http.StatusOK, resp.StatusCode) - if completedAcceptRequest != nil { - *c.callTrace = append(*c.callTrace, ConsentAccept) - } - assert.NotNil(t, completedAcceptRequest) + require.NotNil(t, completedAcceptRequest) + *c.callTrace = append(*c.callTrace, ConsentAccept) t.Logf("[consentTS] navigating to %s", completedAcceptRequest.RedirectTo) resp, err = c.browserClient.Get(completedAcceptRequest.RedirectTo) diff --git a/selfservice/strategy/password/op_registration_test.go b/selfservice/strategy/password/op_registration_test.go index 55e9907aba07..77f91cfb1ee3 100644 --- a/selfservice/strategy/password/op_registration_test.go +++ b/selfservice/strategy/password/op_registration_test.go @@ -43,9 +43,10 @@ func TestOAuth2ProviderRegistration(t *testing.T) { router := x.NewRouterPublic() + type contextKey string const ( - TestUIConfig = "test-ui-config" - TestOAuthClientState = "test-oauth-client-state" + TestUIConfig contextKey = "test-ui-config" + TestOAuthClientState contextKey = "test-oauth-client-state" ) router.GET("/login-ts", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { @@ -176,10 +177,8 @@ func TestOAuth2ProviderRegistration(t *testing.T) { require.NoError(t, err) assert.Equal(t, http.StatusOK, resp.StatusCode) - if completedAcceptRequest != nil { - *c.callTrace = append(*c.callTrace, ConsentAccept) - } - assert.NotNil(t, completedAcceptRequest) + require.NotNil(t, completedAcceptRequest) + *c.callTrace = append(*c.callTrace, ConsentAccept) t.Logf("[consentTS] navigating to %s", completedAcceptRequest.RedirectTo) resp, err = c.browserClient.Get(completedAcceptRequest.RedirectTo) @@ -244,9 +243,6 @@ func TestOAuth2ProviderRegistration(t *testing.T) { conf.MustSet(ctx, config.HookStrategyKey(config.ViperKeySelfServiceRegistrationAfter, identity.CredentialsTypePassword.String()), []config.SelfServiceHook{{Name: "session"}}) testhelpers.SetDefaultIdentitySchema(conf, "file://./stub/registration.schema.json") - type state struct { - cas clientAppState - } doOAuthFlow := func(t *testing.T, ctx context.Context, oauthClient *oauth2.Config, browserClient *http.Client) { t.Helper()