Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
fix: catch InvalidToken exceptions from fernet
Browse files Browse the repository at this point in the history
Closes #530
  • Loading branch information
bbangert committed Jul 19, 2016
1 parent a79f3a6 commit 04b2d1e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions autopush/tests/test_web_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from boto.dynamodb2.exceptions import (
ItemNotFound,
)
from cryptography.fernet import InvalidToken
from jose import jws
from marshmallow import Schema, fields
from mock import Mock
Expand Down Expand Up @@ -343,6 +344,19 @@ def throw_item(*args, **kwargs):

eq_(cm.exception.errno, 102)

def test_invalid_fernet_token(self):
schema = self._makeFUT()

def throw_item(*args, **kwargs):
raise InvalidToken

schema.context["settings"].parse_endpoint.side_effect = throw_item

with assert_raises(InvalidRequest) as cm:
schema.load(self._make_test_data())

eq_(cm.exception.errno, 102)

def test_invalid_uaid_not_found(self):
schema = self._makeFUT()
schema.context["settings"].parse_endpoint.return_value = dict(
Expand Down
3 changes: 2 additions & 1 deletion autopush/web/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from boto.dynamodb2.exceptions import (
ItemNotFound,
)
from cryptography.fernet import InvalidToken
from marshmallow import (
Schema,
fields,
Expand Down Expand Up @@ -194,7 +195,7 @@ def extract_subscription(self, d):
version=d["api_ver"],
ckey_header=d["ckey_header"],
)
except InvalidTokenException:
except (InvalidTokenException, InvalidToken):
raise InvalidRequest("invalid token", errno=102)
return result

Expand Down

0 comments on commit 04b2d1e

Please sign in to comment.