revert codacy

This commit is contained in:
Pascal Fischer 2023-03-30 18:59:35 +02:00
parent f273fe9f51
commit ce775d59ae
2 changed files with 7 additions and 7 deletions

View File

@ -19,7 +19,7 @@ const (
UserIDClaim = "sub"
)
// Extract function type
// ExtractClaims Extract function type
type ExtractClaims func(r *http.Request) AuthorizationClaims
// ClaimsExtractor struct that holds the extract function
@ -65,7 +65,7 @@ func NewClaimsExtractor(options ...ClaimsExtractorOption) *ClaimsExtractor {
ce.FromRequestContext = ce.fromRequestContext
}
if ce.userIDClaim == "" {
ce.userIDClaim = string(UserIDClaim)
ce.userIDClaim = UserIDClaim
}
return ce
}

View File

@ -12,16 +12,16 @@ import (
func newTestRequestWithJWT(t *testing.T, claims AuthorizationClaims, audiance string) *http.Request {
claimMaps := jwt.MapClaims{}
if claims.UserId != "" {
claimMaps[string(UserIDClaim)] = claims.UserId
claimMaps[UserIDClaim] = claims.UserId
}
if claims.AccountId != "" {
claimMaps[audiance+string(AccountIDSuffix)] = claims.AccountId
claimMaps[audiance+AccountIDSuffix] = claims.AccountId
}
if claims.Domain != "" {
claimMaps[audiance+string(DomainIDSuffix)] = claims.Domain
claimMaps[audiance+DomainIDSuffix] = claims.Domain
}
if claims.DomainCategory != "" {
claimMaps[audiance+string(DomainCategorySuffix)] = claims.DomainCategory
claimMaps[audiance+DomainCategorySuffix] = claims.DomainCategory
}
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claimMaps)
r, err := http.NewRequest(http.MethodGet, "http://localhost", nil)
@ -124,7 +124,7 @@ func TestExtractClaimsSetOptions(t *testing.T) {
t.Error("audience should be empty")
return
}
if c.extractor.userIDClaim != string(UserIDClaim) {
if c.extractor.userIDClaim != UserIDClaim {
t.Errorf("user id claim should be default, expected %s, got %s", UserIDClaim, c.extractor.userIDClaim)
return
}