-
Notifications
You must be signed in to change notification settings - Fork 70
/
line_endings.t
executable file
·160 lines (137 loc) · 4.38 KB
/
line_endings.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
#!/usr/bin/perl -T
use lib '.'; use lib 't';
use SATest; sa_t_init("line_endings");
use Test::More;
plan skip_all => "Long running tests disabled" unless conf_bool('run_long_tests');
plan tests => 26;
# ---------------------------------------------------------------------------
# Use a slightly modified gtube ...
my $origtest = 'data/spam/gtube.eml';
my $test = "$workdir/report_safe.eml";
my $test2 = "$workdir/report_safe2.eml";
my $original = '';
if (open(OTEST, $origtest) && open(TEST, ">$test") && open(TEST2, ">$test2")) {
binmode OTEST;
binmode TEST;
binmode TEST2;
local $/=undef;
$original .= "X-Spam-Prev-Subject: this is a test\n";
$original .= "X-Spam-Status: No, this should fail horribly!\n";
$original .= <OTEST>;
$original =~ s/\r*\n/\r\n/gs; print TEST $original;
$original =~ s/\r*\n/\n/gs; print TEST2 $original;
close(TEST);
close(TEST2);
close(OTEST);
}
else {
die "can't open input files: $!";
}
my $description = 'original message before SpamAssassin';
my $disposition = 'inline';
my $message;
my $resulttext;
my $count_crnl;
my $count_nl;
%patterns = ('X-Spam-Status: Yes' => 'XSS_Yes');
%anti_patterns = ($original => P_1, 'X-Spam-Status: No' => 'XSS_No', q{ MISSING_HB_SEP }, 'hb_sep');
tstprefs ("report_safe 0\n");
sarun ("-L < $test", \&my_patterns_run);
ok_all_patterns();
# support one *or* the other, depending on platform
count_line_endings($resulttext);
if ($count_crnl) {
ok ($count_crnl!=0 && $count_nl==0);
} else {
ok ($count_crnl==0 && $count_nl!=0);
}
$message = safe($boundary, '', 'message/rfc822', $description, 'inline');
%patterns = ($message => P_2, 'X-Spam-Status: Yes' => 'XSS_Yes');
%anti_patterns = ( q{ MISSING_HB_SEP }, 'hb_sep');
tstprefs ("report_safe 1\n");
sarun ("-L < $test", \&my_patterns_run);
ok_all_patterns();
count_line_endings($resulttext);
if ($count_crnl) {
ok ($count_crnl!=0 && $count_nl==0);
} else {
ok ($count_crnl==0 && $count_nl!=0);
}
$message = safe($boundary, '', 'text/plain', $description, 'inline');
%patterns = ($message => P_3, 'X-Spam-Status: Yes' => 'XSS_Yes');
%anti_patterns = ( q{ MISSING_HB_SEP }, 'hb_sep');
tstprefs ("report_safe 2\n");
sarun ("-L < $test", \&my_patterns_run);
ok_all_patterns();
count_line_endings($resulttext);
if ($count_crnl) {
ok ($count_crnl!=0 && $count_nl==0);
} else {
ok ($count_crnl==0 && $count_nl!=0);
}
# now with the other line-ending style...
%patterns = ('X-Spam-Status: Yes' => 'XSS_Yes');
%anti_patterns = ($original => P_1, 'X-Spam-Status: No' => 'XSS_No', q{ MISSING_HB_SEP }, 'hb_sep');
tstprefs ("report_safe 0\n");
sarun ("-L < $test2", \&my_patterns_run);
ok_all_patterns();
# support one *or* the other, depending on platform
count_line_endings($resulttext);
if ($count_crnl) {
ok ($count_crnl!=0 && $count_nl==0);
} else {
ok ($count_crnl==0 && $count_nl!=0);
}
$message = safe($boundary, '', 'message/rfc822', $description, 'inline');
%patterns = ($message => P_2, 'X-Spam-Status: Yes' => 'XSS_Yes');
%anti_patterns = ( q{ MISSING_HB_SEP }, 'hb_sep');
tstprefs ("report_safe 1\n");
sarun ("-L < $test2", \&my_patterns_run);
ok_all_patterns();
count_line_endings($resulttext);
if ($count_crnl) {
ok ($count_crnl!=0 && $count_nl==0);
} else {
ok ($count_crnl==0 && $count_nl!=0);
}
$message = safe($boundary, '', 'text/plain', $description, 'inline');
%patterns = ($message => P_3, 'X-Spam-Status: Yes' => 'XSS_Yes');
%anti_patterns = ( q{ MISSING_HB_SEP }, 'hb_sep');
tstprefs ("report_safe 2\n");
sarun ("-L < $test2", \&my_patterns_run);
ok_all_patterns();
count_line_endings($resulttext);
if ($count_crnl) {
ok ($count_crnl!=0 && $count_nl==0);
} else {
ok ($count_crnl==0 && $count_nl!=0);
}
exit;
# ---------------------------------------------------------------------------
# unfortunately, we cannot use a regexp since quotemeta is used on patterns
sub safe {
my ($boundary, $report_charset, $type, $description, $disposition) = @_;
return <<"EOM";
Content-Type: $type; x-spam-type=original
Content-Description: $description
Content-Disposition: $disposition
Content-Transfer-Encoding: 8bit
$original
EOM
}
sub my_patterns_run {
$resulttext = join ('', <IN>);
return patterns_run_cb($resulttext);
}
sub count_line_endings {
$count_crnl = 0;
$count_nl = 0;
foreach my $line (split(/\n/s, shift)) {
if ($line =~ /\r$/) {
$count_crnl++;
} else {
$count_nl++;
}
}
print "line endings found: NL=$count_nl CRNL=$count_crnl\n";
}