summaryrefslogtreecommitdiff
path: root/900-implements.yarn
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-03-18 19:42:58 +0200
committerLars Wirzenius <liw@liw.fi>2017-03-18 19:42:58 +0200
commit3885c7e424e94ad4abf7c120aafe7ebdc4570100 (patch)
treeb0fe7896bd9ffb7e78e7c34b6be66d4ad43a1689 /900-implements.yarn
parent8f2cf6cd84f54a1db8bdd51c93253cd8e41d6d9d (diff)
downloadserver-yarns-3885c7e424e94ad4abf7c120aafe7ebdc4570100.tar.gz
Add scenarios to test if relaying is allowed
Diffstat (limited to '900-implements.yarn')
-rw-r--r--900-implements.yarn42
1 files changed, 42 insertions, 0 deletions
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)