From b81d464c872867f8df65847f522db6a0df4a96bf Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Tue, 11 May 2010 01:31:52 -0400 Subject: 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 --- config.sample/plugins | 1 + t/plugin_tests/greylisting | 111 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 0 deletions(-) create mode 100644 t/plugin_tests/greylisting diff --git a/config.sample/plugins b/config.sample/plugins index 0b51124..6a01ba0 100644 --- a/config.sample/plugins +++ b/config.sample/plugins @@ -34,6 +34,7 @@ check_badrcptto check_spamhelo # sender_permitted_from +# greylisting p0f genre,windows auth/auth_flat_file auth/authdeny diff --git a/t/plugin_tests/greylisting b/t/plugin_tests/greylisting new file mode 100644 index 0000000..38ed08b --- /dev/null +++ b/t/plugin_tests/greylisting @@ -0,0 +1,111 @@ +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'); +} + + + -- 1.7.2.2