|
@@ -161,8 +161,8 @@ def new_message(from_email, to_email):
|
161
|
161
|
|
162
|
162
|
|
163
|
163
|
class MailTests(unittest.TestCase):
|
164
|
|
- def assertEmailReceived(self, subject):
|
165
|
|
- """Connects with IMAP and asserts the existance of an email, then deletes it"""
|
|
164
|
+ def assertIMAPReceived(self, subject):
|
|
165
|
+ """Connects with IMAP and asserts the existence of an email, then deletes it"""
|
166
|
166
|
import imaplib
|
167
|
167
|
|
168
|
168
|
sleep(1)
|
|
@@ -172,7 +172,7 @@ class MailTests(unittest.TestCase):
|
172
|
172
|
m.login(TEST_ADDRESS, TEST_PASSWORD)
|
173
|
173
|
m.select()
|
174
|
174
|
|
175
|
|
- # Assert the message exist
|
|
175
|
+ # Assert the message exists
|
176
|
176
|
typ, data = m.search(None, '(SUBJECT \"{}\")'.format(subject))
|
177
|
177
|
self.assertTrue(len(data[0].split()), 1)
|
178
|
178
|
|
|
@@ -182,6 +182,26 @@ class MailTests(unittest.TestCase):
|
182
|
182
|
m.close()
|
183
|
183
|
m.logout()
|
184
|
184
|
|
|
185
|
+ def assertPOP3Received(self, subject):
|
|
186
|
+ """Connects with POP3S and asserts the existence of an email, then deletes it"""
|
|
187
|
+ import poplib
|
|
188
|
+
|
|
189
|
+ sleep(1)
|
|
190
|
+
|
|
191
|
+ # Login to POP3
|
|
192
|
+ mail = poplib.POP3_SSL(TEST_SERVER, 995)
|
|
193
|
+ mail.user(TEST_ADDRESS)
|
|
194
|
+ mail.pass_(TEST_PASSWORD)
|
|
195
|
+
|
|
196
|
+ # Assert the message exists
|
|
197
|
+ num = len(mail.list()[1])
|
|
198
|
+ resp, text, octets = mail.retr(num)
|
|
199
|
+ self.assertTrue("Subject: " + subject in text)
|
|
200
|
+
|
|
201
|
+ # Delete it and log out
|
|
202
|
+ mail.dele(num)
|
|
203
|
+ mail.quit()
|
|
204
|
+
|
185
|
205
|
def test_imap_requires_ssl(self):
|
186
|
206
|
"""IMAP without SSL is NOT available"""
|
187
|
207
|
import imaplib
|
|
@@ -189,6 +209,13 @@ class MailTests(unittest.TestCase):
|
189
|
209
|
with self.assertRaisesRegexp(socket.timeout, 'timed out'):
|
190
|
210
|
imaplib.IMAP4(TEST_SERVER, 143)
|
191
|
211
|
|
|
212
|
+ def test_pop3_requires_ssl(self):
|
|
213
|
+ """POP3 without SSL is NOT available"""
|
|
214
|
+ import poplib
|
|
215
|
+
|
|
216
|
+ with self.assertRaisesRegexp(socket.timeout, 'timed out'):
|
|
217
|
+ poplib.POP3(TEST_SERVER, 110)
|
|
218
|
+
|
192
|
219
|
def test_smtps(self):
|
193
|
220
|
"""Email sent from an MUA via SMTPS is delivered"""
|
194
|
221
|
import smtplib
|
|
@@ -197,7 +224,7 @@ class MailTests(unittest.TestCase):
|
197
|
224
|
s.login(TEST_ADDRESS, TEST_PASSWORD)
|
198
|
225
|
s.sendmail(TEST_ADDRESS, ['root@sovereign.local'], msg)
|
199
|
226
|
s.quit()
|
200
|
|
- self.assertEmailReceived(subject)
|
|
227
|
+ self.assertIMAPReceived(subject)
|
201
|
228
|
|
202
|
229
|
def test_smtps_delimiter_to(self):
|
203
|
230
|
"""Email sent to address with delimiter is delivered"""
|
|
@@ -207,7 +234,7 @@ class MailTests(unittest.TestCase):
|
207
|
234
|
s.login(TEST_ADDRESS, TEST_PASSWORD)
|
208
|
235
|
s.sendmail(TEST_ADDRESS, ['root+foo@sovereign.local'], msg)
|
209
|
236
|
s.quit()
|
210
|
|
- self.assertEmailReceived(subject)
|
|
237
|
+ self.assertIMAPReceived(subject)
|
211
|
238
|
|
212
|
239
|
def test_smtps_requires_auth(self):
|
213
|
240
|
"""SMTPS with no authentication is rejected"""
|
|
@@ -226,7 +253,7 @@ class MailTests(unittest.TestCase):
|
226
|
253
|
s = smtplib.SMTP(TEST_SERVER, 25)
|
227
|
254
|
s.sendmail('someone@example.com', [TEST_ADDRESS], msg)
|
228
|
255
|
s.quit()
|
229
|
|
- self.assertEmailReceived(subject)
|
|
256
|
+ self.assertIMAPReceived(subject)
|
230
|
257
|
|
231
|
258
|
def test_smtp_tls(self):
|
232
|
259
|
"""Email sent from an MTA via SMTP+TLS is delivered"""
|
|
@@ -236,7 +263,7 @@ class MailTests(unittest.TestCase):
|
236
|
263
|
s.starttls()
|
237
|
264
|
s.sendmail('someone@example.com', [TEST_ADDRESS], msg)
|
238
|
265
|
s.quit()
|
239
|
|
- self.assertEmailReceived(subject)
|
|
266
|
+ self.assertIMAPReceived(subject)
|
240
|
267
|
|
241
|
268
|
def test_smtps_headers(self):
|
242
|
269
|
"""Email sent from an MUA has DKIM and TLS headers"""
|
|
@@ -312,6 +339,16 @@ class MailTests(unittest.TestCase):
|
312
|
339
|
m.close()
|
313
|
340
|
m.logout()
|
314
|
341
|
|
|
342
|
+ def test_pop3s(self):
|
|
343
|
+ """Connects with POP3S and asserts the existance of an email, then deletes it"""
|
|
344
|
+ import smtplib
|
|
345
|
+ msg, subject = new_message(TEST_ADDRESS, 'root@sovereign.local')
|
|
346
|
+ s = smtplib.SMTP_SSL(TEST_SERVER, 465)
|
|
347
|
+ s.login(TEST_ADDRESS, TEST_PASSWORD)
|
|
348
|
+ s.sendmail(TEST_ADDRESS, ['root@sovereign.local'], msg)
|
|
349
|
+ s.quit()
|
|
350
|
+ self.assertPOP3Received(subject)
|
|
351
|
+
|
315
|
352
|
|
316
|
353
|
class XMPPTests(unittest.TestCase):
|
317
|
354
|
def test_xmpp_c2s(self):
|