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 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
#!/usr/bin/perl -T
use lib '.'; use lib 't';
use SATest; sa_t_init("welcomelist_addrs");
use IO::File;
use constant HAS_DB_FILE => eval { require DB_File };
use Test::More;
plan skip_all => 'Long running tests disabled' unless conf_bool('run_long_tests');
plan skip_all => 'Need DB_File for this test' unless HAS_DB_FILE;
plan tests => 35;
# ---------------------------------------------------------------------------
tstpre ("
loadplugin Mail::SpamAssassin::Plugin::AWL
");
tstprefs ("
header AWL eval:check_from_in_auto_welcomelist()
tflags AWL userconf noautolearn
priority AWL 1000
");
%added_address_welcomelist_patterns = (
q{SpamAssassin auto-welcomelist: adding address to welcomelist:}, 'added address to welcomelist',
);
%added_address_blocklist_patterns = (
q{SpamAssassin auto-welcomelist: adding address to blocklist:}, 'added address to blocklist',
);
%removed_address_patterns = (
q{SpamAssassin auto-welcomelist: removing address:}, 'removed address',
);
%is_nonspam_patterns = (
q{X-Spam-Status: No}, 'spamno',
);
%is_spam_patterns = (
q{X-Spam-Status: Yes}, 'spamyes',
);
%patterns = %added_address_welcomelist_patterns;
ok(sarun ("--add-addr-to-welcomelist whitelist_test\@whitelist.spamassassin.taint.org", \&patterns_run_cb));
ok_all_patterns();
%patterns = %is_nonspam_patterns;
ok (sarun ("-L < data/nice/002", \&patterns_run_cb));
ok_all_patterns();
%patterns = %is_nonspam_patterns;
sarun ("-L < data/spam/004", \&patterns_run_cb);
ok_all_patterns();
%patterns = %removed_address_patterns;
ok(sarun ("--remove-addr-from-welcomelist whitelist_test\@whitelist.spamassassin.taint.org", \&patterns_run_cb));
ok_all_patterns();
%patterns = %is_spam_patterns;
sarun ("-L < data/spam/004", \&patterns_run_cb);
ok_all_patterns();
%patterns = %added_address_blocklist_patterns;
ok(sarun ("--add-addr-to-blocklist whitelist_test\@whitelist.spamassassin.taint.org", \&patterns_run_cb));
ok_all_patterns();
%patterns = %is_spam_patterns;
sarun ("-L < data/nice/002", \&patterns_run_cb);
ok_all_patterns();
ok(sarun ("--remove-addr-from-welcomelist whitelist_test\@whitelist.spamassassin.taint.org", \&patterns_run_cb));
# The following section tests the object oriented interface to adding/removing welcomelist
# and blocklist entries. Primarily this is testing basic functionality and that the
# "print" commands that are present in the command line interface are not being printed
# when you call the methods directly. This is why we are manipulating STDOUT.
open my $oldout, ">&STDOUT" || die "Cannot dup STDOUT";
my $fh = IO::File->new_tmpfile();
ok($fh);
open(STDOUT, ">&=".fileno($fh)) || die "Cannot reopen STDOUT";
select STDOUT; $| = 1;
my $sa = create_saobj();
$sa->init();
$sa->add_address_to_welcomelist("whitelist_test\@whitelist.spamassassin.taint.org");
seek($fh, 0, 0);
my $error = do {
local $/;
<$fh>;
};
$fh->close();
open STDOUT, ">&".fileno($oldout) || die "Cannot dupe \$oldout: $!";
select STDOUT; $| = 1;
#warn "# $error\n";
ok($error !~ /SpamAssassin auto-welcomelist: /);
%patterns = %is_nonspam_patterns;
ok (sarun ("-L < data/nice/002", \&patterns_run_cb));
ok_all_patterns();
%patterns = %is_nonspam_patterns;
sarun ("-L < data/spam/004", \&patterns_run_cb);
ok_all_patterns();
$fh = IO::File->new_tmpfile();
ok($fh);
open(STDOUT, ">&=".fileno($fh)) || die "Cannot reopen STDOUT";
select STDOUT; $| = 1;
$sa->remove_address_from_welcomelist("whitelist_test\@whitelist.spamassassin.taint.org");
seek($fh, 0, 0);
$error = do {
local $/;
<$fh>;
};
$fh->close();
open STDOUT, ">&".fileno($oldout) || die "Cannot dupe \$oldout: $!";
select STDOUT; $| = 1;
#warn "# $error\n";
ok($error !~ /SpamAssassin auto-welcomelist: /);
%patterns = %is_spam_patterns;
sarun ("-L < data/spam/004", \&patterns_run_cb);
ok_all_patterns();
$fh = IO::File->new_tmpfile();
ok($fh);
open(STDOUT, ">&=".fileno($fh)) || die "Cannot reopen STDOUT";
select STDOUT; $| = 1;
$sa->add_address_to_blocklist("whitelist_test\@whitelist.spamassassin.taint.org");
seek($fh, 0, 0);
$error = do {
local $/;
<$fh>;
};
$fh->close();
open STDOUT, ">&".fileno($oldout) || die "Cannot dupe \$oldout: $!";
select STDOUT; $| = 1;
#warn "# $error\n";
ok($error !~ /SpamAssassin auto-welcomelist: /);
%patterns = %is_spam_patterns;
sarun ("-L < data/nice/002", \&patterns_run_cb);
ok_all_patterns();
$sa->remove_address_from_welcomelist("whitelist_test\@whitelist.spamassassin.taint.org");
# Now we can test the "all" methods
open(MAIL,"< data/nice/002");
my $raw_message = do {
local $/;
<MAIL>;
};
close(MAIL);
ok($raw_message);
my $mail = $sa->parse( $raw_message );
$fh = IO::File->new_tmpfile();
ok($fh);
open(STDOUT, ">&=".fileno($fh)) || die "Cannot reopen STDOUT";
select STDOUT; $| = 1;
$sa->add_all_addresses_to_welcomelist($mail);
seek($fh, 0, 0);
$error = do {
local $/;
<$fh>;
};
$fh->close();
open STDOUT, ">&".fileno($oldout) || die "Cannot dupe \$oldout: $!";
select STDOUT; $| = 1;
#warn "# $error\n";
ok($error !~ /SpamAssassin auto-welcomelist: /);
%patterns = %is_nonspam_patterns;
ok (sarun ("-L < data/nice/002", \&patterns_run_cb));
ok_all_patterns();
%patterns = %is_nonspam_patterns;
sarun ("-L < data/spam/004", \&patterns_run_cb);
ok_all_patterns();
$fh = IO::File->new_tmpfile();
ok($fh);
open(STDOUT, ">&=".fileno($fh)) || die "Cannot reopen STDOUT";
select STDOUT; $| = 1;
$sa->remove_all_addresses_from_welcomelist($mail);
seek($fh, 0, 0);
$error = do {
local $/;
<$fh>;
};
$fh->close();
open STDOUT, ">&".fileno($oldout) || die "Cannot dupe \$oldout: $!";
select STDOUT; $| = 1;
#warn "# $error\n";
ok($error !~ /SpamAssassin auto-welcomelist: /);
%patterns = %is_spam_patterns;
sarun ("-L < data/spam/004", \&patterns_run_cb);
ok_all_patterns();
$fh = IO::File->new_tmpfile();
ok($fh);
open(STDOUT, ">&=".fileno($fh)) || die "Cannot reopen STDOUT";
select STDOUT; $| = 1;
$sa->add_all_addresses_to_blocklist($mail);
seek($fh, 0, 0);
$error = do {
local $/;
<$fh>;
};
$fh->close();
open STDOUT, ">&".fileno($oldout) || die "Cannot dupe \$oldout: $!";
select STDOUT; $| = 1;
#warn "# $error\n";
ok($error !~ /SpamAssassin auto-welcomelist: /);
%patterns = %is_spam_patterns;
sarun ("-L < data/nice/002", \&patterns_run_cb);
ok_all_patterns();
$sa->remove_all_addresses_from_welcomelist($mail);
|