-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheocTests.py
1124 lines (946 loc) · 43.1 KB
/
eocTests.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import unittest
import shutil
import os
import re
import time
import string
import eoc
DOTDIR = "dot-dir-for-testing"
eoc.DOTDIR = DOTDIR
eoc.quiet = 1
def no_op(*args):
pass
class AddressCleaningTestCases(unittest.TestCase):
def setUp(self):
self.ap = eoc.AddressParser(["[email protected]",
def verify(self, address, wanted, skip_prefix=None, forced_domain=None):
self.ap.set_skip_prefix(skip_prefix)
self.ap.set_forced_domain(forced_domain)
address = self.ap.clean(address)
self.failUnlessEqual(address, wanted)
def testSimpleAddress(self):
self.verify("[email protected]", "[email protected]")
def testUpperCaseAddress(self):
self.verify("[email protected]", "[email protected]")
def testPrefixRemoval(self):
self.verify("[email protected]", "[email protected]",
skip_prefix="user-")
self.verify("[email protected]", "[email protected]",
skip_prefix="user-")
def testForcedDomain(self):
self.verify("[email protected]", "[email protected]",
forced_domain="example.com")
self.verify("[email protected]", "[email protected]",
forced_domain="example.com")
def testPrefixRemovalWithForcedDomain(self):
self.verify("[email protected]", "[email protected]",
skip_prefix="user-",
forced_domain="example.com")
self.verify("[email protected]", "[email protected]",
skip_prefix="user-",
forced_domain="example.com")
self.verify("[email protected]", "[email protected]",
skip_prefix="user-",
forced_domain="example.com")
self.verify("[email protected]", "[email protected]",
skip_prefix="user-",
forced_domain="example.com")
class AddressParserTestCases(unittest.TestCase):
def setUp(self):
self.ap = eoc.AddressParser(["[email protected]",
def verify_parser(self, address, wanted_listname, wanted_parts):
listname, parts = self.ap.parse(address)
self.failUnlessEqual(listname, wanted_listname)
self.failUnlessEqual(parts, wanted_parts)
def testParser(self):
self.verify_parser("[email protected]",
[])
self.verify_parser("[email protected]",
["subscribe"])
self.verify_parser("[email protected]",
["subscribe", "joe=example.com"])
self.verify_parser("[email protected]",
["bounce", "123", "abcdef"])
class ParseRecipientAddressBase(unittest.TestCase):
def setUp(self):
self.lists = ["[email protected]",
self.mlm = eoc.MailingListManager(DOTDIR, lists=self.lists)
def environ(self, sender, recipient):
eoc.set_environ({
"SENDER": sender,
"RECIPIENT": recipient,
})
class ParseUnsignedAddressTestCases(ParseRecipientAddressBase):
def testEmpty(self):
self.failUnlessRaises(eoc.UnknownList,
self.mlm.parse_recipient_address,
"", None, None)
def verify(self, address, skip_prefix, forced_domain, wanted_dict):
dict = self.mlm.parse_recipient_address(address, skip_prefix,
forced_domain)
self.failUnlessEqual(dict, wanted_dict)
def testSimpleAddresses(self):
self.verify("[email protected]",
None,
None,
{ "name": "[email protected]", "command": "post" })
self.verify("[email protected]",
None,
None,
{ "name": "[email protected]", "command": "post" })
self.verify("[email protected]",
"prefix-",
None,
{ "name": "[email protected]", "command": "post" })
self.verify("[email protected]",
None,
"lists.example.com",
{ "name": "[email protected]", "command": "post" })
self.verify("[email protected]",
"prefix-",
"lists.example.com",
{ "name": "[email protected]", "command": "post" })
def testSubscription(self):
self.verify("[email protected]",
None,
None,
{ "name": "[email protected]",
"command": "subscribe",
"sender": "",
})
self.verify("[email protected]",
None,
None,
{ "name": "[email protected]",
"command": "subscribe",
"sender": "[email protected]",
})
self.verify("[email protected]",
None,
None,
{ "name": "[email protected]",
"command": "unsubscribe",
"sender": "",
})
self.verify("[email protected]",
None,
None,
{ "name": "[email protected]",
"command": "unsubscribe",
"sender": "[email protected]",
})
def testPost(self):
for name in self.lists:
self.verify(name, None, None, { "name": name, "command": "post" })
def testSimpleCommands(self):
for name in self.lists:
for command in ["help", "list", "owner"]:
localpart, domain = name.split("@")
address = "%s-%s@%s" % (localpart, command, domain)
self.verify(address, None, None,
{ "name": name,
"command": command
})
class ParseWellSignedAddressTestCases(ParseRecipientAddressBase):
def try_good_signature(self, command):
s = "foo-announce-%s-1" % command
hash = self.mlm.compute_hash("%s@%s" % (s, "example.com"))
local_part = "%s-%s" % (s, hash)
dict = self.mlm.parse_recipient_address("%[email protected]" % local_part,
None, None)
self.failUnlessEqual(dict,
{
"name": "[email protected]",
"command": command,
"id": "1",
})
def testProperlySignedCommands(self):
self.try_good_signature("subyes")
self.try_good_signature("subapprove")
self.try_good_signature("subreject")
self.try_good_signature("unsubyes")
self.try_good_signature("bounce")
self.try_good_signature("approve")
self.try_good_signature("reject")
self.try_good_signature("probe")
class ParseBadlySignedAddressTestCases(ParseRecipientAddressBase):
def try_bad_signature(self, command_part):
self.failUnlessRaises(eoc.BadSignature,
self.mlm.parse_recipient_address,
"foo-announce-" + command_part +
None, None)
def testBadlySignedCommands(self):
self.try_bad_signature("subyes")
self.try_bad_signature("subapprove")
self.try_bad_signature("subreject")
self.try_bad_signature("unsubyes")
self.try_bad_signature("bounce")
self.try_bad_signature("approve")
self.try_bad_signature("reject")
self.try_bad_signature("probe")
class DotDirTestCases(unittest.TestCase):
def setUp(self):
self.secret_name = os.path.join(DOTDIR, "secret")
def tearDown(self):
shutil.rmtree(DOTDIR)
def dotdir_is_ok(self):
self.failUnless(os.path.isdir(DOTDIR))
self.failUnless(os.path.isfile(self.secret_name))
def testNoDotDirExists(self):
self.failIf(os.path.exists(DOTDIR))
mlm = eoc.MailingListManager(DOTDIR)
self.dotdir_is_ok()
def testDotDirDoesExistButSecretDoesNot(self):
self.failIf(os.path.exists(DOTDIR))
os.makedirs(DOTDIR)
self.failUnless(os.path.isdir(DOTDIR))
self.failIf(os.path.exists(self.secret_name))
mlm = eoc.MailingListManager(DOTDIR)
self.dotdir_is_ok()
class RemoveSomeHeadersTest(unittest.TestCase):
def testRemoveSomeHeaders(self):
mlm = eoc.MailingListManager(DOTDIR)
ml = eoc.MailingList(mlm, "[email protected]")
mail = """\
Header-1: this is a simple header
Header-2: this
is
a
complex header with a colon: yes it is
Header-3: odd numbered headers are simple
Body.
"""
mail2 = ml.remove_some_headers(mail, ["Header-2"])
self.failUnlessEqual(mail2, """\
Header-1: this is a simple header
Header-3: odd numbered headers are simple
Body.
""")
class ListBase(unittest.TestCase):
def setUp(self):
if os.path.exists(DOTDIR):
shutil.rmtree(DOTDIR)
self.mlm = eoc.MailingListManager(DOTDIR)
def tearDown(self):
self.mlm = None
shutil.rmtree(DOTDIR)
class ListCreationTestCases(ListBase):
def setUp(self):
ListBase.setUp(self)
self.names = None
def listdir(self, listname):
return os.path.join(DOTDIR, listname)
def listdir_has_file(self, listdir, filename):
self.failUnless(os.path.isfile(os.path.join(listdir, filename)))
self.names.remove(filename)
def listdir_has_dir(self, listdir, dirname):
self.failUnless(os.path.isdir(os.path.join(listdir, dirname)))
self.names.remove(dirname)
def listdir_may_have_dir(self, listdir, dirname):
if dirname in self.names:
self.listdir_has_dir(listdir, dirname)
def listdir_is_ok(self, listname):
listdir = self.listdir(listname)
self.failUnless(os.path.isdir(listdir))
self.names = os.listdir(listdir)
self.listdir_has_file(listdir, "config")
self.listdir_has_file(listdir, "subscribers")
self.listdir_has_dir(listdir, "bounce-box")
self.listdir_has_dir(listdir, "subscription-box")
self.listdir_may_have_dir(listdir, "moderation-box")
self.listdir_may_have_dir(listdir, "templates")
# Make sure there are no extras.
self.failUnlessEqual(self.names, [])
def testCreateNew(self):
self.failIf(os.path.exists(self.listdir("[email protected]")))
ml = self.mlm.create_list("[email protected]")
self.failUnlessEqual(ml.__class__, eoc.MailingList)
self.failUnlessEqual(ml.dirname, self.listdir("[email protected]"))
self.listdir_is_ok("[email protected]")
def testCreateExisting(self):
list = self.mlm.create_list("[email protected]")
self.failUnlessRaises(eoc.ListExists,
self.mlm.create_list, "[email protected]")
self.listdir_is_ok("[email protected]")
class ListOptionTestCases(ListBase):
def check(self, ml, wanted):
self.failUnlessEqual(ml.cp.sections(), ["list"])
cpdict = {}
for key, value in ml.cp.items("list"):
cpdict[key] = value
self.failUnlessEqual(cpdict, wanted)
def testDefaultOptionsOnCreateAndOpenExisting(self):
self.mlm.create_list("[email protected]")
ml = self.mlm.open_list("[email protected]")
self.check(ml,
{
"owners": "",
"moderators": "",
"subscription": "free",
"posting": "free",
"archived": "no",
"mail-on-subscription-changes": "no",
"mail-on-forced-unsubscribe": "no",
"ignore-bounce": "no",
"language": "",
"pristine-headers": "",
})
def testChangeOptions(self):
# Create a list, change some options, and save the result.
ml = self.mlm.create_list("[email protected]")
self.failUnlessEqual(ml.cp.get("list", "owners"), "")
self.failUnlessEqual(ml.cp.get("list", "posting"), "free")
ml.cp.set("list", "owners", "[email protected]")
ml.cp.set("list", "posting", "moderated")
ml.save_config()
# Re-open the list and check that the new instance has read the
# values from the disk correctly.
ml2 = self.mlm.open_list("[email protected]")
self.check(ml2,
{
"owners": "[email protected]",
"moderators": "",
"subscription": "free",
"posting": "moderated",
"archived": "no",
"mail-on-subscription-changes": "no",
"mail-on-forced-unsubscribe": "no",
"ignore-bounce": "no",
"language": "",
"pristine-headers": "",
})
class SubscriberDatabaseTestCases(ListBase):
def has_subscribers(self, ml, addrs):
subs = ml.subscribers.get_all()
subs.sort()
self.failUnlessEqual(subs, addrs)
def testAddAndRemoveSubscribers(self):
addrs.sort()
ml = self.mlm.create_list("[email protected]")
self.failUnlessEqual(ml.subscribers.get_all(), [])
self.failUnless(ml.subscribers.lock())
ml.subscribers.add_many(addrs)
self.has_subscribers(ml, addrs)
ml.subscribers.save()
self.failIf(ml.subscribers.locked)
ml = None
ml2 = self.mlm.open_list("[email protected]")
self.has_subscribers(ml2, addrs)
ml2.subscribers.lock()
ml2.subscribers.remove(addrs[0])
self.has_subscribers(ml2, addrs[1:])
ml2.subscribers.save()
ml3 = self.mlm.open_list("[email protected]")
self.has_subscribers(ml3, addrs[1:])
def testSubscribeTwice(self):
ml = self.mlm.create_list("[email protected]")
self.failUnlessEqual(ml.subscribers.get_all(), [])
ml.subscribers.lock()
ml.subscribers.add("[email protected]")
ml.subscribers.add("[email protected]")
self.failUnlessEqual(map(string.lower, ml.subscribers.get_all()),
map(string.lower, ["[email protected]"]))
def testSubscriberAttributesAndGroups(self):
addrs = ["[email protected]", "[email protected]"]
addrs.sort()
ml = self.mlm.create_list("[email protected]")
self.failUnlessEqual(ml.subscribers.groups(), [])
ml.subscribers.lock()
id = ml.subscribers.add_many(addrs)
self.failUnlessEqual(ml.subscribers.groups(), ["0"])
self.failUnlessEqual(ml.subscribers.get(id, "status"), "ok")
ml.subscribers.set(id, "status", "bounced")
self.failUnlessEqual(ml.subscribers.get(id, "status"), "bounced")
subs = ml.subscribers.in_group(id)
subs.sort()
self.failUnlessEqual(subs, addrs)
class ModerationBoxTestCases(ListBase):
def testModerationBox(self):
ml = self.mlm.create_list("[email protected]")
listdir = os.path.join(DOTDIR, "[email protected]")
boxdir = os.path.join(listdir, "moderation-box")
self.failUnlessEqual(boxdir, ml.moderation_box.boxdir)
self.failUnless(os.path.isdir(boxdir))
mailtext = "From: foo\nTo: bar\n\nhello\n"
id = ml.moderation_box.add("foo", mailtext)
self.failUnless(ml.moderation_box.has(id))
self.failUnlessEqual(ml.moderation_box.get_address(id), "foo")
self.failUnlessEqual(ml.moderation_box.get(id), mailtext)
filename = os.path.join(boxdir, id)
self.failUnless(os.path.isfile(filename))
self.failUnless(os.path.isfile(filename + ".address"))
ml.moderation_box.remove(id)
self.failIf(ml.moderation_box.has(id))
self.failUnless(not os.path.exists(filename))
class IncomingBase(unittest.TestCase):
def setUp(self):
if os.path.isdir(DOTDIR):
shutil.rmtree(DOTDIR)
self.mlm = eoc.MailingListManager(DOTDIR)
self.ml = None
ml = self.mlm.create_list("[email protected]")
ml.cp.set("list", "owners", "[email protected]")
ml.save_config()
ml.subscribers.lock()
ml.subscribers.add("[email protected]")
ml.subscribers.add("[email protected]")
ml.subscribers.save()
self.write_file_in_listdir(ml, "headers-to-add", "X-Foo: foo\n")
self.write_file_in_listdir(ml, "headers-to-remove", "Received\n")
self.sent_mail = []
def tearDown(self):
shutil.rmtree(DOTDIR)
def write_file_in_listdir(self, ml, basename, contents):
f = open(os.path.join(ml.dirname, basename), "w")
f.write(contents)
f.close()
def configure_list(self, subscription, posting):
list = self.mlm.open_list("[email protected]")
list.cp.set("list", "subscription", subscription)
list.cp.set("list", "posting", posting)
list.save_config()
def environ(self, sender, recipient):
eoc.set_environ({
"SENDER": sender,
"RECIPIENT": recipient,
})
def catch_sendmail(self, sender, recipients, text):
self.sent_mail.append({
"sender": sender,
"recipients": recipients,
"text": text,
})
def send(self, sender, recipient, text="", force_moderation=0,
force_posting=0):
self.environ(sender, recipient)
dict = self.mlm.parse_recipient_address(recipient, None, None)
dict["force-moderation"] = force_moderation
dict["force-posting"] = force_posting
self.ml = self.mlm.open_list(dict["name"])
if "\n\n" not in text:
text = "\n\n" + text
text = "Received: foobar\n" + text
self.ml.read_stdin = lambda t=text: t
self.mlm.send_mail = self.catch_sendmail
self.sent_mail = []
self.ml.obey(dict)
def sender_matches(self, mail, sender):
pat = "(?P<address>" + sender + ")"
m = re.match(pat, mail["sender"], re.I)
if m:
return m.group("address")
else:
return None
def replyto_matches(self, mail, replyto):
pat = "(.|\n)*(?P<address>" + replyto + ")"
m = re.match(pat, mail["text"], re.I)
if m:
return m.group("address")
else:
return None
def receiver_matches(self, mail, recipient):
return map(string.lower, mail["recipients"]) == [recipient.lower()]
def body_matches(self, mail, body):
if body:
pat = re.compile("(.|\n)*" + body + "(.|\n)*")
m = re.match(pat, mail["text"])
return m
else:
return 1
def headers_match(self, mail, header):
if header:
pat = re.compile("(.|\n)*" + header + "(.|\n)*", re.I)
m = re.match(pat, mail["text"])
return m
else:
return 1
def match(self, sender, replyto, receiver, body=None, header=None,
anti_header=None):
ret = None
for mail in self.sent_mail:
if replyto is None:
m1 = self.sender_matches(mail, sender)
m3 = self.receiver_matches(mail, receiver)
m4 = self.body_matches(mail, body)
m5 = self.headers_match(mail, header)
m6 = self.headers_match(mail, anti_header)
no_anti_header = anti_header == None or m6 == None
if m1 != None and m3 and m4 and m5 and no_anti_header:
ret = m1
self.sent_mail.remove(mail)
break
else:
m1 = self.sender_matches(mail, sender)
m2 = self.replyto_matches(mail, replyto)
m3 = self.receiver_matches(mail, receiver)
m4 = self.body_matches(mail, body)
m5 = self.headers_match(mail, header)
m6 = self.headers_match(mail, anti_header)
no_anti_header = anti_header == None or m6 == None
if m1 != None and m2 != None and m3 and m4 and m5 and \
no_anti_header:
ret = m2
self.sent_mail.remove(mail)
break
self.failUnless(ret != None)
return ret
def no_more_mail(self):
self.failUnlessEqual(self.sent_mail, [])
class SimpleCommandAddressTestCases(IncomingBase):
def testHelp(self):
self.send("[email protected]", "[email protected]")
self.match("[email protected]", None, "[email protected]",
"Subject: Help for")
self.no_more_mail()
def testOwner(self):
self.send("[email protected]", "[email protected]", "abcde")
self.match("[email protected]", None, "[email protected]",
"abcde")
self.no_more_mail()
def testIgnore(self):
self.send("[email protected]", "[email protected]", "abcde")
self.no_more_mail()
class OwnerCommandTestCases(IncomingBase):
def testList(self):
self.send("[email protected]", "[email protected]")
self.match("[email protected]", None, "[email protected]",
"[uU][sS][eE][rR][12]@" +
"[eE][xX][aA][mM][pP][lL][eE]\\.[cC][oO][mM]\n" +
"[uU][sS][eE][rR][12]@" +
"[eE][xX][aA][mM][pP][lL][eE]\\.[cC][oO][mM]\n")
self.no_more_mail()
def testListDenied(self):
self.send("[email protected]", "[email protected]")
self.match("[email protected]", None, "[email protected]",
"Subject: Subscriber list denied")
self.no_more_mail()
def testSetlist(self):
self.send("[email protected]", "[email protected]",
"From: foo\n\[email protected]\[email protected]\n")
a = self.match("[email protected]",
"foo-setlistyes-[^@]*@example.com",
"Subject: Please moderate subscriber list")
self.no_more_mail()
self.send("[email protected]", a)
self.match("[email protected]", None, "[email protected]",
"Subject: Subscriber list has been changed")
self.match("[email protected]", None, "[email protected]",
"Subject: Welcome to")
self.match("[email protected]", None, "[email protected]",
"Subject: Goodbye from")
self.no_more_mail()
def testSetlistSilently(self):
self.send("[email protected]", "[email protected]",
"From: foo\n\[email protected]\[email protected]\n")
a = self.match("[email protected]",
"foo-setlistsilentyes-[^@]*@example.com",
"Subject: Please moderate subscriber list")
self.no_more_mail()
self.send("[email protected]", a)
self.match("[email protected]", None, "[email protected]",
"Subject: Subscriber list has been changed")
self.no_more_mail()
def testSetlistDenied(self):
self.send("[email protected]", "[email protected]",
"From: foo\n\[email protected]\[email protected]\n")
self.match("[email protected]",
None,
"Subject: You can't set the subscriber list")
self.no_more_mail()
def testSetlistBadlist(self):
self.send("[email protected]", "[email protected]",
"From: foo\n\nBlah blah blah.\n")
self.match("[email protected]",
None,
"Subject: Bad address list")
self.no_more_mail()
def testOwnerSubscribesSomeoneElse(self):
# Send subscription request. List sends confirmation request.
self.send("[email protected]",
a = self.match("[email protected]",
"foo-subyes-[^@]*@example.com",
"Please confirm subscription")
self.no_more_mail()
# Confirm sub. req. List sends welcome.
self.send("[email protected]", a)
self.match("[email protected]",
None,
"Welcome to the")
self.no_more_mail()
def testOwnerUnubscribesSomeoneElse(self):
# Send unsubscription request. List sends confirmation request.
self.send("[email protected]",
a = self.match("[email protected]",
"foo-unsubyes-[^@]*@example.com",
"Subject: Please confirm UNsubscription")
self.no_more_mail()
# Confirm sub. req. List sends welcome.
self.send("[email protected]", a)
self.match("[email protected]", None, "[email protected]",
"Goodbye")
self.no_more_mail()
class SubscriptionTestCases(IncomingBase):
def confirm(self, recipient):
# List has sent confirmation request. Respond to it.
a = self.match("[email protected]",
"foo-subyes-[^@]*@example.com",
recipient,
"Please confirm subscription")
self.no_more_mail()
# Confirm sub. req. List response will be analyzed later.
self.send("[email protected]", a)
def got_welcome(self, recipient):
self.match("[email protected]",
None,
recipient,
"Welcome to the")
self.no_more_mail()
def approve(self, user_recipient):
self.match("[email protected]", None, user_recipient)
a = self.match("[email protected]",
"foo-subapprove-[^@]*@example.com",
self.send("[email protected]", a)
def reject(self, user_recipient):
self.match("[email protected]", None, user_recipient)
a = self.match("[email protected]",
"foo-subreject-[^@]*@example.com",
self.send("[email protected]", a)
def testSubscribeToUnmoderatedWithoutAddressNotOnList(self):
self.configure_list("free", "free")
self.send("[email protected]", "[email protected]")
self.confirm("[email protected]")
self.got_welcome("[email protected]")
def testSubscribeToUnmoderatedWithoutAddressAlreadyOnList(self):
self.configure_list("free", "free")
self.send("[email protected]", "[email protected]")
self.confirm("[email protected]")
self.got_welcome("[email protected]")
def testSubscribeToUnmoderatedWithAddressNotOnList(self):
self.configure_list("free", "free")
self.send("[email protected]",
self.confirm("[email protected]")
self.got_welcome("[email protected]")
def testSubscribeToUnmoderatedWithAddressAlreadyOnList(self):
self.configure_list("free", "free")
self.send("[email protected]",
self.confirm("[email protected]")
self.got_welcome("[email protected]")
def testSubscribeToModeratedWithoutAddressNotOnListApproved(self):
self.configure_list("moderated", "moderated")
self.send("[email protected]", "[email protected]")
self.confirm("[email protected]")
self.approve("[email protected]")
self.got_welcome("[email protected]")
def testSubscribeToModeratedWithoutAddressNotOnListRejected(self):
self.configure_list("moderated", "moderated")
self.send("[email protected]", "[email protected]")
self.confirm("[email protected]")
self.reject("[email protected]")
def testSubscribeToModeratedWithoutAddressAlreadyOnListApproved(self):
self.configure_list("moderated", "moderated")
self.send("[email protected]", "[email protected]")
self.confirm("[email protected]")
self.approve("[email protected]")
self.got_welcome("[email protected]")
def testSubscribeToModeratedWithoutAddressAlreadyOnListRejected(self):
self.configure_list("moderated", "moderated")
self.send("[email protected]", "[email protected]")
self.confirm("[email protected]")
self.reject("[email protected]")
def testSubscribeToModeratedWithAddressNotOnListApproved(self):
self.configure_list("moderated", "moderated")
self.send("[email protected]",
self.confirm("[email protected]")
self.approve("[email protected]")
self.got_welcome("[email protected]")
def testSubscribeToModeratedWithAddressNotOnListRejected(self):
self.configure_list("moderated", "moderated")
self.send("[email protected]",
self.confirm("[email protected]")
self.reject("[email protected]")
def testSubscribeToModeratedWithAddressAlreadyOnListApproved(self):
self.configure_list("moderated", "moderated")
self.send("[email protected]",
self.confirm("[email protected]")
self.approve("[email protected]")
self.got_welcome("[email protected]")
def testSubscribeToModeratedWithAddressAlreadyOnListRejected(self):
self.configure_list("moderated", "moderated")
self.send("[email protected]",
self.confirm("[email protected]")
self.reject("[email protected]")
class UnsubscriptionTestCases(IncomingBase):
def confirm(self, recipient):
# List has sent confirmation request. Respond to it.
a = self.match("[email protected]",
"foo-unsubyes-[^@]*@example.com",
recipient,
"Please confirm UNsubscription")
self.no_more_mail()
# Confirm sub. req. List response will be analyzed later.
self.send("[email protected]", a)
def got_goodbye(self, recipient):
self.match("[email protected]",
None,
recipient,
"Goodbye from")
self.no_more_mail()
def testUnsubscribeWithoutAddressNotOnList(self):
self.send("[email protected]", "[email protected]")
self.confirm("[email protected]")
self.got_goodbye("[email protected]")
def testUnsubscribeWithoutAddressOnList(self):
self.send("[email protected]", "[email protected]")
self.confirm("[email protected]")
self.got_goodbye("[email protected]")
def testUnsubscribeWithAddressNotOnList(self):
self.send("[email protected]",
self.confirm("[email protected]")
self.got_goodbye("[email protected]")
def testUnsubscribeWithAddressOnList(self):
self.send("[email protected]",
self.confirm("[email protected]")
self.got_goodbye("[email protected]")
class PostTestCases(IncomingBase):
msg = u"Subject: something \u00c4\n\nhello, world\n".encode("utf8")
def approve(self, user_recipient):
self.match("[email protected]", None, user_recipient)
a = self.match("[email protected]",
"foo-approve-[^@]*@example.com",
self.send("[email protected]", a)
def reject(self, user_recipient):
self.match("[email protected]", None, user_recipient)
a = self.match("[email protected]",
"foo-reject-[^@]*@example.com",
self.send("[email protected]", a)
def check_headers_are_encoded(self):
ok_chars = "\t\r\n"
for code in range(32, 127):
ok_chars = ok_chars + chr(code)
for mail in self.sent_mail:
text = mail["text"]
self.failUnless("\n\n" in text)
headers = text.split("\n\n")[0]
for c in headers:
if c not in ok_chars: print headers
self.failUnless(c in ok_chars)
def check_mail_to_list(self):
self.check_headers_are_encoded()
self.match("foo-bounce-.*@example.com", None, "[email protected]",
body="hello, world",
header="X-Foo: FOO",
anti_header="Received:")
self.match("foo-bounce-.*@example.com", None, "[email protected]",
body="hello, world",
header="x-foo: foo",
anti_header="Received:")
self.no_more_mail()
def check_that_moderation_box_is_empty(self):
ml = self.mlm.open_list("[email protected]")
self.failUnlessEqual(os.listdir(ml.moderation_box.boxdir), [])
def testSubscriberPostsToUnmoderated(self):
self.configure_list("free", "free")
self.send("[email protected]", "[email protected]",
self.msg)
self.check_mail_to_list()
def testOutsiderPostsToUnmoderated(self):
self.configure_list("free", "free")
self.send("[email protected]", "[email protected]", self.msg)
self.check_mail_to_list()
def testSubscriberPostToAutomoderated(self):
self.configure_list("free", "auto")
self.check_that_moderation_box_is_empty()
self.send("[email protected]", "[email protected]", self.msg)
self.check_mail_to_list()
self.check_that_moderation_box_is_empty()
def testOutsiderPostsToAutomoderatedRejected(self):
self.configure_list("free", "auto")
self.check_that_moderation_box_is_empty()
self.send("[email protected]", "[email protected]", self.msg)
self.reject("[email protected]")
self.check_that_moderation_box_is_empty()
def testOutsiderPostsToAutomoderatedApproved(self):
self.configure_list("free", "auto")
self.check_that_moderation_box_is_empty()
self.send("[email protected]", "[email protected]", self.msg)
self.approve("[email protected]")
self.check_mail_to_list()
self.check_that_moderation_box_is_empty()
def testSubscriberPostsToModeratedRejected(self):
self.configure_list("free", "moderated")
self.check_that_moderation_box_is_empty()
self.send("[email protected]", "[email protected]", self.msg)
self.reject("[email protected]")
self.check_that_moderation_box_is_empty()
def testOutsiderPostsToMderatedApproved(self):
self.configure_list("free", "moderated")
self.check_that_moderation_box_is_empty()
self.send("[email protected]", "[email protected]", self.msg)
self.approve("[email protected]")
self.check_mail_to_list()
self.check_that_moderation_box_is_empty()
def testSubscriberPostsWithRequestToBeModerated(self):
self.configure_list("free", "free")
self.check_that_moderation_box_is_empty()
self.send("[email protected]", "[email protected]", self.msg,
force_moderation=1)
self.match("[email protected]",
None,
"Subject: Please wait")
a = self.match("[email protected]",
"foo-approve-[^@]*@example.com",
self.no_more_mail()
self.send("[email protected]", a)
self.check_mail_to_list()
self.check_that_moderation_box_is_empty()
def testSubscriberPostsWithModerationOverride(self):
self.configure_list("moderated", "moderated")
self.send("[email protected]", "[email protected]", self.msg,
force_posting=1)
self.check_mail_to_list()
self.check_that_moderation_box_is_empty()
class BounceTestCases(IncomingBase):
def check_subscriber_status(self, must_be):
ml = self.mlm.open_list("[email protected]")
for id in ml.subscribers.groups():
self.failUnlessEqual(ml.subscribers.get(id, "status"), must_be)