2012-05-06 04:58:49 +02:00
|
|
|
#!perl -w
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Mail::Header;
|
|
|
|
use Qpsmtpd::Constants;
|
|
|
|
|
|
|
|
my $r;
|
|
|
|
|
|
|
|
sub register_tests {
|
|
|
|
my $self = shift;
|
|
|
|
|
2014-09-17 08:16:53 +02:00
|
|
|
$self->register_test('test_get_dspam_results');
|
|
|
|
$self->register_test('test_log_and_return');
|
|
|
|
$self->register_test('test_reject_type');
|
2012-05-06 04:58:49 +02:00
|
|
|
}
|
|
|
|
|
2012-06-22 11:38:01 +02:00
|
|
|
sub test_log_and_return {
|
2012-05-06 04:58:49 +02:00
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
my $transaction = $self->qp->transaction;
|
|
|
|
|
|
|
|
# reject not set
|
2012-11-17 02:03:10 +01:00
|
|
|
$self->{_args}{reject} = undef;
|
2012-05-06 04:58:49 +02:00
|
|
|
$transaction->notes('dspam', { class=> 'Spam', probability => .99, confidence=>1 } );
|
2012-06-22 11:38:01 +02:00
|
|
|
($r) = $self->log_and_return( $transaction );
|
|
|
|
cmp_ok( $r, '==', DECLINED, "($r)");
|
2012-05-06 04:58:49 +02:00
|
|
|
|
|
|
|
# reject exceeded
|
2012-06-22 11:38:01 +02:00
|
|
|
$self->{_args}{reject} = .95;
|
2012-05-06 04:58:49 +02:00
|
|
|
$transaction->notes('dspam', { class=> 'Spam', probability => .99, confidence=>1 } );
|
2012-06-22 11:38:01 +02:00
|
|
|
($r) = $self->log_and_return( $transaction );
|
|
|
|
cmp_ok( $r, '==', DENY, "($r)");
|
2012-05-06 04:58:49 +02:00
|
|
|
|
|
|
|
# below reject threshold
|
|
|
|
$transaction->notes('dspam', { class=> 'Spam', probability => .94, confidence=>1 } );
|
2012-06-22 11:38:01 +02:00
|
|
|
($r) = $self->log_and_return( $transaction );
|
|
|
|
cmp_ok( $r, '==', DECLINED, "($r)");
|
2012-05-06 04:58:49 +02:00
|
|
|
|
|
|
|
# requires agreement
|
2012-06-22 11:38:01 +02:00
|
|
|
$self->{_args}{reject} = 'agree';
|
2012-05-11 07:50:06 +02:00
|
|
|
$transaction->notes('spamassassin', { is_spam => 'Yes', score => 25 } );
|
2012-05-06 04:58:49 +02:00
|
|
|
$transaction->notes('dspam', { class=> 'Spam', probability => .90, confidence=>1 } );
|
2012-06-22 11:38:01 +02:00
|
|
|
($r) = $self->log_and_return( $transaction );
|
|
|
|
cmp_ok( $r, '==', DENY, "($r)");
|
2012-05-06 04:58:49 +02:00
|
|
|
|
|
|
|
# requires agreement
|
2012-05-11 07:50:06 +02:00
|
|
|
$transaction->notes('spamassassin', { is_spam => 'No', score => 15 } );
|
2012-05-06 04:58:49 +02:00
|
|
|
$transaction->notes('dspam', { class=> 'Spam', probability => .96, confidence=>1 } );
|
2012-06-22 11:38:01 +02:00
|
|
|
($r) = $self->log_and_return( $transaction );
|
|
|
|
cmp_ok( $r, '==', DECLINED, "($r)");
|
2012-05-06 04:58:49 +02:00
|
|
|
|
|
|
|
# requires agreement
|
2012-05-11 07:50:06 +02:00
|
|
|
$transaction->notes('spamassassin', { is_spam => 'Yes', score => 10 } );
|
2012-05-06 04:58:49 +02:00
|
|
|
$transaction->notes('dspam', { class=> 'Innocent', probability => .96, confidence=>1 } );
|
2012-06-22 11:38:01 +02:00
|
|
|
($r) = $self->log_and_return( $transaction );
|
|
|
|
cmp_ok( $r, '==', DECLINED, "($r)");
|
2012-05-06 04:58:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
2012-06-22 11:38:01 +02:00
|
|
|
ok( ref $r, "r: ($header)" );
|
2012-05-06 04:58:49 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2012-06-22 11:38:01 +02:00
|
|
|
sub test_reject_type {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
$self->{_args}{reject_type} = undef;
|
|
|
|
cmp_ok( $self->get_reject_type(), '==', DENY, "default");
|
|
|
|
|
|
|
|
$self->{_args}{reject_type} = 'temp';
|
|
|
|
cmp_ok( $self->get_reject_type(), '==', DENYSOFT, "defer");
|
|
|
|
|
|
|
|
$self->{_args}{reject_type} = 'disconnect';
|
|
|
|
cmp_ok( $self->get_reject_type(), '==', DENY_DISCONNECT, "disconnect");
|
|
|
|
};
|