2012-05-13 05:27:49 +02:00
|
|
|
#!perl -w
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Data::Dumper;
|
2012-05-15 07:19:04 +02:00
|
|
|
use POSIX qw(strftime);
|
2012-05-13 05:27:49 +02:00
|
|
|
|
|
|
|
use Qpsmtpd::Address;
|
|
|
|
use Qpsmtpd::Constants;
|
|
|
|
|
2012-05-15 07:19:04 +02:00
|
|
|
|
2012-05-13 05:27:49 +02:00
|
|
|
sub register_tests {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
$self->register_test("test_hook_data_post", 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub test_hook_data_post {
|
|
|
|
my $self = shift;
|
|
|
|
|
2012-05-15 07:19:04 +02:00
|
|
|
my $reject = $self->{_args}{reject_type};
|
|
|
|
my $deny = $reject =~ /^temp|soft$/i ? DENYSOFT : DENY;
|
|
|
|
|
2012-05-13 05:27:49 +02:00
|
|
|
my $transaction = $self->qp->transaction;
|
|
|
|
my $test_email = 'matt@example.com';
|
|
|
|
my $address = Qpsmtpd::Address->new( "<$test_email>" );
|
|
|
|
my $header = Mail::Header->new(Modify => 0, MailFrom => "COERCE");
|
2012-05-15 07:19:04 +02:00
|
|
|
my $now = strftime "%a %b %e %H:%M:%S %Y", localtime time;
|
|
|
|
my $future = strftime "%a %b %e %H:%M:%S %Y", localtime time + 518400; #6d
|
|
|
|
my $past = strftime "%a %b %e %H:%M:%S %Y", localtime time - 518400; #6d
|
2012-05-13 05:27:49 +02:00
|
|
|
$self->{_args}{days} = 5;
|
|
|
|
|
|
|
|
$transaction->sender($address);
|
|
|
|
$transaction->header($header);
|
|
|
|
$transaction->header->add('From', "<$test_email>");
|
|
|
|
$transaction->header->add('Date', $now );
|
|
|
|
$transaction->body_write( "test message body " );
|
|
|
|
|
|
|
|
my ($code, $mess) = $self->hook_data_post( $transaction );
|
|
|
|
cmp_ok( DECLINED, '==', $code, "okay" );
|
|
|
|
|
|
|
|
$transaction->header->delete('Date');
|
|
|
|
($code, $mess) = $self->hook_data_post( $transaction );
|
2012-05-15 07:19:04 +02:00
|
|
|
cmp_ok( $deny, '==', $code, "missing date ( $mess )" );
|
2012-05-13 05:27:49 +02:00
|
|
|
|
|
|
|
$transaction->header->add('Date', $now );
|
2012-05-15 07:19:04 +02:00
|
|
|
$transaction->header->delete('From');
|
2012-05-13 05:27:49 +02:00
|
|
|
($code, $mess) = $self->hook_data_post( $transaction );
|
2012-05-15 07:19:04 +02:00
|
|
|
cmp_ok( $deny, '==', $code, "missing from ( $mess )" );
|
|
|
|
$transaction->header->add('From', "<$test_email>");
|
2012-05-13 05:27:49 +02:00
|
|
|
|
2012-05-15 07:19:04 +02:00
|
|
|
$transaction->header->replace('Date', $future );
|
|
|
|
($code, $mess) = $self->hook_data_post( $transaction );
|
|
|
|
cmp_ok( $deny, '==', $code, "too new ( $mess )" );
|
2012-05-13 05:27:49 +02:00
|
|
|
|
2012-05-15 07:19:04 +02:00
|
|
|
$transaction->header->replace('Date', $past );
|
|
|
|
($code, $mess) = $self->hook_data_post( $transaction );
|
|
|
|
cmp_ok( $deny, '==', $code, "too old ( $mess )" );
|
2012-05-13 05:27:49 +02:00
|
|
|
|
|
|
|
$self->{_args}{reject_type} = 'temp';
|
|
|
|
($code, $mess) = $self->hook_data_post( $transaction );
|
|
|
|
cmp_ok( DENYSOFT, '==', $code, "defer, not deny ( $mess )" );
|
2012-05-15 07:19:04 +02:00
|
|
|
|
|
|
|
$self->{_args}{reject_type} = 'perm';
|
|
|
|
($code, $mess) = $self->hook_data_post( $transaction );
|
|
|
|
cmp_ok( DENY, '==', $code, "deny ( $mess )" );
|
2012-05-13 05:27:49 +02:00
|
|
|
};
|