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

Commit

Permalink
fix: Check connected month bounds for preflight
Browse files Browse the repository at this point in the history
Add full checks for preflight failure conditions.

Closes #461
  • Loading branch information
jrconlin committed May 5, 2016
1 parent c2ac073 commit 148daa7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
3 changes: 3 additions & 0 deletions autopush/router/webpush.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def preflight_check(self, uaid, channel_id):
log_exception=False, errno=106)

month_table = record["current_month"]
if month_table not in self.ap_settings.message_tables:
raise RouterException("No such subscription", status_code=404,
log_exception=False, errno=106)
exists, chans = yield deferToThread(
self.ap_settings.message_tables[month_table].all_channels,
uaid=uaid)
Expand Down
50 changes: 49 additions & 1 deletion autopush/tests/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,14 +757,62 @@ def verify_deliver(fail):
d.addBoth(verify_deliver)
return d

def test_route_with_missing_month(self):
self.agent_mock.request.return_value = response_mock = Mock()
response_mock.addCallback.return_value = response_mock
type(response_mock).code = PropertyMock(
side_effect=MockAssist([202, 200]))
self.message_mock.store_message.return_value = True
self.message_mock.all_channels.return_value = (True, [])
router_data = dict(node_id="http://somewhere",
uaid=dummy_uaid)
self.router_mock.get_uaid.return_value = router_data
self.router.message_id = uuid.uuid4().hex

d = self.router.route_notification(self.notif, router_data)

def verify_deliver(fail):
exc = fail.value
ok_(exc, RouterException)
eq_(exc.status_code, 404)
self.flushLoggedErrors()
d.addBoth(verify_deliver)
return d

def test_route_with_invalid_channel_id(self):
self.agent_mock.request.return_value = response_mock = Mock()
response_mock.addCallback.return_value = response_mock
type(response_mock).code = PropertyMock(
side_effect=MockAssist([202, 200]))
self.message_mock.store_message.return_value = True
self.message_mock.all_channels.return_value = (True, [])
router_data = dict(node_id="http://somewhere", uaid=dummy_uaid)
month = self.router.ap_settings.current_msg_month
router_data = dict(node_id="http://somewhere",
current_month=month,
uaid=dummy_uaid)
self.router_mock.get_uaid.return_value = router_data
self.router.message_id = uuid.uuid4().hex

d = self.router.route_notification(self.notif, router_data)

def verify_deliver(fail):
exc = fail.value
ok_(exc, RouterException)
eq_(exc.status_code, 404)
self.flushLoggedErrors()
d.addBoth(verify_deliver)
return d

def test_route_with_invalid_month(self):
self.agent_mock.request.return_value = response_mock = Mock()
response_mock.addCallback.return_value = response_mock
type(response_mock).code = PropertyMock(
side_effect=MockAssist([202, 200]))
self.message_mock.store_message.return_value = True
self.message_mock.all_channels.return_value = (True, [])
router_data = dict(node_id="http://somewhere",
current_month="invalid_month",
uaid=dummy_uaid)
self.router_mock.get_uaid.return_value = router_data
self.router.message_id = uuid.uuid4().hex

Expand Down

0 comments on commit 148daa7

Please sign in to comment.