From c3bc7988c90d25d65d1eb8d2142a58686bacab40 Mon Sep 17 00:00:00 2001 From: Ionut Filip Date: Fri, 2 Nov 2018 14:27:46 +0200 Subject: [PATCH] Implemented email test for travis --- .travis.yml | 4 ++ tests/compose/{core => }/email_test.py | 0 tests/compose/fetchmail/email_test.py | 55 -------------------------- tests/compose/filters/email_test.py | 55 -------------------------- tests/compose/rainloop/email_test.py | 55 -------------------------- tests/compose/roundcube/email_test.py | 55 -------------------------- tests/compose/test.py | 15 ++----- tests/compose/webdav/email_test.py | 55 -------------------------- 8 files changed, 7 insertions(+), 287 deletions(-) rename tests/compose/{core => }/email_test.py (100%) delete mode 100755 tests/compose/fetchmail/email_test.py delete mode 100755 tests/compose/filters/email_test.py delete mode 100755 tests/compose/rainloop/email_test.py delete mode 100755 tests/compose/roundcube/email_test.py delete mode 100755 tests/compose/webdav/email_test.py diff --git a/.travis.yml b/.travis.yml index 54b3b3c7..ffb6af43 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,10 @@ install: before_script: - docker-compose -v - docker-compose -f tests/build.yml build + - docker-compose up -d admin + - docker-compose exec admin python manage.py admin admin mailu.io password + - docker-compose exec admin python manage.py user --hash_scheme='SHA512-CRYPT' user mailu.io 'password' + - docker-compose down script: # test.py, test name and timeout between start and tests. diff --git a/tests/compose/core/email_test.py b/tests/compose/email_test.py similarity index 100% rename from tests/compose/core/email_test.py rename to tests/compose/email_test.py diff --git a/tests/compose/fetchmail/email_test.py b/tests/compose/fetchmail/email_test.py deleted file mode 100755 index c16ce9d8..00000000 --- a/tests/compose/fetchmail/email_test.py +++ /dev/null @@ -1,55 +0,0 @@ -import string -import random -import smtplib -import imaplib -import time - -def secret(length=16): - charset = string.ascii_uppercase + string.digits - return ''.join( - random.SystemRandom().choice(charset) - for _ in range(length) - ) - -#Generating secret message -secret_message = secret(16) - -#Login to smt server and sending email with secret message -def send_email(msg): - print("Sending email ...") - server = smtplib.SMTP('localhost') - server.set_debuglevel(1) - server.connect('localhost', 587) - server.ehlo() - server.starttls() - server.ehlo() - server.login("admin@mailu.io", "password") - - server.sendmail("admin@mailu.io", "user@mailu.io", msg) - server.quit() - - print("email sent with message " + msg) - -#Login to imap server, read latest email and check for secret message -def read_email(): - print("Receiving email ...") - server = imaplib.IMAP4_SSL('localhost') - server.login('user@mailu.io', 'password') - - stat, count = server.select('inbox') - stat, data = server.fetch(count[0], '(UID BODY[TEXT])') - - print("email received with message " + str(data[0][1])) - - if secret_message in str(data[0][1]): - print("Success!") - else: - print("Failed! Something went wrong") - server.close() - server.logout() - - -send_email(secret_message) -print("Sleeping for 1m") -time.sleep(60) -read_email() diff --git a/tests/compose/filters/email_test.py b/tests/compose/filters/email_test.py deleted file mode 100755 index c16ce9d8..00000000 --- a/tests/compose/filters/email_test.py +++ /dev/null @@ -1,55 +0,0 @@ -import string -import random -import smtplib -import imaplib -import time - -def secret(length=16): - charset = string.ascii_uppercase + string.digits - return ''.join( - random.SystemRandom().choice(charset) - for _ in range(length) - ) - -#Generating secret message -secret_message = secret(16) - -#Login to smt server and sending email with secret message -def send_email(msg): - print("Sending email ...") - server = smtplib.SMTP('localhost') - server.set_debuglevel(1) - server.connect('localhost', 587) - server.ehlo() - server.starttls() - server.ehlo() - server.login("admin@mailu.io", "password") - - server.sendmail("admin@mailu.io", "user@mailu.io", msg) - server.quit() - - print("email sent with message " + msg) - -#Login to imap server, read latest email and check for secret message -def read_email(): - print("Receiving email ...") - server = imaplib.IMAP4_SSL('localhost') - server.login('user@mailu.io', 'password') - - stat, count = server.select('inbox') - stat, data = server.fetch(count[0], '(UID BODY[TEXT])') - - print("email received with message " + str(data[0][1])) - - if secret_message in str(data[0][1]): - print("Success!") - else: - print("Failed! Something went wrong") - server.close() - server.logout() - - -send_email(secret_message) -print("Sleeping for 1m") -time.sleep(60) -read_email() diff --git a/tests/compose/rainloop/email_test.py b/tests/compose/rainloop/email_test.py deleted file mode 100755 index c16ce9d8..00000000 --- a/tests/compose/rainloop/email_test.py +++ /dev/null @@ -1,55 +0,0 @@ -import string -import random -import smtplib -import imaplib -import time - -def secret(length=16): - charset = string.ascii_uppercase + string.digits - return ''.join( - random.SystemRandom().choice(charset) - for _ in range(length) - ) - -#Generating secret message -secret_message = secret(16) - -#Login to smt server and sending email with secret message -def send_email(msg): - print("Sending email ...") - server = smtplib.SMTP('localhost') - server.set_debuglevel(1) - server.connect('localhost', 587) - server.ehlo() - server.starttls() - server.ehlo() - server.login("admin@mailu.io", "password") - - server.sendmail("admin@mailu.io", "user@mailu.io", msg) - server.quit() - - print("email sent with message " + msg) - -#Login to imap server, read latest email and check for secret message -def read_email(): - print("Receiving email ...") - server = imaplib.IMAP4_SSL('localhost') - server.login('user@mailu.io', 'password') - - stat, count = server.select('inbox') - stat, data = server.fetch(count[0], '(UID BODY[TEXT])') - - print("email received with message " + str(data[0][1])) - - if secret_message in str(data[0][1]): - print("Success!") - else: - print("Failed! Something went wrong") - server.close() - server.logout() - - -send_email(secret_message) -print("Sleeping for 1m") -time.sleep(60) -read_email() diff --git a/tests/compose/roundcube/email_test.py b/tests/compose/roundcube/email_test.py deleted file mode 100755 index c16ce9d8..00000000 --- a/tests/compose/roundcube/email_test.py +++ /dev/null @@ -1,55 +0,0 @@ -import string -import random -import smtplib -import imaplib -import time - -def secret(length=16): - charset = string.ascii_uppercase + string.digits - return ''.join( - random.SystemRandom().choice(charset) - for _ in range(length) - ) - -#Generating secret message -secret_message = secret(16) - -#Login to smt server and sending email with secret message -def send_email(msg): - print("Sending email ...") - server = smtplib.SMTP('localhost') - server.set_debuglevel(1) - server.connect('localhost', 587) - server.ehlo() - server.starttls() - server.ehlo() - server.login("admin@mailu.io", "password") - - server.sendmail("admin@mailu.io", "user@mailu.io", msg) - server.quit() - - print("email sent with message " + msg) - -#Login to imap server, read latest email and check for secret message -def read_email(): - print("Receiving email ...") - server = imaplib.IMAP4_SSL('localhost') - server.login('user@mailu.io', 'password') - - stat, count = server.select('inbox') - stat, data = server.fetch(count[0], '(UID BODY[TEXT])') - - print("email received with message " + str(data[0][1])) - - if secret_message in str(data[0][1]): - print("Success!") - else: - print("Failed! Something went wrong") - server.close() - server.logout() - - -send_email(secret_message) -print("Sleeping for 1m") -time.sleep(60) -read_email() diff --git a/tests/compose/test.py b/tests/compose/test.py index d3b2d109..84281123 100755 --- a/tests/compose/test.py +++ b/tests/compose/test.py @@ -17,7 +17,7 @@ containers = [] # Stop containers def stop(exit_code): print_logs() - os.system("docker-compose -f " + compose_file + " -p ${DOCKER_ORG:-mailu} down") + os.system("docker-compose -f " + compose_file + " down") sys.exit(exit_code) # Sleep for a defined amount of time @@ -69,25 +69,17 @@ def print_logs(): #Iterating over hooks in test folder and running them def hooks(): print("Running hooks") + os.system("python3 tests/compose/email_test.py") for test_file in sorted(os.listdir(test_path)): if test_file.endswith(".py"): os.system("python3 " + test_path + test_file) elif test_file.endswith(".sh"): os.system("./" + test_path + test_file) -#Create admin and user -def create_users(): - print("Creating admin account...") - os.system("docker-compose -p $DOCKER_ORG exec admin python manage.py admin admin mailu.io password") - print("Admin account created") - print("Creating user account...") - os.system("docker-compose -p $DOCKER_ORG exec admin python manage.py user --hash_scheme='SHA512-CRYPT' user mailu.io 'password'") - print("User account created") - # Start up containers os.system("mkdir -p /mailu && cp -r tests/certs /mailu") os.system("chmod 600 /mailu/certs/* ") -os.system("docker-compose -f " + compose_file + " -p ${DOCKER_ORG:-mailu} up -d ") +os.system("docker-compose -f " + compose_file + " up -d ") print() sleep() print() @@ -95,7 +87,6 @@ os.system("docker ps -a") print() health_checks() print() -create_users() hooks() print() stop(0) diff --git a/tests/compose/webdav/email_test.py b/tests/compose/webdav/email_test.py deleted file mode 100755 index c16ce9d8..00000000 --- a/tests/compose/webdav/email_test.py +++ /dev/null @@ -1,55 +0,0 @@ -import string -import random -import smtplib -import imaplib -import time - -def secret(length=16): - charset = string.ascii_uppercase + string.digits - return ''.join( - random.SystemRandom().choice(charset) - for _ in range(length) - ) - -#Generating secret message -secret_message = secret(16) - -#Login to smt server and sending email with secret message -def send_email(msg): - print("Sending email ...") - server = smtplib.SMTP('localhost') - server.set_debuglevel(1) - server.connect('localhost', 587) - server.ehlo() - server.starttls() - server.ehlo() - server.login("admin@mailu.io", "password") - - server.sendmail("admin@mailu.io", "user@mailu.io", msg) - server.quit() - - print("email sent with message " + msg) - -#Login to imap server, read latest email and check for secret message -def read_email(): - print("Receiving email ...") - server = imaplib.IMAP4_SSL('localhost') - server.login('user@mailu.io', 'password') - - stat, count = server.select('inbox') - stat, data = server.fetch(count[0], '(UID BODY[TEXT])') - - print("email received with message " + str(data[0][1])) - - if secret_message in str(data[0][1]): - print("Success!") - else: - print("Failed! Something went wrong") - server.close() - server.logout() - - -send_email(secret_message) -print("Sleeping for 1m") -time.sleep(60) -read_email()