Browse Source

In api.views.notification_status, always return HTTP 200 so the other party doesn't retry over and over again

pull/415/head
Pēteris Caune 4 years ago
parent
commit
a29b82a0ed
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
2 changed files with 8 additions and 3 deletions
  1. +5
    -1
      hc/api/tests/test_notification_status.py
  2. +3
    -2
      hc/api/views.py

+ 5
- 1
hc/api/tests/test_notification_status.py View File

@ -57,7 +57,11 @@ class NotificationStatusTestCase(BaseTestCase):
self.n.save() self.n.save()
r = self.client.post(self.url, {"MessageStatus": "failed"}) 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): def test_it_handles_missing_notification(self):
fake_code = "07c2f548-9850-4b27-af5d-6c9dc157ec02" fake_code = "07c2f548-9850-4b27-af5d-6c9dc157ec02"


+ 3
- 2
hc/api/views.py View File

@ -422,10 +422,11 @@ def notification_status(request, code):
notification = get_object_or_404(Notification, code=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 td = timezone.now() - notification.created
if td.total_seconds() > 3600: 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 error, mark_not_verified = None, False


Loading…
Cancel
Save