This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug: trap JWS/JWT errors from being reported as Sentry Errors
Silence Jose errors from handling the Auth header. Closes #610
- Loading branch information
Showing
4 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
) | ||
from cryptography.fernet import InvalidToken | ||
from jose import jws | ||
from jose.exceptions import JWTClaimsError | ||
from marshmallow import Schema, fields | ||
from mock import Mock, patch | ||
from moto import mock_dynamodb2 | ||
|
@@ -689,6 +690,41 @@ def test_invalid_encryption_header(self, mock_jwt): | |
eq_(cm.exception.status_code, 401) | ||
eq_(cm.exception.errno, 110) | ||
|
||
@patch("autopush.web.validation.extract_jwt") | ||
def test_invalid_encryption_jwt(self, mock_jwt): | ||
schema = self._makeFUT() | ||
self.fernet_mock.decrypt.return_value = dummy_token | ||
# use a deeply superclassed error to make sure that it gets picked up. | ||
mock_jwt.side_effect = JWTClaimsError("invalid claim") | ||
|
||
header = {"typ": "JWT", "alg": "ES256"} | ||
payload = {"aud": "https://push.example.com", | ||
"exp": int(time.time()) + 86400, | ||
"sub": "mailto:[email protected]"} | ||
|
||
token, crypto_key = self._gen_jwt(header, payload) | ||
auth = "Bearer %s" % token | ||
ckey = 'keyid="a1"; dh="foo";p256ecdsa="%s"' % crypto_key | ||
info = self._make_test_data( | ||
body="asdfasdfasdfasdf", | ||
path_kwargs=dict( | ||
api_ver="v0", | ||
token="asdfasdf", | ||
), | ||
headers={ | ||
"content-encoding": "aes128", | ||
"encryption": "salt=stuff", | ||
"authorization": auth, | ||
"crypto-key": ckey | ||
} | ||
) | ||
|
||
with assert_raises(InvalidRequest) as cm: | ||
schema.load(info) | ||
|
||
eq_(cm.exception.status_code, 401) | ||
eq_(cm.exception.errno, 109) | ||
|
||
@patch("autopush.web.validation.extract_jwt") | ||
def test_invalid_crypto_key_header_content(self, mock_jwt): | ||
schema = self._makeFUT() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters