You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by he...@apache.org on 2022/04/18 16:30:06 UTC

svn commit: r1899993 - in /spamassassin/branches/trunk-welcomelist: MANIFEST t/SATest.pm t/db_awl_path_welcome_block.t t/db_awl_perms_welcome_block.t t/priorities.t t/priorities_welcome_block.t

Author: hege
Date: Mon Apr 18 16:30:06 2022
New Revision: 1899993

URL: http://svn.apache.org/viewvc?rev=1899993&view=rev
Log:
Improve tests

Added:
    spamassassin/branches/trunk-welcomelist/t/db_awl_path_welcome_block.t   (with props)
    spamassassin/branches/trunk-welcomelist/t/db_awl_perms_welcome_block.t   (with props)
    spamassassin/branches/trunk-welcomelist/t/priorities_welcome_block.t   (with props)
Modified:
    spamassassin/branches/trunk-welcomelist/MANIFEST
    spamassassin/branches/trunk-welcomelist/t/SATest.pm
    spamassassin/branches/trunk-welcomelist/t/priorities.t

Modified: spamassassin/branches/trunk-welcomelist/MANIFEST
URL: http://svn.apache.org/viewvc/spamassassin/branches/trunk-welcomelist/MANIFEST?rev=1899993&r1=1899992&r2=1899993&view=diff
==============================================================================
--- spamassassin/branches/trunk-welcomelist/MANIFEST (original)
+++ spamassassin/branches/trunk-welcomelist/MANIFEST Mon Apr 18 16:30:06 2022
@@ -486,7 +486,9 @@ t/data/welcomelists/winxpnews.com
 t/data/welcomelists/yahoo-inc.com
 t/date.t
 t/db_awl_path.t
+t/db_awl_path_welcome_block.t
 t/db_awl_perms.t
+t/db_awl_perms_welcome_block.t
 t/db_based_welcomelist.t
 t/db_based_welcomelist_ips.t
 t/db_based_whitelist.t
@@ -539,6 +541,7 @@ t/plugin_file.t
 t/plugin_priorities.t
 t/prefs_include.t
 t/priorities.t
+t/priorities_welcome_block.t
 t/pyzor.t
 t/razor2.t
 t/rcvd_parser.t

