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 #573 from mozilla-services/bug/561a
Browse files Browse the repository at this point in the history
bug: Fix up FCM library to reject enpdoints with invalid FCM senderids
  • Loading branch information
jrconlin authored Jul 29, 2016
2 parents 0ede5f7 + 56633e4 commit 68c6a51
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 8 additions & 0 deletions autopush/router/fcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def register(self, uaid, router_data, router_token=None, *kwargs):
if "token" not in router_data:
raise self._error("connect info missing FCM Instance 'token'",
status=401)
# router_token and router_data['token'] are semi-legacy from when
# we were considering having multiple senderids for outbound
# GCM support. That was abandoned, but it is still useful to
# ensure that the client's senderid value matches what we need
# it to be. (If the client has an unexpected or invalid SenderID,
# it is impossible for us to reach them.
if not (router_token == router_data['token'] == self.senderID):
raise self._error("Invalid SenderID", status=410, errno=105)
# Assign a senderid
router_data["creds"] = {"senderID": self.senderID, "auth": self.auth}
return router_data
Expand Down
11 changes: 9 additions & 2 deletions autopush/tests/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,14 +626,21 @@ def check_results(fail):
d.addBoth(check_results)
return d

def test_ammend(self):
self.router.register("uaid", {"token": "connect_data"})
def test_amend(self):
self.router.register(uaid="uaid",
router_data={"token": "test123"},
router_token="test123")
resp = {"key": "value"}
result = self.router.amend_msg(resp,
self.router_data.get('router_data'))
eq_({"key": "value", "senderid": "test123"},
result)

def test_register_invalid_token(self):
self.assertRaises(RouterException, self.router.register,
uaid="uaid", router_data={"token": "invalid"},
router_token="invalid")


class SimplePushRouterTestCase(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit 68c6a51

Please sign in to comment.