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/08 21:27:04 UTC

svn commit: r494187 - in /spamassassin/trunk: MANIFEST t/data/taintcheckplugin.pm t/tainted_msg.t

Author: jm
Date: Mon Jan  8 12:27:03 2007
New Revision: 494187

URL: http://svn.apache.org/viewvc?view=rev&rev=494187
Log:
add test to ensure that most of the Message APIs preserve the tainted status of the message data

Added:
    spamassassin/trunk/t/data/taintcheckplugin.pm
    spamassassin/trunk/t/tainted_msg.t   (with props)
Modified:
    spamassassin/trunk/MANIFEST

Modified: spamassassin/trunk/MANIFEST
URL: http://svn.apache.org/viewvc/spamassassin/trunk/MANIFEST?view=diff&rev=494187&r1=494186&r2=494187
==============================================================================
--- spamassassin/trunk/MANIFEST (original)
+++ spamassassin/trunk/MANIFEST Mon Jan  8 12:27:03 2007
@@ -476,3 +476,4 @@
 t/data/testplugin2.pm
 t/plugin_priorities.t
 t/basic_obj_api.t
+t/tainted_msg.t

Added: spamassassin/trunk/t/data/taintcheckplugin.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/data/taintcheckplugin.pm?view=auto&rev=494187
==============================================================================
--- spamassassin/trunk/t/data/taintcheckplugin.pm (added)
+++ spamassassin/trunk/t/data/taintcheckplugin.pm Mon Jan  8 12:27:03 2007
@@ -0,0 +1,78 @@
+=head1 
+
+To try this out, write these lines to /etc/mail/spamassassin/plugintest.cf:
+
+  loadplugin     myTestPlugin
+  header         MY_TEST_PLUGIN eval:check_test_plugin()
+
+=cut
+
+package myTestPlugin;
+
+use Mail::SpamAssassin::Plugin;
+use Mail::SpamAssassin::Logger;
+use strict;
+use bytes;
+use Test;
+
+our @ISA = qw(Mail::SpamAssassin::Plugin);
+
+# constructor: register the eval rule
+sub new {
+  my $class = shift;
+  my $mailsaobject = shift;
+
+  # some boilerplate...
+  $class = ref($class) || $class;
+  my $self = $class->SUPER::new($mailsaobject);
+  bless ($self, $class);
+
+  print "registered myTestPlugin: $self\n";
+  return $self;
+}
+
+sub check_post_learn {
+  my ($self, $opts) = @_;
+  print "running check_end: $self\n";
+  my $m = $opts->{permsgstatus}->{msg};
+
+  print "tainted get_header found\n"
+    if (is_tainted($m->get_header("Subject")));
+
+  # TODO?
+  # print "tainted get_all_metadata found\n"
+  # if (is_tainted($m->get_all_metadata()));
+
+  # TODO!
+  # print "tainted get_pristine_header found\n"
+  # if (is_tainted($m->get_pristine_header("Subject")));
+
+  print "tainted get_pristine found\n"
+    if (is_tainted($m->get_pristine()));
+  print "tainted get_pristine_body found\n"
+    if (is_tainted($m->get_pristine_body()));
+
+  print "tainted get_body found\n"
+    if (is_tainted($m->get_body()->[0]));
+  print "tainted get_visible_rendered_body_text_array found\n"
+    if (is_tainted($m->get_visible_rendered_body_text_array()->[0]));
+
+  # skip get_invisible_rendered_body_text_array; it produces no output
+  # on that msg (TODO)
+
+  print "tainted get_decoded_body_text_array found\n"
+    if (is_tainted($m->get_decoded_body_text_array()->[0]));
+  print "tainted get_rendered_body_text_array found\n"
+    if (is_tainted($m->get_rendered_body_text_array()->[0]));
+ 
+  return 1;
+}
+
+
+sub is_tainted {
+  # from perldoc perlsec
+  return ! eval { eval("#" . substr(join("", @_), 0, 0)); 1 };
+}
+
+
+1;

Added: spamassassin/trunk/t/tainted_msg.t
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/tainted_msg.t?view=auto&rev=494187
==============================================================================
--- spamassassin/trunk/t/tainted_msg.t (added)
+++ spamassassin/trunk/t/tainted_msg.t Mon Jan  8 12:27:03 2007
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+
+use lib '.'; use lib 't';
+use SATest; sa_t_init("tainted_msg");
+use Test; BEGIN { plan tests => 8 };
+
+# ---------------------------------------------------------------------------
+
+%patterns = (
+
+  q{ tainted get_header found } => '',
+  q{ tainted get_pristine found } => '',
+  q{ tainted get_pristine_body found } => '',
+  q{ tainted get_body found } => '',
+  q{ tainted get_visible_rendered_body_text_array found } => '',
+  q{ tainted get_decoded_body_text_array found } => '',
+  q{ tainted get_rendered_body_text_array found } => '',
+
+);
+%anti_patterns = ();
+
+tstlocalrules ("
+    loadplugin myTestPlugin ../../data/taintcheckplugin.pm
+");
+
+ok (sarun ("-L -t < data/spam/gtube.eml", \&patterns_run_cb));
+ok_all_patterns();
+

Propchange: spamassassin/trunk/t/tainted_msg.t
------------------------------------------------------------------------------
    svn:executable = *