Merge pull request #135 from jaredj/consolidate_exclusions

Consolidate greylist exclusions into exclude()
This commit is contained in:
Matt Simerson 2014-10-28 12:50:51 -07:00
commit 0d149f0381
2 changed files with 23 additions and 3 deletions

View File

@ -285,9 +285,7 @@ sub greylist {
map { $_ . '=' . $config->{$_} } sort keys %$config) map { $_ . '=' . $config->{$_} } sort keys %$config)
); );
return DECLINED if $self->is_immune(); return DECLINED if $self->exclude();
return DECLINED if !$self->p0f_match();
return DECLINED if $self->geoip_match();
my $db = $self->get_db_location(); my $db = $self->get_db_location();
my $lock = $self->get_db_lock($db) or return DECLINED; 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); 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 { sub p0f_match {
my $self = shift; my $self = shift;

View File

@ -19,6 +19,7 @@ sub register_tests {
$self->register_test('test_hook_data'); $self->register_test('test_hook_data');
$self->register_test('test_get_db_key'); $self->register_test('test_get_db_key');
$self->register_test('test_get_db_location'); $self->register_test('test_get_db_location');
$self->register_test('test_exclude');
$self->register_test("test_greylist_geoip"); $self->register_test("test_greylist_geoip");
$self->register_test("test_greylist_p0f_genre"); $self->register_test("test_greylist_p0f_genre");
$self->register_test("test_greylist_p0f_distance"); $self->register_test("test_greylist_p0f_distance");
@ -87,6 +88,15 @@ sub test_get_db_location {
ok( $db, "db location: $db"); 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 { sub test_greylist_geoip {
my $self = shift; my $self = shift;
@ -98,11 +108,13 @@ sub test_greylist_geoip {
foreach my $cc ( @valid ) { foreach my $cc ( @valid ) {
$self->connection->notes('geoip_country', $cc ); $self->connection->notes('geoip_country', $cc );
ok( $self->geoip_match(), "match + ($cc)"); ok( $self->geoip_match(), "match + ($cc)");
ok( $self->exclude(), "match + ($cc) results in exclude() hit");
}; };
foreach my $cc ( @invalid ) { foreach my $cc ( @invalid ) {
$self->connection->notes('geoip_country', $cc ); $self->connection->notes('geoip_country', $cc );
ok( ! $self->geoip_match(), "bad - ($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->{_args}{'p0f'} = 'link,dsl';
$self->connection->notes('p0f'=> { link=>'DSL' } ); $self->connection->notes('p0f'=> { link=>'DSL' } );
ok( $self->p0f_match(), 'p0f link hit'); ok( $self->p0f_match(), 'p0f link hit');
ok( ! $self->exclude(), 'p0f link hit results in exclude() miss' );
$self->{_args}{'p0f'} = 'link,dsl'; $self->{_args}{'p0f'} = 'link,dsl';
$self->connection->notes('p0f'=> { link=>'Ethernet' } ); $self->connection->notes('p0f'=> { link=>'Ethernet' } );
ok( ! $self->p0f_match(), 'p0f link miss'); ok( ! $self->p0f_match(), 'p0f link miss');
ok( $self->exclude(), 'p0f link miss results in exclude() hit' );
} }
sub test_greylist_p0f_uptime { sub test_greylist_p0f_uptime {