Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

disable auth_vpopmail_sql tests if DBI missing

  • Loading branch information...
commit 8adfb9c5229cb54370df0f087c2826dbaaf5d423 1 parent 76307d3
@msimerson authored
View
5 t/plugin_tests/auth/auth_vpopmail_sql
@@ -6,6 +6,11 @@ use warnings;
sub register_tests {
my $self = shift;
+ eval 'use DBI';
+ if ( $@ ) {
+ warn "skipping auth_vpopmail_sql tests, DBI missing\n";
+ return;
+ };
$self->register_test("auth_vpopmail_sql", 3);
}
View
172 t/plugin_tests/resolvable_fromhost
@@ -0,0 +1,172 @@
+#!perl -w
+
+use strict;
+
+use Data::Dumper;
+use Net::DNS;
+use Qpsmtpd::Address;
+use Qpsmtpd::Constants;
+
+my $res = new Net::DNS::Resolver(dnsrch => 0);
+my $test_email = 'user@example.com';
+
+sub register_tests {
+ my $self = shift;
+
+ my %args = ( );
+ $self->register( $self->qp, reject => 'none' );
+
+ $self->register_test('test_is_immune', 3);
+ $self->register_test('test_populate_invalid_networks', 2);
+ $self->register_test('test_mx_address_resolves', 2);
+ $self->register_test('test_get_host_records', 2);
+ $self->register_test('test_get_and_validate_mx', 2);
+ $self->register_test('test_check_dns', 2);
+ $self->register_test('test_hook_rcpt', 10);
+ $self->register_test('test_hook_mail', 4);
+}
+
+sub test_hook_mail {
+ my $self = shift;
+
+ my $transaction = $self->qp->transaction;
+ my $address = Qpsmtpd::Address->new('remote@example.com');
+ $transaction->sender($address);
+
+ my $sender = $transaction->sender;
+ $sender->host('perl.com');
+
+ ok( $self->hook_mail( $transaction, $sender ), "hook_mail +");
+ ok( $self->hook_mail( $transaction, $sender ), "hook_mail +");
+
+ $sender->host('');
+ $self->{_args}{reject} = 'soft';
+ my ($r) = $self->hook_mail( $transaction, $sender );
+ ok( $r == DENYSOFT, "hook_mail - ($r)");
+
+ $self->{_args}{reject} = 'hard';
+ ($r) = $self->hook_mail( $transaction, $sender );
+ ok( $r == DENY, "hook_mail - ($r)");
+
+};
+
+sub test_hook_rcpt {
+ my $self = shift;
+
+ my $transaction = $self->qp->transaction;
+ my $recipient = 'foo@example.com';
+
+ $transaction->notes('resolvable_fromhost', 'a');
+ ok( DECLINED == $self->hook_rcpt( $transaction, $recipient ), "hook_rcpt +");
+
+ $transaction->notes('resolvable_fromhost', 'mx');
+ ok( DECLINED == $self->hook_rcpt( $transaction, $recipient ), "hook_rcpt +");
+
+ $transaction->notes('resolvable_fromhost', 'ip');
+ ok( DECLINED == $self->hook_rcpt( $transaction, $recipient ), "hook_rcpt +");
+
+ $transaction->notes('resolvable_fromhost', 'whitelist');
+ ok( DECLINED == $self->hook_rcpt( $transaction, $recipient ), "hook_rcpt +");
+
+ $transaction->notes('resolvable_fromhost', 'null');
+ ok( DECLINED == $self->hook_rcpt( $transaction, $recipient ), "hook_rcpt +");
+
+ $transaction->notes('resolvable_fromhost', 'config');
+ ok( DECLINED == $self->hook_rcpt( $transaction, $recipient ), "hook_rcpt +");
+
+ $transaction->notes('resolvable_fromhost', 'oops!');
+ ok( DECLINED == $self->hook_rcpt( $transaction, $recipient ), "hook_rcpt +");
+
+ $transaction->notes('resolvable_fromhost', 'oops!');
+ ok( DECLINED == $self->hook_rcpt( $transaction, $recipient ), "hook_rcpt +");
+
+ $transaction->notes('resolvable_fromhost', 'oops!');
+ $self->{_args}{reject} = 'soft';
+ my ($r) = $self->hook_rcpt( $transaction, $recipient );
+ ok( DENYSOFT == $r, "hook_rcpt - ($r)");
+
+ $transaction->notes('resolvable_fromhost', 'failed again');
+ $self->{_args}{reject} = 'hard';
+ ($r) = $self->hook_rcpt( $transaction, $recipient );
+ ok( DENY == $r, "hook_rcpt - ($r)");
+};
+
+sub test_check_dns {
+ my $self = shift;
+
+ my $transaction = $self->qp->transaction;
+ ok( ! $self->check_dns( '', $transaction ), 'check_dns -');
+ ok( $self->check_dns( 'perl.com', $transaction ), 'check_dns +');
+}
+
+sub test_get_and_validate_mx {
+ my $self = shift;
+ my $transaction = $self->qp->transaction;
+
+ ok( scalar $self->get_and_validate_mx( $res, 'perl.com', $transaction ),
+ "get_and_validate_mx +");
+
+ ok( ! scalar $self->get_host_records( $res, 'fake-domain-name-for-test.com', $transaction ),
+ "get_and_validate_mx -");
+
+};
+
+sub test_get_host_records {
+ my $self = shift;
+ my $transaction = $self->qp->transaction;
+
+ ok( scalar $self->get_host_records( $res, 'perl.com', $transaction ),
+ "get_host_records +");
+
+ ok( ! scalar $self->get_host_records( $res, 'fake-domain-name-for-test.com', $transaction ),
+ "get_host_records -");
+
+};
+
+sub test_mx_address_resolves {
+ my $self = shift;
+
+ my $fromhost = 'perl.com';
+
+ ok( $self->mx_address_resolves('mail.perl.com', $fromhost),
+ "mx_address_resolves +");
+ ok( ! $self->mx_address_resolves('no-such-mx.perl.com', $fromhost),
+ "mx_address_resolves -");
+};
+
+sub test_populate_invalid_networks {
+ my $self = shift;
+
+ my $ip = '10.9.8.7';
+ ok( $self->ip_is_valid($ip), "ip_is_valid +" );
+
+ $self->qp->config('invalid_resolvable_fromhost', $ip);
+ $self->populate_invalid_networks();
+ ok( ! $self->ip_is_valid($ip), "populate_invalid_networks" );
+
+ # clean up afterwards
+ $self->qp->config('invalid_resolvable_fromhost', undef );
+ $self->{invalid} = ();
+};
+
+sub test_is_immune {
+ my $self = shift;
+
+ my $transaction = $self->qp->transaction;
+
+ # null sender should be immune
+ $transaction->sender('<>');
+ ok( $self->is_immune( $transaction->sender, $transaction ) );
+
+ # whitelisted host should be immune
+ my $connection = $self->qp->connection->notes('whitelisthost', 1);
+ ok( $self->is_immune( $transaction->sender, $transaction ) );
+ $self->qp->connection->notes('whitelisthost', undef);
+
+ # reject is not defined, so email should not be immune
+ my $address = Qpsmtpd::Address->new( "<$test_email>" );
+ $transaction->sender($address);
+ ok( ! $self->is_immune( $transaction->sender, $transaction ) );
+};
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.