From bbb24a886325cb67f44ff5c01f64f0f7360ddc54 Mon Sep 17 00:00:00 2001 From: Dario Ernst Date: Sat, 5 Jan 2019 15:12:29 +0100 Subject: [PATCH 1/6] Add more tests: Auto-forwarding, sending to an alias and auto-reply Add simple test for auto-reply --- tests/alias_test.py | 60 ++++++++++++++++++ tests/compose/core/00_create_users.sh | 1 + tests/compose/core/02_forward_test.sh | 21 +++++++ tests/compose/core/03_alias_test.sh | 12 ++++ tests/compose/core/04_reply_test.sh | 21 +++++++ tests/compose/core/mailu.env | 2 + tests/email_test.py | 14 +++-- tests/forward_test.py | 87 +++++++++++++++++++++++++++ tests/reply_test.py | 87 +++++++++++++++++++++++++++ 9 files changed, 301 insertions(+), 4 deletions(-) create mode 100755 tests/alias_test.py create mode 100755 tests/compose/core/02_forward_test.sh create mode 100755 tests/compose/core/03_alias_test.sh create mode 100755 tests/compose/core/04_reply_test.sh create mode 100755 tests/forward_test.py create mode 100755 tests/reply_test.py diff --git a/tests/alias_test.py b/tests/alias_test.py new file mode 100755 index 00000000..003b1fcc --- /dev/null +++ b/tests/alias_test.py @@ -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() + diff --git a/tests/compose/core/00_create_users.sh b/tests/compose/core/00_create_users.sh index 40d0bd6e..eb214f64 100755 --- a/tests/compose/core/00_create_users.sh +++ b/tests/compose/core/00_create_users.sh @@ -1,4 +1,5 @@ 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 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!" diff --git a/tests/compose/core/02_forward_test.sh b/tests/compose/core/02_forward_test.sh new file mode 100755 index 00000000..595820cf --- /dev/null +++ b/tests/compose/core/02_forward_test.sh @@ -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 diff --git a/tests/compose/core/03_alias_test.sh b/tests/compose/core/03_alias_test.sh new file mode 100755 index 00000000..dce1918a --- /dev/null +++ b/tests/compose/core/03_alias_test.sh @@ -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 diff --git a/tests/compose/core/04_reply_test.sh b/tests/compose/core/04_reply_test.sh new file mode 100755 index 00000000..83c114f6 --- /dev/null +++ b/tests/compose/core/04_reply_test.sh @@ -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 diff --git a/tests/compose/core/mailu.env b/tests/compose/core/mailu.env index d77f3a2d..f18422f4 100644 --- a/tests/compose/core/mailu.env +++ b/tests/compose/core/mailu.env @@ -6,6 +6,8 @@ # For a detailed list of configuration variables, see the documentation at # https://mailu.io +DISABLE_FTS_LUCENE=true + ################################### # Common configuration variables ################################### diff --git a/tests/email_test.py b/tests/email_test.py index 853b76b5..046cf0ea 100755 --- a/tests/email_test.py +++ b/tests/email_test.py @@ -29,7 +29,7 @@ try: smtp_server.starttls() smtp_server.ehlo() smtp_server.login("admin@mailu.io", "password") - + smtp_server.sendmail("admin@mailu.io", "user@mailu.io", msg.as_string()) smtp_server.quit() except: @@ -47,13 +47,19 @@ stat, count = imap_server.select('inbox') try: stat, data = imap_server.fetch(count[0], '(UID BODY[TEXT])') except : + print("Couldn’t list email in imap inbox") sys.exit(99) - + if sys.argv[1] in str(data[0][1]): print("Success sending and receiving email!") else: - print("Failed receiving email with message %s" % sys.argv[1]) + print("Failed receiving email with message %s, message not contained" % sys.argv[1]) 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() diff --git a/tests/forward_test.py b/tests/forward_test.py new file mode 100755 index 00000000..830fcf30 --- /dev/null +++ b/tests/forward_test.py @@ -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() diff --git a/tests/reply_test.py b/tests/reply_test.py new file mode 100755 index 00000000..f343b039 --- /dev/null +++ b/tests/reply_test.py @@ -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() From 7a85d01f9f627b9e104e9ace8577ce2ed424b06d Mon Sep 17 00:00:00 2001 From: Ionut Filip Date: Fri, 11 Jan 2019 12:13:52 +0200 Subject: [PATCH 2/6] Removed unused imports and fixed indentation --- tests/alias_test.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/alias_test.py b/tests/alias_test.py index 003b1fcc..1943c11e 100755 --- a/tests/alias_test.py +++ b/tests/alias_test.py @@ -4,9 +4,6 @@ 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" @@ -52,7 +49,7 @@ for user in ['user@mailu.io', 'admin@mailu.io', 'user/with/slash@mailu.io']: typ, data = imap_server.search(None, 'ALL') for num in data[0].split(): - imap_server.store(num, '+FLAGS', '\\Deleted') + imap_server.store(num, '+FLAGS', '\\Deleted') imap_server.expunge() imap_server.close() From 6914028e9c68f6491fed326a2ba6cdbcb39793eb Mon Sep 17 00:00:00 2001 From: Ionut Filip Date: Fri, 11 Jan 2019 12:50:41 +0200 Subject: [PATCH 3/6] Fix indentation --- tests/email_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/email_test.py b/tests/email_test.py index 046cf0ea..e7cd66ed 100755 --- a/tests/email_test.py +++ b/tests/email_test.py @@ -58,7 +58,7 @@ else: typ, data = imap_server.search(None, 'ALL') for num in data[0].split(): - imap_server.store(num, '+FLAGS', '\\Deleted') + imap_server.store(num, '+FLAGS', '\\Deleted') imap_server.expunge() imap_server.close() From ebed267c1b37e16adab0e4cd1b4f19ad876c6c46 Mon Sep 17 00:00:00 2001 From: Ionut Filip Date: Fri, 11 Jan 2019 12:55:47 +0200 Subject: [PATCH 4/6] Removed unused imports and fixed indentation --- tests/forward_test.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/forward_test.py b/tests/forward_test.py index 830fcf30..76ca8ac6 100755 --- a/tests/forward_test.py +++ b/tests/forward_test.py @@ -4,9 +4,6 @@ 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" @@ -52,7 +49,7 @@ else: typ, data = imap_server.search(None, 'ALL') for num in data[0].split(): - imap_server.store(num, '+FLAGS', '\\Deleted') + imap_server.store(num, '+FLAGS', '\\Deleted') imap_server.expunge() imap_server.close() @@ -80,7 +77,7 @@ else: typ, data = imap_server.search(None, 'ALL') for num in data[0].split(): - imap_server.store(num, '+FLAGS', '\\Deleted') + imap_server.store(num, '+FLAGS', '\\Deleted') imap_server.expunge() imap_server.close() From f50e9055c119ff4e00d8cf756b3f6af23f252e1e Mon Sep 17 00:00:00 2001 From: Ionut Filip Date: Fri, 11 Jan 2019 12:57:45 +0200 Subject: [PATCH 5/6] Unused imports and bad indentation --- tests/reply_test.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/reply_test.py b/tests/reply_test.py index f343b039..be6ddabb 100755 --- a/tests/reply_test.py +++ b/tests/reply_test.py @@ -4,9 +4,6 @@ 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" @@ -52,7 +49,7 @@ else: typ, data = imap_server.search(None, 'ALL') for num in data[0].split(): - imap_server.store(num, '+FLAGS', '\\Deleted') + imap_server.store(num, '+FLAGS', '\\Deleted') imap_server.expunge() imap_server.close() @@ -80,7 +77,7 @@ else: typ, data = imap_server.search(None, 'ALL') for num in data[0].split(): - imap_server.store(num, '+FLAGS', '\\Deleted') + imap_server.store(num, '+FLAGS', '\\Deleted') imap_server.expunge() imap_server.close() From cb1c90b4230a5611bba223667fe4a6a49f6561f8 Mon Sep 17 00:00:00 2001 From: Ionut Filip Date: Fri, 11 Jan 2019 15:18:42 +0200 Subject: [PATCH 6/6] Removed DISABLE_FTS_LUCENE --- tests/compose/core/mailu.env | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/compose/core/mailu.env b/tests/compose/core/mailu.env index f18422f4..d77f3a2d 100644 --- a/tests/compose/core/mailu.env +++ b/tests/compose/core/mailu.env @@ -6,8 +6,6 @@ # For a detailed list of configuration variables, see the documentation at # https://mailu.io -DISABLE_FTS_LUCENE=true - ################################### # Common configuration variables ###################################