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 2006/09/04 19:21:43 UTC

svn commit: r440125 - in /spamassassin/trunk: build/mkrules t/mkrules.t

Author: jm
Date: Mon Sep  4 10:21:42 2006
New Revision: 440125

URL: http://svn.apache.org/viewvc?view=rev&rev=440125
Log:
bug 5063: rules that use plugins from the sandboxes, should not be promoted to 72_active.cf.  Instead keep them in 70_sandbox.cf

Modified:
    spamassassin/trunk/build/mkrules
    spamassassin/trunk/t/mkrules.t

Modified: spamassassin/trunk/build/mkrules
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/mkrules?view=diff&rev=440125&r1=440124&r2=440125
==============================================================================
--- spamassassin/trunk/build/mkrules (original)
+++ spamassassin/trunk/build/mkrules Mon Sep  4 10:21:42 2006
@@ -451,14 +451,26 @@
     elsif (/^loadplugin\s*(\S+)\b/) {
       my $name = 'loadplugin_'.$1;
 
+      unless ($rules->{$name}) {
+        $rules->{$name} = rule_entry_create();
+        $rules->{$name}->{issandbox} = $issandbox;
+        $rules->{$name}->{iscommand} = 1;
+      }
+
       if (/^loadplugin\s*\S+\s+(\S+)/) {
         my $fname = $1;
         my $fpath = dirname($f)."/".$fname;
+
         if (!-f $fpath) {
           warn "$f: WARNING: plugin code file '$fpath' not found, line ignored: $orig";
           next;
         }
 
+        if ($fpath =~ /sandbox/i) {
+          # Since this is a sandbox plugin, force its output to the sandbox area.
+          $rules->{$name}->{sandbox_plugin} = 1;
+        }
+
         # If a 'loadplugin' line is found, and the plugin .pm is not listed in
         # the MANIFEST file, this will mean that the .pm will not be copied
         # during "make dist".  This causes failures during "make disttest",
@@ -478,12 +490,6 @@
         }
       }
 
-      unless ($rules->{$name}) {
-        $rules->{$name} = rule_entry_create();
-        $rules->{$name}->{issandbox} = $issandbox;
-        $rules->{$name}->{iscommand} = 1;
-      }
-
       $rules->{$name}->{text} .= $orig;
       unshift (@$rule_order, $name);
     }
@@ -571,29 +577,41 @@
       $is_active++;
     }
 
-    $output_files->{$pubfile} = {
-      header => $default_file_header
-    };
-
     # fix up any rule renamings we were supposed to do
     sed_renamed_rule_names(\$text);
 
     my $cond = $rules->{$name}->{cond};
