mirror of
				https://github.com/optim-enterprises-bv/Mailu.git
				synced 2025-10-30 17:47:55 +00: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): | ||||
|     print_logs() | ||||
|     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) | ||||
|  | ||||
| # Sleep for a defined amount of time | ||||
| @@ -67,30 +67,31 @@ def print_logs(): | ||||
|     for container in containers: | ||||
|         print(Fore.LIGHTMAGENTA_EX + "Printing logs for: " + Fore.GREEN + container['Name'] + Style.RESET_ALL) | ||||
|         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 | ||||
| def hooks(): | ||||
|     print("Running hooks") | ||||
|     print(Fore.LIGHTMAGENTA_EX + "Running hooks" + Style.RESET_ALL) | ||||
|     for test_file in sorted(os.listdir(test_path)): | ||||
|         if test_file.endswith(".py"): | ||||
|             sys.stdout.flush() | ||||
|             print(subprocess.check_output("python3 " + test_path + test_file, shell=True)) | ||||
|         elif test_file.endswith(".sh"): | ||||
|             sys.stdout.flush() | ||||
|             print(subprocess.check_output("./" + test_path + test_file, shell=True)) | ||||
|      | ||||
|     sys.stdout.flush() | ||||
|     print(subprocess.check_output("python3 tests/email_test.py", shell=True)) | ||||
|         try: | ||||
|             if test_file.endswith(".py"): | ||||
|                 sys.stdout.flush() | ||||
|                 print(subprocess.check_output("python3 " + test_path + test_file, shell=True).decode()) | ||||
|             elif test_file.endswith(".sh"): | ||||
|                 sys.stdout.flush() | ||||
|                 print(subprocess.check_output("./" + test_path + test_file, shell=True).decode()) | ||||
|         except subprocess.CalledProcessError as e: | ||||
|             sys.stderr.write("[ERROR]: output = %s, error code = %s\n" % (e.output.decode(), e.returncode)) | ||||
|             stop(1) | ||||
|  | ||||
| # Start up containers | ||||
| 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() | ||||
| sleep() | ||||
| print() | ||||
| sys.stdout.flush() | ||||
| print(subprocess.check_output("docker ps -a", shell=True)) | ||||
| print(subprocess.check_output("docker ps -a", shell=True).decode()) | ||||
| print() | ||||
| health_checks() | ||||
| print() | ||||
|   | ||||
| @@ -1,19 +1,9 @@ | ||||
| import string | ||||
| import random | ||||
| import smtplib | ||||
| import imaplib | ||||
| import time | ||||
| import sys | ||||
|  | ||||
| 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) | ||||
| email_msg = sys.argv[1] | ||||
|  | ||||
| #Login to smt server and sending email with secret message     | ||||
| def send_email(msg): | ||||
| @@ -42,16 +32,16 @@ def read_email(): | ||||
|      | ||||
|     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!") | ||||
|     else: | ||||
|         print("Failed! Something went wrong") | ||||
|         print("Failed receiving email with message %s" % email_msg) | ||||
|         sys.exit(1) | ||||
|     server.close() | ||||
|     server.logout() | ||||
|  | ||||
|      | ||||
| send_email(secret_message) | ||||
| send_email(email_msg) | ||||
| print("Sleeping for 1m") | ||||
| time.sleep(60) | ||||
| read_email() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Ionut Filip
					Ionut Filip