Skip to content

Commit

Permalink
feat: GetClaimsをmap[string]interface{}でアサーションする
Browse files Browse the repository at this point in the history
  • Loading branch information
ken109 committed Feb 4, 2021
1 parent eda4385 commit ab98118
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func Verify(c *gin.Context) {

func GetClaims(c *gin.Context) Claims {
if claims, ok := c.Get("claims"); ok {
return claims.(Claims)
return claims.(map[string]interface{})
} else {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ func TestVerifyValidToken(t *testing.T) {

c.Request, _ = http.NewRequest("GET", "/", nil)

token, err := GetToken(map[string]interface{}{})
token, err := GetToken(Claims{})

c.Request.Header.Add("Authorization", "bearer "+string(token))

Verify(c)

assert.Equal(t, res.Code, http.StatusOK)
assert.Equal(t, GetClaims(c), map[string]interface{}{})
assert.Equal(t, GetClaims(c), Claims{})
}

0 comments on commit ab98118

Please sign in to comment.