blob: 2ddcd71b69f42da348643a353ba782cea7f0db06 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#!/bin/bash
# Dependencies
# - swaks
#
# Usage
#
# In order to send authenticated mail to the tmp_user you need to
# export these environment variables before running this script:
# - FROM_EXTERNAL_OPTS for sending mails from external mailservers to the tmp_user account
#
# as an example:
# export FROM_EXTERNAL_OPTS='-f user@example.org --tlsc --au user@example.or -ap MYPASSWORD -s smtp.example.org'
#
# then:
#
# source venv/bin/activate
# make dev-latest-backend
# make test_e2e
#
#
# TODO:
# - Timeout waiting for mail
# - Decrease poll interval
# - Make it less noisy (fix the vext warnings)
# - move away from cdev.bm
# - remove test user on success
set -e
PROVIDER='cdev.bitmask.net'
BCTL='bitmaskctl'
LEAP_HOME="$HOME/.config/leap"
MAIL_UUID=$(uuidgen)
username="tmp_user_$(date +%Y%m%d%H%M%S)"
user="${username}@${PROVIDER}"
pw="$(head -c 10 < /dev/urandom | base64)"
SWAKS="swaks -t $user --h-Subject $MAIL_UUID --silent 2"
# Stop any previously started bitmaskd
# and start a new instance
"$BCTL" stop
[ -d "$LEAP_HOME" ] && rm -rf "$LEAP_HOME"
"$BCTL" start
# Register a new user
"$BCTL" user create "$user" --pass "$pw"
# Authenticate
"$BCTL" user auth "$user" --pass "$pw" > /dev/null
# Note that imap_pw is the same for smtp
imap_pw="None"
# FIXME -- this would be prettier if we had the auth command block on
# the first-time run, so that we just return when the key has been generated
# and explicitely raise any error found
while [[ $imap_pw == *"None"* ]]; do
response=$("$BCTL" mail get_token)
sleep 2
imap_pw=$(echo "$response" | head -n 1 | sed 's/ */ /g' | cut -d' ' -f 2)
done
$SWAKS $FROM_EXTERNAL_OPTS
echo "IMAP/SMTP PASSWD: $imap_pw"
# Send testmail
$SWAKS $FROM_EXTERNAL_OPTS
# wait until we the get mail we just sent.
while ! ./tests/e2e/getmail --mailbox INBOX --subject "$MAIL_UUID" "$user" "$imap_pw" > /dev/null
do
echo "Waiting for incoming test mail..."
sleep 10
done
echo "Succeeded - mail arrived"
|