Mail-SpamAssassin

 view release on metacpan or  search on metacpan

lib/Mail/SpamAssassin/DnsResolver.pm  view on Meta::CPAN

  if ($available_portscount > 0) {
    my $ports_bitset = $conf->{dns_available_ports_bitset};
    my $n = int(rand($available_portscount));
    my $bucket_counts_ref = $conf->{dns_available_portscount_buckets};
    my $ind = 0;
    foreach my $bucket (0..255) {
      # find the bucket containing n-th turned-on bit
      my $cnt = $bucket_counts_ref->[$bucket];
      if ($cnt > $n) { last } else { $n -= $cnt; $ind += 256 }
    }
    while ($ind <= 65535) {  # scans one bucket, runs at most 256 iterations
      # find the n-th turned-on bit within the corresponding bucket
      if (vec($ports_bitset, $ind, 1)) {
        if ($n <= 0) { $port_number = $ind; last } else { $n-- }
      }
      $ind++;
    }
  }
  return $port_number;
}

t/basic_meta2.t  view on Meta::CPAN

#!/usr/bin/perl -T

use lib '.'; 
use lib 't';
use SATest; sa_t_init("basic_meta2");

use Test::More;

# run many times to catch some random natured failures
my $iterations = 5;
plan tests => 24 * $iterations;

# ---------------------------------------------------------------------------

%patterns = (
  q{ 1.0 TEST_FOO_1 }     => '',
  q{ 1.0 TEST_FOO_2 }     => '',
  q{ 1.0 TEST_FOO_3 }     => '',
  q{ 1.0 TEST_META_1 }    => '',
  q{ 1.0 TEST_META_2 }    => '',
  q{ 1.0 TEST_META_3 }    => '',

t/basic_meta2.t  view on Meta::CPAN

   meta __TEST_META_H1  6
   meta __TEST_META_H2  2
   meta __TEST_META_H3  1
   meta TEST_META_H   (__TEST_META_H1 > 2) && (__TEST_META_H2 > 1) && __TEST_META_H3

   # bug 7735, comment 87
   meta __TEST_META_K  (1 || TEST_DISABLED || TEST_DISABLED2 || TEST_DISABLED3)
   meta TEST_META_K  __TEST_META_K
});

for (1 .. $iterations) {
  sarun ("-L -t < data/nice/001 2>&1", \&patterns_run_cb);
  ok_all_patterns();
}

t/dnsbl.t  view on Meta::CPAN

#!/usr/bin/perl -T

use lib '.'; use lib 't';
use SATest; sa_t_init("dnsbl");

use Test::More;
plan skip_all => "Net tests disabled" unless conf_bool('run_net_tests');
plan skip_all => "Can't use Net::DNS Safely" unless can_use_net_dns_safely();

# run many times to catch some random natured failures
my $iterations = 5;
plan tests => 21 * $iterations;

# ---------------------------------------------------------------------------
# bind configuration currently used to support this test
# update when DNS changes for *.dnsbltest.spamassassin.org

my $bind = <<'EOF';

; records to support SA test t/dns.t
;
; 127.0.0.1 -> whitelisted sender

t/dnsbl.t  view on Meta::CPAN

# It also needs to hit even if priority is lower than dnsbl (-100)
meta META_DNSBL_B DNSBL_TEST_SPAM
priority META_DNSBL_B -500
# Or super high
meta META_DNSBL_C DNSBL_TEST_RELAY
priority META_DNSBL_C 2000
priority DNSBL_TEST_RELAY 2000

");

for (1 .. $iterations) {
  clear_localrules() if $_ == 3; # do some tests without any other rules to check meta bugs
  sarun ("-t < data/spam/dnsbl.eml 2>&1", \&patterns_run_cb);
  ok_all_patterns();
}

t/hashbl.t  view on Meta::CPAN

#!/usr/bin/perl -T

use lib '.'; use lib 't';
use SATest; sa_t_init("hashbl");

use Test::More;
plan skip_all => "Net tests disabled"          unless conf_bool('run_net_tests');
plan skip_all => "Can't use Net::DNS Safely"   unless can_use_net_dns_safely();

# run many times to catch some random natured failures
my $iterations = 5;
plan tests => 14 * $iterations;

# ---------------------------------------------------------------------------

