Skip to content

Commit

Permalink
feat: pass input to validation function to allow checks on challenge …
Browse files Browse the repository at this point in the history
…inputs (#17)
  • Loading branch information
bludot authored Mar 29, 2022
1 parent d74bd46 commit 4c4b446
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion examples/graphql_flow/flows/single_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (f SingleFlow) Initialize(ctx context.Context) (*JWTEntities.JWTAdditions,
}, nil
}

func (f SingleFlow) Validate(ctx context.Context, challenge string, JWTData mfaEntities.JWTData) error {
func (f SingleFlow) Validate(ctx context.Context, challenge string, JWTData mfaEntities.JWTData, challengeInput *string) error {
//TODO implement me
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (f SingleFlow) Resolve(jwtData mfaEntities.JWTData) (*map[string]interface{
}, nil
}

func (f SingleFlow) Validate(ctx context.Context, challenge string, JWTData mfaEntities.JWTData) (context.Context, error) {
func (f SingleFlow) Validate(ctx context.Context, challenge string, JWTData mfaEntities.JWTData, challengeInput *string) (context.Context, error) {
//TODO implement me
return ctx, nil
}
Expand Down
2 changes: 1 addition & 1 deletion examples/single_flow_single_challenge/flows/single_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (f SingleFlow) Initialize(ctx context.Context) (*JWTEntities.JWTAdditions,
}, nil
}

func (f SingleFlow) Validate(ctx context.Context, challenge string, JWTData mfaEntities.JWTData) (context.Context, error) {
func (f SingleFlow) Validate(ctx context.Context, challenge string, JWTData mfaEntities.JWTData, challengeInput *string) (context.Context, error) {
//TODO implement me
return ctx, nil
}
Expand Down
2 changes: 1 addition & 1 deletion flow/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type IFlow interface {
Solve(ctx context.Context, challenge string, input string, JWTData mfaEntities.JWTData) (*map[string]interface{}, error)
Request(ctx context.Context, challenge string, input string, JWTData mfaEntities.JWTData) (*map[string]interface{}, error)
Resolve(JWTData mfaEntities.JWTData) (*map[string]interface{}, error)
Validate(ctx context.Context, challenge string, JWTData mfaEntities.JWTData) (context.Context, error)
Validate(ctx context.Context, challenge string, JWTData mfaEntities.JWTData, challengeInput *string) (context.Context, error)
GetChallenges() []string
GetName() string
Initialize(ctx context.Context) (*entities.JWTAdditions, error)
Expand Down
8 changes: 4 additions & 4 deletions mfa/mfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (m *Service) decodeJWT(jwt string) (*entities.JWTData, error) {
return &decodedJWT, nil
}

func (m *Service) getFlow(ctx context.Context, flow string, decodedJWT *entities.JWTData, challenge *string) (context.Context, flow.IFlow, error) {
func (m *Service) getFlow(ctx context.Context, flow string, decodedJWT *entities.JWTData, challenge *string, input *string) (context.Context, flow.IFlow, error) {
requestedFlow := m.Flows[flow]
if requestedFlow == nil {
return ctx, nil, errors.New("Flow not found")
Expand All @@ -56,7 +56,7 @@ func (m *Service) getFlow(ctx context.Context, flow string, decodedJWT *entities
if challenge == nil {
return ctx, requestedFlow, nil
}
newCtx, err := requestedFlow.Validate(ctx, *challenge, *decodedJWT)
newCtx, err := requestedFlow.Validate(ctx, *challenge, *decodedJWT, input)
if err != nil {
return ctx, nil, err
}
Expand All @@ -69,7 +69,7 @@ func (m *Service) Process(ctx context.Context, jwt string, challenge string, inp
if err != nil {
return nil, err
}
newCtx, requestFlow, err := m.getFlow(ctx, decodedJWT.Flow, decodedJWT, &challenge)
newCtx, requestFlow, err := m.getFlow(ctx, decodedJWT.Flow, decodedJWT, &challenge, &input)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func (m *Service) setContext(ctx context.Context, requestFlow flow.IFlow, input
}

func (m *Service) Request(ctx context.Context, flow string, input *FlowInput) (*entities.MFAResult, error) {
newCtx, requestFlow, err := m.getFlow(ctx, flow, &entities.JWTData{}, nil)
newCtx, requestFlow, err := m.getFlow(ctx, flow, &entities.JWTData{}, nil, nil)
if err != nil {
return nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions mfa/mfa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestNewMFAService(t *testing.T) {
jwtService.EXPECT().GenerateToken(gomock.Any(), gomock.Any()).Return(validJWT, nil)

mockflow.EXPECT().Request(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
mockflow.EXPECT().Validate(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
mockflow.EXPECT().Validate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
mockflow.EXPECT().GetName().Return("test")
mockflow.EXPECT().GetChallenges().Return([]string{"dummy"})
mockflow.EXPECT().GetChallenges().Return([]string{"dummy"})
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestNewMFAService(t *testing.T) {
jwtService.EXPECT().GenerateToken(gomock.Any(), gomock.Any()).Return(validJWT, nil)

mockflow.EXPECT().Solve(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
mockflow.EXPECT().Validate(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
mockflow.EXPECT().Validate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
mockflow.EXPECT().GetName().Return("test")
mockflow.EXPECT().GetChallenges().Return([]string{"dummy"})
mockflow.EXPECT().GetChallenges().Return([]string{"dummy"})
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestNewMFAService(t *testing.T) {
jwtService.EXPECT().GenerateToken(gomock.Any(), gomock.Any()).Return(validJWT, nil)

mockflow.EXPECT().Solve(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("Failed to solve"))
mockflow.EXPECT().Validate(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
mockflow.EXPECT().Validate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
mockflow.EXPECT().GetName().Return("test")
mockflow.EXPECT().GetChallenges().Return([]string{"dummy"})
mockflow.EXPECT().GetChallenges().Return([]string{"dummy"})
Expand Down Expand Up @@ -365,7 +365,7 @@ func TestNewMFAService(t *testing.T) {
jwtService.EXPECT().GenerateToken(gomock.Any(), gomock.Any()).Return(validJWT, nil)

mockflow.EXPECT().Solve(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
mockflow.EXPECT().Validate(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
mockflow.EXPECT().Validate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
mockflow.EXPECT().GetName().Return("test")
mockflow.EXPECT().GetChallenges().Return([]string{"dummy"})
mockflow.EXPECT().GetChallenges().Return([]string{"dummy"})
Expand Down Expand Up @@ -401,7 +401,7 @@ func TestNewMFAService(t *testing.T) {
jwtService.EXPECT().GenerateToken(gomock.Any(), gomock.Any()).Return(validJWT, nil)

mockflow.EXPECT().Solve(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
mockflow.EXPECT().Validate(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
mockflow.EXPECT().Validate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
mockflow.EXPECT().GetName().Return("test")
mockflow.EXPECT().GetChallenges().Return([]string{"dummy"})
mockflow.EXPECT().GetChallenges().Return([]string{"dummy"})
Expand Down
8 changes: 4 additions & 4 deletions mocks/mock_flow.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4c4b446

Please sign in to comment.