Modified: spamassassin/branches/trunk-welcomelist/t/SATest.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/trunk-welcomelist/t/SATest.pm?rev=1899993&r1=1899992&r2=1899993&view=diff
==============================================================================
--- spamassassin/branches/trunk-welcomelist/t/SATest.pm (original)
+++ spamassassin/branches/trunk-welcomelist/t/SATest.pm Mon Apr 18 16:30:06 2022
@@ -197,7 +197,7 @@ sub sa_t_init {
   $set_user_prefs = 0;
   $default_cf_lines = "
     bayes_path ./$userstate/bayes
-    auto_whitelist_path ./$userstate/auto-welcomelist
+    auto_welcomelist_path ./$userstate/auto-welcomelist
   ";
 
   read_config();

Added: spamassassin/branches/trunk-welcomelist/t/db_awl_path_welcome_block.t
URL: http://svn.apache.org/viewvc/spamassassin/branches/trunk-welcomelist/t/db_awl_path_welcome_block.t?rev=1899993&view=auto
==============================================================================
--- spamassassin/branches/trunk-welcomelist/t/db_awl_path_welcome_block.t (added)
+++ spamassassin/branches/trunk-welcomelist/t/db_awl_path_welcome_block.t Mon Apr 18 16:30:06 2022
@@ -0,0 +1,46 @@
+#!/usr/bin/perl -T
+
+use lib '.'; use lib 't';
+use SATest; sa_t_init("db_awl_path_welcome_block");
+use Test::More tests => 4;
+use IO::File;
+
+# ---------------------------------------------------------------------------
+
+%is_spam_patterns = (
+q{ X-Spam-Status: Yes}, 'isspam',
+);
+
+# We can't easily test to see if a given AWL was used.  so what we do
+# is tell SpamAssassin to use an inaccessible one, then verify that
+# the address in question was *not* welcomelisted successfully.   '
+
+open (OUT, ">$workdir/awl");
+print OUT "file created to block AWL from working; AWL expects a dir";
+close OUT;
+
+tstprefs ("
+  auto_welcomelist_path ./$workdir/awl/shouldbeinaccessible
+  auto_welcomelist_file_mode 0755
+");
+
+my $fh = IO::File->new_tmpfile();
+ok($fh);
+open(STDERR, ">&=".fileno($fh)) || die "Cannot reopen STDERR";
+sarun("--add-addr-to-welcomelist whitelist_test\@whitelist.spamassassin.taint.org",
+      \&patterns_run_cb);
+seek($fh, 0, 0);
+my $error = do {
+  local $/;
+  <$fh>;
+};
+
+diag $error;
+like($error, qr/(cannot create tmp lockfile)|(unlink of lock file.*failed)/, "Check we get the right error back");
+
+# and this mail should *not* be welcomelisted as a result.
+%patterns = %is_spam_patterns;
+sarun ("-L -t < data/spam/004", \&patterns_run_cb);
+ok_all_patterns();
+
+ok(unlink "$workdir/awl"); # need a little cleanup

Propchange: spamassassin/branches/trunk-welcomelist/t/db_awl_path_welcome_block.t
------------------------------------------------------------------------------
    svn:executable = *

Added: spamassassin/branches/trunk-welcomelist/t/db_awl_perms_welcome_block.t
URL: http://svn.apache.org/viewvc/spamassassin/branches/trunk-welcomelist/t/db_awl_perms_welcome_block.t?rev=1899993&view=auto
==============================================================================
--- spamassassin/branches/trunk-welcomelist/t/db_awl_perms_welcome_block.t (added)
+++ spamassassin/branches/trunk-welcomelist/t/db_awl_perms_welcome_block.t Mon Apr 18 16:30:06 2022
@@ -0,0 +1,41 @@
+#!/usr/bin/perl -T
+
+use lib '.'; use lib 't';
+use SATest; sa_t_init("db_awl_perms_welcome_block");
+use Test::More tests => 5;
+use IO::File;
+
+# ---------------------------------------------------------------------------
+# bug 6173
+
+tstprefs ("
+  use_auto_welcomelist 1
+  auto_welcomelist_path ./$userstate/awl
+  auto_welcomelist_file_mode 0755
+  lock_method flock
+");
+
+unlink "$userstate/awl";
+unlink "$userstate/awl.mutex";
+umask 022;
+sarun("--add-addr-to-welcomelist whitelist_test\@example.org",
+      \&patterns_run_cb);
+
+untaint_system "ls -l $userstate";          # for the logs
+
+sub checkmode {
+  my $fname = shift;
+  if (!-f $fname) { return 1; }
+  my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = stat $fname;
+  return (($mode & 0777) == 0644);
+}
+
+ok checkmode "$userstate/awl";              # DB_File
+ok checkmode "$userstate/awl.dir";          # SDBM
+ok checkmode "$userstate/awl.pag";          # SDBM
+ok checkmode "$userstate/awl.mutex";
+
+unlink "$userstate/awl",
+    "$userstate/awl.dir",
+    "$userstate/awl.pag";
+ok unlink "$userstate/awl.mutex";

Propchange: spamassassin/branches/trunk-welcomelist/t/db_awl_perms_welcome_block.t
------------------------------------------------------------------------------
    svn:executable = *

Modified: spamassassin/branches/trunk-welcomelist/t/priorities.t
URL: http://svn.apache.org/viewvc/spamassassin/branches/trunk-welcomelist/t/priorities.t?rev=1899993&r1=1899992&r2=1899993&view=diff
==============================================================================
--- spamassassin/branches/trunk-welcomelist/t/priorities.t (original)
+++ spamassassin/branches/trunk-welcomelist/t/priorities.t Mon Apr 18 16:30:06 2022
@@ -9,10 +9,10 @@ use Mail::SpamAssassin;
 
 tstlocalrules (q{
 
-  priority USER_IN_WELCOMELIST     -1000
-  priority USER_IN_DEF_WELCOMELIST -1000
+  priority USER_IN_WHITELIST     -1000
+  priority USER_IN_DEF_WHITELIST -1000
   priority USER_IN_ALL_SPAM_TO   -1000
-  priority SUBJECT_IN_WELCOMELIST  -1000
+  priority SUBJECT_IN_WHITELIST  -1000
 
   priority ALL_TRUSTED            -950
 
@@ -64,7 +64,7 @@ ok($sa);
 my $conf = $sa->{conf};
 sub assert_rule_pri;
 
-ok assert_rule_pri 'USER_IN_WELCOMELIST', -1000;
+ok assert_rule_pri 'USER_IN_WHITELIST', -1000;
 
 ok assert_rule_pri 'SC_URIBL_SURBL', -530;
 ok assert_rule_pri 'SC_URIBL_HASH', -510;

Added: spamassassin/branches/trunk-welcomelist/t/priorities_welcome_block.t
URL: http://svn.apache.org/viewvc/spamassassin/branches/trunk-welcomelist/t/priorities_welcome_block.t?rev=1899993&view=auto
==============================================================================
--- spamassassin/branches/trunk-welcomelist/t/priorities_welcome_block.t (added)
+++ spamassassin/branches/trunk-welcomelist/t/priorities_welcome_block.t Mon Apr 18 16:30:06 2022
@@ -0,0 +1,109 @@
+#!/usr/bin/perl -T
+
+use lib '.'; use lib 't';
+use SATest; sa_t_init("priorities_welcome_block");
+use strict;
+use Test::More tests => 10;
+
+use Mail::SpamAssassin;
+
+tstlocalrules (q{
+
+  priority USER_IN_WELCOMELIST     -1000
+  priority USER_IN_DEF_WELCOMELIST -1000
+  priority USER_IN_ALL_SPAM_TO   -1000
+  priority SUBJECT_IN_WELCOMELIST  -1000
+
+  priority ALL_TRUSTED            -950
+
+  priority SUBJECT_IN_BLOCKLIST   -900
+  priority USER_IN_BLOCKLIST_TO   -900
+  priority USER_IN_BLOCKLIST      -900
+
+  priority BAYES_99               -400
+
+  header XX_RCVD_IN_SORBS_SMTP     eval:check_rbl_sub('sorbs', '127.0.0.5')
+  tflags XX_RCVD_IN_SORBS_SMTP     net
+  score  XX_RCVD_IN_SORBS_SMTP     1
+
+  meta SC_URIBL_SURBL  (URIBL_BLACK && (URIBL_SC_SURBL || URIBL_JP_SURBL || URIBL_OB_SURBL ) && RCVD_IN_SORBS_SMTP)
+  meta SC_URIBL_HASH   ((URIBL_BLACK || URIBL_SC_SURBL || URIBL_JP_SURBL || URIBL_OB_SURBL) && (RAZOR2_CHECK || DCC_CHECK || PYZOR_CHECK))
+  meta SC_URIBL_SBL    ((URIBL_BLACK || URIBL_SC_SURBL || URIBL_JP_SURBL || URIBL_OB_SURBL) && URIBL_SBL)
+  meta SC_URIBL_BAYES  ((URIBL_BLACK || URIBL_SC_SURBL || URIBL_JP_SURBL || URIBL_OB_SURBL) && BAYES_99)
+
+  shortcircuit SC_URIBL_SURBL        spam
+  shortcircuit SC_URIBL_HASH         spam
+  shortcircuit SC_URIBL_SBL          spam
+  shortcircuit SC_URIBL_BAYES        spam
+
+  priority SC_URIBL_SURBL            -530
+  priority SC_URIBL_HASH             -510
+  priority SC_URIBL_SBL              -510
+  priority SC_URIBL_BAYES            -510
+
+  shortcircuit DIGEST_MULTIPLE       spam
+  priority DIGEST_MULTIPLE           -300
+
+  meta FOO1 (FOO2 && FOO3)
+  meta FOO2 (1)
+  meta FOO3 (FOO4 && FOO5)
+  meta FOO4 (2)
+  meta FOO5 (3)
+  priority FOO5 -23
+  priority FOO1 -28
+
+});
+
+my $sa = create_saobj({
+  dont_copy_prefs => 1,
+  # debug => 1
+});
+
+$sa->init(0); # parse rules
+ok($sa);
+my $conf = $sa->{conf};
+sub assert_rule_pri;
+
+ok assert_rule_pri 'USER_IN_WELCOMELIST', -1000;
+
+ok assert_rule_pri 'SC_URIBL_SURBL', -530;
+ok assert_rule_pri 'SC_URIBL_HASH', -510;
+ok assert_rule_pri 'SC_URIBL_SBL', -510;
+ok assert_rule_pri 'SC_URIBL_BAYES', -510;
+ok assert_rule_pri 'XX_RCVD_IN_SORBS_SMTP', -530;
+
+# SC_URIBL_BAYES will have overridden its base priority setting
+ok assert_rule_pri 'BAYES_99', -510;
+
+ok assert_rule_pri 'FOO5', -28;
+ok assert_rule_pri 'FOO1', -28;
+
+# ---------------------------------------------------------------------------
+
+sub assert_rule_pri {
+  my ($r, $pri) = @_;
+
+  if (defined $conf->{rbl_evals}->{$r} || defined $conf->{meta_tests}->{$r}) {
+    # ignore rbl_evals and metas; they do not use the priority system at all
+    return 1;
+  }
+
+  foreach my $ruletype (qw(
+    body_tests head_tests meta_tests uri_tests rawbody_tests full_tests
+    full_evals rawbody_evals head_evals body_evals
+  ))
+  {
+    if (defined $conf->{$ruletype}->{$pri}->{$r}) {
+      return 1;
+    }
+    foreach my $foundpri (keys %{$conf->{priorities}}) {
+      next unless (defined $conf->{$ruletype}->{$foundpri}->{$r});
+      warn "FAIL: rule '$r' not found at priority $pri; found at $foundpri\n";
+      return 0;
+    }
+  }
+
+  warn "FAIL: no rule '$r' found of any type at any priority\n";
+  return 0;
+}
+

Propchange: spamassassin/branches/trunk-welcomelist/t/priorities_welcome_block.t
------------------------------------------------------------------------------
    svn:executable = *