1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
#!/usr/bin/perl -T
use lib '.'; use lib 't';
use SATest; sa_t_init("spamd_client");
use constant HAS_SDBM_FILE => eval { require SDBM_File; };
use Test::More;
plan skip_all => "Disabling this test for now";
plan skip_all => "Spamd tests disabled" if $SKIP_SPAMD_TESTS;
plan skip_all => "Long running tests disabled" unless conf_bool('run_long_tests');
diag "\nIf test fails 'connection reset by peer', may be low memory on test machine";
# TODO: These should be skips down in the code, not changing the test count.
my $num_tests = 18;
# UNIX socket tests
if (!$RUNNING_ON_WINDOWS) {
$num_tests += 13;
}
# learn tests
if (HAS_SDBM_FILE) {
$num_tests += 21;
}
plan tests => $num_tests;
# ---------------------------------------------------------------------------
my $testmsg = getmessage("data/spam/gtube.eml");
ok($testmsg);
%patterns = (
qr/^X-Spam-Flag: YES/m, 'flag',
q{ 1000 GTUBE }, 'gtube',
'XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X', 'gtube string',
);
# Bug 8253 - starting spamd after creating client object makes test failures
# caused by low memory on test machine less likely.
my $client = create_clientobj({
port => $spamdport,
host => $spamdhost,
});
ok($client);
ok(start_spamd("-L"));
ok($client->ping());
my $result = $client->check($testmsg);
ok($result);
ok($result->{isspam} eq 'True');
ok(!$result->{message});
$result = $client->process($testmsg);
ok($result);
ok($result->{isspam} eq 'True');
ok($result->{message});
patterns_run_cb($result->{message});
ok_all_patterns();
clear_pattern_counters();
%patterns = (
qr/^X-Spam-Flag: YES/m, 'flag',
);
%anti_patterns = (
'XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X', 'gtube string',
);
$result = $client->headers($testmsg);
ok($result);
ok($result->{message});
patterns_run_cb($result->{message});
ok_all_patterns();
ok(stop_spamd());
if (!$RUNNING_ON_WINDOWS) {
clear_pattern_counters();
$spamd_already_killed = undef;
%patterns = (
qr/^X-Spam-Flag: YES/m, 'flag',
q{ 1000 GTUBE }, 'gtube',
'XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X', 'gtube string',
);
%anti_patterns = ();
my $sockpath = mk_socket_tempdir()."/spamd.sock";
$client = create_clientobj({
socketpath => $sockpath,
});
ok($client);
ok(start_spamd("-L --socketpath=$sockpath"));
ok($client->ping());
$result = $client->check($testmsg);
ok($result);
ok($result->{isspam} eq 'True');
ok(!$result->{message});
$result = $client->process($testmsg);
ok($result);
ok($result->{isspam} eq 'True');
ok($result->{message});
patterns_run_cb($result->{message});
ok_all_patterns();
ok(stop_spamd());
}
if (HAS_SDBM_FILE) {
clear_pattern_counters();
$spamd_already_killed = undef;
tstprefs ("
bayes_store_module Mail::SpamAssassin::BayesStore::SDBM
");
my $client = create_clientobj({
port => $spamdport,
host => $spamdhost,
});
ok($client);
my $spammsg = getmessage("data/spam/001");
ok($spammsg);
ok(start_spamd("-L --allow-tell"));
ok($client->learn($spammsg, 0));
ok(!$client->learn($spammsg, 0));
%patterns = ( '1 0 non-token data: nspam' => 'spam in database' );
ok(salearnrun("--dump magic", \&patterns_run_cb));
ok_all_patterns();
clear_pattern_counters();
ok($client->learn($spammsg, 2));
%patterns = ( '0 0 non-token data: nspam' => 'spam in database',
'0 0 non-token data: nham' => 'ham in database' );
ok(salearnrun("--dump magic", \&patterns_run_cb));
ok_all_patterns();
clear_pattern_counters();
my $hammsg = getmessage("data/nice/001");
ok($hammsg);
ok($client->learn($spammsg, 1));
ok(!$client->learn($spammsg, 1));
%patterns = ( '1 0 non-token data: nham' => 'ham in database' );
ok(salearnrun("--dump magic", \&patterns_run_cb));
ok_all_patterns();
clear_pattern_counters();
ok($client->learn($spammsg, 2));
%patterns = ( '0 0 non-token data: nspam' => 'spam in database',
'0 0 non-token data: nham' => 'ham in database' );
ok(salearnrun("--dump magic", \&patterns_run_cb));
ok_all_patterns();
clear_pattern_counters();
ok(stop_spamd());
}
sub getmessage {
my ($msgpath) = @_;
open(MSG, $msgpath) || return undef;
my @file = <MSG>;
my $msg = join('', @file);
close(MSG);
return $msg;
}
|