diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5a388126..0889d216 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,7 @@ This document describes changes between each past release. **Bug fix** - Update the `last_modified` value when updating the collection status and signature (#97) +- Prevents crash with events on ``default`` bucket on Kinto < 3.3 0.7.0 (2016-06-28) diff --git a/kinto_signer/__init__.py b/kinto_signer/__init__.py index 7aac99cd..3015dd9a 100644 --- a/kinto_signer/__init__.py +++ b/kinto_signer/__init__.py @@ -19,6 +19,12 @@ def on_collection_changed(event, resources): and update the destination. """ payload = event.payload + + if 'bucket_id' not in payload: + # Safety check for kinto < 3.3 where events have incoherent payloads + # on default bucket. + return + key = "/buckets/{bucket_id}/collections/{collection_id}".format(**payload) resource = resources.get(key) diff --git a/kinto_signer/tests/test_plugin_setup.py b/kinto_signer/tests/test_plugin_setup.py index 42f18698..8882aa3b 100644 --- a/kinto_signer/tests/test_plugin_setup.py +++ b/kinto_signer/tests/test_plugin_setup.py @@ -151,6 +151,11 @@ def test_updater_is_called_when_resource_and_status_matches(self): mocked = self.updater_mocked.return_value assert mocked.sign_and_update_destination.called + def test_updater_does_not_fail_when_payload_is_inconsistent(self): + # This happens with events on default bucket for kinto < 3.3 + evt = mock.MagicMock(payload={"subpath": "collections/boom"}) + on_collection_changed(evt, resources=utils.parse_resources("a/b;c/d")) + class SigningErrorTest(BaseWebTest, unittest.TestCase): def test_returns_503_if_autograph_cannot_be_reached(self):