qpsmtpd/t/plugin_tests/check_badmailfrom

81 lines
2.4 KiB
Plaintext
Raw Normal View History

use strict;
use Data::Dumper;
use Qpsmtpd::Address;
sub register_tests {
my $self = shift;
2012-04-29 11:46:03 +02:00
$self->register_test("test_badmailfrom_match", 7);
$self->register_test("test_badmailfrom_hook_mail", 4);
$self->register_test("test_badmailfrom_hook_rcpt", 2);
}
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'];
$transaction->notes('badmailfrom', '');
my ($r) = $self->hook_mail( $transaction, $address );
ok( $r == 909, "badmailfrom hook_mail");
ok( $transaction->notes('badmailfrom') eq 'Your envelope sender is in my badmailfrom list',
"badmailfrom hook_mail: default reason");
$self->{_badmailfrom_config} = ['matt@test.net','matt@test.com Yer a spammin bastert'];
$transaction->notes('badmailfrom', '');
2012-04-29 11:46:03 +02:00
($r) = $self->hook_mail( $transaction, $address );
ok( $r == 909, "badmailfrom hook_mail");
ok( $transaction->notes('badmailfrom') eq 'Yer a spammin bastert',
"badmailfrom hook_mail: custom reason");
};
sub test_badmailfrom_hook_rcpt {
my $self = shift;
my $transaction = $self->qp->transaction;
$transaction->notes('badmailfrom', 'Yer a spammin bastart. Be gon wit yuh.' );
my ($code,$note) = $self->hook_rcpt( $transaction );
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");
};