From 5580e0d2e3a99035c899721bf36e6f1018f38e38 Mon Sep 17 00:00:00 2001 From: jrconlin Date: Fri, 11 Mar 2016 16:29:03 -0800 Subject: [PATCH] bug: Clear corrupted router records Records containing only a UAID are corrupt. Drop these records and return a 410 to the server. Closes #400 --- autopush/db.py | 7 ++++++- autopush/tests/test_db.py | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/autopush/db.py b/autopush/db.py index 2481b2a6..6c45f650 100644 --- a/autopush/db.py +++ b/autopush/db.py @@ -539,7 +539,12 @@ def get_uaid(self, uaid): """ try: - return self.table.get_item(consistent=True, uaid=hasher(uaid)) + item = self.table.get_item(consistent=True, uaid=hasher(uaid)) + if item.keys() == ['uaid']: + # Incomplete record, drop it. + self.drop_user(uaid) + raise ItemNotFound("uaid not found") + return item except ProvisionedThroughputExceededException: # We unfortunately have to catch this here, as track_provisioned # will not see this, since JSONResponseError is a subclass and diff --git a/autopush/tests/test_db.py b/autopush/tests/test_db.py index e7399d30..f6e36c4b 100644 --- a/autopush/tests/test_db.py +++ b/autopush/tests/test_db.py @@ -448,6 +448,15 @@ def test_save_uaid(self): eq_(bool(result), True) eq_(result["node_id"], "me") + def test_incomplete_uaid(self): + uaid = str(uuid.uuid4()) + r = get_router_table() + router = Router(r, SinkMetrics()) + router.register_user(dict(uaid=uaid)) + self.assertRaises(ItemNotFound, router.get_uaid, uaid) + self.assertRaises(ItemNotFound, router.table.get_item, + consistent=True, uaid=uaid) + def test_save_new(self): r = get_router_table() router = Router(r, SinkMetrics())