From a0c7dfaee117bad13642cc067e237bf3997c7d95 Mon Sep 17 00:00:00 2001 From: jrconlin Date: Tue, 3 Oct 2017 16:42:12 -0700 Subject: [PATCH] bug: Handle legacy simplepush records as candidate webpush records Some older records in the database appear to have been miscategorized as "simplepush". We should try to handle those as "webpush". Closes #1033 --- autopush/tests/test_endpoint.py | 2 +- autopush/tests/test_integration.py | 15 +++++++++++++++ autopush/web/registration.py | 2 +- autopush/web/webpush.py | 5 +++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/autopush/tests/test_endpoint.py b/autopush/tests/test_endpoint.py index 13c78e7a..dc9b7951 100644 --- a/autopush/tests/test_endpoint.py +++ b/autopush/tests/test_endpoint.py @@ -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", diff --git a/autopush/tests/test_integration.py b/autopush/tests/test_integration.py index 7442ba48..7087b07f 100644 --- a/autopush/tests/test_integration.py +++ b/autopush/tests/test_integration.py @@ -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): diff --git a/autopush/web/registration.py b/autopush/web/registration.py index 3aec81ca..235a6469 100644 --- a/autopush/web/registration.py +++ b/autopush/web/registration.py @@ -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, diff --git a/autopush/web/webpush.py b/autopush/web/webpush.py index fd39581f..6b2cbd7a 100644 --- a/autopush/web/webpush.py +++ b/autopush/web/webpush.py @@ -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)