You've already forked Mailu
mirror of
https://github.com/Mailu/Mailu.git
synced 2025-07-17 01:32:29 +02:00
Calling email test as hook with msg as arg
This commit is contained in:
1
tests/compose/core/01_email_test.sh
Executable file
1
tests/compose/core/01_email_test.sh
Executable file
@ -0,0 +1 @@
|
|||||||
|
python3 tests/email_test.py message-core
|
1
tests/compose/filters/01_email_test.sh
Executable file
1
tests/compose/filters/01_email_test.sh
Executable file
@ -0,0 +1 @@
|
|||||||
|
python3 tests/email_test.py message-filters
|
@ -19,7 +19,7 @@ containers = []
|
|||||||
def stop(exit_code):
|
def stop(exit_code):
|
||||||
print_logs()
|
print_logs()
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
print(subprocess.check_output("docker-compose -f " + compose_file + " down", shell=True))
|
print(subprocess.check_output("docker-compose -f " + compose_file + " down", shell=True).decode())
|
||||||
sys.exit(exit_code)
|
sys.exit(exit_code)
|
||||||
|
|
||||||
# Sleep for a defined amount of time
|
# Sleep for a defined amount of time
|
||||||
@ -67,30 +67,31 @@ def print_logs():
|
|||||||
for container in containers:
|
for container in containers:
|
||||||
print(Fore.LIGHTMAGENTA_EX + "Printing logs for: " + Fore.GREEN + container['Name'] + Style.RESET_ALL)
|
print(Fore.LIGHTMAGENTA_EX + "Printing logs for: " + Fore.GREEN + container['Name'] + Style.RESET_ALL)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
print(subprocess.check_output('docker container logs ' + container['Name'], shell=True))
|
print(subprocess.check_output('docker container logs ' + container['Name'], shell=True).decode())
|
||||||
|
|
||||||
#Iterating over hooks in test folder and running them
|
#Iterating over hooks in test folder and running them
|
||||||
def hooks():
|
def hooks():
|
||||||
print("Running hooks")
|
print(Fore.LIGHTMAGENTA_EX + "Running hooks" + Style.RESET_ALL)
|
||||||
for test_file in sorted(os.listdir(test_path)):
|
for test_file in sorted(os.listdir(test_path)):
|
||||||
|
try:
|
||||||
if test_file.endswith(".py"):
|
if test_file.endswith(".py"):
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
print(subprocess.check_output("python3 " + test_path + test_file, shell=True))
|
print(subprocess.check_output("python3 " + test_path + test_file, shell=True).decode())
|
||||||
elif test_file.endswith(".sh"):
|
elif test_file.endswith(".sh"):
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
print(subprocess.check_output("./" + test_path + test_file, shell=True))
|
print(subprocess.check_output("./" + test_path + test_file, shell=True).decode())
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
sys.stdout.flush()
|
sys.stderr.write("[ERROR]: output = %s, error code = %s\n" % (e.output.decode(), e.returncode))
|
||||||
print(subprocess.check_output("python3 tests/email_test.py", shell=True))
|
stop(1)
|
||||||
|
|
||||||
# Start up containers
|
# Start up containers
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
print(subprocess.check_output("docker-compose -f " + compose_file + " up -d", shell=True))
|
print(subprocess.check_output("docker-compose -f " + compose_file + " up -d", shell=True).decode())
|
||||||
print()
|
print()
|
||||||
sleep()
|
sleep()
|
||||||
print()
|
print()
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
print(subprocess.check_output("docker ps -a", shell=True))
|
print(subprocess.check_output("docker ps -a", shell=True).decode())
|
||||||
print()
|
print()
|
||||||
health_checks()
|
health_checks()
|
||||||
print()
|
print()
|
||||||
|
@ -1,19 +1,9 @@
|
|||||||
import string
|
|
||||||
import random
|
|
||||||
import smtplib
|
import smtplib
|
||||||
import imaplib
|
import imaplib
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def secret(length=16):
|
email_msg = sys.argv[1]
|
||||||
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
|
#Login to smt server and sending email with secret message
|
||||||
def send_email(msg):
|
def send_email(msg):
|
||||||
@ -42,16 +32,16 @@ def read_email():
|
|||||||
|
|
||||||
print("email received with message " + str(data[0][1]))
|
print("email received with message " + str(data[0][1]))
|
||||||
|
|
||||||
if secret_message in str(data[0][1]):
|
if email_msg in str(data[0][1]):
|
||||||
print("Success!")
|
print("Success!")
|
||||||
else:
|
else:
|
||||||
print("Failed! Something went wrong")
|
print("Failed receiving email with message %s" % email_msg)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
server.close()
|
server.close()
|
||||||
server.logout()
|
server.logout()
|
||||||
|
|
||||||
|
|
||||||
send_email(secret_message)
|
send_email(email_msg)
|
||||||
print("Sleeping for 1m")
|
print("Sleeping for 1m")
|
||||||
time.sleep(60)
|
time.sleep(60)
|
||||||
read_email()
|
read_email()
|
||||||
|
Reference in New Issue
Block a user