2012-05-05 09:03:40 +02:00
|
|
|
#!perl -w
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Qpsmtpd::Constants;
|
2004-09-08 23:48:27 +02:00
|
|
|
|
|
|
|
sub register_tests {
|
|
|
|
my $self = shift;
|
2012-05-05 09:03:40 +02:00
|
|
|
|
|
|
|
$self->register_test('test_hook_connect', 2);
|
|
|
|
$self->register_test('test_hook_rcpt', 2);
|
|
|
|
$self->register_test('test_ip_whitelisted', 3);
|
|
|
|
$self->register_test('test_is_set_rblsmtpd', 4);
|
|
|
|
$self->register_test('test_hook_disconnect', 1);
|
2012-05-21 22:59:07 +02:00
|
|
|
$self->register_test('test_reject_type', 3);
|
2004-09-08 23:48:27 +02:00
|
|
|
}
|
|
|
|
|
2012-05-05 09:03:40 +02:00
|
|
|
sub test_ip_whitelisted {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
$self->qp->connection->remote_ip('10.1.1.1');
|
|
|
|
|
|
|
|
$self->qp->connection->relay_client(1);
|
2012-05-21 22:59:07 +02:00
|
|
|
ok( $self->ip_whitelisted('10.1.1.1'), "yes, +");
|
2012-05-05 09:03:40 +02:00
|
|
|
|
|
|
|
$self->qp->connection->relay_client(0);
|
2012-05-21 22:59:07 +02:00
|
|
|
ok( ! $self->ip_whitelisted('10.1.1.1'), "no, -");
|
2012-05-05 09:03:40 +02:00
|
|
|
|
|
|
|
$self->qp->connection->notes('whitelisthost', 'hello honey!');
|
2012-05-21 22:59:07 +02:00
|
|
|
ok( $self->ip_whitelisted('10.1.1.1'), "yes, +");
|
2012-05-05 09:03:40 +02:00
|
|
|
$self->qp->connection->notes('whitelisthost', undef);
|
|
|
|
};
|
|
|
|
|
|
|
|
sub test_is_set_rblsmtpd {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
$self->qp->connection->remote_ip('10.1.1.1');
|
2012-05-21 22:59:07 +02:00
|
|
|
ok( ! defined $self->is_set_rblsmtpd('10.1.1.1'), "undef");
|
2012-05-05 09:03:40 +02:00
|
|
|
|
|
|
|
$ENV{RBLSMTPD} = "Yes we can!";
|
2012-05-21 22:59:07 +02:00
|
|
|
cmp_ok( 'Yes we can!','eq',$self->is_set_rblsmtpd('10.1.1.1'), "value");
|
2012-05-05 09:03:40 +02:00
|
|
|
|
|
|
|
$ENV{RBLSMTPD} = "Oh yeah?";
|
2012-05-21 22:59:07 +02:00
|
|
|
cmp_ok( 'Oh yeah?','eq',$self->is_set_rblsmtpd('10.1.1.1'), "value");
|
2012-05-05 09:03:40 +02:00
|
|
|
|
|
|
|
$ENV{RBLSMTPD} = '';
|
2012-05-21 22:59:07 +02:00
|
|
|
cmp_ok( 1,'==',$self->is_set_rblsmtpd('10.1.1.1'), "empty");
|
2012-05-05 09:03:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
sub test_hook_connect {
|
2004-09-08 23:48:27 +02:00
|
|
|
my $self = shift;
|
2012-05-05 09:03:40 +02:00
|
|
|
|
2004-09-08 23:48:27 +02:00
|
|
|
my $connection = $self->qp->connection;
|
2012-05-21 22:59:07 +02:00
|
|
|
$connection->relay_client(0); # other tests may leave it enabled
|
2004-09-08 23:48:27 +02:00
|
|
|
$connection->remote_ip('127.0.0.2'); # standard dnsbl test value
|
2012-05-05 09:03:40 +02:00
|
|
|
|
|
|
|
cmp_ok( DECLINED, '==', $self->hook_connect($self->qp->transaction),
|
2012-05-21 22:59:07 +02:00
|
|
|
"connect +");
|
2012-05-05 09:03:40 +02:00
|
|
|
|
2012-05-21 22:59:07 +02:00
|
|
|
ok($connection->notes('dnsbl_sockets'), "sockets +");
|
|
|
|
ok($connection->notes('dnsbl_domains'), "domains +");
|
2004-09-08 23:48:27 +02:00
|
|
|
}
|
|
|
|
|
2012-05-05 09:03:40 +02:00
|
|
|
sub test_hook_rcpt {
|
2004-09-08 23:48:27 +02:00
|
|
|
my $self = shift;
|
2005-02-22 01:38:06 +01:00
|
|
|
|
|
|
|
my $address = Qpsmtpd::Address->parse('<rcpt@example.com>');
|
2012-05-05 09:03:40 +02:00
|
|
|
my ($ret, $note) = $self->hook_rcpt($self->qp->transaction, $address);
|
|
|
|
is($ret, DENY, "Check we got a DENY ($note)");
|
|
|
|
#print("# dnsbl result: $note\n");
|
2004-09-08 23:48:27 +02:00
|
|
|
}
|
2012-05-05 09:03:40 +02:00
|
|
|
sub test_hook_disconnect {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
cmp_ok( DECLINED, '==', $self->hook_connect($self->qp->transaction),
|
|
|
|
"hook_disconnect +");
|
|
|
|
}
|
|
|
|
|
2012-05-21 22:59:07 +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");
|
|
|
|
};
|