Skip to content

Commit

Permalink
check type of audience parameter in old place
Browse files Browse the repository at this point in the history
  • Loading branch information
Rene Springer committed Nov 14, 2017
1 parent fcf32b3 commit dd3df0f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 3 additions & 3 deletions jwt/api_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ def _validate_claims(self, payload, options, audience=None, issuer=None,
if isinstance(leeway, timedelta):
leeway = timedelta_total_seconds(leeway)

if not isinstance(audience, (string_types, type(None), list)):
raise TypeError('audience must be a string, list of strings, or None')

self._validate_required_claims(payload, options)

now = timegm(datetime.utcnow().utctimetuple())
Expand Down Expand Up @@ -162,9 +165,6 @@ def _validate_aud(self, payload, audience):
if isinstance(audience, string_types):
audience = [audience]

if not isinstance(audience, list):
raise InvalidAudienceError('Invalid audience format')

for aud in audience:
if aud in audience_claims:
return
Expand Down
3 changes: 1 addition & 2 deletions tests/test_api_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_decode_with_invalid_audience_param_throws_exception(self, jwt):
jwt.decode(example_jwt, secret, audience=1)

exception = context.value
assert str(exception) == 'audience must be a string or None'
assert str(exception) == 'audience must be a string, list of strings, or None'

def test_decode_with_nonlist_aud_claim_throws_exception(self, jwt):
secret = 'secret'
Expand Down Expand Up @@ -289,7 +289,6 @@ def test_check_audience_list_when_valid(self, jwt):
token = jwt.encode(payload, 'secret')
jwt.decode(token, 'secret', audience=['urn:you', 'urn:me'])


def test_raise_exception_invalid_audience_list(self, jwt):
payload = {
'some': 'payload',
Expand Down

0 comments on commit dd3df0f

Please sign in to comment.