mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2025-04-20 02:52:11 +00:00
test: code cleanup
This commit is contained in:
parent
c9cf148b03
commit
a2350c4591
@ -4,7 +4,6 @@ from subprocess import check_call, check_output
|
|||||||
import smtplib
|
import smtplib
|
||||||
|
|
||||||
from settings import *
|
from settings import *
|
||||||
from common import random_id
|
|
||||||
from test_mail import new_message, check_imap_received
|
from test_mail import new_message, check_imap_received
|
||||||
|
|
||||||
|
|
||||||
@ -16,7 +15,7 @@ def test_backup_mail():
|
|||||||
s.login(TEST_ADDRESS, TEST_PASSWORD)
|
s.login(TEST_ADDRESS, TEST_PASSWORD)
|
||||||
s.sendmail(TEST_ADDRESS, [TEST_ADDRESS], msg)
|
s.sendmail(TEST_ADDRESS, [TEST_ADDRESS], msg)
|
||||||
s.quit()
|
s.quit()
|
||||||
|
|
||||||
# trigger a backup
|
# trigger a backup
|
||||||
sleep(2)
|
sleep(2)
|
||||||
cmd_ssh = "sshpass -p vagrant ssh vagrant@{} -p {} ".format(TEST_SERVER, TEST_PORT)
|
cmd_ssh = "sshpass -p vagrant ssh vagrant@{} -p {} ".format(TEST_SERVER, TEST_PORT)
|
||||||
@ -26,11 +25,11 @@ def test_backup_mail():
|
|||||||
check_call(cmd, shell=True)
|
check_call(cmd, shell=True)
|
||||||
num_backup_files_new = int(check_output(cmd_count, shell=True))
|
num_backup_files_new = int(check_output(cmd_count, shell=True))
|
||||||
assert num_backup_files_new > num_backup_files
|
assert num_backup_files_new > num_backup_files
|
||||||
|
|
||||||
# delete mail
|
# delete mail
|
||||||
assert check_imap_received(subject)
|
assert check_imap_received(subject)
|
||||||
assert not check_imap_received(subject)
|
assert not check_imap_received(subject)
|
||||||
|
|
||||||
# restore backup
|
# restore backup
|
||||||
path = "/home/user-data"
|
path = "/home/user-data"
|
||||||
passphrase = "export PASSPHRASE=\$(sudo cat /home/user-data/backup/secret_key.txt) &&"
|
passphrase = "export PASSPHRASE=\$(sudo cat /home/user-data/backup/secret_key.txt) &&"
|
||||||
@ -40,6 +39,6 @@ def test_backup_mail():
|
|||||||
move = "sudo rsync -av {0}/restore/* {0}/ &&".format(path)
|
move = "sudo rsync -av {0}/restore/* {0}/ &&".format(path)
|
||||||
rm = "sudo rm -rf {0}/restore/".format(path)
|
rm = "sudo rm -rf {0}/restore/".format(path)
|
||||||
check_call(cmd_ssh + "\"" + passphrase + restore + move + rm + "\"", shell=True)
|
check_call(cmd_ssh + "\"" + passphrase + restore + move + rm + "\"", shell=True)
|
||||||
|
|
||||||
# check the mail is there again
|
# check the mail is there again
|
||||||
assert check_imap_received(subject)
|
assert check_imap_received(subject)
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from pycarddav import carddav
|
from pycarddav import carddav
|
||||||
from time import sleep
|
|
||||||
|
|
||||||
from settings import *
|
from settings import *
|
||||||
from common import random_id
|
|
||||||
|
|
||||||
|
|
||||||
test_vcf = """
|
test_vcf = """
|
||||||
|
@ -18,7 +18,7 @@ def new_message(from_email, to_email):
|
|||||||
msg['From'] = from_email
|
msg['From'] = from_email
|
||||||
msg['To'] = to_email
|
msg['To'] = to_email
|
||||||
return msg.as_string(), msg['subject']
|
return msg.as_string(), msg['subject']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def check_imap_received(subject):
|
def check_imap_received(subject):
|
||||||
@ -34,7 +34,7 @@ def check_imap_received(subject):
|
|||||||
# check the message exists
|
# check the message exists
|
||||||
typ, data = m.search(None, '(SUBJECT \"{}\")'.format(subject))
|
typ, data = m.search(None, '(SUBJECT \"{}\")'.format(subject))
|
||||||
res = len(data[0].split()) == 1
|
res = len(data[0].split()) == 1
|
||||||
|
|
||||||
if res:
|
if res:
|
||||||
m.store(data[0].strip(), '+FLAGS', '\\Deleted')
|
m.store(data[0].strip(), '+FLAGS', '\\Deleted')
|
||||||
m.expunge()
|
m.expunge()
|
||||||
@ -132,41 +132,6 @@ def test_smtp_tls():
|
|||||||
assert check_imap_received(subject)
|
assert check_imap_received(subject)
|
||||||
|
|
||||||
|
|
||||||
# FIXME
|
|
||||||
#def test_smtps_headers():
|
|
||||||
# """Email sent from an MUA has DKIM and TLS headers"""
|
|
||||||
# import smtplib
|
|
||||||
# import imaplib
|
|
||||||
#
|
|
||||||
# # Send a message to admin
|
|
||||||
# mail_address = "admin@" + TEST_DOMAIN
|
|
||||||
# msg, subject = new_message(TEST_ADDRESS, mail_address)
|
|
||||||
# s = smtplib.SMTP(TEST_DOMAIN, 587)
|
|
||||||
# s.starttls()
|
|
||||||
# s.login(TEST_ADDRESS, TEST_PASSWORD)
|
|
||||||
# s.sendmail(TEST_ADDRESS, [mail_address], msg)
|
|
||||||
# s.quit()
|
|
||||||
#
|
|
||||||
# sleep(3)
|
|
||||||
#
|
|
||||||
# # Get the message
|
|
||||||
# m = imaplib.IMAP4_SSL(TEST_DOMAIN, 993)
|
|
||||||
# m.login(TEST_ADDRESS, TEST_PASSWORD)
|
|
||||||
# m.select()
|
|
||||||
# _, res = m.search(None, '(SUBJECT \"{}\")'.format(subject))
|
|
||||||
# _, data = m.fetch(res[0], '(RFC822)')
|
|
||||||
#
|
|
||||||
# assert 'DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailinabox.lan;' in data[0][1]
|
|
||||||
#
|
|
||||||
# assert 'ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)' in data[0][1]
|
|
||||||
#
|
|
||||||
# # Clean up
|
|
||||||
# m.store(res[0].strip(), '+FLAGS', '\\Deleted')
|
|
||||||
# m.expunge()
|
|
||||||
# m.close()
|
|
||||||
# m.logout()
|
|
||||||
|
|
||||||
|
|
||||||
def test_smtp_headers():
|
def test_smtp_headers():
|
||||||
"""Email sent from an MTA via SMTP+TLS has TLS headers"""
|
"""Email sent from an MTA via SMTP+TLS has TLS headers"""
|
||||||
# Send a message to root
|
# Send a message to root
|
||||||
|
Loading…
Reference in New Issue
Block a user