-
Notifications
You must be signed in to change notification settings - Fork 70
/
spf.t
executable file
·308 lines (235 loc) · 6.8 KB
/
spf.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
#!/usr/bin/perl
use lib '.'; use lib 't';
use SATest; sa_t_init("spf");
use Test;
use constant TEST_ENABLED => conf_bool('run_net_tests');
use constant HAS_SPFQUERY => eval { require Mail::SPF::Query; };
# bug 3806:
# Do not run this test on non-Linux unices as root, due to a bug
# in Sys::Hostname::Long (which Mail::Query::SPF uses.)
use constant IS_LINUX => $^O eq 'linux';
use constant IS_WINDOWS => ($^O =~ /^(mswin|dos|os2)/oi);
use constant AM_ROOT => $< == 0;
use constant DO_RUN => TEST_ENABLED && HAS_SPFQUERY &&
!(AM_ROOT &&
!(IS_LINUX || IS_WINDOWS));
BEGIN {
plan tests => (DO_RUN ? 36 : 0);
};
exit unless (DO_RUN);
# ---------------------------------------------------------------------------
# ensure all rules will fire
tstlocalrules ("
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
");
%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();