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

Commit

Permalink
bug: Handle legacy simplepush records as candidate webpush records
Browse files Browse the repository at this point in the history
Some older records in the database appear to have been miscategorized as
"simplepush". We should try to handle those as "webpush".

Closes #1033
  • Loading branch information
jrconlin committed Oct 3, 2017
1 parent a9a1330 commit a0c7dfa
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion autopush/tests/test_endpoint.py
Original file line number Diff line number Diff line change
@@ -330,7 +330,7 @@ def test_post_bad_router_type(self):
self.patch('uuid.uuid4', return_value=dummy_uaid)

resp = yield self.client.post(
self.url(router_type="foo"),
self.url(router_type="simplepush"),
headers={"Authorization": self.auth},
body=json.dumps(dict(
type="invalid",
15 changes: 15 additions & 0 deletions autopush/tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -462,6 +462,21 @@ def test_webpush_data_delivery_to_connected_client_uaid_fail(self):
))
yield self.shut_down(client)

@inlineCallbacks
def test_legacy_simplepush_record(self):
"""convert to webpush record and see if it works"""
client = yield self.quick_register()
uaid = "deadbeef00000000deadbeef00000001"
self.ep.db.router.get_uaid = Mock(
return_value={'router_type': 'simplepush',
'uaid': uaid,
'current_month': self.ep.db.current_msg_month})
self.ep.db.message_tables[
self.ep.db.current_msg_month].all_channels = Mock(
return_value=(True, client.channels))
yield client.send_notification()
yield self.shut_down(client)

@patch("autopush.metrics.datadog")
@inlineCallbacks
def test_webpush_data_delivery_to_disconnected_client(self, m_ddog):
2 changes: 1 addition & 1 deletion autopush/web/registration.py
Original file line number Diff line number Diff line change
@@ -176,7 +176,7 @@ def validate_auth(self, data):
def conditional_token_check(object_dict, parent_dict):
ptype = parent_dict['path_kwargs']['type']
# Basic "bozo-filter" to prevent customer surprises later.
if ptype not in ['apns', 'fcm', 'gcm', 'webpush', 'simplepush', 'test']:
if ptype not in ['apns', 'fcm', 'gcm', 'webpush', 'test']:
raise InvalidRequest("Unknown registration type",
status_code=400,
errno=108,
5 changes: 5 additions & 0 deletions autopush/web/webpush.py
Original file line number Diff line number Diff line change
@@ -99,6 +99,11 @@ def validate_uaid_month_and_chid(self, d):
result.get("critical_failure"),
status_code=410,
errno=105)
# Some stored user records are marked as "simplepush".
# If you encounter one, may need to tweak it a bit to get it as
# a valid WebPush record.
if result["router_type"] == "simplepush":
result["router_type"] = "webpush"

if result["router_type"] == "webpush":
self._validate_webpush(d, result)

0 comments on commit a0c7dfa

Please sign in to comment.