t/00-basic.t
changeset 27 32c8d3292079
parent 25 e97dd97b582c
child 39 0f95ea2ef883
equal deleted inserted replaced
26:3190e55f104b 27:32c8d3292079
     2 use warnings;
     2 use warnings;
     3 use Test::More qw(no_plan);
     3 use Test::More qw(no_plan);
     4 use Test::Exception;
     4 use Test::Exception;
     5 
     5 
     6 use_ok 'Nagios::Check::DNS::check_tlsa_record' or BAIL_OUT;
     6 use_ok 'Nagios::Check::DNS::check_tlsa_record' or BAIL_OUT;
     7 can_ok 'Nagios::Check::DNS::check_tlsa_record', qw(get_tlsa_from_dns) or BAIL_OUT;
     7 can_ok 'Nagios::Check::DNS::check_tlsa_record', qw(get_tlsa_from_dns)
       
     8   or BAIL_OUT;
     8 
     9 
     9 # The above package doesn't use the Exporter currently, for shortcut
    10 # The above package doesn't use the Exporter currently, for shortcut
    10 # reasons we import the relevant subs into *this* module
    11 # reasons we import the relevant subs into *this* module
    11 *get_tlsa_from_dns = \&Nagios::Check::DNS::check_tlsa_record::get_tlsa_from_dns;
    12 *get_tlsa_from_dns = \&Nagios::Check::DNS::check_tlsa_record::get_tlsa_from_dns;
    12 
    13 
    13 # API conformance
    14 # API conformance
    14 subtest 'API' => sub {
    15 subtest 'API' => sub {
    15     dies_ok { get_tlsa_from_dns('example.org') } 'API: get_tlsa_from_dns() missing port';
    16     dies_ok { get_tlsa_from_dns('example.org') }
       
    17     'API: get_tlsa_from_dns() missing port';
    16 };
    18 };
    17 
    19 
    18 # get and compare the TLSA records via get_tlsa_from_dns with `dig …`
    20 # get and compare the TLSA records via get_tlsa_from_dns with `dig …`
    19 subtest 'Data' => sub {
    21 subtest 'Data' => sub {
    20     foreach (['ssl.schlittermann.de' => 443], 
    22     foreach (
    21              ['mx1.mailbox.org' => 25], 
    23         ['ssl.schlittermann.de' => 443],
    22              ['ssl.kugelbus.de' => 443]) {
    24         ['mx1.mailbox.org'      => 25],
       
    25         ['ssl.kugelbus.de'      => 443]
       
    26       )
       
    27     {
    23         my ($domain, $port) = @$_;
    28         my ($domain, $port) = @$_;
    24         my (@tlsa) = map { /^_$port._tcp.\S+\s+\d+\s+IN\s+TLSA\s+(.*\n)/i  } `dig tlsa _$port._tcp.$domain`;
    29         my (@tlsa) = map { /^_$port._tcp.\S+\s+\d+\s+IN\s+TLSA\s+(.*\n)/i }
    25   #is get_tlsa_from_dns($domain, $port), $tlsa[0] => "TLSA for $domain:$port";
    30           `dig tlsa _$port._tcp.$domain`;
       
    31 
       
    32     #is get_tlsa_from_dns($domain, $port), $tlsa[0] => "TLSA for $domain:$port";
    26         my @check = get_tlsa_from_dns($domain, $port);
    33         my @check = get_tlsa_from_dns($domain, $port);
    27         is $check[0], $tlsa[0] => "TLSA for $domain:$port";
    34         is $check[0], $tlsa[0] => "TLSA for $domain:$port";
    28     }
    35     }
    29 };
    36 };