diff --git a/.env b/.env index c5805aa9..330514b6 100644 --- a/.env +++ b/.env @@ -15,6 +15,7 @@ LOKOLE_EMAIL_SERVER_QUEUES_NAMESPACE= LOKOLE_SENDGRID_KEY= LOKOLE_RESOURCE_SUFFIX= REGISTRATION_CREDENTIALS=admin:password +TEST_STEP_DELAY=10 CLOUDBROWSER_PORT=10001 AZURITE_PORT=10000 diff --git a/.travis.yml b/.travis.yml index 98b52da2..64c0182d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,7 @@ before_script: | export AZURITE_KEY="$TEST_AZURE_STORAGE_KEY" export AZURITE_HOST="" export AZURITE_SECURE="True" + export TEST_STEP_DELAY=90 else export REGISTRATION_CREDENTIALS="admin:password" export LOKOLE_QUEUE_BROKER_SCHEME="amqp" diff --git a/docker/docker-compose.test.yml b/docker/docker-compose.test.yml index 4ccd81c1..458fd144 100644 --- a/docker/docker-compose.test.yml +++ b/docker/docker-compose.test.yml @@ -13,5 +13,6 @@ services: AZURITE_ACCOUNT: ${AZURITE_ACCOUNT} AZURITE_KEY: ${AZURITE_KEY} AZURITE_HOST: ${AZURITE_HOST} + TEST_STEP_DELAY: ${TEST_STEP_DELAY} volumes: - /var/run/docker.sock:/var/run/docker.sock diff --git a/docker/integtest/2-client-uploads-emails.sh b/docker/integtest/2-client-uploads-emails.sh index e4796abd..c4595e4a 100755 --- a/docker/integtest/2-client-uploads-emails.sh +++ b/docker/integtest/2-client-uploads-emails.sh @@ -9,6 +9,8 @@ mkdir -p "${out_dir}" . "${scriptdir}/utils.sh" emails_to_send="${in_dir}/client-emails.tar.gz" +tar -czf "${emails_to_send}" -C "${in_dir}" emails.jsonl zzusers.jsonl + client_id="$(jq -r '.client_id' < "${out_dir}/register1.json")" resource_container="$(jq -r '.resource_container' < "${out_dir}/register1.json")" resource_id="$(uuidgen).tar.gz" diff --git a/docker/integtest/3-receive-email-for-client.sh b/docker/integtest/3-receive-email-for-client.sh index b3d995ca..a0be2bee 100755 --- a/docker/integtest/3-receive-email-for-client.sh +++ b/docker/integtest/3-receive-email-for-client.sh @@ -26,3 +26,10 @@ http --check-status -f POST \ "dkim={@sendgrid.com : pass}" \ "SPF=pass" \ "email=@${email_to_receive}" + +# simulate delivery of another email +http --check-status -f POST \ + "http://nginx:8888/api/email/sendgrid/${client_id}" \ + "dkim={@sendgrid.com : pass}" \ + "SPF=pass" \ + "email=@${in_dir}/inbound-email-2.mime" diff --git a/docker/integtest/4-client-downloads-emails.sh b/docker/integtest/4-client-downloads-emails.sh index 9cfca1a4..d655e206 100755 --- a/docker/integtest/4-client-downloads-emails.sh +++ b/docker/integtest/4-client-downloads-emails.sh @@ -7,6 +7,10 @@ mkdir -p "${out_dir}" # shellcheck disable=SC1090 . "${scriptdir}/utils.sh" +declare -A num_emails_expected_for_client +num_emails_expected_for_client[1]=2 +num_emails_expected_for_client[2]=1 + for i in 1 2; do client_id="$(jq -r '.client_id' < "${out_dir}/register${i}.json")" @@ -29,7 +33,7 @@ az_storage download "${resource_container}" "${resource_id}" "${out_dir}/downloa tar xzf "${out_dir}/downloaded${i}.tar.gz" -C "${out_dir}" num_emails_actual="$(wc -l "${out_dir}/emails.jsonl" | cut -d' ' -f1)" -num_emails_expected=1 +num_emails_expected="${num_emails_expected_for_client[${i}]}" if [[ "${num_emails_actual}" -ne "${num_emails_expected}" ]]; then echo "Got ${num_emails_actual} emails but expected ${num_emails_expected}" >&2 diff --git a/docker/integtest/files/.gitignore b/docker/integtest/files/.gitignore index 071eb825..a151876c 100644 --- a/docker/integtest/files/.gitignore +++ b/docker/integtest/files/.gitignore @@ -1 +1,2 @@ test.out/ +client-emails.tar.gz diff --git a/docker/integtest/files/client-emails.tar.gz b/docker/integtest/files/client-emails.tar.gz deleted file mode 100644 index 89aee01f..00000000 Binary files a/docker/integtest/files/client-emails.tar.gz and /dev/null differ diff --git a/docker/integtest/files/emails.jsonl b/docker/integtest/files/emails.jsonl new file mode 100644 index 00000000..2f439698 --- /dev/null +++ b/docker/integtest/files/emails.jsonl @@ -0,0 +1,3 @@ +{"from":"clemens@developer1.lokole.ca","to":["clemens.wolff@gmail.com","laura.barluzzi@gmail.com"],"subject":"First test email sent from Lokole client","body":"Some content","_uid":"ed262575-73db-49cc-9c87-e2e95f8ac9cc","sent_at":"2019-10-26 11:23"} +{"from":"laura@developer1.lokole.ca","to":["clemens.wolff@gmail.com"],"subject":"Second test email sent from Lokole client","body":"Some more content","_uid":"d03fff22-5c51-4f10-8111-5b24686964ba","attachments":[{"filename":"test.txt","content":"dGVzdCBhdHRhY2htZW50"}],"sent_at":"2019-10-25 05:00"} +{"from":"Clemens@developer1.lokole.ca","to":["clemens@gmail.com","laura.barluzzi@gmail.com"],"subject":"Third test email sent from Lokole client","body":"Some extra content","_uid":"43f619b3-64ba-4ea3-963d-740cf0e58989","sent_at":"2019-10-26 12:34"} diff --git a/docker/integtest/files/inbound-email-2.mime b/docker/integtest/files/inbound-email-2.mime new file mode 100644 index 00000000..3ef34b5c --- /dev/null +++ b/docker/integtest/files/inbound-email-2.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: Two recipients +To: Clemens@developer1.lokole.ca, LaUrA@developer1.lokole.ca +Content-Type: multipart/alternative; boundary=001a1146392641b94705486384bf + +--001a1146392641b94705486384bf +Content-Type: text/plain; charset=UTF-8 + +Body of the message. + +--001a1146392641b94705486384bf +Content-Type: text/html; charset=UTF-8 + +
Body of the message.
+ +--001a1146392641b94705486384bf-- diff --git a/docker/integtest/files/zzusers.jsonl b/docker/integtest/files/zzusers.jsonl new file mode 100644 index 00000000..bf63cd96 --- /dev/null +++ b/docker/integtest/files/zzusers.jsonl @@ -0,0 +1 @@ +{"email":"clemens@developer1.lokole.ca","password":"$2b$12$9LaXqZMPJi0PiTY.95dIQOvc8LkYQzRlg5a9pDWX47L/npaYqynU2"} diff --git a/docker/integtest/tests.sh b/docker/integtest/tests.sh index 648cc131..e01fc19d 100755 --- a/docker/integtest/tests.sh +++ b/docker/integtest/tests.sh @@ -2,11 +2,13 @@ set -eo pipefail scriptdir="$(dirname "$0")" +# shellcheck disable=SC1090 +. "${scriptdir}/utils.sh" "${scriptdir}/0-wait-for-services.sh" "${scriptdir}/1-register-client.sh" -"${scriptdir}/2-client-uploads-emails.sh" && sleep 10s -"${scriptdir}/3-receive-email-for-client.sh" && sleep 10s +"${scriptdir}/2-client-uploads-emails.sh" && wait_seconds "${TEST_STEP_DELAY}" +"${scriptdir}/3-receive-email-for-client.sh" && wait_seconds "${TEST_STEP_DELAY}" "${scriptdir}/4-client-downloads-emails.sh" "${scriptdir}/5-assert-on-results.sh" diff --git a/docker/integtest/utils.sh b/docker/integtest/utils.sh index a0708c9b..4787ae36 100755 --- a/docker/integtest/utils.sh +++ b/docker/integtest/utils.sh @@ -30,3 +30,15 @@ az_storage() { --connection-string "$(az_connection_string)" \ > /dev/null } + +wait_seconds() { + local seconds="$1" + + printf 'Waiting' >&2 + while [[ "${seconds}" -gt 0 ]]; do + printf '.' >&2 + sleep 1 + seconds="$((seconds - 1))" + done + echo >&2 +} diff --git a/opwen_email_client/webapp/templates/macros/email.html b/opwen_email_client/webapp/templates/macros/email.html index 1f7579a2..9c39b8d7 100644 --- a/opwen_email_client/webapp/templates/macros/email.html +++ b/opwen_email_client/webapp/templates/macros/email.html @@ -27,7 +27,7 @@

{% if show_sent_to %}