98 lines
3.2 KiB
Plaintext
98 lines
3.2 KiB
Plaintext
|
#!perl -w
|
||
|
|
||
|
use strict;
|
||
|
use warnings;
|
||
|
|
||
|
use Mail::Header;
|
||
|
use Qpsmtpd::Constants;
|
||
|
|
||
|
my $r;
|
||
|
|
||
|
sub register_tests {
|
||
|
my $self = shift;
|
||
|
|
||
|
$self->register_test('test_get_filter_cmd', 2);
|
||
|
$self->register_test('test_get_dspam_results', 6);
|
||
|
$self->register_test('test_dspam_reject', 6);
|
||
|
}
|
||
|
|
||
|
sub test_dspam_reject {
|
||
|
my $self = shift;
|
||
|
|
||
|
my $transaction = $self->qp->transaction;
|
||
|
|
||
|
# reject not set
|
||
|
$transaction->notes('dspam', { class=> 'Spam', probability => .99, confidence=>1 } );
|
||
|
($r) = $self->dspam_reject( $transaction );
|
||
|
cmp_ok( $r, '==', DECLINED, "dspam_reject ($r)");
|
||
|
|
||
|
# reject exceeded
|
||
|
$self->{_args}->{reject} = .95;
|
||
|
$transaction->notes('dspam', { class=> 'Spam', probability => .99, confidence=>1 } );
|
||
|
($r) = $self->dspam_reject( $transaction );
|
||
|
cmp_ok( $r, '==', DENY, "dspam_reject ($r)");
|
||
|
|
||
|
# below reject threshold
|
||
|
$transaction->notes('dspam', { class=> 'Spam', probability => .94, confidence=>1 } );
|
||
|
($r) = $self->dspam_reject( $transaction );
|
||
|
cmp_ok( $r, '==', DECLINED, "dspam_reject ($r)");
|
||
|
|
||
|
# requires agreement
|
||
|
$self->{_args}->{reject} = 'agree';
|
||
|
$transaction->notes('spamassassin', { is_spam => 'Yes' } );
|
||
|
$transaction->notes('dspam', { class=> 'Spam', probability => .90, confidence=>1 } );
|
||
|
($r) = $self->dspam_reject( $transaction );
|
||
|
cmp_ok( $r, '==', DENY, "dspam_reject ($r)");
|
||
|
|
||
|
# requires agreement
|
||
|
$transaction->notes('spamassassin', { is_spam => 'No' } );
|
||
|
$transaction->notes('dspam', { class=> 'Spam', probability => .96, confidence=>1 } );
|
||
|
($r) = $self->dspam_reject( $transaction );
|
||
|
cmp_ok( $r, '==', DECLINED, "dspam_reject ($r)");
|
||
|
|
||
|
# requires agreement
|
||
|
$transaction->notes('spamassassin', { is_spam => 'Yes' } );
|
||
|
$transaction->notes('dspam', { class=> 'Innocent', probability => .96, confidence=>1 } );
|
||
|
($r) = $self->dspam_reject( $transaction );
|
||
|
cmp_ok( $r, '==', DECLINED, "dspam_reject ($r)");
|
||
|
};
|
||
|
|
||
|
sub test_get_dspam_results {
|
||
|
my $self = shift;
|
||
|
|
||
|
my $transaction = $self->qp->transaction;
|
||
|
my $header = Mail::Header->new(Modify => 0, MailFrom => "COERCE");
|
||
|
$transaction->header( $header );
|
||
|
|
||
|
my @dspam_sample_headers = (
|
||
|
'Innocent, probability=0.0000, confidence=0.69',
|
||
|
'Innocent, probability=0.0000, confidence=0.85',
|
||
|
'Innocent, probability=0.0023, confidence=1.00',
|
||
|
'Spam, probability=1.0000, confidence=0.87',
|
||
|
'Spam, probability=1.0000, confidence=0.99',
|
||
|
'Whitelisted',
|
||
|
);
|
||
|
|
||
|
foreach my $header ( @dspam_sample_headers ) {
|
||
|
$transaction->header->delete('X-DSPAM-Result');
|
||
|
$transaction->header->add('X-DSPAM-Result', $header);
|
||
|
my $r = $self->get_dspam_results($transaction);
|
||
|
ok( ref $r, "get_dspam_results ($header)" );
|
||
|
#warn Data::Dumper::Dumper($r);
|
||
|
};
|
||
|
};
|
||
|
|
||
|
sub test_get_filter_cmd {
|
||
|
my $self = shift;
|
||
|
|
||
|
my $transaction = $self->qp->transaction;
|
||
|
my $dspam = "/usr/local/bin/dspam";
|
||
|
$self->{_args}{dspam_bin} = $dspam;
|
||
|
|
||
|
foreach my $user ( qw/ smtpd matt@example.com / ) {
|
||
|
my $answer = "$dspam --user smtpd --mode=tum --process --deliver=summary --stdout";
|
||
|
my $r = $self->get_filter_cmd($transaction, 'smtpd');
|
||
|
cmp_ok( $r, 'eq', $answer, "get_filter_cmd $user" );
|
||
|
};
|
||
|
};
|