diff --git a/docker/integtest/6-receive-service-email.sh b/docker/integtest/6-receive-service-email.sh new file mode 100755 index 00000000..47e50c19 --- /dev/null +++ b/docker/integtest/6-receive-service-email.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -eo pipefail + +scriptdir="$(dirname "$0")" +in_dir="${scriptdir}/files" +out_dir="${scriptdir}/files/test.out" +mkdir -p "${out_dir}" +# shellcheck disable=SC1090 +. "${scriptdir}/utils.sh" + +email_to_receive="${in_dir}/service-email.mime" + + +#receive an email directed at the service endpoint +http --check-status -f POST \ + "http://nginx:8888/api/email/sendgrid/service" \ + "dkim={@sendgrid.com : pass}" \ + "SPF=pass" \ + "email=@${email_to_receive}" diff --git a/docker/integtest/files/service-email.mime b/docker/integtest/files/service-email.mime new file mode 100644 index 00000000..daa0d2b8 --- /dev/null +++ b/docker/integtest/files/service-email.mime @@ -0,0 +1,27 @@ +Received: by mx0028p1mdw1.sendgrid.net with SMTP id Yt3NEnbnLU Mon, 13 Feb 2017 06:25:41 +0000 (UTC) +Received: from mail-yw0-f176.google.com (mail-yw0-f176.google.com [209.85.161.176]) by mx0028p1mdw1.sendgrid.net (Postfix) with ESMTPS id C726D640B63; Mon, 13 Feb 2017 06:25:41 +0000 (UTC) +Received: by mail-yw0-f176.google.com with SMTP id w75so45612320ywg.1; Sun, 12 Feb 2017 22:25:41 -0800 (PST) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=ViHLGS6kOdo9Q9CkDDSSSS3bgKuN0a+UXhwMw06ak4Q=; b=f3WGzjgLe0tPG2edhiHxiCEZatThUga/qJFnWZNyY4lEVjRM9l3qn1BZ4ITawT9tDK LS6qFx//6in7u0rV0YKoa8TfScUFOpPHGCmq1Wxdp7mrWP7GDuCOz3LzyXQsrBe/erGy YEjAVU876sWJ109mcMcmbgOL1SD3d4ak+8GVBSC8oMKPj5XWZsET7WmsonhKf5PHE9IW eJHKqdOkxiPbmDutVx7uS1Bi5u4d9UYPhgxFwAK9lWyJ/Esw6yffjlrUvmQCPibSCxRv o979yY6FyJXDJ82l4ErntcOloFNpzWZ89WkRhb1aBLUoZs3402s6D3wC0ljpmvneIAkw 3D6A== +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=ViHLGS6kOdo9Q9CkDDSSSS3bgKuN0a+UXhwMw06ak4Q=; b=sWY7uU6kK3dg62wVuxcLsRYLg3eGcoLuoLjL0Ju/sl9rGqSDxVc2saIS0ThfUaHlfZ g1zvF+rBoxa7v9jk7MhEw3izW01WXDMm0w2JGc1QLTo3ZM2xW9Clss63R3ZtNKabuyhd 77NHAgbarmQGW5XuqwS1Fy0NMWHkAlLsZd2AnkNb6gCI/VHCCv/oem19bWvNWwRTPBYE cQDPJfzRiUzRPNZPLtlL5ybd2yyb4lcuG+2QoQV8uxPsKS4eDOjNmM76UWZ9s/Ul/mR+ Qbyui7suOO0vPy8GFJHPV9X2ffLqesafTAetCj3LClCdLIdfQDaK86mmVHOT6zldeCTa HH6Q== +X-Gm-Message-State: AMke39n2h/OZU6fwgOdDltzsKqISVbe3ez6t19OeVrg2sT3pDRhSSQiIcwGzKjdWOD/oX96rQlTi0O9t9yhUfA== +X-Received: by 10.129.81.4 with SMTP id f4mr15409224ywb.239.1486967141412; Sun, 12 Feb 2017 22:25:41 -0800 (PST) +MIME-Version: 1.0 +Received: by 10.129.156.139 with HTTP; Sun, 12 Feb 2017 22:25:01 -0800 (PST) +From: Clemens Wolff +Date: Sun, 12 Feb 2017 22:25:01 -0800 +Message-ID: +Subject: Service Email +To: echo@bot.lokole.ca, +Content-Type: multipart/alternative; boundary=001a1146392641b94705486384bf + +--001a1146392641b94705486384bf +Content-Type: text/plain; charset=UTF-8 + +This is an email that should be echoed. + +--001a1146392641b94705486384bf +Content-Type: text/html; charset=UTF-8 + +
Body of the message.
+ +--001a1146392641b94705486384bf-- diff --git a/docker/integtest/tests.sh b/docker/integtest/tests.sh index e01fc19d..67f4cce8 100755 --- a/docker/integtest/tests.sh +++ b/docker/integtest/tests.sh @@ -11,5 +11,6 @@ scriptdir="$(dirname "$0")" "${scriptdir}/3-receive-email-for-client.sh" && wait_seconds "${TEST_STEP_DELAY}" "${scriptdir}/4-client-downloads-emails.sh" "${scriptdir}/5-assert-on-results.sh" +"${scriptdir}/6-receive-service-email.sh" rm -rf "${scriptdir}/files/test.out" diff --git a/opwen_email_server/actions.py b/opwen_email_server/actions.py index cc523917..27bb00ac 100644 --- a/opwen_email_server/actions.py +++ b/opwen_email_server/actions.py @@ -221,7 +221,10 @@ def __init__(self, auth: Union[AzureAuth, NoAuth], raw_email_storage: AzureTextS self._raw_email_storage = raw_email_storage self._next_task = next_task - def _action(self, client_id, email, **sendgrid_args): # type: ignore + def _action(self, client_id=None, email=None, **sendgrid_args): # type: ignore + if email is None: + return 'email cannot be None', 400 + domain = self._auth.domain_for(client_id) if not domain: self.log_event(events.UNREGISTERED_CLIENT, {'client_id': client_id}) # noqa: E501 # yapf: disable diff --git a/opwen_email_server/swagger/email-receive.yaml b/opwen_email_server/swagger/email-receive.yaml index cbbab32b..99d113e9 100644 --- a/opwen_email_server/swagger/email-receive.yaml +++ b/opwen_email_server/swagger/email-receive.yaml @@ -60,6 +60,8 @@ paths: responses: 200: description: The email was succesfully received. No need to retry it. + 400: + description: Malformed email. 403: description: Error in receiving email.