Skip to content

Commit

Permalink
Upgrade to latest linter
Browse files Browse the repository at this point in the history
Fix linting problems
  • Loading branch information
aviadl committed Sep 30, 2024
1 parent fb08474 commit 9e8b832
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 66 deletions.
2 changes: 1 addition & 1 deletion descope/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ func NewClient(conf ClientParams) *Client {
httpClient = &http.Client{
Timeout: timeout,
Transport: rt,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
CheckRedirect: func(_ *http.Request, _ []*http.Request) error {
return http.ErrUseLastResponse // notest
},
}
Expand Down
6 changes: 3 additions & 3 deletions descope/api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ func TestPostUnauthorized(t *testing.T) {
}

func TestPostRateLimitExceeded(t *testing.T) {
c := NewClient(ClientParams{ProjectID: "test", DefaultClient: mocks.NewTestClient(func(r *http.Request) (*http.Response, error) {
c := NewClient(ClientParams{ProjectID: "test", DefaultClient: mocks.NewTestClient(func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusTooManyRequests, Body: io.NopCloser(strings.NewReader(`{"errorCode":"E130429"}`))}, nil
})})

_, err := c.DoPostRequest(context.Background(), "path", nil, nil, "")
require.ErrorIs(t, err, descope.ErrRateLimitExceeded)
require.Nil(t, err.(*descope.Error).Info[descope.ErrorInfoKeys.RateLimitExceededRetryAfter])

c = NewClient(ClientParams{ProjectID: "test", DefaultClient: mocks.NewTestClient(func(r *http.Request) (*http.Response, error) {
c = NewClient(ClientParams{ProjectID: "test", DefaultClient: mocks.NewTestClient(func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusTooManyRequests, Header: http.Header{"Retry-After": []string{"10"}}, Body: io.NopCloser(strings.NewReader(`{"errorCode":"E130429"}`))}, nil
})})

Expand All @@ -229,7 +229,7 @@ func TestPostError(t *testing.T) {
expectedErr := "error here"
c := NewClient(ClientParams{ProjectID: projectID, DefaultClient: mocks.NewTestClient(func(r *http.Request) (*http.Response, error) {
assert.Nil(t, r.Body)
return nil, fmt.Errorf(expectedErr)
return nil, fmt.Errorf("%s", expectedErr)
})})

_, err := c.DoPostRequest(context.Background(), "path", nil, nil, "")
Expand Down
2 changes: 1 addition & 1 deletion descope/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestDescopeSDKMock(t *testing.T) {
Management: &mocksmgmt.MockManagement{
MockJWT: &mocksmgmt.MockJWT{
UpdateJWTWithCustomClaimsResponse: updateJWTWithCustomClaimsResponse,
UpdateJWTWithCustomClaimsAssert: func(jwt string, customClaims map[string]any) {
UpdateJWTWithCustomClaimsAssert: func(jwt string, _ map[string]any) {
updateJWTWithCustomClaimsCalled = true
assert.EqualValues(t, "some jwt", jwt)
},
Expand Down
2 changes: 1 addition & 1 deletion descope/internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func (auth *authenticationService) ExchangeAccessKey(ctx context.Context, access
if len(errMsg) == 0 {
errMsg = "Missing token in JWT response"
}
return false, nil, descope.ErrUnexpectedResponse.WithMessage(errMsg)
return false, nil, descope.ErrUnexpectedResponse.WithMessage("%s", errMsg)
}

if len(tokens) == 0 {
Expand Down
48 changes: 24 additions & 24 deletions descope/internal/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func TestAuthDefaultURL(t *testing.T) {
}

func TestEmptyPublicKey(t *testing.T) {
a, err := newTestAuthConf(&AuthParams{ProjectID: "a"}, nil, mocks.Do(func(r *http.Request) (*http.Response, error) {
a, err := newTestAuthConf(&AuthParams{ProjectID: "a"}, nil, mocks.Do(func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(strings.NewReader("[]"))}, nil
}))
require.NoError(t, err)
Expand All @@ -244,7 +244,7 @@ func TestEmptyPublicKey(t *testing.T) {
}

func TestErrorFetchPublicKey(t *testing.T) {
a, err := newTestAuthConf(&AuthParams{ProjectID: "a"}, nil, mocks.Do(func(r *http.Request) (*http.Response, error) {
a, err := newTestAuthConf(&AuthParams{ProjectID: "a"}, nil, mocks.Do(func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusInternalServerError, Body: io.NopCloser(strings.NewReader("what"))}, nil
}))
require.NoError(t, err)
Expand Down Expand Up @@ -532,7 +532,7 @@ func TestValidateAndRefreshSessionWithTokenExpired(t *testing.T) {

func TestValidateSessionFetchKeyCalledOnce(t *testing.T) {
count := 0
a, err := newTestAuthConf(&AuthParams{ProjectID: "a"}, nil, mocks.Do(func(r *http.Request) (*http.Response, error) {
a, err := newTestAuthConf(&AuthParams{ProjectID: "a"}, nil, mocks.Do(func(_ *http.Request) (*http.Response, error) {
count++
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(strings.NewReader(fmt.Sprintf(`{"keys":[%s]}`, publicKey)))}, nil
}))
Expand All @@ -548,7 +548,7 @@ func TestValidateSessionFetchKeyCalledOnce(t *testing.T) {
}

func TestValidateSessionFetchKeyMalformed(t *testing.T) {
a, err := newTestAuthConf(&AuthParams{ProjectID: "a"}, nil, mocks.Do(func(r *http.Request) (*http.Response, error) {
a, err := newTestAuthConf(&AuthParams{ProjectID: "a"}, nil, mocks.Do(func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(strings.NewReader(fmt.Sprintf(`{"keys":[%s]}`, unknownPublicKey)))}, nil
}))
require.NoError(t, err)
Expand All @@ -561,7 +561,7 @@ func TestValidateSessionFetchKeyMalformed(t *testing.T) {

func TestValidateSessionFailWithInvalidKey(t *testing.T) {
count := 0
a, err := newTestAuthConf(&AuthParams{PublicKey: unknownPublicKey}, nil, mocks.Do(func(r *http.Request) (*http.Response, error) {
a, err := newTestAuthConf(&AuthParams{PublicKey: unknownPublicKey}, nil, mocks.Do(func(_ *http.Request) (*http.Response, error) {
count++
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(strings.NewReader(fmt.Sprintf("[%s]", publicKey)))}, nil
}))
Expand All @@ -573,7 +573,7 @@ func TestValidateSessionFailWithInvalidKey(t *testing.T) {
}

func TestValidateSessionFailWithInvalidAlgorithm(t *testing.T) {
a, err := newTestAuthConf(&AuthParams{ProjectID: "a"}, nil, mocks.Do(func(r *http.Request) (*http.Response, error) {
a, err := newTestAuthConf(&AuthParams{ProjectID: "a"}, nil, mocks.Do(func(_ *http.Request) (*http.Response, error) {
badKey := strings.ReplaceAll(publicKey, "ES384", "ES123")
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(strings.NewReader(fmt.Sprintf(`{"keys":[%s]}`, badKey)))}, nil
}))
Expand Down Expand Up @@ -608,7 +608,7 @@ func TestValidateSessionRequestHeader(t *testing.T) {
}

func TestValidateSessionRequestRefreshSession(t *testing.T) {
a, err := newTestAuthConf(&AuthParams{ProjectID: "a", PublicKey: publicKey, CookieDomain: "cookiedomain.com"}, nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuthConf(&AuthParams{ProjectID: "a", PublicKey: publicKey, CookieDomain: "cookiedomain.com"}, nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewBufferString(mockAuthSessionBody))}, nil
})
a.conf.SessionJWTViaCookie = true
Expand Down Expand Up @@ -655,7 +655,7 @@ func TestConvertError(t *testing.T) {
}

func TestLogout(t *testing.T) {
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewBufferString(mockAuthSessionBody))}, nil
})
require.NoError(t, err)
Expand Down Expand Up @@ -683,7 +683,7 @@ func TestLogout(t *testing.T) {
}

func TestLogoutWithToken(t *testing.T) {
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewBufferString(mockAuthSessionBody))}, nil
})
require.NoError(t, err)
Expand All @@ -709,7 +709,7 @@ func TestLogoutWithToken(t *testing.T) {
}

func TestLogoutAll(t *testing.T) {
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewBufferString(mockAuthSessionBody))}, nil
})
require.NoError(t, err)
Expand Down Expand Up @@ -737,7 +737,7 @@ func TestLogoutAll(t *testing.T) {
}

func TestLogoutAllWithToken(t *testing.T) {
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewBufferString(mockAuthSessionBody))}, nil
})
require.NoError(t, err)
Expand All @@ -763,7 +763,7 @@ func TestLogoutAllWithToken(t *testing.T) {
}

func TestLogoutNoClaims(t *testing.T) {
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusOK}, nil
})
require.NoError(t, err)
Expand All @@ -788,7 +788,7 @@ func TestLogoutNoClaims(t *testing.T) {
}

func TestLogoutAllNoClaims(t *testing.T) {
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusOK}, nil
})
require.NoError(t, err)
Expand All @@ -813,7 +813,7 @@ func TestLogoutAllNoClaims(t *testing.T) {
}

func TestLogoutFailure(t *testing.T) {
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusBadGateway}, nil
})
require.NoError(t, err)
Expand All @@ -825,7 +825,7 @@ func TestLogoutFailure(t *testing.T) {
}

func TestLogoutAllFailure(t *testing.T) {
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusBadGateway}, nil
})
require.NoError(t, err)
Expand Down Expand Up @@ -857,7 +857,7 @@ func TestLogoutAllInvalidRefreshToken(t *testing.T) {
}

func TestLogoutEmptyRequest(t *testing.T) {
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusBadGateway}, nil
})
require.NoError(t, err)
Expand All @@ -868,7 +868,7 @@ func TestLogoutEmptyRequest(t *testing.T) {
}

func TestLogoutAllEmptyRequest(t *testing.T) {
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusBadGateway}, nil
})
require.NoError(t, err)
Expand All @@ -879,7 +879,7 @@ func TestLogoutAllEmptyRequest(t *testing.T) {
}

func TestLogoutMissingToken(t *testing.T) {
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusBadGateway}, nil
})
require.NoError(t, err)
Expand All @@ -891,7 +891,7 @@ func TestLogoutMissingToken(t *testing.T) {
}

func TestLogoutAllMissingToken(t *testing.T) {
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusBadGateway}, nil
})
require.NoError(t, err)
Expand Down Expand Up @@ -1156,7 +1156,7 @@ func TestGetTenants(t *testing.T) {
}

