t/00-basic.t
changeset 72 f095f28db247
parent 71 46ba051d29bd
equal deleted inserted replaced
71:46ba051d29bd 72:f095f28db247
     4 use Test::More qw(no_plan);
     4 use Test::More qw(no_plan);
     5 use File::Temp;
     5 use File::Temp;
     6 
     6 
     7 use_ok 'Exim::Grey' => qw(unseen seen) or BAIL_OUT;
     7 use_ok 'Exim::Grey' => qw(unseen seen) or BAIL_OUT;
     8 
     8 
     9 my $db = File::Temp->new();
     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 };
    10 
    17 
    11 is seen('a->x', 1, "$db"), 'no' => 'not seen a->x';
    18 subtest 'whitelist' => sub {
    12 is unseen('a->b', 1, "$db"), 'yes' => 'unseen a->b';
    19     my $db = File::Temp->new();
    13 is unseen('a->b', 1, "$db"), 'yes' => 'unseen a->b';
    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';
    14 
    22 
    15 is unseen('x->y/1.1.1.1', 1, "$db"), 'yes' => 'unseen x->y/1.1.1.1';
    23     is unseen('x->y/1.1.1.1', 0, "$db"), 'no' => 'not unseen x->y/1.1.1.1';
    16 is unseen('x->y/1.1.1.1', 1, "$db"), 'yes' => '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';
    17 
    26 
    18 is unseen('a->b',         0, "$db"), 'no' => 'not unseen a->b';
    27 };
    19 is unseen('x->y/1.1.1.1', 0, "$db"), 'no' => 'not unseen x->y/1.1.1.1';
       
    20 is unseen('x->z/1.1.1.1', 0, "$db"), 'no' => 'not unseen x->z/1.1.1.1';
       
    21 is seen('x->z/1.1.1.1', 0, "$db"), 'yes' => 'seen x->z/1.1.1.1';
       
    22 
    28 
    23 is unseen('a->b', 600, "$db"), 'yes' => 'unseen a->b with 600s delay';
    29 subtest 'whitelist multiple subkeys' => sub {
    24 is seen('a->b', 600, "$db"), 'no' => 'not seen a->b with 600s delay';
    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 };