t/10-interface.tt
changeset 73 e2559ee78cb3
parent 72 f095f28db247
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/t/10-interface.tt	Wed Jun 21 00:26:46 2017 +0200
@@ -0,0 +1,40 @@
+use strict;
+use warnings;
+
+use Test::More qw(no_plan);
+use File::Temp;
+
+use_ok 'Exim::Grey' => qw(unseen seen) or BAIL_OUT;
+
+subtest 'simple' => sub {
+    my $db = File::Temp->new();
+    is seen('a->x', 0, "$db"), 'no' => 'not seen a->x';
+    is unseen('a->b', 0,   "$db"), 'yes' => 'unseen a->b';
+    is unseen('a->b', 600, "$db"), 'yes' => 'unseen a->b with 600s delay';
+    is unseen('a->b', 0,   "$db"), 'no'  => 'not unseen a->b';
+    is seen('a->b', 600, "$db"), 'no' => 'not seen a->b with 600s delay';
+};
+
+subtest 'whitelist' => sub {
+    my $db = File::Temp->new();
+    is unseen('x->y/1.1.1.1', 1, "$db"), 'yes' => 'unseen x->y/1.1.1.1';
+    is unseen('x->y/1.1.1.1', 1, "$db"), 'yes' => 'unseen x->y/1.1.1.1';
+
+    is seen('x->y/1.1.1.1', 0, "$db"), 'yes' => 'seen x->y/1.1.1.1';
+    is seen('x->z/1.1.1.1', 0, "$db"), 'yes' => 'seen x->z/1.1.1.1 (subkey known)';
+    is seen('1.1.1.1', 0, "$db"), 'yes' => 'seen 1.1.1.1';
+
+};
+__END__
+
+subtest 'whitelist multiple subkeys' => sub {
+    my $db = File::Temp->new();
+
+    is unseen('x->y/1.1.1.1', 0, "$db"), 'yes' => 'unseen x->y/1.1.1.1';
+    is unseen('x->y/2.2.2.2', 3, "$db"), 'yes' => 'unseen x->y/3.3.3.3';
+    is unseen('x->y/3.3.3.3', 0, "$db"), 'no' => 'not unseen x->y/2.2.2.2';
+
+    is unseen('a->b/1.1.1.1', 0, "$db"), 'no' => 'not unseen (whitelisted source)';
+    is unseen('a->c/2.2.2.2', 0, "$db"), 'no' => 'not unseen (whitelisted source)';
+    is unseen('x->y/3.3.3.3', 0, "$db"), 'no' => 'not unseen x->y/3.3.3.3 (known key)';
+};