diff --git a/plugins/greylisting b/plugins/greylisting index edd7324..654b64e 100644 --- a/plugins/greylisting +++ b/plugins/greylisting @@ -285,9 +285,7 @@ sub greylist { map { $_ . '=' . $config->{$_} } sort keys %$config) ); - return DECLINED if $self->is_immune(); - return DECLINED if !$self->p0f_match(); - return DECLINED if $self->geoip_match(); + return DECLINED if $self->exclude(); my $db = $self->get_db_location(); my $lock = $self->get_db_lock($db) or return DECLINED; @@ -507,6 +505,14 @@ sub prune_db { return $self->cleanup_and_return($tied, $lock, DECLINED); } +sub exclude { + my ( $self ) = @_; + return 1 if $self->is_immune(); + return 1 if !$self->p0f_match(); + return 1 if $self->geoip_match(); + return; +} + sub p0f_match { my $self = shift; diff --git a/t/plugin_tests/greylisting b/t/plugin_tests/greylisting index afd1acd..0cac7eb 100644 --- a/t/plugin_tests/greylisting +++ b/t/plugin_tests/greylisting @@ -19,6 +19,7 @@ sub register_tests { $self->register_test('test_hook_data'); $self->register_test('test_get_db_key'); $self->register_test('test_get_db_location'); + $self->register_test('test_exclude'); $self->register_test("test_greylist_geoip"); $self->register_test("test_greylist_p0f_genre"); $self->register_test("test_greylist_p0f_distance"); @@ -87,6 +88,15 @@ sub test_get_db_location { ok( $db, "db location: $db"); }; +sub test_exclude { + my ( $self ) = @_; + + $self->connection->relay_client(1); + ok( $self->exclude(), "Relay client results in exclude() hit" ); + $self->connection->relay_client(0); + ok( ! $self->exclude(), "Non-relay client results in exclude() miss" ); +}; + sub test_greylist_geoip { my $self = shift; @@ -98,11 +108,13 @@ sub test_greylist_geoip { foreach my $cc ( @valid ) { $self->connection->notes('geoip_country', $cc ); ok( $self->geoip_match(), "match + ($cc)"); + ok( $self->exclude(), "match + ($cc) results in exclude() hit"); }; foreach my $cc ( @invalid ) { $self->connection->notes('geoip_country', $cc ); ok( ! $self->geoip_match(), "bad - ($cc)"); + ok( ! $self->exclude(), "miss - ($cc) results in exclude() miss"); }; }; @@ -136,10 +148,12 @@ sub test_greylist_p0f_link { $self->{_args}{'p0f'} = 'link,dsl'; $self->connection->notes('p0f'=> { link=>'DSL' } ); ok( $self->p0f_match(), 'p0f link hit'); + ok( ! $self->exclude(), 'p0f link hit results in exclude() miss' ); $self->{_args}{'p0f'} = 'link,dsl'; $self->connection->notes('p0f'=> { link=>'Ethernet' } ); ok( ! $self->p0f_match(), 'p0f link miss'); + ok( $self->exclude(), 'p0f link miss results in exclude() hit' ); } sub test_greylist_p0f_uptime {