func TestMe(t *testing.T) {
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewBufferString(mockUserResponseBody))}, nil
})
require.NoError(t, err)
Expand Down Expand Up @@ -1202,7 +1202,7 @@ func TestMeInvalidToken(t *testing.T) {
}

func TestMeEmptyResponse(t *testing.T) {
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewBufferString(""))}, nil
})
require.NoError(t, err)
Expand Down Expand Up @@ -1234,7 +1234,7 @@ func TestTenants(t *testing.T) {
}

func TestTenantsInvalidArgs(t *testing.T) {
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
res := descope.TenantsResponse{Tenants: []descope.MeTenant{{ID: "a"}}}
bs, err := utils.Marshal(res)
require.NoError(t, err)
Expand Down Expand Up @@ -1279,7 +1279,7 @@ func TestTenantsInvalidToken(t *testing.T) {
}

func TestHistory(t *testing.T) {
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewBufferString(mockUserHistoryResponseBody))}, nil
})
require.NoError(t, err)
Expand Down Expand Up @@ -1334,7 +1334,7 @@ func TestHistoryInvalidToken(t *testing.T) {
}

func TestHistoryEmptyResponse(t *testing.T) {
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewBufferString(""))}, nil
})
require.NoError(t, err)
Expand Down
10 changes: 5 additions & 5 deletions descope/internal/auth/enchantedlink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestSignInEnchantedLinkStepup(t *testing.T) {
func TestSignInEnchantedLinkInvalidResponse(t *testing.T) {
email := "[email protected]"
uri := "http://test.me"
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBufferString(`{"pendingRef"`)),
Expand Down Expand Up @@ -243,7 +243,7 @@ func TestGetSession(t *testing.T) {

func TestGetSessionGenerateAuthenticationInfoValidDSRCookie(t *testing.T) {
pendingRef := "pending_ref"
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
cookie := &http.Cookie{Name: descope.RefreshCookieName, Value: jwtRTokenValid} // valid token
return &http.Response{StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBufferString(mockAuthSessionBodyNoRefreshJwt)),
Expand All @@ -262,7 +262,7 @@ func TestGetSessionGenerateAuthenticationInfoValidDSRCookie(t *testing.T) {

func TestGetSessionGenerateAuthenticationInfoInValidDSRCookie(t *testing.T) {
pendingRef := "pending_ref"
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
cookie := &http.Cookie{Name: descope.RefreshCookieName, Value: jwtTokenExpired} // invalid token
return &http.Response{StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBufferString(mockAuthSessionBodyNoRefreshJwt)),
Expand All @@ -279,7 +279,7 @@ func TestGetSessionGenerateAuthenticationInfoInValidDSRCookie(t *testing.T) {

func TestGetSessionGenerateAuthenticationInfoNoDSRCookie(t *testing.T) {
pendingRef := "pending_ref"
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBufferString(mockAuthSessionBodyNoRefreshJwt)),
}, nil
Expand All @@ -296,7 +296,7 @@ func TestGetSessionGenerateAuthenticationInfoNoDSRCookie(t *testing.T) {

func TestGetEnchantedLinkSessionError(t *testing.T) {
pendingRef := "pending_ref"
a, err := newTestAuth(nil, func(r *http.Request) (*http.Response, error) {
a, err := newTestAuth(nil, func(_ *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: http.StatusBadGateway}, nil
})
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions descope/internal/auth/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func TestAuthenticationMiddlewareFailure(t *testing.T) {
a, err := newTestAuth(nil, DoOk(nil))
require.NoError(t, err)
handlerToTest := sdk.AuthenticationMiddleware(a, func(w http.ResponseWriter, r *http.Request, err error) {
handlerToTest := sdk.AuthenticationMiddleware(a, func(w http.ResponseWriter, _ *http.Request, err error) {
require.ErrorIs(t, err, descope.ErrPublicKey)
w.WriteHeader(http.StatusBadGateway)
}, nil)(nil)
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestAuthenticationMiddlewareSuccess(t *testing.T) {
handlerToTest := sdk.AuthenticationMiddleware(a, nil, func(w http.ResponseWriter, r *http.Request, next http.Handler, token *descope.Token) {
assert.EqualValues(t, "someuser", token.ID)
next.ServeHTTP(w, r)
})(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
})(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusTeapot)
}))

Expand Down
Loading

0 comments on commit 9e8b832

Please sign in to comment.