| 1 |
#!perl -w |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use Qpsmtpd::Constants; |
| 7 |
|
| 8 |
sub register_tests { |
| 9 |
my $self = shift; |
| 10 |
|
| 11 |
$self->register_test('test_hook_connect', 1); |
| 12 |
$self->register_test('test_ip_whitelisted', 3); |
| 13 |
$self->register_test('test_is_set_rblsmtpd', 4); |
| 14 |
$self->register_test('test_reject_type', 3); |
| 15 |
} |
| 16 |
|
| 17 |
sub test_ip_whitelisted { |
| 18 |
my $self = shift; |
| 19 |
|
| 20 |
$self->qp->connection->remote_ip('192.168.99.5'); |
| 21 |
ok( $self->ip_whitelisted(), "+"); |
| 22 |
|
| 23 |
$self->qp->connection->remote_ip('192.168.99.6'); |
| 24 |
ok( ! $self->ip_whitelisted(), "-"); |
| 25 |
|
| 26 |
$self->qp->connection->remote_ip('192.168.99.5'); |
| 27 |
$self->qp->connection->notes('whitelisthost', 'hello honey!'); |
| 28 |
ok( $self->ip_whitelisted(), "+"); |
| 29 |
$self->qp->connection->notes('whitelisthost', undef); |
| 30 |
}; |
| 31 |
|
| 32 |
sub test_is_set_rblsmtpd { |
| 33 |
my $self = shift; |
| 34 |
|
| 35 |
$self->qp->connection->remote_ip('10.1.1.1'); |
| 36 |
ok( ! defined $self->is_set_rblsmtpd('10.1.1.1'), "undef"); |
| 37 |
|
| 38 |
$ENV{RBLSMTPD} = "Yes we can!"; |
| 39 |
cmp_ok( 'Yes we can!','eq',$self->is_set_rblsmtpd('10.1.1.1'), "value"); |
| 40 |
|
| 41 |
$ENV{RBLSMTPD} = "Oh yeah?"; |
| 42 |
cmp_ok( 'Oh yeah?','eq',$self->is_set_rblsmtpd('10.1.1.1'), "value"); |
| 43 |
|
| 44 |
$ENV{RBLSMTPD} = ''; |
| 45 |
cmp_ok( 1,'==',$self->is_set_rblsmtpd('10.1.1.1'), "empty"); |
| 46 |
}; |
| 47 |
|
| 48 |
sub test_hook_connect { |
| 49 |
my $self = shift; |
| 50 |
|
| 51 |
# reset values that other tests may have fiddled with |
| 52 |
my $conn = $self->qp->connection; |
| 53 |
$conn->relay_client(0); # other tests may leave it enabled |
| 54 |
$conn->notes('whitelisthost', undef ); |
| 55 |
$conn->notes('whitelistsender', undef); |
| 56 |
$conn->notes('naughty', undef); |
| 57 |
$conn->remote_ip('127.0.0.2'); # standard dnsbl test value |
| 58 |
|
| 59 |
my ($rc, $mess) = $self->hook_connect($self->qp->transaction); |
| 60 |
if ( $rc == DENY ) { |
| 61 |
cmp_ok( $rc, '==', DENY, "connect +"); |
| 62 |
} |
| 63 |
else { |
| 64 |
ok( 1, "connect +, skipped (is DNS working?)" ); |
| 65 |
}; |
| 66 |
} |
| 67 |
|
| 68 |
sub test_reject_type { |
| 69 |
my $self = shift; |
| 70 |
|
| 71 |
$self->{_args}{reject_type} = undef; |
| 72 |
cmp_ok( $self->get_reject_type(), '==', DENY, "default"); |
| 73 |
|
| 74 |
$self->{_args}{reject_type} = 'temp'; |
| 75 |
cmp_ok( $self->get_reject_type(), '==', DENYSOFT, "defer"); |
| 76 |
|
| 77 |
$self->{_args}{reject_type} = 'disconnect'; |
| 78 |
cmp_ok( $self->get_reject_type(), '==', DENY_DISCONNECT, "disconnect"); |
| 79 |
}; |