2012-05-05 06:27:16 +02:00
|
|
|
#!perl -w
|
2012-04-26 10:52:21 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Data::Dumper;
|
|
|
|
|
|
|
|
use Qpsmtpd::Address;
|
|
|
|
|
|
|
|
sub register_tests {
|
|
|
|
my $self = shift;
|
|
|
|
|
2012-06-03 03:44:46 +02:00
|
|
|
$self->register_test("test_badmailfrom_is_immune_sender", 5);
|
2012-04-29 11:46:03 +02:00
|
|
|
$self->register_test("test_badmailfrom_match", 7);
|
|
|
|
$self->register_test("test_badmailfrom_hook_mail", 4);
|
2012-06-22 11:38:01 +02:00
|
|
|
$self->register_test("test_badmailfrom_rcpt_handler", 2);
|
2012-04-26 10:52:21 +02:00
|
|
|
}
|
|
|
|
|
2012-06-03 03:44:46 +02:00
|
|
|
sub test_badmailfrom_is_immune_sender {
|
2012-05-05 06:27:16 +02:00
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
my $transaction = $self->qp->transaction;
|
|
|
|
my $test_email = 'matt@test.com';
|
|
|
|
my $address = Qpsmtpd::Address->new( "<$test_email>" );
|
|
|
|
$transaction->sender($address);
|
2012-06-03 03:44:46 +02:00
|
|
|
ok( $self->is_immune_sender( $transaction->sender, [] ), "empty list");
|
2012-05-05 06:27:16 +02:00
|
|
|
|
|
|
|
$address = Qpsmtpd::Address->new( '<>' );
|
|
|
|
$transaction->sender($address);
|
2012-06-03 03:44:46 +02:00
|
|
|
ok( $self->is_immune_sender( $transaction->sender, ['bad@example.com'] ), "null sender");
|
2012-05-05 06:27:16 +02:00
|
|
|
|
|
|
|
$address = Qpsmtpd::Address->new( '<matt@>' );
|
|
|
|
$transaction->sender($address);
|
2012-06-03 03:44:46 +02:00
|
|
|
ok( $self->is_immune_sender( $transaction->sender, ['bad@example.com'] ), "missing host");
|
2012-05-05 06:27:16 +02:00
|
|
|
|
|
|
|
$address = Qpsmtpd::Address->new( '<@example.com>' );
|
|
|
|
$transaction->sender($address);
|
2012-06-03 03:44:46 +02:00
|
|
|
ok( $self->is_immune_sender( $transaction->sender, ['bad@example.com'] ), "missing user");
|
2012-05-05 06:27:16 +02:00
|
|
|
|
|
|
|
$address = Qpsmtpd::Address->new( '<matt@example.com>' );
|
|
|
|
$transaction->sender($address);
|
2012-06-03 03:44:46 +02:00
|
|
|
ok( ! $self->is_immune_sender( $transaction->sender, ['bad@example.com'] ), "false");
|
2012-05-05 06:27:16 +02:00
|
|
|
};
|
|
|
|
|
2012-04-26 10:52:21 +02:00
|
|
|
sub test_badmailfrom_hook_mail {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
my $transaction = $self->qp->transaction;
|
|
|
|
|
|
|
|
my $test_email = 'matt@test.com';
|
|
|
|
my $address = Qpsmtpd::Address->new( "<$test_email>" );
|
|
|
|
$transaction->sender($address);
|
|
|
|
|
|
|
|
$self->{_badmailfrom_config} = ['matt@test.net','matt@test.com'];
|
2012-06-22 11:38:01 +02:00
|
|
|
$self->connection->notes('badmailfrom', '');
|
2012-04-26 10:52:21 +02:00
|
|
|
my ($r) = $self->hook_mail( $transaction, $address );
|
|
|
|
ok( $r == 909, "badmailfrom hook_mail");
|
2012-06-22 11:38:01 +02:00
|
|
|
cmp_ok( $self->connection->notes('naughty'), 'eq', 'Your envelope sender is in my badmailfrom list', "default reason");
|
2012-04-26 10:52:21 +02:00
|
|
|
|
|
|
|
$self->{_badmailfrom_config} = ['matt@test.net','matt@test.com Yer a spammin bastert'];
|
2012-06-22 11:38:01 +02:00
|
|
|
$self->connection->notes('badmailfrom', '');
|
2012-04-29 11:46:03 +02:00
|
|
|
($r) = $self->hook_mail( $transaction, $address );
|
2012-04-26 10:52:21 +02:00
|
|
|
ok( $r == 909, "badmailfrom hook_mail");
|
2012-06-22 11:38:01 +02:00
|
|
|
cmp_ok( $self->connection->notes('naughty'), 'eq', 'Yer a spammin bastert', "custom reason");
|
2012-04-26 10:52:21 +02:00
|
|
|
};
|
|
|
|
|
2012-06-22 11:38:01 +02:00
|
|
|
sub test_badmailfrom_rcpt_handler {
|
2012-04-26 10:52:21 +02:00
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
my $transaction = $self->qp->transaction;
|
|
|
|
|
|
|
|
$transaction->notes('badmailfrom', 'Yer a spammin bastart. Be gon wit yuh.' );
|
|
|
|
|
2012-06-22 11:38:01 +02:00
|
|
|
my ($code,$note) = $self->rcpt_handler( $transaction );
|
2012-04-26 10:52:21 +02:00
|
|
|
|
|
|
|
ok( $code == 901, 'badmailfrom hook hit');
|
|
|
|
ok( $note, $note );
|
|
|
|
}
|
|
|
|
|
|
|
|
sub test_badmailfrom_match {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# is_match receives ( $from, $bad, $host )
|
|
|
|
|
|
|
|
my $r = $self->is_match( 'matt@test.net', 'matt@test.net', 'test.net' );
|
|
|
|
ok($r, "check_badmailfrom match");
|
|
|
|
|
|
|
|
ok( ! $self->is_match( 'matt@test.net', 'matt@test.com', 'tnpi.net' ),
|
|
|
|
"check_badmailfrom non-match");
|
|
|
|
|
|
|
|
ok( $self->is_match( 'matt@test.net', '@test.net', 'test.net' ),
|
|
|
|
"check_badmailfrom match host");
|
|
|
|
|
|
|
|
ok( ! $self->is_match( 'matt@test.net', '@test.not', 'test.net' ),
|
|
|
|
"check_badmailfrom non-match host");
|
|
|
|
|
|
|
|
ok( ! $self->is_match( 'matt@test.net', '@test.net', 'test.not' ),
|
|
|
|
"check_badmailfrom non-match host");
|
|
|
|
|
|
|
|
ok( $self->is_match( 'matt@test.net', 'test.net$', 'tnpi.net' ),
|
|
|
|
"check_badmailfrom pattern match");
|
|
|
|
|
|
|
|
ok( ! $self->is_match( 'matt@test.net', 'test.not$', 'tnpi.net' ),
|
|
|
|
"check_badmailfrom pattern non-match");
|
|
|
|
};
|
|
|
|
|