Skip to content

Commit

Permalink
Add test case for no kid without new option
Browse files Browse the repository at this point in the history
  • Loading branch information
darnmason committed Oct 13, 2020
1 parent ad72c86 commit 34eadc3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions jwt/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@ func TestJWTParseVerify(t *testing.T) {
return
}
})
t.Run("No kid should fail", func(t *testing.T) {
pubkey := jwk.NewRSAPublicKey()
if !assert.NoError(t, pubkey.FromRaw(&key.PublicKey)) {
return
}

pubkey.Set(jwk.KeyIDKey, kid)
signedNoKid, err := jwt.Sign(t1, alg, key)
if err != nil {
t.Fatal("Failed to sign JWT")
}
_, err = jwt.Parse(bytes.NewReader(signedNoKid), jwt.WithKeySet(&jwk.Set{Keys: []jwk.Key{pubkey}}))
if !assert.Error(t, err, `jwt.Parse should fail`) {
return
}
})
t.Run("Pick default key from set of 1", func(t *testing.T) {
pubkey := jwk.NewRSAPublicKey()
if !assert.NoError(t, pubkey.FromRaw(&key.PublicKey)) {
Expand Down

0 comments on commit 34eadc3

Please sign in to comment.