Skip to content

Commit 1ce256e

Browse files
committed
Fix test coverage
1 parent 534857a commit 1ce256e

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

jose/exceptions.py

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class ExpiredSignatureError(JWTError):
2929
class JWKError(JOSEError):
3030
pass
3131

32+
3233
class JWKAlgMismatchError(JWKError):
3334
'''JWK Key type doesn't support the given algorithm.'''
3435
pass

tests/test_jws.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
import pytest
55

6-
from jose import jwk, jws, jwt
6+
from jose import jwk, jws
77
from jose.backends import RSAKey
88
from jose.constants import ALGORITHMS
9-
from jose.exceptions import JWSError
9+
from jose.exceptions import JWSError, JWKAlgMismatchError
1010

1111
try:
1212
from jose.backends.cryptography_backend import CryptographyRSAKey
@@ -26,14 +26,14 @@ def test_unicode_token(self):
2626
jws.verify(token, "secret", ["HS256"])
2727

2828
def test_hetero_keys(self):
29-
private_key = b"-----BEGIN PRIVATE KEY-----\nMIGEAgEAMBAGByqGSM49AgEGBS..."
30-
public_key = b"-----BEGIN PUBLIC KEY-----\nMHYwEAYHKoZIzj0CAQYFK4EEAC..."
31-
token = jwt.encode({"some": "claims"}, private_key, algorithm="RS256")
32-
33-
rsa_key = jwk.RSAKey(public_key, "RS256").to_dict()
34-
hmac_key = jwk.HMACKey("secret", "HS256").to_dict()
35-
# RSA key must come second to exercise "JWKAlgMismatchError"
36-
jws.verify(token, {"keys": [hmac_key, rsa_key]}, ["HS256", "RS256"])
29+
class BadKey(jwk.Key):
30+
def __init__(self, key, algorithm):
31+
if key != "xyzw":
32+
raise JWKAlgMismatchError("%s is not a valid XYZW algorithm" % algorithm)
33+
34+
token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhIjoiYiJ9.jiMyrsmD8AoHWeQgmxZ5yq8z0lXS67_QGs52AzC8Ru8"
35+
jwk.register_key("XYZW", BadKey)
36+
jws.verify(token, {"keys": [{"alg": "XYZW"}, "secret"]}, ["XYZW", "HS256"])
3737

3838
def test_multiple_keys(self):
3939
old_jwk_verify = jwk.HMACKey.verify

0 commit comments

Comments
 (0)