Skip to content

Commit 139dd05

Browse files
committed
Fixed jpadilla#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
1 parent d338883 commit 139dd05

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

jwt/api_jws.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ def _load(self, jwt):
138138
try:
139139
signing_input, crypto_segment = jwt.rsplit(b'.', 1)
140140
header_segment, payload_segment = signing_input.split(b'.', 1)
141+
except AttributeError:
142+
raise DecodeError('Invalid payload type. It should be a {} not {}'.format(
143+
text_type, type(jwt)))
141144
except ValueError:
142145
raise DecodeError('Not enough segments')
143146

tests/test_api_jws.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@ def test_decode_missing_segments_throws_exception(self, jws):
122122
exception = context.value
123123
assert str(exception) == 'Not enough segments'
124124

125+
def test_decode_invalid_payload_type_is_none(self, jws):
126+
example_jws = None
127+
example_secret = 'secret'
128+
129+
with pytest.raises(DecodeError) as context:
130+
jws.decode(example_jws, example_secret)
131+
132+
assert 'Invalid payload type' in str(context.value)
133+
134+
def test_decode_invalid_payload_type_is_int(self, jws):
135+
example_jws = 123
136+
example_secret = 'secret'
137+
138+
with pytest.raises(DecodeError) as context:
139+
jws.decode(example_jws, example_secret)
140+
141+
assert 'Invalid payload type' in str(context.value)
142+
125143
def test_decode_with_non_mapping_header_throws_exception(self, jws):
126144
secret = 'secret'
127145
example_jws = ('MQ' # == 1

0 commit comments

Comments
 (0)