12 c |
12 c |
13 __ |
13 __ |
14 $tmp->flush; |
14 $tmp->flush; |
15 |
15 |
16 sub dig_serial { (split " ", `dig +short SOA @_`)[2] } |
16 sub dig_serial { (split " ", `dig +short SOA @_`)[2] } |
17 sub dig_ns { sort map { /(\S+?)\.?$/ } `dig +short NS @_` } |
17 |
|
18 sub dig_ns { |
|
19 sort map { /(\S+?)\.?$/ } `dig +short NS @_`; |
|
20 } |
18 |
21 |
19 # we require it, it's not a normal module |
22 # we require it, it's not a normal module |
20 require_ok 'blib/nagios/plugins/ius/check_dns-serial' |
23 require_ok 'blib/nagios/plugins/ius/check_dns-serial' |
21 or BAIL_OUT q{can't require the module}; |
24 or BAIL_OUT q{can't require the module}; |
22 |
25 |
29 is_deeply [get_domains('a', "$tmp", 'z')], |
32 is_deeply [get_domains('a', "$tmp", 'z')], |
30 [qw(a a b c z)] => 'domains from args and file'; |
33 [qw(a a b c z)] => 'domains from args and file'; |
31 |
34 |
32 for (qw(heise.de schlittermann.de google.com debian.org example.org)) { |
35 for (qw(heise.de schlittermann.de google.com debian.org example.org)) { |
33 |
36 |
34 subtest $_ => sub { |
37 subtest $_ => sub { |
35 |
38 |
36 # get_ns should return the NS from public dns servers |
39 throws_ok { ns($_, nameservers => [qw/8.8.8.8/], aa => 1) } |
37 is_deeply [get_ns($_)], [dig_ns($_)] => "ns \@default"; |
40 qr/no aa/ => 'not authoritive @8.8.8.8'; |
38 is_deeply [get_ns('@8.8.4.4', $_)], [dig_ns('@8.8.4.4', $_)] => "ns \@8.8.4.4"; |
41 is_deeply [ns($_)], [dig_ns($_)] => "ns \@default"; |
39 is get_serial('@8.8.8.8', $_), dig_serial('@8.8.8.8', $_) => 'serial'; |
42 is_deeply [ns($_, nameservers => [qw/8.8.4.4/])], |
40 }; |
43 [dig_ns('@8.8.4.4', $_)] => "ns \@8.8.4.4"; |
|
44 is serial($_, nameservers => [qw/8.8.8.8/]), |
|
45 dig_serial('@8.8.8.8', $_) => 'serial'; |
|
46 }; |
41 |
47 |
42 } |
48 } |
43 |
49 |
44 # ns for some domain we're not the master for, should be refused |
50 # ns for some domain we're not the master for, should be refused |
45 throws_ok { get_ns('@212.80.235.130', 'heise.de') } qr/^REFUSED/ => 'throws on refused query'; |
51 throws_ok { ns('example.org', nameservers => [qw/f.nic.de a.nic.de b.nic.de/]) } |
46 throws_ok { get_ns('safasdfasdfrandomadsfefvddeas') } qr/^NXDOMAIN/ => 'throws on nx domain'; |
52 qr/^REFUSED/ => 'throws on refused query'; |
|
53 throws_ok { ns('safasdfasdfrandomadsfefvddeas') } |
|
54 qr/^NXDOMAIN/ => 'throws on nx domain'; |
47 |
55 |
48 ok ns_ok('@212.80.235.130', 'schlittermann.de') => 'ns for schlittermann.de'; |
56 ok ns_ok('schlittermann.de', '212.80.235.130') => 'ns_ok for schlittermann.de'; |
49 throws_ok { ns_ok('@212.80.235.130', 'heise.de') } qr/differ/ => 'ns for heise.de'; |
57 throws_ok { ns_ok('heise.de', '212.80.235.130') } qr/no aa|differ|REFUSED/ => 'ns_ok for heise.de'; |
50 |
58 throws_ok { ns_ok('heise.de', '8.8.8.8') } qr/no aa|differ|REFUSED/ => 'ns_ok for heise.de'; |
51 |
59 |
52 # serial |
60 # serial |
53 |
61 |
54 done_testing(); |
62 done_testing(); |