From 3885c7e424e94ad4abf7c120aafe7ebdc4570100 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 18 Mar 2017 19:42:58 +0200 Subject: Add scenarios to test if relaying is allowed --- 900-implements.yarn | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to '900-implements.yarn') diff --git a/900-implements.yarn b/900-implements.yarn index 477158f..8a0c8db 100644 --- a/900-implements.yarn +++ b/900-implements.yarn @@ -161,3 +161,45 @@ imapobj.store(msgid, '+FLAGS', '(\\Deleted)') h.iterate_mails_in_imap_mailbox( address, user, password, delete_matching, True) + +## Run sequence of SMTP commands, check SMTP status + + IMPLEMENTS WHEN client SMTP authenticates as (\S+) + import yarnhelper + h = yarnhelper.YarnHelper() + user = h.get_next_match() + h.set_variable('smtp_username', user) + + IMPLEMENTS WHEN client sends (.*) + import yarnhelper + h = yarnhelper.YarnHelper() + command = h.get_next_match() + smtp_commands = h.get_variable('smtp_commands', []) + smtp_commands.append(command) + h.set_variable('smtp_commands', smtp_commands) + + IMPLEMENTS THEN SMTP status code is (\d+) + import os, smtplib, yarnhelper + h = yarnhelper.YarnHelper() + wanted_status = int(h.get_next_match()) + smtp_commands = h.get_variable('smtp_commands') + smtp_username = h.get_variable('smtp_username') + if smtp_username is not None: + pass_home = os.environ['PASS_HOME'] + pass_user = 'pieni.net/{}'.format(smtp_username) + smtp_password = h.get_password_with_pass(pass_home, pass_user) + address = os.environ['ADDRESS'] + server = smtplib.SMTP() + print 'connecting to', address + server.connect(host=address, port=587) + server.set_debuglevel(True) + print 'starttls' + server.starttls() + if smtp_username is not None: + print 'Authenticating as', smtp_username + print server.login(smtp_username, smtp_password) + for cmd in smtp_commands: + print 'Command:', cmd + actual_status, msg = server.docmd(cmd) + server.quit() + h.assertEqual(actual_status, wanted_status) -- cgit v1.2.1