2012-05-11 07:50:04 +02:00
|
|
|
#!perl -w
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Qpsmtpd::Constants;
|
2007-03-15 07:55:24 +01:00
|
|
|
|
|
|
|
sub register_tests {
|
|
|
|
my $self = shift;
|
2012-05-11 07:50:04 +02:00
|
|
|
|
2014-09-17 08:16:53 +02:00
|
|
|
$self->register_test('test_get_rcpt_host');
|
|
|
|
$self->register_test('test_is_in_rcpthosts');
|
|
|
|
$self->register_test('test_is_in_morercpthosts');
|
|
|
|
$self->register_test('test_hook_rcpt');
|
2007-03-15 07:55:24 +01:00
|
|
|
}
|
|
|
|
|
2012-05-11 07:50:04 +02:00
|
|
|
sub test_hook_rcpt {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
my $transaction = $self->qp->transaction;
|
|
|
|
|
|
|
|
my $address = Qpsmtpd::Address->parse('<user@localhost>');
|
|
|
|
my ($r, $mess) = $self->hook_rcpt( $transaction, $address );
|
2012-06-23 06:54:27 +02:00
|
|
|
cmp_ok( $r, '==', OK, "localhost");
|
2012-05-11 07:50:04 +02:00
|
|
|
|
|
|
|
$address = Qpsmtpd::Address->parse('<user@example.com>');
|
|
|
|
($r, $mess) = $self->hook_rcpt( $transaction, $address );
|
2012-06-23 06:54:27 +02:00
|
|
|
cmp_ok( $r, '==', DENY, "example.com");
|
2012-05-11 07:50:04 +02:00
|
|
|
|
|
|
|
$self->qp->connection->relay_client(1);
|
|
|
|
($r, $mess) = $self->hook_rcpt( $transaction, $address );
|
2012-06-23 06:54:27 +02:00
|
|
|
cmp_ok( $r, '==', OK, "example.com");
|
2012-05-11 07:50:04 +02:00
|
|
|
$self->qp->connection->relay_client(0);
|
|
|
|
};
|
|
|
|
|
|
|
|
sub test_is_in_rcpthosts {
|
2007-03-15 07:55:24 +01:00
|
|
|
my $self = shift;
|
2012-05-11 07:50:04 +02:00
|
|
|
|
|
|
|
my @hosts = $self->qp->config('rcpthosts');
|
|
|
|
my $host = $hosts[0];
|
|
|
|
|
|
|
|
if ( $host ) {
|
|
|
|
ok( $self->is_in_rcpthosts( $host ), "is_in_rcpthosts, $host");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ok(1, "is_in_rcpthosts (skip, no entries)" );
|
|
|
|
};
|
|
|
|
|
|
|
|
ok( $self->is_in_rcpthosts( 'localhost' ), "is_in_rcpthosts +");
|
|
|
|
ok( ! $self->is_in_rcpthosts( 'example.com' ), "is_in_rcpthosts -");
|
|
|
|
};
|
|
|
|
|
|
|
|
sub test_is_in_morercpthosts {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
my $ref = $self->qp->config('morercpthosts', 'map');
|
|
|
|
my ($domain) = keys %$ref;
|
|
|
|
if ( $domain ) {
|
2012-06-23 06:54:27 +02:00
|
|
|
ok( $self->is_in_morercpthosts( $domain ), "$domain");
|
2012-05-11 07:50:04 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ok(1, "is_in_morercpthosts (skip, no entries)" );
|
|
|
|
};
|
|
|
|
|
2012-06-23 06:54:27 +02:00
|
|
|
ok( ! $self->is_in_morercpthosts( 'example.com' ), "missing -");
|
2012-05-11 07:50:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
sub test_get_rcpt_host {
|
|
|
|
my $self = shift;
|
|
|
|
|
2007-03-15 07:55:24 +01:00
|
|
|
my $address = Qpsmtpd::Address->parse('<me@example.com>');
|
2012-06-23 06:54:27 +02:00
|
|
|
cmp_ok( $self->get_rcpt_host( $address ), 'eq', 'example.com', "+" );
|
2012-05-11 07:50:04 +02:00
|
|
|
|
|
|
|
$address = Qpsmtpd::Address->parse('<me@exaMple.com>');
|
2012-06-23 06:54:27 +02:00
|
|
|
cmp_ok( $self->get_rcpt_host( $address ), 'eq', 'example.com', "+" );
|
2012-05-11 07:50:04 +02:00
|
|
|
|
|
|
|
$address = Qpsmtpd::Address->parse('<root@example.com>');
|
2012-06-23 06:54:27 +02:00
|
|
|
cmp_ok( $self->get_rcpt_host( $address ), 'eq', 'example.com', "+" );
|
2012-05-11 07:50:04 +02:00
|
|
|
|
|
|
|
$address = Qpsmtpd::Address->parse('<postmaster>');
|
2012-05-11 07:50:10 +02:00
|
|
|
my $local_hostname = $self->get_rcpt_host( $address );
|
|
|
|
if ( $local_hostname eq 'some.host.example.org' ) {
|
|
|
|
cmp_ok( $self->get_rcpt_host( $address ), 'eq', 'some.host.example.org',
|
2012-06-23 06:54:27 +02:00
|
|
|
"special postmaster +" );
|
2012-05-11 07:50:10 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-06-23 06:54:27 +02:00
|
|
|
ok( 1, "special postmaster + ($local_hostname)" );
|
2012-05-11 07:50:10 +02:00
|
|
|
}
|
2012-05-11 07:50:04 +02:00
|
|
|
|
|
|
|
# I think this is a bug. Qpsmtpd::Address fails to parse <abuse>
|
|
|
|
$address = Qpsmtpd::Address->parse('<abuse>');
|
2012-06-23 06:54:27 +02:00
|
|
|
ok( ! $self->get_rcpt_host( $address ), "missing host" );
|
2012-05-11 07:50:04 +02:00
|
|
|
|
|
|
|
$address = Qpsmtpd::Address->parse('<>');
|
2012-06-23 06:54:27 +02:00
|
|
|
ok( ! $self->get_rcpt_host( $address ), "null recipient" );
|
2012-05-11 07:50:04 +02:00
|
|
|
|
|
|
|
$address = Qpsmtpd::Address->parse('<@example.com>');
|
2012-06-23 06:54:27 +02:00
|
|
|
ok( ! $self->get_rcpt_host( $address ), "missing user" );
|
2012-05-11 07:50:04 +02:00
|
|
|
};
|
2007-03-15 07:55:24 +01:00
|
|
|
|