helo: refine plugin tests

This commit is contained in:
Matt Simerson 2012-06-22 19:24:16 -04:00
parent 97fda310ee
commit e2c84987f3
3 changed files with 11 additions and 17 deletions

View File

@ -209,7 +209,7 @@ use Qpsmtpd::Constants;
use Net::DNS; use Net::DNS;
sub register { sub register {
my ($self, $qp) = shift, shift; my ($self, $qp) = (shift, shift);
$self->{_args} = { @_ }; $self->{_args} = { @_ };
$self->{_args}{reject_type} = 'disconnect'; $self->{_args}{reject_type} = 'disconnect';
$self->{_args}{policy} ||= 'lenient'; $self->{_args}{policy} ||= 'lenient';
@ -262,8 +262,8 @@ sub populate_tests {
@{ $self->{_helo_tests} } = qw/ is_in_badhelo invalid_localhost is_forged_literal /; @{ $self->{_helo_tests} } = qw/ is_in_badhelo invalid_localhost is_forged_literal /;
if ( $policy eq 'rfc' || $policy eq 'strict' ) { if ( $policy eq 'rfc' || $policy eq 'strict' ) {
push @{ $self->{_helo_tests} }, qw/ is_plain_ip is_not_fqdn no_forward_dns push @{ $self->{_helo_tests} }, qw/ is_plain_ip is_not_fqdn
no_reverse_dns /; no_forward_dns no_reverse_dns /;
}; };
if ( $policy eq 'strict' ) { if ( $policy eq 'strict' ) {

View File

@ -1,16 +1,11 @@
use Test::More tests => 14; use Test::More tests => 12;
use strict; use strict;
use lib 't'; use lib 't';
use_ok('Test::Qpsmtpd'); use_ok('Test::Qpsmtpd');
ok(my ($smtpd, $conn) = Test::Qpsmtpd->new_conn(), "get new connection"); ok(my ($smtpd, $conn) = Test::Qpsmtpd->new_conn(), "get new connection");
# check_spamhelo plugin
is(($smtpd->command('HELO yahoo.com'))[0], 550, 'HELO yahoo.com');
# fault method # fault method
is(($smtpd->command('HELO localhost'))[0], 250, 'HELO localhost');
is(($smtpd->fault)->[0], 451, 'fault returns 451'); is(($smtpd->fault)->[0], 451, 'fault returns 451');
is(($smtpd->fault("test message"))->[1], is(($smtpd->fault("test message"))->[1],
"Internal error - try again later - test message", "Internal error - try again later - test message",

View File

@ -15,12 +15,11 @@ sub register_tests {
$self->register_test('test_is_plain_ip', 3); $self->register_test('test_is_plain_ip', 3);
$self->register_test('test_is_address_literal', 3); $self->register_test('test_is_address_literal', 3);
$self->register_test('test_no_forward_dns', 2); $self->register_test('test_no_forward_dns', 2);
$self->register_test('test_no_reverse_dns', 2); $self->register_test('test_no_reverse_dns', 3);
$self->register_test('test_no_matching_dns', 4); $self->register_test('test_no_matching_dns', 2);
$self->register_test('test_no_matching_dns', 4);
$self->register_test('test_helo_handler', 1); $self->register_test('test_helo_handler', 1);
$self->register_test('test_check_ip_match', 4); $self->register_test('test_check_ip_match', 3);
$self->register_test('test_check_name_match', 4); $self->register_test('test_check_name_match', 3);
} }
sub test_helo_handler { sub test_helo_handler {
@ -150,15 +149,15 @@ sub test_check_ip_match {
$self->connection->notes('helo_forward_match', 0); $self->connection->notes('helo_forward_match', 0);
$self->check_ip_match('192.0.2.1'); $self->check_ip_match('192.0.2.1');
ok( $self->connection->notes('helo_forward_match'), "exact"; ok( $self->connection->notes('helo_forward_match'), "exact");
$self->connection->notes('helo_forward_match', 0); $self->connection->notes('helo_forward_match', 0);
$self->check_ip_match('192.0.2.2'); $self->check_ip_match('192.0.2.2');
ok( $self->connection->notes('helo_forward_match'), "network"; ok( $self->connection->notes('helo_forward_match'), "network");
$self->connection->notes('helo_forward_match', 0); $self->connection->notes('helo_forward_match', 0);
$self->check_ip_match('192.0.1.1'); $self->check_ip_match('192.0.1.1');
ok( ! $self->connection->notes('helo_forward_match'), "miss"; ok( ! $self->connection->notes('helo_forward_match'), "miss");
}; };
sub test_check_name_match { sub test_check_name_match {