44
50
self._mlist = create_list('test@example.com')
51
scheme = lookup(config.passwords.password_scheme.upper())
52
self._mlist.moderator_password = make_secret('super secret', scheme)
53
self._rule = approved.Approved()
55
From: anne@example.com
57
Subject: A Message with non-ascii body
64
def test_approved_header(self):
65
self._msg['Approved'] = 'super secret'
66
result = self._rule.check(self._mlist, self._msg, {})
67
self.assertTrue(result)
69
def test_approve_header(self):
70
self._msg['Approve'] = 'super secret'
71
result = self._rule.check(self._mlist, self._msg, {})
72
self.assertTrue(result)
74
def test_x_approved_header(self):
75
self._msg['X-Approved'] = 'super secret'
76
result = self._rule.check(self._mlist, self._msg, {})
77
self.assertTrue(result)
79
def test_x_approve_header(self):
80
self._msg['X-Approve'] = 'super secret'
81
result = self._rule.check(self._mlist, self._msg, {})
82
self.assertTrue(result)
84
def test_approved_header_wrong_password(self):
85
self._msg['Approved'] = 'not the password'
86
result = self._rule.check(self._mlist, self._msg, {})
87
self.assertFalse(result)
89
def test_approve_header_wrong_password(self):
90
self._msg['Approve'] = 'not the password'
91
result = self._rule.check(self._mlist, self._msg, {})
92
self.assertFalse(result)
94
def test_x_approved_header_wrong_password(self):
95
self._msg['X-Approved'] = 'not the password'
96
result = self._rule.check(self._mlist, self._msg, {})
97
self.assertFalse(result)
99
def test_x_approve_header_wrong_password(self):
100
self._msg['X-Approve'] = 'not the password'
101
result = self._rule.check(self._mlist, self._msg, {})
102
self.assertFalse(result)
104
def test_removes_approved_header(self):
105
self._msg['Approved'] = 'super secret'
106
self._rule.check(self._mlist, self._msg, {})
107
self.assertEqual(self._msg['approved'], None)
109
def test_removes_approve_header(self):
110
self._msg['Approve'] = 'super secret'
111
self._rule.check(self._mlist, self._msg, {})
112
self.assertEqual(self._msg['approve'], None)
114
def test_removes_x_approved_header(self):
115
self._msg['X-Approved'] = 'super secret'
116
self._rule.check(self._mlist, self._msg, {})
117
self.assertEqual(self._msg['x-approved'], None)
119
def test_removes_x_approve_header(self):
120
self._msg['X-Approve'] = 'super secret'
121
self._rule.check(self._mlist, self._msg, {})
122
self.assertEqual(self._msg['x-approve'], None)
124
def test_removes_approved_header_wrong_password(self):
125
self._msg['Approved'] = 'not the password'
126
self._rule.check(self._mlist, self._msg, {})
127
self.assertEqual(self._msg['approved'], None)
129
def test_removes_approve_header_wrong_password(self):
130
self._msg['Approve'] = 'not the password'
131
self._rule.check(self._mlist, self._msg, {})
132
self.assertEqual(self._msg['approve'], None)
134
def test_removes_x_approved_header_wrong_password(self):
135
self._msg['X-Approved'] = 'not the password'
136
self._rule.check(self._mlist, self._msg, {})
137
self.assertEqual(self._msg['x-approved'], None)
139
def test_removes_x_approve_header_wrong_password(self):
140
self._msg['X-Approve'] = 'not the password'
141
self._rule.check(self._mlist, self._msg, {})
142
self.assertEqual(self._msg['x-approve'], None)
146
class TestApprovedPseudoHeader(unittest.TestCase):
147
"""Test the approved handler."""
152
self._mlist = create_list('test@example.com')
153
scheme = lookup(config.passwords.password_scheme.upper())
154
self._mlist.moderator_password = make_secret('super secret', scheme)
155
self._rule = approved.Approved()
157
From: anne@example.com
159
Subject: A Message with non-ascii body
165
def test_approved_pseudo_header(self):
166
self._msg.set_payload("""\
167
Approved: super secret
169
result = self._rule.check(self._mlist, self._msg, {})
170
self.assertTrue(result)
172
def test_approve_pseudo_header(self):
173
self._msg.set_payload("""\
174
Approve: super secret
176
result = self._rule.check(self._mlist, self._msg, {})
177
self.assertTrue(result)
179
def test_x_approved_pseudo_header(self):
180
self._msg.set_payload("""\
181
X-Approved: super secret
183
result = self._rule.check(self._mlist, self._msg, {})
184
self.assertTrue(result)
186
def test_x_approve_pseudo_header(self):
187
self._msg.set_payload("""\
188
X-Approve: super secret
190
result = self._rule.check(self._mlist, self._msg, {})
191
self.assertTrue(result)
193
def test_approved_pseudo_header_wrong_password(self):
194
self._msg.set_payload("""\
195
Approved: not the password
197
result = self._rule.check(self._mlist, self._msg, {})
198
self.assertFalse(result)
200
def test_approve_pseudo_header_wrong_password(self):
201
self._msg.set_payload("""\
202
Approve: not the password
204
result = self._rule.check(self._mlist, self._msg, {})
205
self.assertFalse(result)
207
def test_x_approved_pseudo_header_wrong_password(self):
208
self._msg.set_payload("""\
209
X-Approved: not the password
211
result = self._rule.check(self._mlist, self._msg, {})
212
self.assertFalse(result)
214
def test_x_approve_pseudo_header_wrong_password(self):
215
self._msg.set_payload("""\
216
X-Approve: not the password
218
result = self._rule.check(self._mlist, self._msg, {})
219
self.assertFalse(result)
221
def test_removes_approved_pseudo_header(self):
222
self._msg.set_payload("""\
223
Approved: super secret
225
self._rule.check(self._mlist, self._msg, {})
226
self.assertFalse('Approved' in self._msg.get_payload())
228
def test_removes_approve_pseudo_header(self):
229
self._msg.set_payload("""\
230
Approve: super secret
232
self._rule.check(self._mlist, self._msg, {})
233
self.assertFalse('Approve' in self._msg.get_payload())
235
def test_removes_x_approved_pseudo_header(self):
236
self._msg.set_payload("""\
237
X-Approved: super secret
239
self._rule.check(self._mlist, self._msg, {})
240
self.assertFalse('X-Approved' in self._msg.get_payload())
242
def test_removes_x_approve_pseudo_header(self):
243
self._msg.set_payload("""\
244
X-Approve: super secret
246
self._rule.check(self._mlist, self._msg, {})
247
self.assertFalse('X-Approve' in self._msg.get_payload())
249
def test_removes_approved_pseudo_header_wrong_password(self):
250
self._msg.set_payload("""\
251
Approved: not the password
253
self._rule.check(self._mlist, self._msg, {})
254
self.assertFalse('Approved' in self._msg.get_payload())
256
def test_removes_approve_pseudo_header_wrong_password(self):
257
self._msg.set_payload("""\
258
Approve: not the password
260
self._rule.check(self._mlist, self._msg, {})
261
self.assertFalse('Approve' in self._msg.get_payload())
263
def test_removes_x_approved_pseudo_header_wrong_password(self):
264
self._msg.set_payload("""\
265
X-Approved: not the password
267
self._rule.check(self._mlist, self._msg, {})
268
self.assertFalse('X-Approved' in self._msg.get_payload())
270
def test_removes_x_approve_pseudo_header_wrong_password(self):
271
self._msg.set_payload("""\
272
X-Approve: not the password
274
self._rule.check(self._mlist, self._msg, {})
275
self.assertFalse('X-Approve' in self._msg.get_payload())
279
class TestApprovedPseudoHeaderMIME(unittest.TestCase):
280
"""Test the approved handler."""
285
self._mlist = create_list('test@example.com')
286
scheme = lookup(config.passwords.password_scheme.upper())
287
self._mlist.moderator_password = make_secret('super secret', scheme)
288
self._rule = approved.Approved()
289
self._msg_text_template = """\
290
From: anne@example.com
292
Subject: A Message with non-ascii body
295
Content-Type: multipart/mixed; boundary="AAA"
298
Content-Type: application/x-ignore
300
{0}: not the password
301
The above line will be ignored.
304
Content-Type: text/plain
307
An important message.
311
def test_approved_pseudo_header_mime(self):
312
msg = mfs(self._msg_text_template.format('Approved', 'super secret'))
313
result = self._rule.check(self._mlist, msg, {})
314
self.assertTrue(result)
316
def test_approve_pseudo_header_mime(self):
317
msg = mfs(self._msg_text_template.format('Approve', 'super secret'))
318
result = self._rule.check(self._mlist, msg, {})
319
self.assertTrue(result)
321
def test_x_approved_pseudo_header_mime(self):
322
msg = mfs(self._msg_text_template.format('X-Approved', 'super secret'))
323
result = self._rule.check(self._mlist, msg, {})
324
self.assertTrue(result)
326
def test_x_approve_pseudo_header_mime(self):
327
msg = mfs(self._msg_text_template.format('X-Approve', 'super secret'))
328
result = self._rule.check(self._mlist, msg, {})
329
self.assertTrue(result)
331
def test_approved_pseudo_header_wrong_password_mime(self):
332
msg = mfs(self._msg_text_template.format('Approved', 'not password'))
333
result = self._rule.check(self._mlist, msg, {})
334
self.assertFalse(result)
336
def test_approve_pseudo_header_wrong_password_mime(self):
337
msg = mfs(self._msg_text_template.format('Approve', 'not password'))
338
result = self._rule.check(self._mlist, msg, {})
339
self.assertFalse(result)
341
def test_x_approved_pseudo_header_wrong_password_mime(self):
342
msg = mfs(self._msg_text_template.format('X-Approved', 'not password'))
343
result = self._rule.check(self._mlist, msg, {})
344
self.assertFalse(result)
346
def test_x_approve_pseudo_header_wrong_password_mime(self):
347
msg = mfs(self._msg_text_template.format('X-Approve', 'not password'))
348
result = self._rule.check(self._mlist, msg, {})
349
self.assertFalse(result)
351
def test_removes_approved_pseudo_header_mime(self):
352
msg = mfs(self._msg_text_template.format('Approved', 'super secret'))
353
self._rule.check(self._mlist, msg, {})
354
self.assertFalse('Approved' in msg.get_payload(1).get_payload())
356
def test_removes_approve_pseudo_header_mime(self):
357
msg = mfs(self._msg_text_template.format('Approve', 'super secret'))
358
self._rule.check(self._mlist, msg, {})
359
self.assertFalse('Approve' in msg.get_payload(1).get_payload())
361
def test_removes_x_approved_pseudo_header_mime(self):
362
msg = mfs(self._msg_text_template.format('X-Approved', 'super secret'))
363
self._rule.check(self._mlist, msg, {})
364
self.assertFalse('X-Approved' in msg.get_payload(1).get_payload())
366
def test_removes_x_approve_pseudo_header_mime(self):
367
msg = mfs(self._msg_text_template.format('X-Approve', 'super secret'))
368
self._rule.check(self._mlist, msg, {})
369
self.assertFalse('X-Approve' in msg.get_payload(1).get_payload())
371
def test_removes_approved_pseudo_header_wrong_password_mime(self):
372
msg = mfs(self._msg_text_template.format('Approved', 'not password'))
373
self._rule.check(self._mlist, msg, {})
374
self.assertFalse('Approved' in msg.get_payload(1).get_payload())
376
def test_removes_approve_pseudo_header_wrong_password_mime(self):
377
msg = mfs(self._msg_text_template.format('Approve', 'not password'))
378
self._rule.check(self._mlist, msg, {})
379
self.assertFalse('Approve' in msg.get_payload(1).get_payload())
381
def test_removes_x_approved_pseudo_header_wrong_password_mime(self):
382
msg = mfs(self._msg_text_template.format('X-Approved', 'not password'))
383
self._rule.check(self._mlist, msg, {})
384
self.assertFalse('X-Approved' in msg.get_payload(1).get_payload())
386
def test_removes_x_approve_pseudo_header_wrong_password_mime(self):
387
msg = mfs(self._msg_text_template.format('X-Approve', 'not password'))
388
self._rule.check(self._mlist, msg, {})
389
self.assertFalse('X-Approve' in msg.get_payload(1).get_payload())
393
class TestApprovedNonASCII(unittest.TestCase):
394
"""Test the approved handler with non-ascii messages."""
399
self._mlist = create_list('test@example.com')
45
400
self._rule = approved.Approved()
46
401
self._msg = mfs("""\
47
402
From: anne@example.com