fix tests and instantiate

This commit is contained in:
Mike Fridman 2024-08-02 08:58:24 -04:00
parent 1378353032
commit 012a151b46
No known key found for this signature in database
2 changed files with 10 additions and 6 deletions

View File

@ -93,7 +93,7 @@ func (p *Parser) ParseWithClaims(tokenString string, claims Claims, keyFunc Keyf
} }
switch have := got.(type) { switch have := got.(type) {
case VerificationKeySet: case VerificationKeySet[VerificationKey]:
if len(have.Keys) == 0 { if len(have.Keys) == 0 {
return token, newError("keyfunc returned empty verification key set", ErrTokenUnverifiable) return token, newError("keyfunc returned empty verification key set", ErrTokenUnverifiable)
} }

View File

@ -30,22 +30,26 @@ var (
nilKeyFunc jwt.Keyfunc = nil nilKeyFunc jwt.Keyfunc = nil
multipleZeroKeyFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) { return []interface{}{}, nil } multipleZeroKeyFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) { return []interface{}{}, nil }
multipleEmptyKeyFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) { multipleEmptyKeyFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) {
return jwt.VerificationKeySet{Keys: []jwt.VerificationKey{nil, nil}}, nil keys := []jwt.VerificationKey{nil, nil}
return jwt.VerificationKeySet[jwt.VerificationKey]{Keys: keys}, nil
} }
multipleVerificationKeysFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) { multipleVerificationKeysFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) {
return []jwt.VerificationKey{jwtTestDefaultKey, jwtTestEC256PublicKey}, nil return []jwt.VerificationKey{jwtTestDefaultKey, jwtTestEC256PublicKey}, nil
} }
multipleLastKeyFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) { multipleLastKeyFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) {
return jwt.VerificationKeySet{Keys: []jwt.VerificationKey{jwtTestEC256PublicKey, jwtTestDefaultKey}}, nil keys := []jwt.VerificationKey{jwtTestEC256PublicKey, jwtTestDefaultKey}
return jwt.VerificationKeySet[jwt.VerificationKey]{Keys: keys}, nil
} }
multipleFirstKeyFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) { multipleFirstKeyFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) {
return jwt.VerificationKeySet{Keys: []jwt.VerificationKey{jwtTestDefaultKey, jwtTestEC256PublicKey}}, nil keys := []jwt.VerificationKey{jwtTestDefaultKey, jwtTestEC256PublicKey}
return jwt.VerificationKeySet[jwt.VerificationKey]{Keys: keys}, nil
} }
multipleAltTypedKeyFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) { multipleAltTypedKeyFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) {
return jwt.VerificationKeySet{Keys: []jwt.VerificationKey{jwtTestDefaultKey, jwtTestDefaultKey}}, nil keys := []jwt.VerificationKey{jwtTestDefaultKey, jwtTestDefaultKey}
return jwt.VerificationKeySet[jwt.VerificationKey]{Keys: keys}, nil
} }
emptyVerificationKeySetFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) { emptyVerificationKeySetFunc jwt.Keyfunc = func(t *jwt.Token) (interface{}, error) {
return jwt.VerificationKeySet{}, nil return jwt.VerificationKeySet[jwt.VerificationKey]{}, nil
} }
) )