Implemented email test for travis

master
Ionut Filip 6 years ago
parent 4e9dc0c3c9
commit c3bc7988c9

@ -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.

@ -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()

@ -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()

@ -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()

@ -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()

@ -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)

@ -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()
Loading…
Cancel
Save