%patterns = (
 q{ 1.0 X_HASHBL_EMAIL } => '',
 q{ 1.0 X_HASHBL_OSENDR } => '',
 q{ 1.0 X_HASHBL_BTC } => '',
 q{ 1.0 X_HASHBL_NUM } => '',
 q{ 1.0 X_HASHBL_ONUM } => '',
 q{ 1.0 X_HASHBL_URI } => '',

t/hashbl.t  view on Meta::CPAN

  meta META_HASHBL_EMAIL X_HASHBL_EMAIL
  # It also needs to hit even if priority is lower than dnsbl (-100)
  meta META_HASHBL_BTC X_HASHBL_BTC
  priority META_HASHBL_BTC -500
  # Or super high
  meta META_HASHBL_URI X_HASHBL_URI
  priority META_HASHBL_URI 2000
  priority X_HASHBL_URI 2000
});

for (1 .. $iterations) {
  clear_localrules() if $_ == 3; # do some tests without any other rules to check meta bugs
  ok sarun ("-t -D async,dns,HashBL < data/spam/hashbl 2>&1", \&patterns_run_cb);
  ok(check_queries());
  ok_all_patterns();
}

t/rule_names.t  view on Meta::CPAN

EOF

    # we are looking for random failures, but we do a deterministic
    # test to prevent too much frustration with "make test".

    # start off sorted
    @tests = sort @tests;

    print MAIL join("\n", @tests) . "\n\n";

    # 25 iterations gets most hits most of the time, but 10 is large enough
    for (1..10) {
      print MAIL join("\n", sha1_shuffle($_, @tests)) . "\n\n";
    }
    close(MAIL);
  }
  else {
    die "can't open output file: $!";
  }
}

t/spamd_hup.t  view on Meta::CPAN

  # now, wait for the PID file to change or disappear; the real order
  # is [SIGHUP, unlink, exec, create] but due to race conditions under
  # load we could have missed the unlink, exec, create part.

  dbgprint "Waiting for PID file to change...\n";
  wait_for_file_to_change_or_disappear($spamd_pidfile, 20, sub {
          $pid1 and kill ('HUP', $pid1);
        });

  dbgprint "Waiting for spamd at pid $pid1 to restart...\n";
    # 26 iterations is 98 seconds, RPi ARM6 takes about 66 seconds
  wait_for_file_to_appear ($spamd_pidfile, 26);

  ok (-e $spamd_pidfile) or warn "$spamd_pidfile does not exist post restart";
  ok (!-z $spamd_pidfile) or warn "$spamd_pidfile is empty post restart";

  ok ($pid2 = read_from_pidfile($spamd_pidfile));
  dbgprint "Looking for new spamd at pid $pid2...\n";
  #ok ($pid2 != $pid1);     # no longer guaranteed with SIGHUP
  ok ($pid2 != 0 and kill (0, $pid2));

t/uribl.t  view on Meta::CPAN

#!/usr/bin/perl -T

use lib '.'; use lib 't';
use SATest; sa_t_init("uribl");

use Test::More;
plan skip_all => "Net tests disabled"          unless conf_bool('run_net_tests');
plan skip_all => "Can't use Net::DNS Safely"   unless can_use_net_dns_safely();

# run many times to catch some random natured failures
my $iterations = 5;
plan tests => 10 * $iterations;

# ---------------------------------------------------------------------------

%patterns = (
 q{ 1.0 X_URIBL_A } => '',
 q{ 1.0 X_URIBL_B } => '',
 q{ 1.0 X_URIBL_NS } => '',
 q{ 1.0 X_URIBL_DOMSONLY } => '',
 q{ 1.0 META_URIBL_A } => '',
 q{ 1.0 META_URIBL_B } => '',

t/uribl.t  view on Meta::CPAN

  priority META_URIBL_NS 2000
  priority X_URIBL_NS 2000

  # Bug 7835 - tflags notrim
  urirhssub  X_URIBL_NOTRIM  dnsbltest.spamassassin.org.    A 16
  body       X_URIBL_NOTRIM  eval:check_uridnsbl('X_URIBL_NOTRIM')
  tflags     X_URIBL_NOTRIM  net domains_only notrim

});

for (1 .. $iterations) {
  clear_localrules() if $_ == 3; # do some tests without any other rules to check meta bugs
  ok sarun ("-t < data/spam/dnsbl.eml", \&patterns_run_cb);
  ok_all_patterns();
}



( run in 0.950 second using v1.01-cache-2.11-cpan-71847e10f99 )