Permalink
Browse files

improve portability of basicheader plugin tests

replaced `date` with POSIX qw(strftime);
  • Loading branch information...
msimerson authored and rspier committed May 15, 2012
1 parent 1c7d26e commit 96144a6a168362821f0de323a7c494b73ccfd76f
Showing with 22 additions and 19 deletions.
  1. +22 −19 t/plugin_tests/check_basicheaders
@@ -2,10 +2,12 @@
use strict;
use Data::Dumper;
+use POSIX qw(strftime);
use Qpsmtpd::Address;
use Qpsmtpd::Constants;
+
sub register_tests {
my $self = shift;
@@ -15,13 +17,16 @@ sub register_tests {
sub test_hook_data_post {
my $self = shift;
+ my $reject = $self->{_args}{reject_type};
+ my $deny = $reject =~ /^temp|soft$/i ? DENYSOFT : DENY;
+
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");
- my $now = `date`;
- my $future = `date -v +6d`;
- my $past = `date -v -6d`;
+ 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
$self->{_args}{days} = 5;
$transaction->sender($address);
@@ -35,29 +40,27 @@ sub test_hook_data_post {
$transaction->header->delete('Date');
($code, $mess) = $self->hook_data_post( $transaction );
- cmp_ok( DENY, '==', $code, "missing date ( $mess )" );
+ cmp_ok( $deny, '==', $code, "missing date ( $mess )" );
- $transaction->header->delete('From');
$transaction->header->add('Date', $now );
+ $transaction->header->delete('From');
($code, $mess) = $self->hook_data_post( $transaction );
- cmp_ok( DENY, '==', $code, "missing from ( $mess )" );
-
- if ( $future ) {
- $transaction->header->replace('Date', $future );
- ($code, $mess) = $self->hook_data_post( $transaction );
- cmp_ok( DENY, '==', $code, "too new ( $mess )" );
+ cmp_ok( $deny, '==', $code, "missing from ( $mess )" );
+ $transaction->header->add('From', "<$test_email>");
- $transaction->header->replace('Date', $past );
- ($code, $mess) = $self->hook_data_post( $transaction );
- cmp_ok( DENY, '==', $code, "too old ( $mess )" );
+ $transaction->header->replace('Date', $future );
+ ($code, $mess) = $self->hook_data_post( $transaction );
+ cmp_ok( $deny, '==', $code, "too new ( $mess )" );
- }
- else {
- ok( 1, "skip: unable to use 'date' output");
- ok( 1, "skip: unable to use 'date' output");
- }
+ $transaction->header->replace('Date', $past );
+ ($code, $mess) = $self->hook_data_post( $transaction );
+ cmp_ok( $deny, '==', $code, "too old ( $mess )" );
$self->{_args}{reject_type} = 'temp';
($code, $mess) = $self->hook_data_post( $transaction );
cmp_ok( DENYSOFT, '==', $code, "defer, not deny ( $mess )" );
+
+ $self->{_args}{reject_type} = 'perm';
+ ($code, $mess) = $self->hook_data_post( $transaction );
+ cmp_ok( DENY, '==', $code, "deny ( $mess )" );
};

0 comments on commit 96144a6

Please sign in to comment.