Permalink
Browse files

adds a test to validate a token generated externally

  • Loading branch information...
henderjon committed Feb 22, 2018
1 parent 0c02049 commit c702dd399b61b2d05337c2de53e65b516d9da7a1
Showing with 14 additions and 3 deletions.
  1. +14 −3 jwt_test.go
@@ -24,8 +24,8 @@ func RunTest(t *testing.T, command func(Algorithm)) {
func TestEncodeAndValidateToken(t *testing.T) {
RunTest(t, func(algorithm Algorithm) {
payload := NewClaim()
payload.SetTime("nbf", time.Now().Add(time.Duration(-1) * time.Hour))
payload.SetTime("exp", time.Now().Add(time.Duration(100) * time.Hour))
payload.SetTime("nbf", time.Now().Add(time.Duration(-1)*time.Hour))
payload.SetTime("exp", time.Now().Add(time.Duration(100)*time.Hour))
token, err := algorithm.Encode(payload)
if err != nil {
@@ -90,7 +90,7 @@ func TestVerifyTokenNbf(t *testing.T) {
RunTest(t, func(algorithm Algorithm) {
payload := NewClaim()
payload.SetTime("nbf", time.Now().Add(time.Duration(1) * time.Hour))
payload.SetTime("nbf", time.Now().Add(time.Duration(1)*time.Hour))
err := json.Unmarshal([]byte(`{"sub":"1234567890","name":"John Doe","admin":true}`), &payload)
if err != nil {
@@ -120,3 +120,14 @@ func TestDecodeMalformedToken(t *testing.T) {
}
})
}
func TestValidateExternalToken(t *testing.T) {
token := "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6ImZmNzJkMWM5LTMzMTktNGIyOS04YjlhLWU1OThkNGJhNDRlZCJ9.eyJpc3MiOiJodHRwOi8vbG9jYWwuaG9zdC5jb20iLCJhdWQiOiJodHRwOi8vbG9jYWwuaG9zdC5jb20iLCJqdGkiOiJmZjcyZDFjOS0zMzE5LTRiMjktOGI5YS1lNTk4ZDRiYTQ0ZWQiLCJpYXQiOjE1MTkzMjc2NDYsIm5iZiI6MTUxOTMyNzY1MCwiZXhwIjoxNjQwMzkwNDAwfQ.ASo8eiekkwZ7on43S9n697x-SqmdehY680GetK_KqpI"
algorithm := HmacSha256("this-needs-a-test")
err := algorithm.Validate(token)
if err != nil {
t.Fatal(err)
}
}

0 comments on commit c702dd3

Please sign in to comment.