replaced `date` with POSIX qw(strftime);
---
 t/plugin_tests/check_basicheaders |   41 ++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 19 deletions(-)

diff --git a/t/plugin_tests/check_basicheaders 
b/t/plugin_tests/check_basicheaders
index 82e2f39..e01aec5 100644
--- a/t/plugin_tests/check_basicheaders
+++ b/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 = 'm...@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 )" );
 };
-- 
1.7.9.6

Reply via email to