Skip to content

Commit

Permalink
feat: add metadata to MFAError (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
bludot authored Apr 18, 2022
1 parent a9ce16e commit 30ea24b
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/semantic-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ on:

jobs:
main:
name: Validate PR title
name: Semantic Pull Request
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v4
name: Semantic Pull Request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12 changes: 8 additions & 4 deletions examples/graphql_flow/challenges/dummy.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package challenges

import (
"errors"
"context"
"log"
"math/rand"
"time"

"github.com/honestbank/mfa-lib/challenge"
"github.com/honestbank/mfa-lib/challenge/entities"
mfaEntities "github.com/honestbank/mfa-lib/mfa/entities"
)

var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
Expand All @@ -25,16 +26,19 @@ type DummyChallenge struct {
Seed string `json:"seed"`
}

func (c *DummyChallenge) Solve(body map[string]interface{}) (*map[string]interface{}, error) {
func (c *DummyChallenge) Solve(ctx context.Context, body map[string]interface{}) (*map[string]interface{}, error) {
log.Println("seed:", c.Seed)
log.Println("password:", body["code"])
if body["reference"] == c.Seed && body["code"] == "123" {
return nil, nil
}
return nil, errors.New("failed!")
return nil, &mfaEntities.MFAError{
Code: "failed",
Message: "failed",
}
}

func (c *DummyChallenge) Request(body map[string]interface{}) (*map[string]interface{}, error) {
func (c *DummyChallenge) Request(ctx context.Context, body map[string]interface{}) (*map[string]interface{}, error) {
rand.Seed(time.Now().UnixNano())
c.Seed = randSeq(10)
log.Println("Seed:", c.Seed)
Expand Down
4 changes: 2 additions & 2 deletions examples/graphql_flow/flows/single_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func (f SingleFlow) Initialize(ctx context.Context) (*JWTEntities.JWTAdditions,
}, nil
}

func (f SingleFlow) Validate(ctx context.Context, challenge string, JWTData mfaEntities.JWTData, challengeInput *string) error {
func (f SingleFlow) Validate(ctx context.Context, challenge string, JWTData mfaEntities.JWTData, challengeInput *string) (context.Context, error) {
//TODO implement me
return nil
return ctx, nil
}

func (f SingleFlow) Resolve(jwtData mfaEntities.JWTData) (*map[string]interface{}, error) {
Expand Down
2 changes: 1 addition & 1 deletion examples/graphql_flow/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.17

require (
github.com/99designs/gqlgen v0.15.1
github.com/honestbank/mfa-lib v1.5.2
github.com/honestbank/mfa-lib v1.10.1
github.com/vektah/gqlparser/v2 v2.2.0
)

Expand Down
2 changes: 2 additions & 0 deletions examples/graphql_flow/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/honestbank/mfa-lib v1.10.1 h1:AShZsLrew0sHPjTA67F47sAATA0/Il4AXfiu9Xjxnmw=
github.com/honestbank/mfa-lib v1.10.1/go.mod h1:YQhuFfNvaJbSoAEgJf6Img4o2DiKgKgK3FZ+hsuaWTc=
github.com/kevinmbeaulieu/eq-go v1.0.0/go.mod h1:G3S8ajA56gKBZm4UB9AOyoOS37JO3roToPzKNM8dtdM=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down
6 changes: 3 additions & 3 deletions examples/graphql_flow/graph/schema.resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func (r *mutationResolver) InitializeFlow(ctx context.Context, flowName string) (*model.InitializeFlowResponse, error) {
result, err := r.MFAService.Request(ctx, flowName)
result, err := r.MFAService.Request(ctx, flowName, nil)
if err != nil {
return nil, err
}
Expand All @@ -30,7 +30,7 @@ func (r *mutationResolver) ChallengesSolveOtp(ctx context.Context, input *model.
return nil, err
}
log.Println(string(jsonInput))
result, err := r.MFAService.Process(ctx, ctx.Value("jwt").(string), "dummy", string(jsonInput), false)
result, err := r.MFAService.Process(ctx, ctx.Value("jwt").(string), "dummy", string(jsonInput), false, nil)
if err != nil {
return nil, err
}
Expand All @@ -42,7 +42,7 @@ func (r *mutationResolver) ChallengesSolveOtp(ctx context.Context, input *model.
}

func (r *mutationResolver) ChallengesRequestOtp(ctx context.Context) (*model.RequestOTPResult, error) {
result, err := r.MFAService.Process(ctx, ctx.Value("jwt").(string), "dummy", "{}", true)
result, err := r.MFAService.Process(ctx, ctx.Value("jwt").(string), "dummy", "{}", true, nil)
if err != nil {
return nil, err
}
Expand Down
7 changes: 5 additions & 2 deletions examples/single_flow_multiple_challenges/challenges/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package challenges

import (
"context"
"errors"
"log"
"math/rand"
"time"

"github.com/honestbank/mfa-lib/challenge"
"github.com/honestbank/mfa-lib/challenge/entities"
mfaEntities "github.com/honestbank/mfa-lib/mfa/entities"
)

var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
Expand All @@ -32,7 +32,10 @@ func (c *DummyChallenge) Solve(ctx context.Context, body map[string]interface{})
if body["username"] == "admin" && body["password"].(string) == c.Seed {
return nil, nil
}
return nil, errors.New("failed!")
return nil, &mfaEntities.MFAError{
Code: "failed",
Message: "failed",
}
}

func (c *DummyChallenge) Request(ctx context.Context, body map[string]interface{}) (*map[string]interface{}, error) {
Expand Down
7 changes: 5 additions & 2 deletions examples/single_flow_multiple_challenges/challenges/dummy2.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package challenges

import (
"context"
"errors"
"log"
"math/rand"
"time"

"github.com/honestbank/mfa-lib/challenge"
"github.com/honestbank/mfa-lib/challenge/entities"
mfaEntities "github.com/honestbank/mfa-lib/mfa/entities"
)

type DummyTwoChallenge struct {
Expand All @@ -22,7 +22,10 @@ func (c *DummyTwoChallenge) Solve(ctx context.Context, body map[string]interface
if body["username"] == "admin" && body["password"].(string) == c.Seed {
return nil, nil
}
return nil, errors.New("failed!")
return nil, &mfaEntities.MFAError{
Code: "failed",
Message: "failed",
}
}

func (c *DummyTwoChallenge) Request(ctx context.Context, body map[string]interface{}) (*map[string]interface{}, error) {
Expand Down
5 changes: 3 additions & 2 deletions mfa/entities/error.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package entities

type MFAError struct {
Code string
Message string
Code string
Message string
Metadata interface{}
}

func (e MFAError) Error() string {
Expand Down

0 comments on commit 30ea24b

Please sign in to comment.