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

Commit

Permalink
feat: Add extended err message for old encryption
Browse files Browse the repository at this point in the history
Also fixes flake8 spacing error in router/apnsrouter.

closes #432
  • Loading branch information
jrconlin committed Apr 20, 2016
1 parent cf1afd6 commit a236c90
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
13 changes: 13 additions & 0 deletions autopush/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,19 @@ def put(self, api_ver="v0", token=None):
self.start_time = time.time()
crypto_key_header = self.request.headers.get('crypto-key')

content_encoding = self.request.headers.get('content-encoding', "")
if content_encoding.lower() == 'aesgcm128' and crypto_key_header:
self.log.debug("Invalid crypto state; aesgcm128 + Crypto-Key",
**self._client_info)
wpe_url = ("https://developers.google.com/web/updates/2016/03/"
"web-push-encryption")
self._write_response(
400,
110,
message="You're using outdated encryption; "
"Please update to the format described in " + wpe_url)
return

d = deferToThread(self.ap_settings.parse_endpoint,
token,
api_ver,
Expand Down
4 changes: 2 additions & 2 deletions autopush/router/apnsrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def _route(self, notification, router_data):
"""Blocking APNS call to route the notification"""
token = router_data["token"]
custom = {
"Chid": notification.channel_id,
"Ver": notification.version,
"Chid": notification.channel_id,
"Ver": notification.version,
}
if notification.data:
custom["Msg"] = notification.data
Expand Down
22 changes: 20 additions & 2 deletions autopush/tests/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,14 @@ def setUp(self, t):
self.endpoint.finish = lambda: d.callback(True)
self.endpoint.start_time = time.time()

def _check_error(self, code, errno, error):
def _check_error(self, code, errno, error=None, message=None):
d = json.loads(self.write_mock.call_args[0][0])
eq_(d.get("code"), code)
eq_(d.get("errno"), errno)
eq_(d.get("error"), error)
if error is not None:
eq_(d.get("error"), error)
if message:
eq_(d.get("message"), message)

def test_uaid_lookup_results(self):
fresult = dict(router_type="test")
Expand Down Expand Up @@ -315,6 +318,21 @@ def handle_finish(result):
self.endpoint.post(None, dummy_uaid)
return self.finish_deferred

def test_webpush_malformed_encryption(self):

def handle_finish(value):
err_msg = ("You're using outdated encryption; Please update "
"to the format described in "
"https://developers.google.com/web/updates/2016/"
"03/web-push-encryption")
self._check_error(400, 110, message=err_msg)
self.request_mock.headers["content-encoding"] = "aesgcm128"
self.request_mock.headers["crypto-key"] = "content"

self.finish_deferred.addCallback(handle_finish)
self.endpoint.put(None, dummy_uaid)
return self.finish_deferred

def test_webpush_bad_routertype(self):
fresult = dict(router_type="fred")
self.endpoint.chid = dummy_chid
Expand Down

0 comments on commit a236c90

Please sign in to comment.