diff --git a/hc/api/tests/test_email_webhook.py b/hc/api/tests/test_email_webhook.py index 431d17c8..8f7ae9bc 100644 --- a/hc/api/tests/test_email_webhook.py +++ b/hc/api/tests/test_email_webhook.py @@ -15,7 +15,10 @@ class EmailTestCase(TestCase): "event": "inbound", "msg": { "raw_msg": "This is raw message", - "to": ["somewhere@example.com", "%s@example.com" % check.code] + "to": [ + ["somewhere@example.com", "Somebody"], + ["%s@example.com" % check.code, "Healthchecks"] + ] } }] @@ -29,3 +32,7 @@ class EmailTestCase(TestCase): pings = list(Ping.objects.all()) assert pings[0].scheme == "email" assert pings[0].body == "This is raw message" + + def test_it_rejects_get(self): + r = self.client.get("/handle_email/") + assert r.status_code == 400 diff --git a/hc/api/views.py b/hc/api/views.py index 9b6b4aef..8cde1dec 100644 --- a/hc/api/views.py +++ b/hc/api/views.py @@ -40,10 +40,13 @@ def ping(request, code): @csrf_exempt def handle_email(request): + if request.method != "POST": + return HttpResponseBadRequest() + events = json.loads(request.POST["mandrill_events"]) for event in events: - for to_address in event["msg"]["to"]: - code, domain = to_address.split("@") + for recipient_address, recipient_name in event["msg"]["to"]: + code, domain = recipient_address.split("@") try: check = Check.objects.get(code=code) except ValueError: