forked from smtpd/qpsmtpd
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merged check_badmailfrom_patterns into check_badmailfrom
- Loading branch information
Showing
3 changed files
with
155 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
|
||
use strict; | ||
use Data::Dumper; | ||
|
||
use Qpsmtpd::Address; | ||
|
||
sub register_tests { | ||
my $self = shift; | ||
|
||
$self->register_test("test_badmailfrom_match", 1); | ||
$self->register_test("test_badmailfrom_hook_mail", 1); | ||
$self->register_test("test_badmailfrom_hook_rcpt", 1); | ||
} | ||
|
||
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', ''); | ||
my ($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"); | ||
}; | ||
|
||
|