summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authordakkar <dakkar@luxion>2007-12-27 14:36:45 +0000
committerdakkar <dakkar@luxion>2007-12-27 14:36:45 +0000
commitf67531bad2b0aaebfea7ec63922290f28e86d6ab (patch)
treec5650db6cef8af570767ccb00bfacdf422a49632 /t
parent r3302@rfc-1918: dakkar | 2007-12-27 13:18:56 +0100 (diff)
downloadGraylister-f67531bad2b0aaebfea7ec63922290f28e86d6ab.tar.gz
Graylister-f67531bad2b0aaebfea7ec63922290f28e86d6ab.tar.bz2
Graylister-f67531bad2b0aaebfea7ec63922290f28e86d6ab.zip
r3304@rfc-1918: dakkar | 2007-12-27 13:19:58 +0100
prepraering fro branching
Diffstat (limited to 't')
-rw-r--r--t/01-use.t16
-rw-r--r--t/02-input.t19
-rw-r--r--t/03-white.t19
-rw-r--r--t/04-gray.t18
-rw-r--r--t/05-gray-empty.t18
-rw-r--r--t/06-age.t34
6 files changed, 124 insertions, 0 deletions
diff --git a/t/01-use.t b/t/01-use.t
new file mode 100644
index 0000000..f151e18
--- /dev/null
+++ b/t/01-use.t
@@ -0,0 +1,16 @@
+# -*- mode: cperl -*-
+use Test::More tests=>3;
+
+BEGIN {
+ use_ok('DAKKAR::Graylister')
+ or die;
+}
+
+my ($host,$from,$to)=qw(10.1.0.0 gino@qui.it pino@li.com);
+is_deeply([DAKKAR::Graylister::_cleanup_data($host,$from,$to)],
+ [$host,$from,$to],
+ 'no cleanup');
+$from='gino-return-10-@qui.it';
+is_deeply([DAKKAR::Graylister::_cleanup_data($host,$from,$to)],
+ [$host,'gino-return-$-@qui.it',,$to],
+ 'ezmlm cleanup');
diff --git a/t/02-input.t b/t/02-input.t
new file mode 100644
index 0000000..3013798
--- /dev/null
+++ b/t/02-input.t
@@ -0,0 +1,19 @@
+# -*- mode: cperl -*-
+use Test::More tests=>2;
+use File::Temp 'tempdir';
+use DAKKAR::Graylister;
+
+my $dbdir=tempdir(CLEANUP=>1);
+
+local $ENV{SMTPMAILFROM}='gino';
+local $ENV{SMTPRCPTTO}='pino';
+local $ENV{TCPREMOTEIP}='10.1.2.3';
+local $ENV{DAKGL_DBNAME}="$dbdir/gray1.db";
+is_deeply([DAKKAR::Graylister::get_from_env()],
+ ['10.1.2.3','gino','pino'],
+ 'from env');
+$ENV{SMTPMAILFROM}='gino-return-12-@pino.it';
+is_deeply([DAKKAR::Graylister::get_from_env()],
+ ['10.1.2.3','gino-return-$-@pino.it','pino'],
+ 'from env, ezmlm');
+
diff --git a/t/03-white.t b/t/03-white.t
new file mode 100644
index 0000000..b2ac66c
--- /dev/null
+++ b/t/03-white.t
@@ -0,0 +1,19 @@
+# -*- mode: cperl -*-
+use Test::More tests=>3;
+use File::Temp 'tempdir';
+use DAKKAR::Graylister;
+
+my $dbdir=tempdir(CLEANUP=>1);
+
+local $ENV{SMTPMAILFROM}='gino';
+local $ENV{SMTPRCPTTO}='pino';
+local $ENV{TCPREMOTEIP}='10.1.2.3';
+local $ENV{DAKGL_DBNAME}="$dbdir/gray2.db";
+my ($host,$from,$to)=DAKKAR::Graylister::get_from_env();
+
+ok(!DAKKAR::Graylister::is_whitelisted($host),'db touch');
+
+ok(-f "$dbdir/gray2.db",'db file created');
+
+DAKKAR::Graylister::add_to_whitelist($host);
+ok(DAKKAR::Graylister::is_whitelisted($host),'whitelist');
diff --git a/t/04-gray.t b/t/04-gray.t
new file mode 100644
index 0000000..893c1d1
--- /dev/null
+++ b/t/04-gray.t
@@ -0,0 +1,18 @@
+# -*- mode: cperl -*-
+use Test::More tests=>3;
+use File::Temp 'tempdir';
+use DAKKAR::Graylister;
+
+my $dbdir=tempdir(CLEANUP=>1);
+
+local $ENV{SMTPMAILFROM}='gino';
+local $ENV{SMTPRCPTTO}='pino';
+local $ENV{TCPREMOTEIP}='10.1.2.3';
+local $ENV{DAKGL_DBNAME}="$dbdir/gray3.db";
+my ($host,$from,$to)=DAKKAR::Graylister::get_from_env();
+
+ok(!DAKKAR::Graylister::is_second_attempt($host,$from,$to),'first attempt');
+DAKKAR::Graylister::record_first_attempt($host,$from,$to);
+ok(DAKKAR::Graylister::is_second_attempt($host,$from,$to),'second attempt');
+DAKKAR::Graylister::cleanup_attempt($host,$from,$to);
+ok(DAKKAR::Graylister::is_second_attempt($host,$from,$to),'updated attempt');
diff --git a/t/05-gray-empty.t b/t/05-gray-empty.t
new file mode 100644
index 0000000..2fe3b0d
--- /dev/null
+++ b/t/05-gray-empty.t
@@ -0,0 +1,18 @@
+# -*- mode: cperl -*-
+use Test::More tests=>3;
+use File::Temp 'tempdir';
+use DAKKAR::Graylister;
+
+my $dbdir=tempdir(CLEANUP=>1);
+
+local $ENV{SMTPMAILFROM}='';
+local $ENV{SMTPRCPTTO}='pino';
+local $ENV{TCPREMOTEIP}='10.1.2.3';
+local $ENV{DAKGL_DBNAME}="$dbdir/gray4.db";
+my ($host,$from,$to)=DAKKAR::Graylister::get_from_env();
+
+ok(!DAKKAR::Graylister::is_second_attempt($host,$from,$to),'first attempt');
+DAKKAR::Graylister::record_first_attempt($host,$from,$to);
+ok(DAKKAR::Graylister::is_second_attempt($host,$from,$to),'second attempt');
+DAKKAR::Graylister::cleanup_attempt($host,$from,$to);
+ok(!DAKKAR::Graylister::is_second_attempt($host,$from,$to),'cleaned attempt');
diff --git a/t/06-age.t b/t/06-age.t
new file mode 100644
index 0000000..0d47c5e
--- /dev/null
+++ b/t/06-age.t
@@ -0,0 +1,34 @@
+# -*- mode: cperl -*-
+use Test::More tests=>3;
+use File::Temp 'tempdir';
+
+my $basetime;
+
+BEGIN {
+*CORE::GLOBAL::time=sub{$basetime};
+}
+
+use DAKKAR::Graylister;
+
+no warnings 'redefine';
+
+my $dbdir=tempdir(CLEANUP=>1);
+
+local $ENV{SMTPMAILFROM}='gino';
+local $ENV{SMTPRCPTTO}='pino';
+local $ENV{TCPREMOTEIP}='10.1.2.3';
+local $ENV{DAKGL_DBNAME}="$dbdir/gray5.db";
+my ($host,$from,$to)=DAKKAR::Graylister::get_from_env();
+
+$basetime=10;
+
+ok(!DAKKAR::Graylister::is_second_attempt($host,$from,$to),'first attempt');
+DAKKAR::Graylister::record_first_attempt($host,$from,$to);
+ok(DAKKAR::Graylister::is_second_attempt($host,$from,$to),'second attempt');
+
+$basetime=90000;
+
+DAKKAR::Graylister::remove_old_attempts();
+
+ok(!DAKKAR::Graylister::is_second_attempt($host,$from,$to),'aged attempt');
+