Skip to content

Commit

Permalink
rename scopes validator to scope validation
Browse files Browse the repository at this point in the history
  • Loading branch information
JarekKa committed Dec 13, 2023
1 parent de27dca commit cb96861
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 32 deletions.
12 changes: 6 additions & 6 deletions .schema/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@
"default": "none",
"description": "Sets the strategy validation algorithm."
},
"scopesValidator": {
"title": "Scope Validator",
"scopeValidation": {
"title": "Scope Validation",
"type": "string",
"enum": ["default", "any"],
"default": "default",
Expand Down Expand Up @@ -611,8 +611,8 @@
"scope_strategy": {
"$ref": "#/definitions/scopeStrategy"
},
"scopes_validator": {
"$ref": "#/definitions/scopesValidator"
"scope_validation": {
"$ref": "#/definitions/ScopeValidation"
},
"token_from": {
"title": "Token From",
Expand Down Expand Up @@ -722,8 +722,8 @@
"scope_strategy": {
"$ref": "#/definitions/scopeStrategy"
},
"scopes_validator": {
"$ref": "#/definitions/scopesValidator"
"scope_validation": {
"$ref": "#/definitions/scopeValidation"
},
"pre_authorization": {
"title": "Pre-Authorization",
Expand Down
2 changes: 1 addition & 1 deletion credentials/scopes_logical_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ory/herodot"
)

type ScopesValidator func(scopeResult map[string]bool) error
type ScopeValidation func(scopeResult map[string]bool) error

func DefaultValidation(scopeResult map[string]bool) error {
for sc, result := range scopeResult {
Expand Down
2 changes: 1 addition & 1 deletion credentials/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type ValidationContext struct {
Issuers []string
Audiences []string
ScopeStrategy fosite.ScopeStrategy
ScopesValidator ScopesValidator
ScopeValidation ScopeValidation
Scope []string
KeyURLs []url.URL
}
2 changes: 1 addition & 1 deletion credentials/verifier_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (v *VerifierDefault) Verify(
scopeResult[sc] = r.ScopeStrategy(s, sc)
}

if err := r.ScopesValidator(scopeResult); err != nil {
if err := r.ScopeValidation(scopeResult); err != nil {
return nil, err
}

Expand Down
26 changes: 13 additions & 13 deletions credentials/verifier_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestVerifierDefault(t *testing.T) {
Scope: []string{"scope-1", "scope-2"},
KeyURLs: []url.URL{*x.ParseURLOrPanic("file://../test/stub/jwks-hs.json")},
ScopeStrategy: fosite.ExactScopeStrategy,
ScopesValidator: DefaultValidation,
ScopeValidation: DefaultValidation,
},
token: sign(jwt.MapClaims{
"sub": "sub",
Expand All @@ -78,7 +78,7 @@ func TestVerifierDefault(t *testing.T) {
Scope: []string{"scope-1", "not-scope-2"},
KeyURLs: []url.URL{*x.ParseURLOrPanic("file://../test/stub/jwks-hs.json")},
ScopeStrategy: fosite.ExactScopeStrategy,
ScopesValidator: AnyValidation,
ScopeValidation: AnyValidation,
},
token: sign(jwt.MapClaims{
"sub": "sub",
Expand All @@ -104,7 +104,7 @@ func TestVerifierDefault(t *testing.T) {
Scope: []string{"scope-1", "not-scope-2"},
KeyURLs: []url.URL{*x.ParseURLOrPanic("file://../test/stub/jwks-hs.json")},
ScopeStrategy: fosite.ExactScopeStrategy,
ScopesValidator: DefaultValidation,
ScopeValidation: DefaultValidation,
},
token: sign(jwt.MapClaims{
"sub": "sub",
Expand All @@ -131,7 +131,7 @@ func TestVerifierDefault(t *testing.T) {
Scope: []string{"scope-1", "scope-2"},
KeyURLs: []url.URL{*x.ParseURLOrPanic("file://../test/stub/jwks-hs.json")},
ScopeStrategy: fosite.ExactScopeStrategy,
ScopesValidator: DefaultValidation,
ScopeValidation: DefaultValidation,
},
token: sign(jwt.MapClaims{
"sub": "sub",
Expand All @@ -157,7 +157,7 @@ func TestVerifierDefault(t *testing.T) {
Scope: []string{"scope-1", "scope-2"},
KeyURLs: []url.URL{*x.ParseURLOrPanic("file://../test/stub/jwks-hs.json")},
ScopeStrategy: fosite.ExactScopeStrategy,
ScopesValidator: DefaultValidation,
ScopeValidation: DefaultValidation,
},
token: sign(jwt.MapClaims{
"sub": "sub",
Expand All @@ -183,7 +183,7 @@ func TestVerifierDefault(t *testing.T) {
Scope: []string{"scope-1", "scope-2"},
KeyURLs: []url.URL{*x.ParseURLOrPanic("file://../test/stub/jwks-hs.json")},
ScopeStrategy: fosite.ExactScopeStrategy,
ScopesValidator: DefaultValidation,
ScopeValidation: DefaultValidation,
},
token: sign(jwt.MapClaims{
"sub": "sub",
Expand Down Expand Up @@ -227,7 +227,7 @@ func TestVerifierDefault(t *testing.T) {
Scope: []string{"scope-1", "scope-2"},
KeyURLs: []url.URL{*x.ParseURLOrPanic("file://../test/stub/jwks-rsa-single.json")},
ScopeStrategy: fosite.ExactScopeStrategy,
ScopesValidator: DefaultValidation,
ScopeValidation: DefaultValidation,
},
token: sign(jwt.MapClaims{
"sub": "sub",
Expand All @@ -247,7 +247,7 @@ func TestVerifierDefault(t *testing.T) {
Scope: []string{"scope-1", "scope-2"},
KeyURLs: []url.URL{*x.ParseURLOrPanic("file://../test/stub/jwks-hs.json")},
ScopeStrategy: fosite.ExactScopeStrategy,
ScopesValidator: DefaultValidation,
ScopeValidation: DefaultValidation,
},
token: sign(jwt.MapClaims{
"sub": "sub",
Expand All @@ -267,7 +267,7 @@ func TestVerifierDefault(t *testing.T) {
Scope: []string{"scope-1", "scope-2"},
KeyURLs: []url.URL{*x.ParseURLOrPanic("file://../test/stub/jwks-hs.json")},
ScopeStrategy: fosite.ExactScopeStrategy,
ScopesValidator: DefaultValidation,
ScopeValidation: DefaultValidation,
},
token: sign(jwt.MapClaims{
"sub": "sub",
Expand All @@ -287,7 +287,7 @@ func TestVerifierDefault(t *testing.T) {
Scope: []string{"scope-1", "scope-2"},
KeyURLs: []url.URL{*x.ParseURLOrPanic("file://../test/stub/jwks-hs.json")},
ScopeStrategy: fosite.ExactScopeStrategy,
ScopesValidator: DefaultValidation,
ScopeValidation: DefaultValidation,
},
token: sign(jwt.MapClaims{
"sub": "sub",
Expand All @@ -307,7 +307,7 @@ func TestVerifierDefault(t *testing.T) {
Scope: []string{"scope-1", "scope-2"},
KeyURLs: []url.URL{*x.ParseURLOrPanic("file://../test/stub/jwks-hs.json")},
ScopeStrategy: fosite.ExactScopeStrategy,
ScopesValidator: DefaultValidation,
ScopeValidation: DefaultValidation,
},
token: sign(jwt.MapClaims{
"sub": "sub",
Expand All @@ -327,7 +327,7 @@ func TestVerifierDefault(t *testing.T) {
Scope: []string{"scope-1", "scope-2"},
KeyURLs: []url.URL{*x.ParseURLOrPanic("file://../test/stub/jwks-hs.json")},
ScopeStrategy: fosite.ExactScopeStrategy,
ScopesValidator: DefaultValidation,
ScopeValidation: DefaultValidation,
},
token: sign(jwt.MapClaims{
"sub": "sub",
Expand All @@ -348,7 +348,7 @@ func TestVerifierDefault(t *testing.T) {
Scope: []string{"scope-1", "scope-2"},
KeyURLs: []url.URL{*x.ParseURLOrPanic("file://../test/stub/jwks-hs.json")},
ScopeStrategy: fosite.ExactScopeStrategy,
ScopesValidator: DefaultValidation,
ScopeValidation: DefaultValidation,
},
token: sign(jwt.MapClaims{
"sub": "sub",
Expand Down
2 changes: 1 addition & 1 deletion driver/configuration/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type Provider interface {
PrometheusHideRequestPaths() bool
PrometheusCollapseRequestPaths() bool

ToScopesValidation(value string, key string) credentials.ScopesValidator
ToScopeValidation(value string, key string) credentials.ScopeValidation
ToScopeStrategy(value string, key string) fosite.ScopeStrategy
ParseURLs(sources []string) ([]url.URL, error)
JSONWebKeyURLs() []string
Expand Down
2 changes: 1 addition & 1 deletion driver/configuration/provider_koanf.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func (v *KoanfProvider) getURL(value string, key string) *url.URL {
return u
}

func (v *KoanfProvider) ToScopesValidation(value string, key string) credentials.ScopesValidator {
func (v *KoanfProvider) ToScopeValidation(value string, key string) credentials.ScopeValidation {
switch strings.ToLower(value) {
case "default":
return credentials.DefaultValidation
Expand Down
12 changes: 6 additions & 6 deletions driver/configuration/provider_koanf_public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func TestKoanfProvider(t *testing.T) {
})
}

func TestToScopesValidation(t *testing.T) {
func TestToScopeValidation(t *testing.T) {
p, err := configuration.NewKoanfProvider(
context.Background(),
nil,
Expand All @@ -398,11 +398,11 @@ func TestToScopesValidation(t *testing.T) {
)
require.NoError(t, err)

assert.Nil(t, p.ToScopesValidation("default", "foo")(map[string]bool{"foo": true}))
assert.NotNil(t, p.ToScopesValidation("default", "foo")(map[string]bool{"foo": true, "bar": false}))
assert.Nil(t, p.ToScopesValidation("any", "foo")(map[string]bool{"foo": true, "bar": false}))
assert.NotNil(t, p.ToScopesValidation("any", "foo")(map[string]bool{}))
assert.NotNil(t, p.ToScopesValidation("whatever", "foo")(map[string]bool{"foo": true, "bar": false}))
assert.Nil(t, p.ToScopeValidation("default", "foo")(map[string]bool{"foo": true}))
assert.NotNil(t, p.ToScopeValidation("default", "foo")(map[string]bool{"foo": true, "bar": false}))
assert.Nil(t, p.ToScopeValidation("any", "foo")(map[string]bool{"foo": true, "bar": false}))
assert.NotNil(t, p.ToScopeValidation("any", "foo")(map[string]bool{}))
assert.NotNil(t, p.ToScopeValidation("whatever", "foo")(map[string]bool{"foo": true, "bar": false}))

}

Expand Down
4 changes: 2 additions & 2 deletions pipeline/authn/authenticator_jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type AuthenticatorOAuth2JWTConfiguration struct {
AllowedAlgorithms []string `json:"allowed_algorithms"`
JWKSURLs []string `json:"jwks_urls"`
ScopeStrategy string `json:"scope_strategy"`
ScopesValidator string `json:"scopes_validator"`
ScopeValidation string `json:"scope_validation"`
BearerTokenLocation *helper.BearerTokenLocation `json:"token_from"`
}

Expand Down Expand Up @@ -112,7 +112,7 @@ func (a *AuthenticatorJWT) Authenticate(r *http.Request, session *Authentication
Issuers: cf.Issuers,
Audiences: cf.Audience,
ScopeStrategy: a.c.ToScopeStrategy(cf.ScopeStrategy, "authenticators.jwt.Config.scope_strategy"),
ScopesValidator: a.c.ToScopesValidation(cf.ScopesValidator, "authenticators.jwt.Config.scopes_validator"),
ScopeValidation: a.c.ToScopeValidation(cf.ScopeValidation, "authenticators.jwt.Config.scope_validation"),
})
if err != nil {
de := herodot.ToDefaultError(err, "")
Expand Down

0 comments on commit cb96861

Please sign in to comment.