Skip to content

Commit

Permalink
Fixed panic for bearer token factory (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristinapathak authored Sep 5, 2019
1 parent c57ecd5 commit a60b791
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion basculehttp/tokenFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ func (btf BearerTokenFactory) ParseAndValidate(ctx context.Context, _ *http.Requ
}

leewayclaims := bascule.ClaimsWithLeeway{
Leeway: btf.Leeway,
MapClaims: make(jwt.MapClaims),
Leeway: btf.Leeway,
}

jwsToken, err := btf.Parser.ParseJWT(value, &leewayclaims, keyfunc)
Expand Down
2 changes: 1 addition & 1 deletion jws.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (parser defaultJWTParser) ParseJWT(token string, claims jwt.Claims, parseFu
var DefaultJWTParser JWTParser = defaultJWTParser{}

type ClaimsWithLeeway struct {
*jwt.MapClaims
jwt.MapClaims
Leeway Leeway
}

Expand Down
22 changes: 22 additions & 0 deletions jws_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package bascule

import (
"testing"

jwt "github.com/dgrijalva/jwt-go"
"github.com/stretchr/testify/assert"
)

func TestValid(t *testing.T) {
assert := assert.New(t)
claims := ClaimsWithLeeway{
MapClaims: make(jwt.MapClaims),
Leeway: Leeway{
EXP: 5,
NBF: 5,
IAT: 5,
},
}
err := claims.Valid()
assert.Nil(err)
}

0 comments on commit a60b791

Please sign in to comment.