|
1 use 5.014; |
|
2 use strict; |
|
3 use warnings; |
|
4 use Test::More; |
|
5 use File::Temp; |
|
6 use Test::Exception; |
|
7 |
|
8 my $tmp = File::Temp->new; |
|
9 $tmp->print(<<__); |
|
10 a |
|
11 b |
|
12 c |
|
13 __ |
|
14 $tmp->flush; |
|
15 |
|
16 sub dig_serial { (split " ", `dig +short SOA @_`)[2] } |
|
17 sub dig_ns { sort map { /(\S+?)\.?$/ } `dig +short NS @_` } |
|
18 |
|
19 # we require it, it's not a normal module |
|
20 require_ok 'blib/nagios/plugins/ius/check_dns-serial' |
|
21 or BAIL_OUT q{can't require the module}; |
|
22 |
|
23 is_deeply [sort +uniq(qw(a b a c))], [qw(a b c)] => 'uniq helper'; |
|
24 |
|
25 # get_domains should read a list of names, either from a file |
|
26 # or from the arguments, or from a combination of both |
|
27 is_deeply [get_domains(qw(a b c))], [qw(a b c)] => 'domains from list'; |
|
28 is_deeply [get_domains("$tmp")], [qw(a b c)] => 'domains from file'; |
|
29 is_deeply [get_domains('a', "$tmp", 'z')], |
|
30 [qw(a a b c z)] => 'domains from args and file'; |
|
31 |
|
32 for (qw(heise.de schlittermann.de google.com debian.org example.org)) { |
|
33 |
|
34 subtest $_ => sub { |
|
35 |
|
36 # get_ns should return the NS from public dns servers |
|
37 is_deeply [get_ns($_)], [dig_ns($_)] => "ns \@default"; |
|
38 is_deeply [get_ns('@8.8.4.4', $_)], [dig_ns('@8.8.4.4', $_)] => "ns \@8.8.4.4"; |
|
39 is get_serial('@8.8.8.8', $_), dig_serial('@8.8.8.8', $_) => 'serial'; |
|
40 }; |
|
41 |
|
42 } |
|
43 |
|
44 # 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'; |
|
46 throws_ok { get_ns('safasdfasdfrandomadsfefvddeas') } qr/^NXDOMAIN/ => 'throws on nx domain'; |
|
47 |
|
48 ok ns_ok('@212.80.235.130', 'schlittermann.de') => 'ns for schlittermann.de'; |
|
49 throws_ok { ns_ok('@212.80.235.130', 'heise.de') } qr/differ/ => 'ns for heise.de'; |
|
50 |
|
51 |
|
52 # serial |
|
53 |
|
54 done_testing(); |