diff options
author | Gabriel Gironda <gabriel@thegroundwork.com> | 2015-07-23 08:50:49 -0400 |
---|---|---|
committer | Gabriel Gironda <gabriel@thegroundwork.com> | 2015-07-23 08:50:49 -0400 |
commit | 2a93fc591805af3608de3330a3fd32bf5d4e9380 (patch) | |
tree | 6704bf03a161d72d3844806b13ac8a17d671c0b0 | |
parent | 91fe6cd68978620845e8c56f17348d0d8e042246 (diff) | |
download | pyjwt-2a93fc591805af3608de3330a3fd32bf5d4e9380.tar.gz |
Change TypeError on bad `kid` to InvalidTokenError
-rw-r--r-- | jwt/api_jws.py | 4 | ||||
-rw-r--r-- | tests/test_api_jws.py | 8 |
2 files changed, 6 insertions, 6 deletions
diff --git a/jwt/api_jws.py b/jwt/api_jws.py index a763638..3e79d41 100644 --- a/jwt/api_jws.py +++ b/jwt/api_jws.py @@ -6,7 +6,7 @@ from collections import Mapping from .algorithms import Algorithm, get_default_algorithms # NOQA from .compat import string_types, text_type -from .exceptions import DecodeError, InvalidAlgorithmError +from .exceptions import DecodeError, InvalidAlgorithmError, InvalidTokenError from .utils import base64url_decode, base64url_encode, merge_dict @@ -190,7 +190,7 @@ class PyJWS(object): def _validate_kid(self, kid): if not isinstance(kid, string_types): - raise TypeError('Key ID header parameter must be a string') + raise InvalidTokenError('Key ID header parameter must be a string') _jws_global_obj = PyJWS() encode = _jws_global_obj.encode diff --git a/tests/test_api_jws.py b/tests/test_api_jws.py index 6b4b881..2079bef 100644 --- a/tests/test_api_jws.py +++ b/tests/test_api_jws.py @@ -6,7 +6,7 @@ from decimal import Decimal from jwt.algorithms import Algorithm from jwt.api_jws import PyJWS from jwt.exceptions import ( - DecodeError, InvalidAlgorithmError + DecodeError, InvalidAlgorithmError, InvalidTokenError ) from jwt.utils import base64url_decode @@ -381,7 +381,7 @@ class TestJWS: '.eyJzdWIiOiIxMjM0NTY3ODkwIn0' '.vs2WY54jfpKP3JGC73Vq5YlMsqM5oTZ1ZydT77SiZSk') - with pytest.raises(TypeError) as exc: + with pytest.raises(InvalidTokenError) as exc: jws.get_unverified_header(example_jws) assert 'Key ID header parameter must be a string' == str(exc.value) @@ -611,12 +611,12 @@ class TestJWS: assert header_obj['testheader'] == headers['testheader'] def test_encode_fails_on_invalid_kid_types(self, jws, payload): - with pytest.raises(TypeError) as exc: + with pytest.raises(InvalidTokenError) as exc: jws.encode(payload, 'secret', headers={'kid': 123}) assert 'Key ID header parameter must be a string' == str(exc.value) - with pytest.raises(TypeError) as exc: + with pytest.raises(InvalidTokenError) as exc: jws.encode(payload, 'secret', headers={'kid': None}) assert 'Key ID header parameter must be a string' == str(exc.value) |