t/00-basic.t
changeset 24 d98e12e07560
parent 23 c52bb12b3ed0
child 25 e97dd97b582c
equal deleted inserted replaced
23:c52bb12b3ed0 24:d98e12e07560
     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(dig_tlsa) or BAIL_OUT;
     7 can_ok 'Nagios::Check::DNS::check_tlsa_record', qw(get_tlsa_from_dns) or BAIL_OUT;
     8 
     8 
     9 # The above package doesn't use the Exporter currently, for shortcut
     9 # The above package doesn't use the Exporter currently, for shortcut
    10 # reasons we import the relevant subs into *this* module
    10 # reasons we import the relevant subs into *this* module
    11 *dig_tlsa = \&Nagios::Check::DNS::check_tlsa_record::dig_tlsa;
    11 *get_tlsa_from_dns = \&Nagios::Check::DNS::check_tlsa_record::get_tlsa_from_dns;
    12 
    12 
    13 # API conformance
    13 # API conformance
    14 subtest 'API' => sub {
    14 subtest 'API' => sub {
    15     dies_ok { dig_tlsa('example.org') } 'API: dig_tlsa() missing port';
    15     dies_ok { get_tlsa_from_dns('example.org') } 'API: get_tlsa_from_dns() missing port';
    16 };
    16 };
    17 
    17 
    18 # get and compare the TLSA records via dig_tlsa with `dig …`
    18 # get and compare the TLSA records via get_tlsa_from_dns with `dig …`
    19 subtest 'Data' => sub {
    19 subtest 'Data' => sub {
    20     foreach (['ssl.schlittermann.de' => 443], ['mx1.mailbox.org' => 25], ['ssl.kugelbus.de' => 443]) {
    20     foreach (['ssl.schlittermann.de' => 443], 
       
    21              ['mx1.mailbox.org' => 25], 
       
    22              ['ssl.kugelbus.de' => 443]) {
    21         my ($domain, $port) = @$_;
    23         my ($domain, $port) = @$_;
    22 	my (@tlsa) = map { /^_$port._tcp.\S+\s+\d+\s+IN\s+TLSA\s+(.*\n)/i  } `dig tlsa _$port._tcp.$domain`;
    24         my (@tlsa) = map { /^_$port._tcp.\S+\s+\d+\s+IN\s+TLSA\s+(.*\n)/i  } `dig tlsa _$port._tcp.$domain`;
    23         is dig_tlsa($domain, $port), $tlsa[0] => "TLSA for $domain:$port";
    25 	#my (@tlsa) = `dig tlsa _$port._tcp.$domain +short`;
       
    26         is get_tlsa_from_dns($domain, $port), $tlsa[0] => "TLSA for $domain:$port";
    24     }
    27     }
    25 };
    28 };