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

Commit

Permalink
Merge pull request #1034 from mozilla-services/bug/1033
Browse files Browse the repository at this point in the history
bug: Handle legacy simplepush records as candidate webpush records
  • Loading branch information
jrconlin authored Oct 4, 2017
2 parents a933325 + a0c7dfa commit 4b9a273
Show file tree
Hide file tree
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
Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions autopush/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion autopush/web/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions autopush/web/webpush.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4b9a273

Please sign in to comment.