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

Commit

Permalink
fix: ensure router_type is present in all records
Browse files Browse the repository at this point in the history
It was possible previously for a corrupted record to be missing a router_type
which caused AWS ValidationError's. This change ensures all records have
a router_type and connected_at which are required values for the register
user expression condition that AWS checks.

Closes #526
  • Loading branch information
bbangert committed Jul 17, 2016
1 parent b22fc38 commit aeeea3a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
38 changes: 38 additions & 0 deletions autopush/tests/test_websocket.py
Expand Up @@ -484,6 +484,7 @@ def test_hello_tomorrow(self):
uaid=orig_uaid,
connected_at=ms_time(),
current_month="message_2016_3",
router_type="simplepush",
))

# router.register_user returns (registered, previous
Expand Down Expand Up @@ -565,13 +566,47 @@ def check_result(msg):
eq_(self.proto.base_tags, ['use_webpush:True'])
return self._check_response(check_result)

def test_hello_with_missing_router_type(self):
self._connect()
uaid = uuid.uuid4().hex
router = self.proto.ap_settings.router
router.register_user(dict(
uaid=uaid,
connected_at=ms_time(),
))
self._send_message(dict(messageType="hello", channelIDs=[],
uaid=uaid))

def check_result(msg):
eq_(msg["status"], 200)
ok_(msg["uaid"] != uaid)
return self._check_response(check_result)

def test_hello_with_missing_current_month(self):
self._connect()
uaid = uuid.uuid4().hex
router = self.proto.ap_settings.router
router.register_user(dict(
uaid=uaid,
connected_at=ms_time(),
router_type="webpush",
))
self._send_message(dict(messageType="hello", channelIDs=[],
uaid=uaid, use_webpush=True))

def check_result(msg):
eq_(msg["status"], 200)
ok_(msg["uaid"] != uaid)
return self._check_response(check_result)

def test_hello_with_uaid(self):
self._connect()
uaid = uuid.uuid4().hex
router = self.proto.ap_settings.router
router.register_user(dict(
uaid=uaid,
connected_at=ms_time(),
router_type="simplepush",
))
self._send_message(dict(messageType="hello", channelIDs=[],
uaid=uaid))
Expand Down Expand Up @@ -1657,6 +1692,7 @@ def test_notification_results(self):
router.register_user(dict(
uaid=uaid,
connected_at=ms_time(),
router_type="simplepush",
))

storage = self.proto.ap_settings.storage
Expand Down Expand Up @@ -1711,6 +1747,7 @@ def test_notification_dont_deliver_after_ack(self):
router.register_user(dict(
uaid=uaid,
connected_at=ms_time(),
router_type="simplepush",
))

storage = self.proto.ap_settings.storage
Expand Down Expand Up @@ -1772,6 +1809,7 @@ def test_notification_dont_deliver(self):
router.register_user(dict(
uaid=uaid,
connected_at=ms_time(),
router_type="simplepush",
))

storage = self.proto.ap_settings.storage
Expand Down
6 changes: 6 additions & 0 deletions autopush/websocket.py
Expand Up @@ -686,6 +686,12 @@ def _verify_user_record(self):
except ItemNotFound:
return None

# All records must have a router_type and connected_at, in some odd
# cases a record exists for some users that doesn't
if "router_type" not in record or "connected_at" not in record:
self.force_retry(self.ap_settings.router.drop_user, self.ps.uaid)
return None

# Validate webpush records
if self.ps.use_webpush:
# Current month must exist and be a valid prior month
Expand Down

0 comments on commit aeeea3a

Please sign in to comment.