Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl committed Dec 12, 2024
1 parent 60c8aa8 commit be22f90
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
26 changes: 17 additions & 9 deletions selfservice/strategy/oidc/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ func isForced(req interface{}) bool {
// Strategy implements selfservice.LoginStrategy, selfservice.RegistrationStrategy and selfservice.SettingsStrategy.
// It supports login, registration and settings via OpenID Providers.
type Strategy struct {
d Dependencies
validator *schema.Validator
dec *decoderx.HTTP
credType identity.CredentialsType
handleUnknownProviderError func(err error) error
d Dependencies
validator *schema.Validator
dec *decoderx.HTTP
credType identity.CredentialsType
handleUnknownProviderError func(err error) error
handleMethodNotAllowedError func(err error) error
}

type AuthCodeContainer struct {
Expand Down Expand Up @@ -217,12 +218,19 @@ func WithUnknownProviderHandler(handler func(error) error) NewStrategyOpt {
return func(s *Strategy) { s.handleUnknownProviderError = handler }

Check warning on line 218 in selfservice/strategy/oidc/strategy.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/strategy.go#L217-L218

Added lines #L217 - L218 were not covered by tests
}

// WithHandleMethodNotAllowedError overrides the error returned when method is
// not allowed.
func WithHandleMethodNotAllowedError(handler func(error) error) NewStrategyOpt {
return func(s *Strategy) { s.handleMethodNotAllowedError = handler }

Check warning on line 224 in selfservice/strategy/oidc/strategy.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/strategy.go#L223-L224

Added lines #L223 - L224 were not covered by tests
}

func NewStrategy(d any, opts ...NewStrategyOpt) *Strategy {
s := &Strategy{
d: d.(Dependencies),
validator: schema.NewValidator(),
credType: identity.CredentialsTypeOIDC,
handleUnknownProviderError: func(err error) error { return err },
d: d.(Dependencies),
validator: schema.NewValidator(),
credType: identity.CredentialsTypeOIDC,
handleUnknownProviderError: func(err error) error { return err },
handleMethodNotAllowedError: func(err error) error { return err },
}
for _, opt := range opts {
opt(s)
Expand Down
8 changes: 4 additions & 4 deletions selfservice/strategy/oidc/strategy_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ func (s *Strategy) Login(w http.ResponseWriter, r *http.Request, f *login.Flow,
return nil, errors.WithStack(flow.ErrStrategyNotResponsible)
}

provider, err := s.provider(ctx, pid)
if err != nil {
return nil, s.handleError(ctx, w, r, f, pid, nil, err)
if err := flow.MethodEnabledAndAllowed(ctx, f.GetFlowName(), s.SettingsStrategyID(), s.SettingsStrategyID(), s.d); err != nil {
return nil, s.handleError(ctx, w, r, f, pid, nil, s.handleMethodNotAllowedError(err))
}

if err := flow.MethodEnabledAndAllowed(ctx, f.GetFlowName(), s.SettingsStrategyID(), s.SettingsStrategyID(), s.d); err != nil {
provider, err := s.provider(ctx, pid)
if err != nil {
return nil, s.handleError(ctx, w, r, f, pid, nil, err)
}

Expand Down
8 changes: 4 additions & 4 deletions selfservice/strategy/oidc/strategy_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ func (s *Strategy) Register(w http.ResponseWriter, r *http.Request, f *registrat
return errors.WithStack(flow.ErrStrategyNotResponsible)
}

provider, err := s.provider(ctx, pid)
if err != nil {
return s.handleError(ctx, w, r, f, pid, nil, err)
if err := flow.MethodEnabledAndAllowed(ctx, f.GetFlowName(), s.SettingsStrategyID(), s.SettingsStrategyID(), s.d); err != nil {
return s.handleError(ctx, w, r, f, pid, nil, s.handleMethodNotAllowedError(err))
}

if err := flow.MethodEnabledAndAllowed(ctx, f.GetFlowName(), s.SettingsStrategyID(), s.SettingsStrategyID(), s.d); err != nil {
provider, err := s.provider(ctx, pid)
if err != nil {
return s.handleError(ctx, w, r, f, pid, nil, err)
}

Expand Down

0 comments on commit be22f90

Please sign in to comment.