test: code cleanup

This commit is contained in:
Wolfgang Steitz 2017-02-02 16:50:39 +01:00
parent c9cf148b03
commit a2350c4591
3 changed files with 6 additions and 44 deletions

View File

@ -4,7 +4,6 @@ from subprocess import check_call, check_output
import smtplib
from settings import *
from common import random_id
from test_mail import new_message, check_imap_received
@ -16,7 +15,7 @@ def test_backup_mail():
s.login(TEST_ADDRESS, TEST_PASSWORD)
s.sendmail(TEST_ADDRESS, [TEST_ADDRESS], msg)
s.quit()
# trigger a backup
sleep(2)
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)
num_backup_files_new = int(check_output(cmd_count, shell=True))
assert num_backup_files_new > num_backup_files
# delete mail
assert check_imap_received(subject)
assert not check_imap_received(subject)
# restore backup
path = "/home/user-data"
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)
rm = "sudo rm -rf {0}/restore/".format(path)
check_call(cmd_ssh + "\"" + passphrase + restore + move + rm + "\"", shell=True)
# check the mail is there again
assert check_imap_received(subject)

View File

@ -1,9 +1,7 @@
import pytest
from pycarddav import carddav
from time import sleep
from settings import *
from common import random_id
test_vcf = """

View File

@ -18,7 +18,7 @@ def new_message(from_email, to_email):
msg['From'] = from_email
msg['To'] = to_email
return msg.as_string(), msg['subject']
def check_imap_received(subject):
@ -34,7 +34,7 @@ def check_imap_received(subject):
# check the message exists
typ, data = m.search(None, '(SUBJECT \"{}\")'.format(subject))
res = len(data[0].split()) == 1
if res:
m.store(data[0].strip(), '+FLAGS', '\\Deleted')
m.expunge()
@ -132,41 +132,6 @@ def test_smtp_tls():
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():
"""Email sent from an MTA via SMTP+TLS has TLS headers"""
# Send a message to root