-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
executable file
·85 lines (63 loc) · 3.26 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
import unittest
from ioproxy.input import StringInput
from ioproxy.logger import DoNothingLogger
from ioproxy.output import StringOutput
from ioproxy.smtp.strangler import SMTPStringStrangler
GENEROUS_READ_LENGTH = 5000
class TestStrangler(unittest.TestCase):
@unittest.skip('soon')
def test_bye_means_quit(self):
request = StringInput(b'BYE plz\r\n')
request_instead = StringOutput()
strangler = SMTPStringStrangler(DoNothingLogger(), request, request_instead, None, None)
strangler.requests.read(GENEROUS_READ_LENGTH)
strangler.requests.send()
self.assertEqual(b'QUIT plz\r\n', request_instead.output_string)
@unittest.skip('soon')
def test_pubmob_gives_pubmob_url(self):
request = StringInput(b'PUBMOB\r\n')
request_instead = StringOutput()
response = StringInput(b'777 incredibly fake server response\r\n')
response_instead = StringOutput()
strangler = SMTPStringStrangler(DoNothingLogger(), request, request_instead, response, response_instead)
strangler.requests.read(GENEROUS_READ_LENGTH)
strangler.requests.send()
self.assertEqual(b'NOOP PUBMOB \r\n', request_instead.output_string)
strangler.responses.read(GENEROUS_READ_LENGTH)
strangler.responses.send()
self.assertEqual(b'250 http://pubmob.com/\r\n', response_instead.output_string)
@unittest.skip('soon')
def test_ehlo_response_includes_gdpr_capability(self):
request = StringInput(b'EHLO\r\n')
response = StringInput(b'250-very.plausible.server\r\n' +
b'250-SINGING\r\n' +
b'250 DANCING\r\n')
response_instead = StringOutput()
expected_response_instead = b'250-very.plausible.server\r\n' +\
b'250-SINGING\r\n' +\
b'250-DANCING\r\n'+\
b'250 GDPR 20160414\r\n'
strangler = SMTPStringStrangler(DoNothingLogger(), request, StringOutput(), response, response_instead)
strangler.requests.read(GENEROUS_READ_LENGTH)
strangler.requests.send()
strangler.responses.read(GENEROUS_READ_LENGTH)
strangler.responses.send()
self.assertEqual(expected_response_instead, response_instead.output_string)
@unittest.skip('soon')
def test_reject_mail_from_jlangr(self):
request = StringInput(b'MAIL FROM: jlangr\r\n')
request_instead = StringOutput()
response = StringInput(b'250 ok\r\n')
response_instead = StringOutput()
strangler = SMTPStringStrangler(DoNothingLogger(), request, request_instead, response, response_instead)
strangler.requests.read(GENEROUS_READ_LENGTH)
strangler.requests.send()
expected_request_instead = b'NOOP MAIL FROM: jlangr\r\n'
self.assertEqual(expected_request_instead, request_instead.output_string)
strangler.responses.read(GENEROUS_READ_LENGTH)
strangler.responses.send()
expected_response_instead = b'553 sorry, your envelope sender is in my badmailfrom list (#5.7.1)\r\n'
self.assertEqual(expected_response_instead, response_instead.output_string)
if __name__ == '__main__':
unittest.main()