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

fix: catch InvalidToken exceptions from fernet #534

Merged
merged 1 commit into from
Jul 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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