qpsmtpd/t/plugin_tests/greylisting
Matt Simerson b81d464c87 added p0f support to greylist plugin
- these changes are in the previous TCPLOCAL patch. Documented here.
added p0f config option
added POD docs to explain usage
modified $dbdir selection logic. The previous logic failed when QPHOME was
 not selected (as is the case when tests are being run).
Added '.' as the dir of last resort for $dbdir selection (others $EMPTY/dir
 dumped greylisting database in / )

  - These changes are included in this patch -
Added t/plugin_tests/greylisting, with greylist logic testing (tests are
 disabled by default, as greylisting is disabled in config.sample/plugins)
Added example entry in config.sample/plugins

Signed-off-by: Robert <rspier@pobox.com>
2010-05-11 21:19:52 -07:00

112 lines
3.4 KiB
Plaintext

use Qpsmtpd::Address;
my $test_email = 'user@example.com';
my $address = Qpsmtpd::Address->new( "<$test_email>" );
my @greydbs = qw( denysoft_greylist.dbm denysoft_greylist.dbm.lock );
foreach ( @greydbs ) {
unlink $_ if -f $_;
};
sub register_tests {
my $self = shift;
$self->register_test("test_greylist_p0f_genre_miss", 1);
$self->register_test("test_greylist_p0f_genre_hit", 1);
$self->register_test("test_greylist_p0f_distance_hit", 1);
$self->register_test("test_greylist_p0f_distance_miss", 1);
$self->register_test("test_greylist_p0f_link_hit", 1);
$self->register_test("test_greylist_p0f_link_miss", 1);
$self->register_test("test_greylist_p0f_uptime_hit", 1);
$self->register_test("test_greylist_p0f_uptime_miss", 1);
}
sub test_greylist_p0f_genre_miss {
my $self = shift;
$self->{_greylist_config}{'p0f'} = 'genre,Linux';
$self->connection->notes('p0f'=> { genre => 'windows', link => 'dsl' } );
my $r = $self->rcpt_handler( $self->qp->transaction );
ok( $r == 909, 'p0f genre miss');
}
sub test_greylist_p0f_genre_hit {
my $self = shift;
$self->{_greylist_config}{'p0f'} = 'genre,Windows';
$self->connection->notes('p0f'=> { genre => 'windows', link => 'dsl' } );
$self->qp->transaction->sender( $address );
my $r = $self->rcpt_handler( $self->qp->transaction );
ok( $r eq 'This mail is temporarily denied', 'p0f genre hit');
}
sub test_greylist_p0f_distance_hit {
my $self = shift;
$self->{_greylist_config}{'p0f'} = 'distance,8';
$self->connection->notes('p0f'=> { distance=>9 } );
$self->qp->transaction->sender( $address );
my $r = $self->rcpt_handler( $self->qp->transaction );
ok( $r eq 'This mail is temporarily denied', 'p0f distance hit');
}
sub test_greylist_p0f_distance_miss {
my $self = shift;
$self->{_greylist_config}{'p0f'} = 'distance,8';
$self->connection->notes('p0f'=> { distance=>7 } );
$self->qp->transaction->sender( $address );
my $r = $self->rcpt_handler( $self->qp->transaction );
ok( $r == 909, 'p0f distance miss');
}
sub test_greylist_p0f_link_hit {
my $self = shift;
$self->{_greylist_config}{'p0f'} = 'link,dsl';
$self->connection->notes('p0f'=> { link=>'DSL' } );
$self->qp->transaction->sender( $address );
my $r = $self->rcpt_handler( $self->qp->transaction );
ok( $r eq 'This mail is temporarily denied', 'p0f link hit');
}
sub test_greylist_p0f_link_miss {
my $self = shift;
$self->{_greylist_config}{'p0f'} = 'link,dsl';
$self->connection->notes('p0f'=> { link=>'Ethernet' } );
$self->qp->transaction->sender( $address );
my $r = $self->rcpt_handler( $self->qp->transaction );
ok( $r == 909, 'p0f link miss');
}
sub test_greylist_p0f_uptime_hit {
my $self = shift;
$self->{_greylist_config}{'p0f'} = 'uptime,100';
$self->connection->notes('p0f'=> { uptime=> 99 } );
$self->qp->transaction->sender( $address );
my $r = $self->rcpt_handler( $self->qp->transaction );
ok( $r eq 'This mail is temporarily denied', 'p0f uptime hit');
}
sub test_greylist_p0f_uptime_miss {
my $self = shift;
$self->{_greylist_config}{'p0f'} = 'uptime,100';
$self->connection->notes('p0f'=> { uptime=>500 } );
$self->qp->transaction->sender( $address );
my $r = $self->rcpt_handler( $self->qp->transaction );
ok( $r == 909, 'p0f uptime miss');
}