From a29b82a0ed20827000a7b318487951d892586a44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Mon, 17 Aug 2020 13:10:07 +0300 Subject: [PATCH] In api.views.notification_status, always return HTTP 200 so the other party doesn't retry over and over again --- hc/api/tests/test_notification_status.py | 6 +++++- hc/api/views.py | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/hc/api/tests/test_notification_status.py b/hc/api/tests/test_notification_status.py index 25128681..9006fd54 100644 --- a/hc/api/tests/test_notification_status.py +++ b/hc/api/tests/test_notification_status.py @@ -57,7 +57,11 @@ class NotificationStatusTestCase(BaseTestCase): self.n.save() r = self.client.post(self.url, {"MessageStatus": "failed"}) - self.assertEqual(r.status_code, 403) + self.assertEqual(r.status_code, 200) + + # The notification should not have the error field set: + self.n.refresh_from_db() + self.assertEqual(self.n.error, "") def test_it_handles_missing_notification(self): fake_code = "07c2f548-9850-4b27-af5d-6c9dc157ec02" diff --git a/hc/api/views.py b/hc/api/views.py index a909f611..9003d717 100644 --- a/hc/api/views.py +++ b/hc/api/views.py @@ -422,10 +422,11 @@ def notification_status(request, code): notification = get_object_or_404(Notification, code=code) - # If webhook is more than 1 hour late, don't accept it: td = timezone.now() - notification.created if td.total_seconds() > 3600: - return HttpResponseForbidden() + # If the webhook is called more than 1 hour after the notification, ignore it. + # Return HTTP 200 so the other party doesn't retry over and over again: + return HttpResponse() error, mark_not_verified = None, False