Skip to content

Commit

Permalink
fix: pass error to status (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
bludot authored Apr 1, 2022
1 parent 793d157 commit 8f70b5d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
10 changes: 10 additions & 0 deletions mfa/entities/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package entities

type MFAError struct {
Code string
Message string
}

func (e MFAError) Error() string {
return e.Message
}
8 changes: 8 additions & 0 deletions mfa/entities/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package entities

const (
StatusPassed string = "PASSED"
StatusFailed string = "FAILED"
StatusSkipped string = "SKIPPED"
StatusPending string = "PENDING"
)
8 changes: 4 additions & 4 deletions mfa/mfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}
Expand Down
5 changes: 4 additions & 1 deletion mfa/mfa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down

0 comments on commit 8f70b5d

Please sign in to comment.