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 #633 from mozilla-services/bug/630
Browse files Browse the repository at this point in the history
bug: add URI to error messages to aid in bad senderIDs
  • Loading branch information
bbangert authored Aug 25, 2016
2 parents 4ff55d6 + 05e5d00 commit 2f783fe
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
5 changes: 3 additions & 2 deletions autopush/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,8 @@ def post(self, router_type="", router_token="", uaid="", chid=""):
self.app_server_key = params.get("key")
if new_uaid:
d = Deferred()
d.addCallback(router.register, params, router_token)
d.addCallback(router.register, params, router_token,
uri=self.request.uri)
d.addCallback(self._save_router_data, router_type)
d.addCallback(self._create_endpoint)
d.addCallback(self._return_endpoint, new_uaid, router)
Expand Down Expand Up @@ -751,7 +752,7 @@ def put(self, router_type="", router_token="", uaid="", chid=""):

self.add_header("Content-Type", "application/json")
d = Deferred()
d.addCallback(router.register, router_data)
d.addCallback(router.register, router_data, uri=self.request.uri)
d.addCallback(self._save_router_data, router_type)
d.addCallback(self._success)
d.addErrback(self._router_fail_err)
Expand Down
2 changes: 1 addition & 1 deletion autopush/router/apnsrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, ap_settings, router_conf):
self._connect()
self.log.debug("Starting APNS router...")

def register(self, uaid, router_data, *kwargs):
def register(self, uaid, router_data, *args, **kwargs):
"""Validate that an APNs instance token is in the ``router_data``"""
if not router_data.get("token"):
raise RouterException("No token registered", status_code=500,
Expand Down
6 changes: 4 additions & 2 deletions autopush/router/fcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,14 @@ def amend_msg(self, msg, data=None):
msg["senderid"] = data.get('creds', {}).get('senderID')
return msg

def register(self, uaid, router_data, senderid=None, *kwargs):
def register(self, uaid, router_data, senderid=None, *args, **kwargs):
"""Validate that the FCM Instance Token is in the ``router_data``"""
# "token" is the GCM registration id token generated by the client.
if "token" not in router_data:
raise self._error("connect info missing FCM Instance 'token'",
status=401)
status=401,
uri=kwargs.get('uri'),
senderid=repr(senderid))
# senderid is the remote client's senderID value. This value is
# very difficult for the client to change, and there was a problem
# where some clients had an older, invalid senderID. We need to
Expand Down
6 changes: 4 additions & 2 deletions autopush/router/gcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def amend_msg(self, msg, data=None):
msg["senderid"] = data.get('creds', {}).get('senderID')
return msg

def register(self, uaid, router_data, senderid=None, *kwargs):
def register(self, uaid, router_data, senderid=None, *args, **kwargs):
"""Validate that the GCM Instance Token is in the ``router_data``"""
# "token" is the GCM registration id token generated by the client.
if "token" not in router_data:
Expand All @@ -57,7 +57,9 @@ def register(self, uaid, router_data, senderid=None, *kwargs):
# If the client has an unexpected or invalid SenderID,
# it is impossible for us to reach them.
if senderid not in self.senderIDs:
raise self._error("Invalid SenderID", status=410, errno=105)
raise self._error("Invalid SenderID", status=410, errno=105,
uri=kwargs.get('uri'),
senderid=repr(senderid))
# Assign a senderid
router_data["creds"] = {"senderID": senderid,
"auth": self.senderIDs[senderid]}
Expand Down
5 changes: 3 additions & 2 deletions autopush/router/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class RouterException(AutopushException):
"""
def __init__(self, message, status_code=500, response_body="",
router_data=None, headers=None, log_exception=True,
errno=None, logged_status=None):
errno=None, logged_status=None, **kwargs):
"""Create a new RouterException"""
super(AutopushException, self).__init__(message)
self.status_code = status_code
Expand All @@ -18,6 +18,7 @@ def __init__(self, message, status_code=500, response_body="",
self.response_body = response_body or message
self.errno = errno
self.logged_status = logged_status
self.extra = kwargs


class RouterResponse(object):
Expand Down Expand Up @@ -45,7 +46,7 @@ def __init__(self, settings, router_conf):
the given settings and router conf."""
raise NotImplementedError("__init__ must be implemented")

def register(self, uaid, routing_data, *kwargs):
def register(self, uaid, routing_data, *args, **kwargs):
"""Register the uaid with the connect dict however is preferred and
return a dict that will be stored as routing_data for this user in the
future.
Expand Down
2 changes: 1 addition & 1 deletion autopush/router/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, ap_settings, router_conf):
self.conf = router_conf
self.waker = None

def register(self, uaid, connect, *kwargs):
def register(self, uaid, connect, *args, **kwargs):
"""Return no additional routing data"""
return {}

Expand Down
7 changes: 5 additions & 2 deletions autopush/tests/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ def setUp(self):
self.reg = endpoint.RegistrationHandler(Application(),
self.request_mock,
ap_settings=settings)

self.reg.request.uri = '/v1/xxx/yyy/register'
self.status_mock = self.reg.set_status = Mock()
self.write_mock = self.reg.write = Mock()
self.auth = ("WebPush %s" %
Expand Down Expand Up @@ -1558,6 +1558,7 @@ def test_post(self, *args):
channelID=dummy_chid,
data={},
))
self.reg.request.uri = "/v1/xxx/yyy/register"
self.fernet_mock.configure_mock(**{
'encrypt.return_value': 'abcd123',
})
Expand Down Expand Up @@ -1808,7 +1809,9 @@ def test_put(self, *args):

def handle_finish(value):
self.reg.write.assert_called_with({})
self.router_mock.register.assert_called_with(dummy_uaid, data)
self.router_mock.register.assert_called_with(
dummy_uaid, data, uri=self.reg.request.uri
)

self.finish_deferred.addCallback(handle_finish)
self.reg.request.headers["Authorization"] = self.auth
Expand Down

0 comments on commit 2f783fe

Please sign in to comment.