-    if ($cond) {
-      $rules->{$name}->{output_text} = "\n".$cond.$text."endif\n";
+    my $pluginclass = $rules->{$name}->{ifplugin};
+    if ($cond)
+    {
+      my $ifplugin_text_name = "loadplugin_".($pluginclass || "");
+
+      if ($pluginclass && $rules->{$ifplugin_text_name})
+      {
+        # if the plugin is a sandbox plugin, ensure it's not
+        # sent to the active file
+        if ($rules->{$ifplugin_text_name}->{sandbox_plugin}) {
+          $pubfile = $opt_out.'/'.$opt_sandboxout;
+          $is_active = 0;
+        }
 
-      # also, if the rule is active, ensure its "loadplugin" line
-      # is copied to the active output file, too
-      my $pluginclass = $rules->{$name}->{ifplugin};
-      if ($is_active && $pluginclass) {
-        my $ifplugin_text_name = "loadplugin_".$pluginclass;
+        # either way, ensure the "loadplugin" line, if there is one,
+        # goes to the same file
         $rules->{$ifplugin_text_name}->{output_file} = $pubfile;
       }
 
+      $rules->{$name}->{output_text} = "\n".$cond.$text."endif\n";
+
     } else {
       $rules->{$name}->{output_text} = $text;
     }
+
+    # note the target file
     $rules->{$name}->{output_file} = $pubfile;
+
+    $output_files->{$pubfile} = {
+      header => $default_file_header
+    };
 
     if ($is_active) {
       $copied_active++;

Modified: spamassassin/trunk/t/mkrules.t
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/mkrules.t?view=diff&rev=440125&r1=440124&r2=440125
==============================================================================
--- spamassassin/trunk/t/mkrules.t (original)
+++ spamassassin/trunk/t/mkrules.t Mon Sep  4 10:21:42 2006
@@ -2,11 +2,11 @@
 
 use lib '.'; use lib 't';
 use SATest; sa_t_init("mkrules");
-use Test; BEGIN { plan tests => 86 };
+use Test; BEGIN { plan tests => 96 };
 use File::Path;
 
 # ---------------------------------------------------------------------------
-# script runs, even with nothing to do
+print " script runs, even with nothing to do\n\n";
 
 my $tdir = "log/mkrules_t";
 rmtree([ $tdir ]);
@@ -22,7 +22,7 @@
 save_tdir();
 
 # ---------------------------------------------------------------------------
-# promotion of an active rule
+print " promotion of an active rule\n\n";
 
 %patterns = (
   '72_active.cf: WARNING: not listed in manifest file' => manif_found,
@@ -50,7 +50,7 @@
 save_tdir();
 
 # ---------------------------------------------------------------------------
-# non-promotion of an inactive rule
+print " non-promotion of an inactive rule\n\n";
 
 %patterns = (
   '70_sandbox.cf: WARNING: not listed in manifest file' => manif_found,
@@ -78,7 +78,7 @@
 save_tdir();
 
 # ---------------------------------------------------------------------------
-# non-promotion of a broken rule
+print " non-promotion of a broken rule\n\n";
 
 %patterns = (
   '70_sandbox.cf: WARNING: not listed in manifest file' => manif_found,
@@ -107,7 +107,7 @@
 save_tdir();
 
 # ---------------------------------------------------------------------------
-# promotion of an active meta rule
+print " promotion of an active meta rule\n\n";
 
 %patterns = (
   '70_sandbox.cf: WARNING: not listed in manifest file' => manif_found,
@@ -138,7 +138,7 @@
 save_tdir();
 
 # ---------------------------------------------------------------------------
-# inactive meta rule
+print " inactive meta rule\n\n";
 
 %patterns = (
   '70_sandbox.cf: WARNING: not listed in manifest file' => manif_found,
@@ -169,7 +169,7 @@
 save_tdir();
 
 # ---------------------------------------------------------------------------
-# active plugin
+print " active plugin in sandbox\n\n";
 
 %patterns = (
   '70_sandbox.cf: WARNING: not listed in manifest file' => manif_found,
@@ -205,6 +205,49 @@
 ]);
 
 ok (mkrun ("--src $tdir/rulesrc --out $tdir/rules --manifest $tdir/MANIFEST --manifestskip $tdir/MANIFEST.SKIP --active $tdir/rules/active.list 2>&1", \&patterns_run_cb));
+# checkfile("$tdir/rules/72_active.cf", \&patterns_run_cb);
+checkfile("$tdir/rules/70_sandbox.cf", \&patterns_run_cb);
+ok (-f "$tdir/rules/plugin.pm");
+ok ok_all_patterns();
+save_tdir();
+
+# ---------------------------------------------------------------------------
+print " active plugin in core\n\n";
+
+%patterns = (
+  '70_sandbox.cf: WARNING: not listed in manifest file' => manif_found,
+  "loadplugin Good plugin.pm" => loadplugin_found,
+  "body GOOD eval:check_foo()"   => rule_line_1,
+  "describe GOOD desc_found"  => rule_line_2,
+  "ifplugin Good" => if1,
+  "endif" => endif_found,
+);
+%anti_patterns = (
+  "describe T_GOOD desc_found"  => rule_line_2,
+);
+
+mkpath ([ "$tdir/rulesrc/core", "$tdir/rules", ]);
+
+write_file("$tdir/MANIFEST", [ "rulesrc/core/20_foo.cf\n", "rulesrc/core/plugin.pm\n" ]);
+write_file("$tdir/MANIFEST.SKIP", [ "foo2\n" ]);
+write_file("$tdir/rules/active.list", [ "GOOD\n" ]);
+write_file("$tdir/rulesrc/core/20_foo.cf", [
+    "loadplugin Good plugin.pm\n",
+    "ifplugin Good\n",
+    "body GOOD eval:check_foo()\n",
+    "describe GOOD desc_found\n",
+    "endif\n",
+]);
+write_file("$tdir/rulesrc/core/plugin.pm", [
+    'package Good;',
+    'use Mail::SpamAssassin::Plugin; our @ISA = qw(Mail::SpamAssassin::Plugin);',
+    'sub new { my ($class, $m) = @_; $class = ref($class) || $class;',
+    'my $self = bless $class->SUPER::new($m), $class;',
+    '$self->register_eval_rule("check_foo"); return $self; }',
+    'sub check_foo { my ($self, $pms) = @_; return 1; }',
+]);
+
+ok (mkrun ("--src $tdir/rulesrc --out $tdir/rules --manifest $tdir/MANIFEST --manifestskip $tdir/MANIFEST.SKIP --active $tdir/rules/active.list 2>&1", \&patterns_run_cb));
 checkfile("$tdir/rules/72_active.cf", \&patterns_run_cb);
 # checkfile("$tdir/rules/70_sandbox.cf", \&patterns_run_cb);
 ok (-f "$tdir/rules/plugin.pm");
@@ -212,7 +255,7 @@
 save_tdir();
 
 # ---------------------------------------------------------------------------
-# inactive plugin
+print " inactive plugin\n\n";
 
 %patterns = (
   '70_sandbox.cf: WARNING: not listed in manifest file' => manif_found,
@@ -257,7 +300,7 @@
 
 
 # ---------------------------------------------------------------------------
-# inactive plugin in non-sandbox
+print " inactive plugin in non-sandbox\n\n";
 
 %patterns = (
   '70_inactive.cf: WARNING: not listed in manifest file' => manif_found,
@@ -302,7 +345,7 @@
 save_tdir();
 
 # ---------------------------------------------------------------------------
-# active plugin, but the .pm file is AWOL
+print " active plugin, but the .pm file is AWOL\n\n";
 
 %patterns = (
   "body GOOD eval:check_foo()"   => rule_line_1,
@@ -336,7 +379,7 @@
 save_tdir();
 
 # ---------------------------------------------------------------------------
-# active plugin, but the .pm file is not in MANIFEST
+print " active plugin, but the .pm file is not in MANIFEST\n\n";
 
 %patterns = (
   "body GOOD eval:check_foo()"   => rule_line_1,
@@ -371,8 +414,8 @@
 ]);
 
 ok (mkrun ("--src $tdir/rulesrc --out $tdir/rules --manifest $tdir/MANIFEST --manifestskip $tdir/MANIFEST.SKIP --active $tdir/rules/active.list 2>&1", \&patterns_run_cb));
-checkfile("$tdir/rules/72_active.cf", \&patterns_run_cb);
-# checkfile("$tdir/rules/70_sandbox.cf", \&patterns_run_cb);
+# checkfile("$tdir/rules/72_active.cf", \&patterns_run_cb);
+checkfile("$tdir/rules/70_sandbox.cf", \&patterns_run_cb);
 ok (-f "$tdir/rules/plugin.pm");
 ok ok_all_patterns();
 save_tdir();
@@ -413,7 +456,7 @@
 
 sub save_tdir {
   rmtree("$tdir.${Test::ntest}");
-  system("cp -pr $tdir $tdir.${Test::ntest}");
+  system("mv $tdir $tdir.${Test::ntest}");
   if ($? >> 8 == 0) {
     print "\ttest output tree copied to $tdir.${Test::ntest}\n";
   }