t/00-basic.t
changeset 73 e2559ee78cb3
parent 72 f095f28db247
child 74 adf33377005c
equal deleted inserted replaced
72:f095f28db247 73:e2559ee78cb3
     1 use strict;
       
     2 use warnings;
       
     3 
       
     4 use Test::More qw(no_plan);
       
     5 use File::Temp;
       
     6 
       
     7 use_ok 'Exim::Grey' => qw(unseen seen) or BAIL_OUT;
       
     8 
       
     9 subtest 'simple' => sub {
       
    10     my $db = File::Temp->new();
       
    11     is seen('a->x', 0, "$db"), 'no' => 'not seen a->x';
       
    12     is unseen('a->b', 0,   "$db"), 'yes' => 'unseen a->b';
       
    13     is unseen('a->b', 600, "$db"), 'yes' => 'unseen a->b with 600s delay';
       
    14     is unseen('a->b', 0,   "$db"), 'no'  => 'not unseen a->b';
       
    15     is seen('a->b', 600, "$db"), 'no' => 'not seen a->b with 600s delay';
       
    16 };
       
    17 
       
    18 subtest 'whitelist' => sub {
       
    19     my $db = File::Temp->new();
       
    20     is unseen('x->y/1.1.1.1', 1, "$db"), 'yes' => 'unseen x->y/1.1.1.1';
       
    21     is unseen('x->y/1.1.1.1', 1, "$db"), 'yes' => 'unseen x->y/1.1.1.1';
       
    22 
       
    23     is unseen('x->y/1.1.1.1', 0, "$db"), 'no' => 'not unseen x->y/1.1.1.1';
       
    24     is unseen('x->z/1.1.1.1', 0, "$db"), 'no' => 'not unseen x->z/1.1.1.1';
       
    25     is seen('x->z/1.1.1.1', 0, "$db"), 'yes' => 'seen x->z/1.1.1.1';
       
    26 
       
    27 };
       
    28 
       
    29 subtest 'whitelist multiple subkeys' => sub {
       
    30     my $db = File::Temp->new();
       
    31 
       
    32     is unseen('x->y/1.1.1.1', 0, "$db"), 'yes' => 'unseen x->y/1.1.1.1';
       
    33     is unseen('x->y/2.2.2.2', 0, "$db"), 'no' => 'not unseen x->y/2.2.2.2';
       
    34 
       
    35     is unseen('a->b/1.1.1.1', 0, "$db"), 'no' => 'not unseen (whitelisted source)';
       
    36     is unseen('a->c/2.2.2.2', 0, "$db"), 'no' => 'not unseen (whitelisted source)';
       
    37     is unseen('x->y/3.3.3.3', 0, "$db"), 'no' => 'not unseen x->y/3.3.3.3 (known key)';
       
    38 };