Skip to content

Commit 2a93fc5

Browse files
author
Gabriel Gironda
committed
Change TypeError on bad kid to InvalidTokenError
1 parent 91fe6cd commit 2a93fc5

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

jwt/api_jws.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from .algorithms import Algorithm, get_default_algorithms # NOQA
88
from .compat import string_types, text_type
9-
from .exceptions import DecodeError, InvalidAlgorithmError
9+
from .exceptions import DecodeError, InvalidAlgorithmError, InvalidTokenError
1010
from .utils import base64url_decode, base64url_encode, merge_dict
1111

1212

@@ -190,7 +190,7 @@ def _validate_headers(self, headers):
190190

191191
def _validate_kid(self, kid):
192192
if not isinstance(kid, string_types):
193-
raise TypeError('Key ID header parameter must be a string')
193+
raise InvalidTokenError('Key ID header parameter must be a string')
194194

195195
_jws_global_obj = PyJWS()
196196
encode = _jws_global_obj.encode

tests/test_api_jws.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from jwt.algorithms import Algorithm
77
from jwt.api_jws import PyJWS
88
from jwt.exceptions import (
9-
DecodeError, InvalidAlgorithmError
9+
DecodeError, InvalidAlgorithmError, InvalidTokenError
1010
)
1111
from jwt.utils import base64url_decode
1212

@@ -381,7 +381,7 @@ def test_get_unverified_header_fails_on_bad_header_types(self, jws, payload):
381381
'.eyJzdWIiOiIxMjM0NTY3ODkwIn0'
382382
'.vs2WY54jfpKP3JGC73Vq5YlMsqM5oTZ1ZydT77SiZSk')
383383

384-
with pytest.raises(TypeError) as exc:
384+
with pytest.raises(InvalidTokenError) as exc:
385385
jws.get_unverified_header(example_jws)
386386

387387
assert 'Key ID header parameter must be a string' == str(exc.value)
@@ -611,12 +611,12 @@ def test_encode_headers_parameter_adds_headers(self, jws, payload):
611611
assert header_obj['testheader'] == headers['testheader']
612612

613613
def test_encode_fails_on_invalid_kid_types(self, jws, payload):
614-
with pytest.raises(TypeError) as exc:
614+
with pytest.raises(InvalidTokenError) as exc:
615615
jws.encode(payload, 'secret', headers={'kid': 123})
616616

617617
assert 'Key ID header parameter must be a string' == str(exc.value)
618618

619-
with pytest.raises(TypeError) as exc:
619+
with pytest.raises(InvalidTokenError) as exc:
620620
jws.encode(payload, 'secret', headers={'kid': None})
621621

622622
assert 'Key ID header parameter must be a string' == str(exc.value)

0 commit comments

Comments
 (0)