mirror of
https://github.com/netbirdio/netbird.git
synced 2025-04-02 20:36:25 +02:00
revert codacy
This commit is contained in:
parent
f273fe9f51
commit
ce775d59ae
@ -19,7 +19,7 @@ const (
|
|||||||
UserIDClaim = "sub"
|
UserIDClaim = "sub"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Extract function type
|
// ExtractClaims Extract function type
|
||||||
type ExtractClaims func(r *http.Request) AuthorizationClaims
|
type ExtractClaims func(r *http.Request) AuthorizationClaims
|
||||||
|
|
||||||
// ClaimsExtractor struct that holds the extract function
|
// ClaimsExtractor struct that holds the extract function
|
||||||
@ -65,7 +65,7 @@ func NewClaimsExtractor(options ...ClaimsExtractorOption) *ClaimsExtractor {
|
|||||||
ce.FromRequestContext = ce.fromRequestContext
|
ce.FromRequestContext = ce.fromRequestContext
|
||||||
}
|
}
|
||||||
if ce.userIDClaim == "" {
|
if ce.userIDClaim == "" {
|
||||||
ce.userIDClaim = string(UserIDClaim)
|
ce.userIDClaim = UserIDClaim
|
||||||
}
|
}
|
||||||
return ce
|
return ce
|
||||||
}
|
}
|
||||||
|
@ -12,16 +12,16 @@ import (
|
|||||||
func newTestRequestWithJWT(t *testing.T, claims AuthorizationClaims, audiance string) *http.Request {
|
func newTestRequestWithJWT(t *testing.T, claims AuthorizationClaims, audiance string) *http.Request {
|
||||||
claimMaps := jwt.MapClaims{}
|
claimMaps := jwt.MapClaims{}
|
||||||
if claims.UserId != "" {
|
if claims.UserId != "" {
|
||||||
claimMaps[string(UserIDClaim)] = claims.UserId
|
claimMaps[UserIDClaim] = claims.UserId
|
||||||
}
|
}
|
||||||
if claims.AccountId != "" {
|
if claims.AccountId != "" {
|
||||||
claimMaps[audiance+string(AccountIDSuffix)] = claims.AccountId
|
claimMaps[audiance+AccountIDSuffix] = claims.AccountId
|
||||||
}
|
}
|
||||||
if claims.Domain != "" {
|
if claims.Domain != "" {
|
||||||
claimMaps[audiance+string(DomainIDSuffix)] = claims.Domain
|
claimMaps[audiance+DomainIDSuffix] = claims.Domain
|
||||||
}
|
}
|
||||||
if claims.DomainCategory != "" {
|
if claims.DomainCategory != "" {
|
||||||
claimMaps[audiance+string(DomainCategorySuffix)] = claims.DomainCategory
|
claimMaps[audiance+DomainCategorySuffix] = claims.DomainCategory
|
||||||
}
|
}
|
||||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claimMaps)
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claimMaps)
|
||||||
r, err := http.NewRequest(http.MethodGet, "http://localhost", nil)
|
r, err := http.NewRequest(http.MethodGet, "http://localhost", nil)
|
||||||
@ -124,7 +124,7 @@ func TestExtractClaimsSetOptions(t *testing.T) {
|
|||||||
t.Error("audience should be empty")
|
t.Error("audience should be empty")
|
||||||
return
|
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)
|
t.Errorf("user id claim should be default, expected %s, got %s", UserIDClaim, c.extractor.userIDClaim)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user