You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jm...@apache.org on 2007/04/20 14:24:03 UTC
svn commit: r530762 - in /spamassassin/trunk: MANIFEST t/line_endings.t
Author: jm
Date: Fri Apr 20 05:24:02 2007
New Revision: 530762
URL: http://svn.apache.org/viewvc?view=rev&rev=530762
Log:
bug 5344: add test case for the win32 line-endings bug
Added:
spamassassin/trunk/t/line_endings.t (with props)
Modified:
spamassassin/trunk/MANIFEST
Modified: spamassassin/trunk/MANIFEST
URL: http://svn.apache.org/viewvc/spamassassin/trunk/MANIFEST?view=diff&rev=530762&r1=530761&r2=530762
==============================================================================
--- spamassassin/trunk/MANIFEST (original)
+++ spamassassin/trunk/MANIFEST Fri Apr 20 05:24:02 2007
@@ -491,3 +491,4 @@
t/whitelist_subject.t
t/whitelist_to.t
t/zz_cleanup.t
+t/line_endings.t
Added: spamassassin/trunk/t/line_endings.t
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/line_endings.t?view=auto&rev=530762
==============================================================================
--- spamassassin/trunk/t/line_endings.t (added)
+++ spamassassin/trunk/t/line_endings.t Fri Apr 20 05:24:02 2007
@@ -0,0 +1,107 @@
+#!/usr/bin/perl
+
+use lib '.'; use lib 't';
+use SATest; sa_t_init("line_endings");
+use Test; BEGIN { plan tests => 14 };
+
+# ---------------------------------------------------------------------------
+
+# Use a slightly modified gtube ...
+my $origtest = 'data/spam/gtube.eml';
+my $test = 'log/report_safe.eml';
+my $original = '';
+if (open(OTEST, $origtest) && open(TEST, ">$test")) {
+ local $/=undef;
+ $original .= "X-Spam-Prev-Subject: this is a test\n";
+ $original .= "X-Spam-Status: No, this should fail horribly!\n";
+ $original .= <OTEST>;
+ print TEST $original;
+ close(TEST);
+ 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);
+}
+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";
+}
Propchange: spamassassin/trunk/t/line_endings.t
------------------------------------------------------------------------------
svn:executable = *