78 lines
2.2 KiB
Perl
78 lines
2.2 KiB
Perl
#!perl -w
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use Qpsmtpd::Constants;
|
|
|
|
sub register_tests {
|
|
my $self = shift;
|
|
|
|
$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);
|
|
}
|
|
|
|
sub test_ip_whitelisted {
|
|
my $self = shift;
|
|
|
|
$self->qp->connection->remote_ip('10.1.1.1');
|
|
|
|
$self->qp->connection->relay_client(1);
|
|
ok( $self->ip_whitelisted('10.1.1.1'), "ip_whitelisted, +");
|
|
|
|
$self->qp->connection->relay_client(0);
|
|
ok( ! $self->ip_whitelisted('10.1.1.1'), "ip_whitelisted, -");
|
|
|
|
$self->qp->connection->notes('whitelisthost', 'hello honey!');
|
|
ok( $self->ip_whitelisted('10.1.1.1'), "ip_whitelisted, +");
|
|
$self->qp->connection->notes('whitelisthost', undef);
|
|
};
|
|
|
|
sub test_is_set_rblsmtpd {
|
|
my $self = shift;
|
|
|
|
$self->qp->connection->remote_ip('10.1.1.1');
|
|
ok( ! defined $self->is_set_rblsmtpd('10.1.1.1'), "is_set_rblsmtpd, undef");
|
|
|
|
$ENV{RBLSMTPD} = "Yes we can!";
|
|
cmp_ok( 'Yes we can!','eq',$self->is_set_rblsmtpd('10.1.1.1'), "is_set_rblsmtpd, value");
|
|
|
|
$ENV{RBLSMTPD} = "Oh yeah?";
|
|
cmp_ok( 'Oh yeah?','eq',$self->is_set_rblsmtpd('10.1.1.1'), "is_set_rblsmtpd, value");
|
|
|
|
$ENV{RBLSMTPD} = '';
|
|
cmp_ok( 1,'==',$self->is_set_rblsmtpd('10.1.1.1'), "is_set_rblsmtpd, empty");
|
|
};
|
|
|
|
sub test_hook_connect {
|
|
my $self = shift;
|
|
|
|
my $connection = $self->qp->connection;
|
|
$connection->remote_ip('127.0.0.2'); # standard dnsbl test value
|
|
|
|
cmp_ok( DECLINED, '==', $self->hook_connect($self->qp->transaction),
|
|
"hook_connect +");
|
|
|
|
ok($connection->notes('dnsbl_sockets'), "hook_connect, sockets");
|
|
ok($connection->notes('dnsbl_domains'), "hook_connect, domains");
|
|
}
|
|
|
|
sub test_hook_rcpt {
|
|
my $self = shift;
|
|
|
|
my $address = Qpsmtpd::Address->parse('<rcpt@example.com>');
|
|
my ($ret, $note) = $self->hook_rcpt($self->qp->transaction, $address);
|
|
is($ret, DENY, "Check we got a DENY ($note)");
|
|
#print("# dnsbl result: $note\n");
|
|
}
|
|
sub test_hook_disconnect {
|
|
my $self = shift;
|
|
|
|
cmp_ok( DECLINED, '==', $self->hook_connect($self->qp->transaction),
|
|
"hook_disconnect +");
|
|
}
|
|
|