Add more tests: Auto-forwarding, sending to an alias and auto-reply
Add simple test for auto-replymaster
parent
4733f15c0c
commit
bbb24a8863
@ -0,0 +1,60 @@
|
|||||||
|
import smtplib
|
||||||
|
import imaplib
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
|
from email.mime.multipart import MIMEMultipart
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
import ntpath
|
||||||
|
from email.mime.base import MIMEBase
|
||||||
|
from email import encoders
|
||||||
|
|
||||||
|
msg = MIMEMultipart()
|
||||||
|
msg['From'] = "admin@mailu.io"
|
||||||
|
msg['To'] = "forwardinguser@mailu.io"
|
||||||
|
msg['Subject'] = "Alias Test"
|
||||||
|
msg.attach(MIMEText("Alias Text", 'plain'))
|
||||||
|
|
||||||
|
try:
|
||||||
|
smtp_server = smtplib.SMTP('localhost')
|
||||||
|
smtp_server.set_debuglevel(1)
|
||||||
|
smtp_server.connect('localhost', 587)
|
||||||
|
smtp_server.ehlo()
|
||||||
|
smtp_server.starttls()
|
||||||
|
smtp_server.ehlo()
|
||||||
|
smtp_server.login("admin@mailu.io", "password")
|
||||||
|
|
||||||
|
smtp_server.sendmail("admin@mailu.io", "alltheusers@mailu.io", msg.as_string())
|
||||||
|
smtp_server.quit()
|
||||||
|
except:
|
||||||
|
sys.exit(25)
|
||||||
|
|
||||||
|
time.sleep(30)
|
||||||
|
|
||||||
|
for user in ['user@mailu.io', 'admin@mailu.io', 'user/with/slash@mailu.io']:
|
||||||
|
try:
|
||||||
|
imap_server = imaplib.IMAP4_SSL('localhost')
|
||||||
|
imap_server.login(user, 'password')
|
||||||
|
except Exception as exc:
|
||||||
|
print("Failed with:", exc)
|
||||||
|
sys.exit(110)
|
||||||
|
|
||||||
|
stat, count = imap_server.select('inbox')
|
||||||
|
try:
|
||||||
|
stat, data = imap_server.fetch(count[0], '(UID BODY[TEXT])')
|
||||||
|
except :
|
||||||
|
sys.exit(99)
|
||||||
|
|
||||||
|
if "Alias Text" in str(data[0][1]):
|
||||||
|
print("Success: Mail is in aliassed inbox", user)
|
||||||
|
else:
|
||||||
|
print("Failed receiving email in aliassed inbox", user)
|
||||||
|
sys.exit(99)
|
||||||
|
|
||||||
|
typ, data = imap_server.search(None, 'ALL')
|
||||||
|
for num in data[0].split():
|
||||||
|
imap_server.store(num, '+FLAGS', '\\Deleted')
|
||||||
|
imap_server.expunge()
|
||||||
|
|
||||||
|
imap_server.close()
|
||||||
|
imap_server.logout()
|
||||||
|
|
@ -1,4 +1,5 @@
|
|||||||
echo "Creating users ..."
|
echo "Creating users ..."
|
||||||
docker-compose -f tests/compose/core/docker-compose.yml exec admin flask mailu admin admin mailu.io password || exit 1
|
docker-compose -f tests/compose/core/docker-compose.yml exec admin flask mailu admin admin mailu.io password || exit 1
|
||||||
docker-compose -f tests/compose/core/docker-compose.yml exec admin flask mailu user user mailu.io 'password' 'SHA512-CRYPT' || exit 1
|
docker-compose -f tests/compose/core/docker-compose.yml exec admin flask mailu user user mailu.io 'password' 'SHA512-CRYPT' || exit 1
|
||||||
|
docker-compose -f tests/compose/core/docker-compose.yml exec admin flask mailu user 'user/with/slash' mailu.io 'password' 'SHA512-CRYPT' || exit 1
|
||||||
echo "Admin and user successfully created!"
|
echo "Admin and user successfully created!"
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
cat << EOF | docker-compose -f tests/compose/core/docker-compose.yml exec -T admin flask mailu config-update -v 1
|
||||||
|
users:
|
||||||
|
- localpart: forwardinguser
|
||||||
|
password_hash: "\$1\$F2OStvi1\$Q8hBIHkdJpJkJn/TrMIZ9/"
|
||||||
|
hash_scheme: MD5-CRYPT
|
||||||
|
domain: mailu.io
|
||||||
|
forward_enabled: true
|
||||||
|
forward_destination: ["user@mailu.io"]
|
||||||
|
EOF
|
||||||
|
|
||||||
|
python3 tests/forward_test.py
|
||||||
|
|
||||||
|
cat << EOF | docker-compose -f tests/compose/core/docker-compose.yml exec -T admin flask mailu config-update -v 1
|
||||||
|
users:
|
||||||
|
- localpart: forwardinguser
|
||||||
|
password_hash: "\$1\$F2OStvi1\$Q8hBIHkdJpJkJn/TrMIZ9/"
|
||||||
|
hash_scheme: MD5-CRYPT
|
||||||
|
domain: mailu.io
|
||||||
|
forward_enabled: false
|
||||||
|
forward_destination: []
|
||||||
|
EOF
|
@ -0,0 +1,12 @@
|
|||||||
|
cat << EOF | docker-compose -f tests/compose/core/docker-compose.yml exec -T admin flask mailu config-update -v 1
|
||||||
|
aliases:
|
||||||
|
- localpart: alltheusers
|
||||||
|
domain: mailu.io
|
||||||
|
destination: "admin@mailu.io,user@mailu.io,user/with/slash@mailu.io"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
python3 tests/alias_test.py
|
||||||
|
|
||||||
|
cat << EOF | docker-compose -f tests/compose/core/docker-compose.yml exec -T admin flask mailu config-update -v 1
|
||||||
|
aliases: []
|
||||||
|
EOF
|
@ -0,0 +1,21 @@
|
|||||||
|
cat << EOF | docker-compose -f tests/compose/core/docker-compose.yml exec -T admin flask mailu config-update -v 1
|
||||||
|
users:
|
||||||
|
- localpart: replyuser
|
||||||
|
password_hash: "\$1\$F2OStvi1\$Q8hBIHkdJpJkJn/TrMIZ9/"
|
||||||
|
hash_scheme: MD5-CRYPT
|
||||||
|
domain: mailu.io
|
||||||
|
reply_enabled: true
|
||||||
|
reply_subject: This will not reach me
|
||||||
|
reply_body: Cause this is just a test
|
||||||
|
EOF
|
||||||
|
|
||||||
|
python3 tests/reply_test.py
|
||||||
|
|
||||||
|
cat << EOF | docker-compose -f tests/compose/core/docker-compose.yml exec -T admin flask mailu config-update -v 1
|
||||||
|
users:
|
||||||
|
- localpart: replyuser
|
||||||
|
password_hash: "\$1\$F2OStvi1\$Q8hBIHkdJpJkJn/TrMIZ9/"
|
||||||
|
hash_scheme: MD5-CRYPT
|
||||||
|
domain: mailu.io
|
||||||
|
reply_enabled: false
|
||||||
|
EOF
|
@ -0,0 +1,87 @@
|
|||||||
|
import smtplib
|
||||||
|
import imaplib
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
|
from email.mime.multipart import MIMEMultipart
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
import ntpath
|
||||||
|
from email.mime.base import MIMEBase
|
||||||
|
from email import encoders
|
||||||
|
|
||||||
|
msg = MIMEMultipart()
|
||||||
|
msg['From'] = "admin@mailu.io"
|
||||||
|
msg['To'] = "forwardinguser@mailu.io"
|
||||||
|
msg['Subject'] = "Forward Test"
|
||||||
|
msg.attach(MIMEText("Forward Text", 'plain'))
|
||||||
|
|
||||||
|
try:
|
||||||
|
smtp_server = smtplib.SMTP('localhost')
|
||||||
|
smtp_server.set_debuglevel(1)
|
||||||
|
smtp_server.connect('localhost', 587)
|
||||||
|
smtp_server.ehlo()
|
||||||
|
smtp_server.starttls()
|
||||||
|
smtp_server.ehlo()
|
||||||
|
smtp_server.login("admin@mailu.io", "password")
|
||||||
|
|
||||||
|
smtp_server.sendmail("admin@mailu.io", "forwardinguser@mailu.io", msg.as_string())
|
||||||
|
smtp_server.quit()
|
||||||
|
except:
|
||||||
|
sys.exit(25)
|
||||||
|
|
||||||
|
time.sleep(30)
|
||||||
|
|
||||||
|
# check forward target
|
||||||
|
try:
|
||||||
|
imap_server = imaplib.IMAP4_SSL('localhost')
|
||||||
|
imap_server.login('user@mailu.io', 'password')
|
||||||
|
except Exception as exc:
|
||||||
|
print("Failed with:", exc)
|
||||||
|
sys.exit(110)
|
||||||
|
|
||||||
|
stat, count = imap_server.select('inbox')
|
||||||
|
try:
|
||||||
|
stat, data = imap_server.fetch(count[0], '(UID BODY[TEXT])')
|
||||||
|
except :
|
||||||
|
sys.exit(99)
|
||||||
|
|
||||||
|
if "Forward Text" in str(data[0][1]):
|
||||||
|
print("Success: Mail is in forwarded inbox")
|
||||||
|
else:
|
||||||
|
print("Failed receiving email in forwarded inbox")
|
||||||
|
sys.exit(99)
|
||||||
|
|
||||||
|
typ, data = imap_server.search(None, 'ALL')
|
||||||
|
for num in data[0].split():
|
||||||
|
imap_server.store(num, '+FLAGS', '\\Deleted')
|
||||||
|
imap_server.expunge()
|
||||||
|
|
||||||
|
imap_server.close()
|
||||||
|
imap_server.logout()
|
||||||
|
|
||||||
|
# check original user
|
||||||
|
try:
|
||||||
|
imap_server = imaplib.IMAP4_SSL('localhost')
|
||||||
|
imap_server.login('forwardinguser@mailu.io', 'password')
|
||||||
|
except Exception as exc:
|
||||||
|
print("Failed with:", exc)
|
||||||
|
sys.exit(110)
|
||||||
|
|
||||||
|
stat, count = imap_server.select('inbox')
|
||||||
|
try:
|
||||||
|
stat, data = imap_server.fetch(count[0], '(UID BODY[TEXT])')
|
||||||
|
except :
|
||||||
|
sys.exit(99)
|
||||||
|
|
||||||
|
if "Forward Text" in str(data[0][1]):
|
||||||
|
print("Success: Mail is in forwarding inbox")
|
||||||
|
else:
|
||||||
|
print("Failed receiving email in forwarding inbox")
|
||||||
|
sys.exit(99)
|
||||||
|
|
||||||
|
typ, data = imap_server.search(None, 'ALL')
|
||||||
|
for num in data[0].split():
|
||||||
|
imap_server.store(num, '+FLAGS', '\\Deleted')
|
||||||
|
imap_server.expunge()
|
||||||
|
|
||||||
|
imap_server.close()
|
||||||
|
imap_server.logout()
|
@ -0,0 +1,87 @@
|
|||||||
|
import smtplib
|
||||||
|
import imaplib
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
|
from email.mime.multipart import MIMEMultipart
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
import ntpath
|
||||||
|
from email.mime.base import MIMEBase
|
||||||
|
from email import encoders
|
||||||
|
|
||||||
|
msg = MIMEMultipart()
|
||||||
|
msg['From'] = "admin@mailu.io"
|
||||||
|
msg['To'] = "replyusea@mailu.io"
|
||||||
|
msg['Subject'] = "Reply Test"
|
||||||
|
msg.attach(MIMEText("Reply Text", 'plain'))
|
||||||
|
|
||||||
|
try:
|
||||||
|
smtp_server = smtplib.SMTP('localhost')
|
||||||
|
smtp_server.set_debuglevel(1)
|
||||||
|
smtp_server.connect('localhost', 587)
|
||||||
|
smtp_server.ehlo()
|
||||||
|
smtp_server.starttls()
|
||||||
|
smtp_server.ehlo()
|
||||||
|
smtp_server.login("admin@mailu.io", "password")
|
||||||
|
|
||||||
|
smtp_server.sendmail("admin@mailu.io", "replyuser@mailu.io", msg.as_string())
|
||||||
|
smtp_server.quit()
|
||||||
|
except:
|
||||||
|
sys.exit(25)
|
||||||
|
|
||||||
|
time.sleep(30)
|
||||||
|
|
||||||
|
# check original target
|
||||||
|
try:
|
||||||
|
imap_server = imaplib.IMAP4_SSL('localhost')
|
||||||
|
imap_server.login('replyuser@mailu.io', 'password')
|
||||||
|
except Exception as exc:
|
||||||
|
print("Failed with:", exc)
|
||||||
|
sys.exit(110)
|
||||||
|
|
||||||
|
stat, count = imap_server.select('inbox')
|
||||||
|
try:
|
||||||
|
stat, data = imap_server.fetch(count[0], '(UID BODY[TEXT])')
|
||||||
|
except :
|
||||||
|
sys.exit(99)
|
||||||
|
|
||||||
|
if "Reply Text" in str(data[0][1]):
|
||||||
|
print("Success: Mail is in target inbox")
|
||||||
|
else:
|
||||||
|
print("Failed receiving email in target inbox")
|
||||||
|
sys.exit(99)
|
||||||
|
|
||||||
|
typ, data = imap_server.search(None, 'ALL')
|
||||||
|
for num in data[0].split():
|
||||||
|
imap_server.store(num, '+FLAGS', '\\Deleted')
|
||||||
|
imap_server.expunge()
|
||||||
|
|
||||||
|
imap_server.close()
|
||||||
|
imap_server.logout()
|
||||||
|
|
||||||
|
# check original/replied user
|
||||||
|
try:
|
||||||
|
imap_server = imaplib.IMAP4_SSL('localhost')
|
||||||
|
imap_server.login('admin@mailu.io', 'password')
|
||||||
|
except Exception as exc:
|
||||||
|
print("Failed with:", exc)
|
||||||
|
sys.exit(110)
|
||||||
|
|
||||||
|
stat, count = imap_server.select('inbox')
|
||||||
|
try:
|
||||||
|
stat, data = imap_server.fetch(count[0], '(UID BODY[TEXT])')
|
||||||
|
except :
|
||||||
|
sys.exit(99)
|
||||||
|
|
||||||
|
if "Cause this is just a test" in str(data[0][1]):
|
||||||
|
print("Success: Reply is in original inbox")
|
||||||
|
else:
|
||||||
|
print("Failed receiving reply in original inbox")
|
||||||
|
sys.exit(99)
|
||||||
|
|
||||||
|
typ, data = imap_server.search(None, 'ALL')
|
||||||
|
for num in data[0].split():
|
||||||
|
imap_server.store(num, '+FLAGS', '\\Deleted')
|
||||||
|
imap_server.expunge()
|
||||||
|
|
||||||
|
imap_server.close()
|
||||||
|
imap_server.logout()
|
Loading…
Reference in New Issue