summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMauricio Aizaga <mauricioaizaga@gmail.com>2015-10-22 15:22:09 -0500
committerMauricio Aizaga <mauricioaizaga@gmail.com>2015-10-22 15:22:09 -0500
commit139dd05d1589ddcb4f8c9bd1b16b743ee4fcd2f6 (patch)
treed9e168653ae3f364d558b571e7422ffab9bf8546
parentd3388831042051862f7fd8ba993bf814d341511d (diff)
downloadpyjwt-139dd05d1589ddcb4f8c9bd1b16b743ee4fcd2f6.tar.gz
Fixed #183 AttributeError: 'NoneType' object has no attribute 'rsplit'
The issue also occurs when payload is int raising: AttributeError: 'int' object has no attribute 'rsplit' Test for None and int payload added
-rw-r--r--jwt/api_jws.py3
-rw-r--r--tests/test_api_jws.py18
2 files changed, 21 insertions, 0 deletions
diff --git a/jwt/api_jws.py b/jwt/api_jws.py
index 3e79d41..557812e 100644
--- a/jwt/api_jws.py
+++ b/jwt/api_jws.py
@@ -138,6 +138,9 @@ class PyJWS(object):
try:
signing_input, crypto_segment = jwt.rsplit(b'.', 1)
header_segment, payload_segment = signing_input.split(b'.', 1)
+ except AttributeError:
+ raise DecodeError('Invalid payload type. It should be a {} not {}'.format(
+ text_type, type(jwt)))
except ValueError:
raise DecodeError('Not enough segments')
diff --git a/tests/test_api_jws.py b/tests/test_api_jws.py
index 2079bef..c08d3e4 100644
--- a/tests/test_api_jws.py
+++ b/tests/test_api_jws.py
@@ -122,6 +122,24 @@ class TestJWS:
exception = context.value
assert str(exception) == 'Not enough segments'
+ def test_decode_invalid_payload_type_is_none(self, jws):
+ example_jws = None
+ example_secret = 'secret'
+
+ with pytest.raises(DecodeError) as context:
+ jws.decode(example_jws, example_secret)
+
+ assert 'Invalid payload type' in str(context.value)
+
+ def test_decode_invalid_payload_type_is_int(self, jws):
+ example_jws = 123
+ example_secret = 'secret'
+
+ with pytest.raises(DecodeError) as context:
+ jws.decode(example_jws, example_secret)
+
+ assert 'Invalid payload type' in str(context.value)
+
def test_decode_with_non_mapping_header_throws_exception(self, jws):
secret = 'secret'
example_jws = ('MQ' # == 1