-
Notifications
You must be signed in to change notification settings - Fork 70
/
spf_welcome_block.t
executable file
·511 lines (397 loc) · 12.6 KB
/
spf_welcome_block.t
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
#!/usr/bin/perl -T
use lib '.'; use lib 't';
use SATest; sa_t_init("spf_welcome_block");
use Test::More;
use constant HAS_MAILSPF => eval { require Mail::SPF; };
plan skip_all => "Long running tests disabled" unless conf_bool('run_long_tests');
plan skip_all => "Net tests disabled" unless conf_bool('run_net_tests');
plan skip_all => "Need Mail::SPF" unless HAS_MAILSPF;
plan skip_all => "Can't use Net::DNS Safely" unless can_use_net_dns_safely();
plan tests => 72;
# ---------------------------------------------------------------------------
# ensure all rules will fire
tstlocalrules ("
header SPF_PASS eval:check_for_spf_pass()
header SPF_NEUTRAL eval:check_for_spf_neutral()
header SPF_FAIL eval:check_for_spf_fail()
header SPF_SOFTFAIL eval:check_for_spf_softfail()
header SPF_HELO_PASS eval:check_for_spf_helo_pass()
header SPF_HELO_NEUTRAL eval:check_for_spf_helo_neutral()
header SPF_HELO_FAIL eval:check_for_spf_helo_fail()
header SPF_HELO_SOFTFAIL eval:check_for_spf_helo_softfail()
tflags SPF_PASS nice userconf net
tflags SPF_HELO_PASS nice userconf net
tflags SPF_NEUTRAL net
tflags SPF_FAIL net
tflags SPF_SOFTFAIL net
tflags SPF_HELO_NEUTRAL net
tflags SPF_HELO_FAIL net
tflags SPF_HELO_SOFTFAIL net
header USER_IN_SPF_WELCOMELIST eval:check_for_spf_welcomelist_from()
tflags USER_IN_SPF_WELCOMELIST userconf nice noautolearn net
header USER_IN_DEF_SPF_WL eval:check_for_def_spf_welcomelist_from()
tflags USER_IN_DEF_SPF_WL userconf nice noautolearn net
meta USER_IN_SPF_WHITELIST (USER_IN_SPF_WELCOMELIST)
tflags USER_IN_SPF_WHITELIST userconf nice noautolearn net
score SPF_FAIL 0.001
score SPF_HELO_FAIL 0.001
score SPF_HELO_NEUTRAL 0.001
score SPF_HELO_SOFTFAIL 0.001
score SPF_NEUTRAL 0.001
score SPF_SOFTFAIL 0.001
score SPF_PASS -0.001
score SPF_HELO_PASS -0.001
score USER_IN_DEF_SPF_WL -0.001
score USER_IN_SPF_WELCOMELIST -0.001
");
%patterns = (
q{ SPF_HELO_PASS }, 'helo_pass',
q{ SPF_PASS }, 'pass',
);
sarun ("-t < data/nice/spf1", \&patterns_run_cb);
ok_all_patterns();
%patterns = (
q{ SPF_NEUTRAL }, 'neutral',
q{ SPF_HELO_NEUTRAL }, 'helo_neutral',
);
sarun ("-t < data/spam/spf1", \&patterns_run_cb);
ok_all_patterns();
%patterns = (
q{ SPF_SOFTFAIL }, 'softfail',
q{ SPF_HELO_SOFTFAIL }, 'helo_softfail',
);
sarun ("-t < data/spam/spf2", \&patterns_run_cb);
ok_all_patterns();
%patterns = (
q{ SPF_FAIL }, 'fail',
q{ SPF_HELO_FAIL }, 'helo_fail',
);
sarun ("-t < data/spam/spf3", \&patterns_run_cb);
ok_all_patterns();
# Test using an assortment of trusted and internal network definitions
# 9-10: Trusted networks contain first header.
tstprefs("
clear_trusted_networks
clear_internal_networks
trusted_networks 65.214.43.157
always_trust_envelope_sender 1
");
%patterns = (
q{ SPF_HELO_PASS }, 'helo_pass',
q{ SPF_PASS }, 'pass',
);
sarun ("-t < data/nice/spf2", \&patterns_run_cb);
ok_all_patterns();
# 11-12: Internal networks contain first header.
# Trusted networks not defined.
tstprefs("
clear_trusted_networks
clear_internal_networks
internal_networks 65.214.43.157
always_trust_envelope_sender 1
");
%patterns = (
q{ SPF_HELO_PASS }, 'helo_pass',
q{ SPF_PASS }, 'pass',
);
sarun ("-t < data/nice/spf2", \&patterns_run_cb);
ok_all_patterns();
# 13-14: Internal networks contain first header.
# Trusted networks contain some other IP.
# jm: commented; this is now an error condition.
tstprefs("
clear_trusted_networks
clear_internal_networks
trusted_networks 1.2.3.4
internal_networks 65.214.43.157
always_trust_envelope_sender 1
");
%patterns = (
q{ SPF_HELO_NEUTRAL }, 'helo_neutral',
q{ SPF_NEUTRAL }, 'neutral',
);
if (0) {
sarun ("-t < data/nice/spf2", \&patterns_run_cb);
ok_all_patterns();
} else {
ok(1); # skip the tests
ok(1);
}
# 15-16: Trusted+Internal networks contain first header.
tstprefs("
clear_trusted_networks
clear_internal_networks
trusted_networks 65.214.43.157
internal_networks 65.214.43.157
always_trust_envelope_sender 1
");
%patterns = (
q{ SPF_HELO_PASS }, 'helo_pass',
q{ SPF_PASS }, 'pass',
);
sarun ("-t < data/nice/spf2", \&patterns_run_cb);
ok_all_patterns();
# 17-18: Trusted networks contain first and second header.
# Internal networks contain first header.
tstprefs("
clear_trusted_networks
clear_internal_networks
trusted_networks 65.214.43.157 64.142.3.173
internal_networks 65.214.43.157
always_trust_envelope_sender 1
");
%patterns = (
q{ SPF_HELO_PASS }, 'helo_pass',
q{ SPF_PASS }, 'pass',
);
sarun ("-t < data/nice/spf2", \&patterns_run_cb);
ok_all_patterns();
# 19-26: Trusted networks contain first and second header.
# Internal networks contain first and second header.
tstprefs("
clear_trusted_networks
clear_internal_networks
trusted_networks 65.214.43.157 64.142.3.173
internal_networks 65.214.43.157 64.142.3.173
always_trust_envelope_sender 1
");
%anti_patterns = (
q{ SPF_HELO_PASS }, 'helo_pass',
q{ SPF_HELO_FAIL }, 'helo_fail',
q{ SPF_HELO_SOFTFAIL }, 'helo_softfail',
q{ SPF_HELO_NEUTRAL }, 'helo_neutral',
q{ SPF_PASS }, 'pass',
q{ SPF_FAIL }, 'fail',
q{ SPF_SOFTFAIL }, 'softfail',
q{ SPF_NEUTRAL }, 'neutral',
);
%patterns = ();
sarun ("-t < data/nice/spf2", \&patterns_run_cb);
ok_all_patterns();
# 27-28: Trusted networks contain first header.
# Internal networks contain first and second header.
tstprefs("
clear_trusted_networks
clear_internal_networks
trusted_networks 65.214.43.157
internal_networks 65.214.43.157 64.142.3.173
always_trust_envelope_sender 1
");
%anti_patterns = ();
%patterns = (
q{ SPF_HELO_PASS }, 'helo_pass',
q{ SPF_PASS }, 'pass',
);
sarun ("-t < data/nice/spf2", \&patterns_run_cb);
ok_all_patterns();
# 29-30: Trusted networks contain top 5 headers.
# Internal networks contain first header.
tstprefs("
clear_trusted_networks
clear_internal_networks
trusted_networks 65.214.43.158 64.142.3.173 65.214.43.155 65.214.43.156 65.214.43.157
internal_networks 65.214.43.158
always_trust_envelope_sender 1
");
%anti_patterns = ();
%patterns = (
q{ SPF_HELO_PASS }, 'helo_pass',
q{ SPF_PASS }, 'pass',
);
sarun ("-t < data/nice/spf3", \&patterns_run_cb);
ok_all_patterns();
# 31-32: Trusted networks contain top 5 headers.
# Internal networks contain top 2 headers.
tstprefs("
clear_trusted_networks
clear_internal_networks
trusted_networks 65.214.43.158 64.142.3.173 65.214.43.155 65.214.43.156 65.214.43.157
internal_networks 65.214.43.158 64.142.3.173
always_trust_envelope_sender 1
");
%anti_patterns = ();
%patterns = (
q{ SPF_HELO_FAIL }, 'helo_fail',
q{ SPF_FAIL }, 'fail',
);
sarun ("-t < data/nice/spf3", \&patterns_run_cb);
ok_all_patterns();
# 33-34: Trusted networks contain top 5 headers.
# Internal networks contain top 3 headers.
tstprefs("
clear_trusted_networks
clear_internal_networks
trusted_networks 65.214.43.158 64.142.3.173 65.214.43.155 65.214.43.156 65.214.43.157
internal_networks 65.214.43.158 64.142.3.173 65.214.43.155
always_trust_envelope_sender 1
");
%anti_patterns = ();
%patterns = (
q{ SPF_HELO_SOFTFAIL }, 'helo_softfail',
q{ SPF_SOFTFAIL }, 'softfail',
);
sarun ("-t < data/nice/spf3", \&patterns_run_cb);
ok_all_patterns();
# 35-36: Trusted networks contain top 5 headers.
# Internal networks contain top 4 headers.
tstprefs("
clear_trusted_networks
clear_internal_networks
trusted_networks 65.214.43.158 64.142.3.173 65.214.43.155 65.214.43.156 65.214.43.157
internal_networks 65.214.43.158 64.142.3.173 65.214.43.155 65.214.43.156
always_trust_envelope_sender 1
");
%anti_patterns = ();
%patterns = (
q{ SPF_HELO_NEUTRAL }, 'helo_neutral',
q{ SPF_NEUTRAL }, 'neutral',
);
sarun ("-t < data/nice/spf3", \&patterns_run_cb);
ok_all_patterns();
# 37-40: same as test 1-2 with some spf whitelisting added
tstprefs("
whitelist_from_spf newsalerts-noreply\@dnsbltest.spamassassin.org
def_whitelist_from_spf *\@dnsbltest.spamassassin.org
");
%patterns = (
q{ SPF_HELO_PASS }, 'helo_pass',
q{ SPF_PASS }, 'pass',
q{ USER_IN_SPF_WELCOMELIST }, 'spf_whitelist',
q{ USER_IN_DEF_SPF_WL }, 'default_spf_whitelist',
);
sarun ("-t < data/nice/spf1", \&patterns_run_cb);
ok_all_patterns();
# 41-44: same as test 1-2 with some spf whitelist entries that don't match
tstprefs("
whitelist_from_spf *\@example.com
def_whitelist_from_spf nothere\@dnsbltest.spamassassin.org
");
%patterns = (
q{ SPF_HELO_PASS }, 'helo_pass',
q{ SPF_PASS }, 'pass',
);
%anti_patterns = (
q{ USER_IN_SPF_WELCOMELIST }, 'spf_whitelist',
q{ USER_IN_DEF_SPF_WL }, 'default_spf_whitelist',
);
sarun ("-t < data/nice/spf1", \&patterns_run_cb);
ok_all_patterns();
# clear these out before we loop
%anti_patterns = ();
%patterns = ();
# 45-48: same as test 37-40 with welcomelist_auth added
tstprefs("
welcomelist_auth newsalerts-noreply\@dnsbltest.spamassassin.org
def_welcomelist_auth *\@dnsbltest.spamassassin.org
");
%patterns = (
q{ SPF_HELO_PASS }, 'helo_pass',
q{ SPF_PASS }, 'pass',
q{ USER_IN_SPF_WELCOMELIST }, 'spf_whitelist',
q{ USER_IN_DEF_SPF_WL }, 'default_spf_whitelist',
);
sarun ("-t < data/nice/spf1", \&patterns_run_cb);
ok_all_patterns();
# test usage of Received-SPF headers added by internal relays
# the Received-SPF headers shouldn't be used in this test
tstprefs("
clear_trusted_networks
clear_internal_networks
trusted_networks 65.214.43.158
internal_networks 65.214.43.158
always_trust_envelope_sender 1
");
%anti_patterns = ();
%patterns = (
q{ SPF_HELO_PASS }, 'helo_pass',
q{ SPF_PASS }, 'pass',
);
sarun ("-t < data/nice/spf3-received-spf", \&patterns_run_cb);
ok_all_patterns();
# Test same with nonfolded headers
sarun ("-t < data/nice/spf4-received-spf-nofold", \&patterns_run_cb);
ok_all_patterns();
# Test same with crlf line endings
sarun ("-t < data/nice/spf5-received-spf-crlf", \&patterns_run_cb);
ok_all_patterns();
# Test same with crlf line endings (bug 7785)
sarun ("-t < data/nice/spf6-received-spf-crlf2", \&patterns_run_cb);
ok_all_patterns();
# test usage of Received-SPF headers added by internal relays
# the Received-SPF headers shouldn't be used in this test
tstprefs("
clear_trusted_networks
clear_internal_networks
trusted_networks 65.214.43.158 64.142.3.173
internal_networks 65.214.43.158 64.142.3.173
always_trust_envelope_sender 1
ignore_received_spf_header 1
");
%anti_patterns = ();
%patterns = (
q{ SPF_HELO_FAIL }, 'helo_fail_ignore_header',
q{ SPF_FAIL }, 'fail_ignore_header',
);
sarun ("-t < data/nice/spf3-received-spf", \&patterns_run_cb);
ok_all_patterns();
# Test same with nonfolded headers
sarun ("-t < data/nice/spf4-received-spf-nofold", \&patterns_run_cb);
ok_all_patterns();
# test usage of Received-SPF headers added by internal relays
# the bottom 2 Received-SPF headers should be used in this test
tstprefs("
clear_trusted_networks
clear_internal_networks
trusted_networks 65.214.43.158 64.142.3.173
internal_networks 65.214.43.158 64.142.3.173
always_trust_envelope_sender 1
");
%anti_patterns = ();
%patterns = (
q{ SPF_HELO_SOFTFAIL }, 'helo_softfail_from_header',
q{ SPF_NEUTRAL }, 'neutral_from_header',
);
sarun ("-t < data/nice/spf3-received-spf", \&patterns_run_cb);
ok_all_patterns();
# Test same with nonfolded headers
sarun ("-t < data/nice/spf4-received-spf-nofold", \&patterns_run_cb);
ok_all_patterns();
# test usage of Received-SPF headers added by internal relays
# the top 2 Received-SPF headers should be used in this test
tstprefs("
clear_trusted_networks
clear_internal_networks
trusted_networks 65.214.43.158 64.142.3.173
internal_networks 65.214.43.158 64.142.3.173
use_newest_received_spf_header 1
always_trust_envelope_sender 1
");
%anti_patterns = ();
%patterns = (
q{ SPF_HELO_SOFTFAIL }, 'helo_softfail_from_header',
q{ SPF_FAIL }, 'fail_from_header',
);
sarun ("-t < data/nice/spf3-received-spf", \&patterns_run_cb);
ok_all_patterns();
# Test same with nonfolded headers
sarun ("-t < data/nice/spf4-received-spf-nofold", \&patterns_run_cb);
ok_all_patterns();
# test unwelcomelist_auth and unwhitelist_from_spf
tstprefs("
welcomelist_auth newsalerts-noreply\@dnsbltest.spamassassin.org
def_welcomelist_auth newsalerts-noreply\@dnsbltest.spamassassin.org
unwelcomelist_auth newsalerts-noreply\@dnsbltest.spamassassin.org
whitelist_from_spf *\@dnsbltest.spamassassin.org
def_whitelist_from_spf *\@dnsbltest.spamassassin.org
unwhitelist_from_spf *\@dnsbltest.spamassassin.org
");
%patterns = (
q{ SPF_HELO_PASS }, 'helo_pass',
q{ SPF_PASS }, 'pass',
);
%anti_patterns = (
q{ USER_IN_SPF_WELCOMELIST }, 'spf_whitelist',
q{ USER_IN_DEF_SPF_WL }, 'default_spf_whitelist',
);
sarun ("-t < data/nice/spf1", \&patterns_run_cb);
ok_all_patterns();