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/01/29 23:32:19 UTC
svn commit: r501204 - in /spamassassin/trunk:
lib/Mail/SpamAssassin/PerMsgStatus.pm t/check_implemented.t
Author: jm
Date: Mon Jan 29 14:32:18 2007
New Revision: 501204
URL: http://svn.apache.org/viewvc?view=rev&rev=501204
Log:
bug 5311: die() if no plugin implements 'check_main' and the check() API is called, otherwise it's reasonably easy to wind up with a non-scanning scanner. also, add a test
Added:
spamassassin/trunk/t/check_implemented.t (with props)
Modified:
spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm?view=diff&rev=501204&r1=501203&r2=501204
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm Mon Jan 29 14:32:18 2007
@@ -155,9 +155,14 @@
$self->{conf}->set_score_set ($set|2);
}
- # The primary check functionality occurs via a plugin call. For more information please
- # see: Mail::SpamAssassin::Plugin::Check
+ # The primary check functionality occurs via a plugin call. For more
+ # information, please see: Mail::SpamAssassin::Plugin::Check
$self->{main}->call_plugins ("check_main", { permsgstatus => $self });
+
+ # did anything happen? if not, this is fatal
+ if (!$self->{score} && !$self->{main}->have_plugin("check_main")) {
+ die "check: no loaded plugin implements 'check_main': cannot scan!";
+ }
# delete temporary storage and memory allocation used during checking
$self->delete_fulltext_tmpfile();
Added: spamassassin/trunk/t/check_implemented.t
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/check_implemented.t?view=auto&rev=501204
==============================================================================
--- spamassassin/trunk/t/check_implemented.t (added)
+++ spamassassin/trunk/t/check_implemented.t Mon Jan 29 14:32:18 2007
@@ -0,0 +1,66 @@
+#!/usr/bin/perl
+
+# detect use of dollar-ampersand somewhere in the perl interpreter;
+# once it is used once, it slows down every regexp match thereafter.
+
+BEGIN {
+ if (-e 't/test_dir') { # if we are running "t/rule_tests.t", kluge around ...
+ chdir 't';
+ }
+
+ if (-e 'test_dir') { # running from test directory, not ..
+ unshift(@INC, '../blib/lib');
+ unshift(@INC, '../lib');
+ }
+}
+
+my $prefix = '.';
+if (-e 'test_dir') { # running from test directory, not ..
+ $prefix = '..';
+}
+
+use lib '.'; use lib 't';
+use SATest; sa_t_init("check_implemented");
+use Test;
+use Carp qw(croak);
+
+BEGIN {
+ plan tests => 2;
+};
+
+# ---------------------------------------------------------------------------
+
+use strict;
+require Mail::SpamAssassin;
+
+# TODO: unportable
+system "perl -pi.bak -e 's/^loadplugin/###loadplugin/g' ".
+ " log/localrules.tmp/*.pre log/test_rules_copy/*.pre";
+
+($? >> 8 != 0) and die "perl failed";
+
+my $sa = create_saobj({
+ 'dont_copy_prefs' => 1,
+ 'local_tests_only' => 1
+});
+
+$sa->init(1);
+ok($sa);
+
+open (IN, "<data/spam/009");
+my $mail = $sa->parse(\*IN);
+close IN;
+
+$SIG{'__WARN__'} = sub {
+ return if /no loaded plugin/;
+ print STDERR @_;
+};
+
+eval {
+ my $status = $sa->check($mail);
+ ok 0; # should never get this far
+};
+
+print "got warning: '$@'\n";
+ok ($@ =~ /no loaded plugin implements/);
+
Propchange: spamassassin/trunk/t/check_implemented.t
------------------------------------------------------------------------------
svn:executable = *
Re: svn commit: r501204 - in /spamassassin/trunk: lib/Mail/SpamAssassin/PerMsgStatus.pm
t/check_implemented.t
Posted by Michael Parker <pa...@pobox.com>.
jm@apache.org wrote:
> Author: jm
> Date: Mon Jan 29 14:32:18 2007
> New Revision: 501204
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=501204
> Log:
> bug 5311: die() if no plugin implements 'check_main' and the check() API is called, otherwise it's reasonably easy to wind up with a non-scanning scanner. also, add a test
>
> Added:
> spamassassin/trunk/t/check_implemented.t (with props)
> Modified:
> spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
>
> Modified: spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
> URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm?view=diff&rev=501204&r1=501203&r2=501204
> ==============================================================================
> --- spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm (original)
> +++ spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm Mon Jan 29 14:32:18 2007
> @@ -155,9 +155,14 @@
> $self->{conf}->set_score_set ($set|2);
> }
>
> - # The primary check functionality occurs via a plugin call. For more information please
> - # see: Mail::SpamAssassin::Plugin::Check
> + # The primary check functionality occurs via a plugin call. For more
> + # information, please see: Mail::SpamAssassin::Plugin::Check
> $self->{main}->call_plugins ("check_main", { permsgstatus => $self });
> +
> + # did anything happen? if not, this is fatal
> + if (!$self->{score} && !$self->{main}->have_plugin("check_main")) {
> + die "check: no loaded plugin implements 'check_main': cannot scan!";
> + }
>
I think I mentioned this before, but my idea here was to build it into
call_plugins. Have a param that said if something MUST implement the
plugin call and die otherwise. I actually thought it had been done
already. I -.5 on adding another if check after the call here, it just
slows things down.
Michael