diff --git a/mfa/entities/error.go b/mfa/entities/error.go new file mode 100644 index 0000000..df424e2 --- /dev/null +++ b/mfa/entities/error.go @@ -0,0 +1,10 @@ +package entities + +type MFAError struct { + Code string + Message string +} + +func (e MFAError) Error() string { + return e.Message +} diff --git a/mfa/entities/status.go b/mfa/entities/status.go new file mode 100644 index 0000000..5f05e3f --- /dev/null +++ b/mfa/entities/status.go @@ -0,0 +1,8 @@ +package entities + +const ( + StatusPassed string = "PASSED" + StatusFailed string = "FAILED" + StatusSkipped string = "SKIPPED" + StatusPending string = "PENDING" +) diff --git a/mfa/mfa.go b/mfa/mfa.go index 7514d03..0b04f6c 100644 --- a/mfa/mfa.go +++ b/mfa/mfa.go @@ -165,7 +165,7 @@ func (m *Service) handleRequest(ctx context.Context, decodedJWT entities.JWTData var challenges []string for _, flowChallenge := range requestFlow.GetChallenges(&claims.Challenges, &challenge) { - if claims.Challenges[flowChallenge].Status != "passed" { + if claims.Challenges[flowChallenge].Status != entities.StatusPassed { challenges = append(challenges, flowChallenge) } } @@ -202,7 +202,7 @@ func (m *Service) handleSolve(ctx context.Context, decodedJWT entities.JWTData, scopes := make([]string, 0) claims, _ := m.generateClaims(requestFlow, decodedJWT, challenge) claims.Challenges[challenge] = entities.Challenge{ - Status: "failed", + Status: err.(*entities.MFAError).Code, } token, _ := m.JWTService.GenerateToken(claims, scopes) var challenges []string @@ -217,12 +217,12 @@ func (m *Service) handleSolve(ctx context.Context, decodedJWT entities.JWTData, scopes := make([]string, 0) claims, _ := m.generateClaims(requestFlow, decodedJWT, challenge) claims.Challenges[challenge] = entities.Challenge{ - Status: "passed", + Status: entities.StatusPassed, } token, _ := m.JWTService.GenerateToken(claims, scopes) var challenges []string for _, flowChallenge := range requestFlow.GetChallenges(&claims.Challenges, &challenge) { - if claims.Challenges[flowChallenge].Status != "passed" { + if claims.Challenges[flowChallenge].Status != entities.StatusPassed { challenges = append(challenges, flowChallenge) } } diff --git a/mfa/mfa_test.go b/mfa/mfa_test.go index c6800e3..7669477 100644 --- a/mfa/mfa_test.go +++ b/mfa/mfa_test.go @@ -174,7 +174,10 @@ 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().Solve(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, &entities.MFAError{ + Code: "FAILED", + Message: "Failed to solve", + }) mockflow.EXPECT().Validate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil) mockflow.EXPECT().GetName().Return("test") mockflow.EXPECT().GetChallenges(gomock.Any(), gomock.Any()).Return([]string{"dummy"})