Zonemaster/Test/Consistency.pm untested

filter: Statementstmt 0.0% 0 / 174 Branchbran 0.0% 0 / 66 Conditioncond 0.0% 0 / 24 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 288 CC 34 SCAR 40.1
CC
34
Cov
0%
consistency01
90.0
consistency02
72.0
consistency03
72.0
CRAP 55.3
1 package Zonemaster::Test::Consistency v1.0.1;
2  
3 use 5.14.2;
4 use strict;
5 use warnings;
6  
7 use Zonemaster;
8 use Zonemaster::Util;
9 use Zonemaster::Test::Address;
10 use Zonemaster::Constants qw[:ip :soa];
11  
12 use List::MoreUtils qw[uniq];
13  
14 ###
15 ### Entry points
16 ###
17  
18 sub all {
19 my ( $class, $zone ) = @_;
20 my @results;
21  
22 push @results, $class->consistency01( $zone ) if Zonemaster->config->should_run('consistency01');
23 push @results, $class->consistency02( $zone ) if Zonemaster->config->should_run('consistency02');
24 push @results, $class->consistency03( $zone ) if Zonemaster->config->should_run('consistency03');
25 push @results, $class->consistency04( $zone ) if Zonemaster->config->should_run('consistency04');
26  
27 return @results;
28 }
29  
30 ###
31 ### Metadata Exposure
32 ###
33  
34 sub metadata {
35 my ( $class ) = @_;
36  
37 return {
38 consistency01 => [
39 qw(
40 NO_RESPONSE
41 NO_RESPONSE_SOA_QUERY
42 ONE_SOA_SERIAL
43 MULTIPLE_SOA_SERIALS
44 SOA_SERIAL
45 SOA_SERIAL_VARIATION
46 IPV4_DISABLED
47 IPV6_DISABLED
48 )
49 ],
50 consistency02 => [
51 qw(
52 NO_RESPONSE
53 NO_RESPONSE_SOA_QUERY
54 ONE_SOA_RNAME
55 MULTIPLE_SOA_RNAMES
56 SOA_RNAME
57 IPV4_DISABLED
58 IPV6_DISABLED
59 )
60 ],
61 consistency03 => [
62 qw(
63 NO_RESPONSE
64 NO_RESPONSE_SOA_QUERY
65 ONE_SOA_TIME_PARAMETER_SET
66 MULTIPLE_SOA_TIME_PARAMETER_SET
67 SOA_TIME_PARAMETER_SET
68 IPV4_DISABLED
69 IPV6_DISABLED
70 )
71 ],
72 consistency04 => [
73 qw(
74 NO_RESPONSE
75 NO_RESPONSE_NS_QUERY
76 ONE_NS_SET
77 MULTIPLE_NS_SET
78 NS_SET
79 IPV4_DISABLED
80 IPV6_DISABLED
81 )
82 ],
83 };
84 } ## end sub metadata
85  
86 sub translation {
87 return {
88 'SOA_TIME_PARAMETER_SET' =>
89 'Saw SOA time parameter set (REFRESH={refresh},RETRY={retry},EXPIRE={expire},MINIMUM={minimum}) on following nameserver set : {servers}.',
90 'ONE_SOA_RNAME' => 'A single SOA rname value was seen ({rname})',
91 'MULTIPLE_SOA_SERIALS' => 'Saw {count} SOA serial numbers.',
92 'SOA_SERIAL' => 'Saw SOA serial number {serial} on following nameserver set : {servers}.',
93 'SOA_RNAME' => 'Saw SOA rname {rname} on following nameserver set : {servers}.',
94 'MULTIPLE_SOA_RNAMES' => 'Saw {count} SOA rname.',
95 'ONE_SOA_SERIAL' => 'A single SOA serial number was seen ({serial}).',
96 'MULTIPLE_SOA_TIME_PARAMETER_SET' => 'Saw {count} SOA time parameter set.',
97 'NO_RESPONSE' => 'Nameserver {ns}/{address} did not respond.',
98 'ONE_SOA_TIME_PARAMETER_SET' =>
99 'A single SOA time parameter set was seen (REFRESH={refresh},RETRY={retry},EXPIRE={expire},MINIMUM={minimum}).',
100 'NO_RESPONSE_SOA_QUERY' => 'No response from nameserver {ns}/{address} on SOA queries.',
101 'SOA_SERIAL_VARIATION' =>
102 'Difference between the smaller serial ({serial_min}) and the bigger one ({serial_max}) is greater than the maximum allowed ({max_variation}).',
103 'NO_RESPONSE_NS_QUERY' => 'No response from nameserver {ns}/{address} on NS queries.',
104 'ONE_NS_SET' => 'A unique NS set was seen ({nsset}).',
105 'MULTIPLE_NS_SET' => 'Saw {count} NS set.',
106 'NS_SET' => 'Saw NS set ({nsset}) on following nameserver set : {servers}.',
107 'IPV4_DISABLED' => 'IPv4 is disabled, not sending "{type}" query to {ns}.',
108 'IPV6_DISABLED' => 'IPv6 is disabled, not sending "{type}" query to {ns}.',
109 };
110 } ## end sub translation
111  
112 sub version {
113 return "$Zonemaster::Test::Consistency::VERSION";
114 }
115  
116 ###
117 ### Tests
118 ###
119  
120 sub consistency01 {
121 my ( $class, $zone ) = @_;
122 my @results;
123 my %nsnames_and_ip;
124 my %serials;
125  
126 foreach
127 my $local_ns ( @{ Zonemaster::TestMethods->method4( $zone ) }, @{ Zonemaster::TestMethods->method5( $zone ) } )
128 {
129  
130 next if $nsnames_and_ip{ $local_ns->name->string . q{/} . $local_ns->address->short };
131  
132 if ( not Zonemaster->config->ipv6_ok and $local_ns->address->version == $IP_VERSION_6 ) {
133 push @results,
134 info(
135 IPV6_DISABLED => {
136 ns => "$local_ns",
137 type => q{SOA},
138 }
139 );
140 next;
141 }
142  
143 if ( not Zonemaster->config->ipv4_ok and $local_ns->address->version == $IP_VERSION_4 ) {
144 push @results,
145 info(
146 IPV4_DISABLED => {
147 ns => "$local_ns",
148 type => q{SOA},
149 }
150 );
151 next;
152 }
153  
154 my $p = $local_ns->query( $zone->name, q{SOA} );
155  
156 if ( not $p ) {
157 push @results,
158 info(
159 NO_RESPONSE => {
160 ns => $local_ns->name,
161 address => $local_ns->address->short,
162 }
163 );
164 next;
165 }
166  
167 my ( $soa ) = $p->get_records_for_name( q{SOA}, $zone->name );
168  
169 if ( not $soa ) {
170 push @results,
171 info(
172 NO_RESPONSE_SOA_QUERY => {
173 ns => $local_ns->name,
174 address => $local_ns->address->short,
175 }
176 );
177 next;
178 }
179 else {
180 push @{ $serials{ $soa->serial } }, $local_ns->name->string . q{/} . $local_ns->address->short;
181 $nsnames_and_ip{ $local_ns->name->string . q{/} . $local_ns->address->short }++;
182 }
183 } ## end foreach my $local_ns ( @{ Zonemaster::TestMethods...})
184  
185 my @serial_numbers = sort keys %serials;
186 if ( scalar( @serial_numbers ) == 1 ) {
187 push @results,
188 info(
189 ONE_SOA_SERIAL => {
190 serial => ( keys %serials )[0],
191 }
192 );
193 }
194 elsif ( scalar @serial_numbers ) {
195 push @results,
196 info(
197 MULTIPLE_SOA_SERIALS => {
198 count => scalar( keys %serials ),
199 }
200 );
201 foreach my $serial ( keys %serials ) {
202 push @results,
203 info(
204 SOA_SERIAL => {
205 serial => $serial,
206 servers => join( q{;}, sort @{ $serials{$serial} } ),
207 }
208 );
209 }
210 if ( $serial_numbers[-1] - $serial_numbers[0] > $MAX_SERIAL_VARIATION ) {
211 push @results,
212 info(
213 SOA_SERIAL_VARIATION => {
214 serial_min => $serial_numbers[0],
215 serial_max => $serial_numbers[-1],
216 max_variation => $MAX_SERIAL_VARIATION,
217 }
218 );
219 }
220 } ## end elsif ( scalar @serial_numbers)
221  
222 return @results;
223 } ## end sub consistency01
224  
225 sub consistency02 {
226 my ( $class, $zone ) = @_;
227 my @results;
228 my %nsnames_and_ip;
229 my %rnames;
230  
231 foreach
232 my $local_ns ( @{ Zonemaster::TestMethods->method4( $zone ) }, @{ Zonemaster::TestMethods->method5( $zone ) } )
233 {
234  
235 next if $nsnames_and_ip{ $local_ns->name->string . q{/} . $local_ns->address->short };
236  
237 if ( not Zonemaster->config->ipv6_ok and $local_ns->address->version == $IP_VERSION_6 ) {
238 push @results,
239 info(
240 IPV6_DISABLED => {
241 ns => "$local_ns",
242 type => q{SOA},
243 }
244 );
245 next;
246 }
247  
248 if ( not Zonemaster->config->ipv4_ok and $local_ns->address->version == $IP_VERSION_4 ) {
249 push @results,
250 info(
251 IPV4_DISABLED => {
252 ns => "$local_ns",
253 type => q{SOA},
254 }
255 );
256 next;
257 }
258  
259 my $p = $local_ns->query( $zone->name, q{SOA} );
260  
261 if ( not $p ) {
262 push @results,
263 info(
264 NO_RESPONSE => {
265 ns => $local_ns->name,
266 address => $local_ns->address->short,
267 }
268 );
269 next;
270 }
271  
272 my ( $soa ) = $p->get_records_for_name( q{SOA}, $zone->name );
273  
274 if ( not $soa ) {
275 push @results,
276 info(
277 NO_RESPONSE_SOA_QUERY => {
278 ns => $local_ns->name,
279 address => $local_ns->address->short,
280 }
281 );
282 next;
283 }
284 else {
285 push @{ $rnames{ lc( $soa->rname ) } }, $local_ns->name->string . q{/} . $local_ns->address->short;
286 $nsnames_and_ip{ $local_ns->name->string . q{/} . $local_ns->address->short }++;
287 }
288 } ## end foreach my $local_ns ( @{ Zonemaster::TestMethods...})
289  
290 if ( scalar( keys %rnames ) == 1 ) {
291 push @results,
292 info(
293 ONE_SOA_RNAME => {
294 rname => ( keys %rnames )[0],
295 }
296 );
297 }
298 elsif ( scalar( keys %rnames ) ) {
299 push @results,
300 info(
301 MULTIPLE_SOA_RNAMES => {
302 count => scalar( keys %rnames ),
303 }
304 );
305 foreach my $rname ( keys %rnames ) {
306 push @results,
307 info(
308 SOA_RNAME => {
309 rname => $rname,
310 servers => join( q{;}, @{ $rnames{$rname} } ),
311 }
312 );
313 }
314 }
315  
316 return @results;
317 } ## end sub consistency02
318  
319 sub consistency03 {
320 my ( $class, $zone ) = @_;
321 my @results;
322 my %nsnames_and_ip;
323 my %time_parameter_sets;
324  
325 foreach
326 my $local_ns ( @{ Zonemaster::TestMethods->method4( $zone ) }, @{ Zonemaster::TestMethods->method5( $zone ) } )
327 {
328  
329 next if $nsnames_and_ip{ $local_ns->name->string . q{/} . $local_ns->address->short };
330  
331 if ( not Zonemaster->config->ipv6_ok and $local_ns->address->version == $IP_VERSION_6 ) {
332 push @results,
333 info(
334 IPV6_DISABLED => {
335 ns => "$local_ns",
336 type => q{SOA},
337 }
338 );
339 next;
340 }
341  
342 if ( not Zonemaster->config->ipv4_ok and $local_ns->address->version == $IP_VERSION_4 ) {
343 push @results,
344 info(
345 IPV4_DISABLED => {
346 ns => "$local_ns",
347 type => q{SOA},
348 }
349 );
350 next;
351 }
352  
353 my $p = $local_ns->query( $zone->name, q{SOA} );
354  
355 if ( not $p ) {
356 push @results,
357 info(
358 NO_RESPONSE => {
359 ns => $local_ns->name,
360 address => $local_ns->address->short,
361 }
362 );
363 next;
364 }
365  
366 my ( $soa ) = $p->get_records_for_name( q{SOA}, $zone->name );
367  
368 if ( not $soa ) {
369 push @results,
370 info(
371 NO_RESPONSE_SOA_QUERY => {
372 ns => $local_ns->name,
373 address => $local_ns->address->short,
374 }
375 );
376 next;
377 }
378 else {
379 push
380 @{ $time_parameter_sets{ sprintf q{%d;%d;%d;%d}, $soa->refresh, $soa->retry, $soa->expire, $soa->minimum }
381 },
382 $local_ns->name->string . q{/} . $local_ns->address->short;
383 $nsnames_and_ip{ $local_ns->name->string . q{/} . $local_ns->address->short }++;
384 }
385 } ## end foreach my $local_ns ( @{ Zonemaster::TestMethods...})
386  
387 if ( scalar( keys %time_parameter_sets ) == 1 ) {
388 my ( $refresh, $retry, $expire, $minimum ) = split /;/sxm, ( keys %time_parameter_sets )[0];
389 push @results,
390 info(
391 ONE_SOA_TIME_PARAMETER_SET => {
392 refresh => $refresh,
393 retry => $retry,
394 expire => $expire,
395 minimum => $minimum,
396 }
397 );
398 }
399 elsif ( scalar( keys %time_parameter_sets ) ) {
400 push @results,
401 info(
402 MULTIPLE_SOA_TIME_PARAMETER_SET => {
403 count => scalar( keys %time_parameter_sets ),
404 }
405 );
406 foreach my $time_parameter_set ( keys %time_parameter_sets ) {
407 my ( $refresh, $retry, $expire, $minimum ) = split /;/sxm, $time_parameter_set;
408 push @results,
409 info(
410 SOA_TIME_PARAMETER_SET => {
411 refresh => $refresh,
412 retry => $retry,
413 expire => $expire,
414 minimum => $minimum,
415 servers => join( q{;}, sort @{ $time_parameter_sets{$time_parameter_set} } ),
416 }
417 );
418 }
419 } ## end elsif ( scalar( keys %time_parameter_sets...))
420  
421 return @results;
422 } ## end sub consistency03
423  
424 sub consistency04 {
425 my ( $class, $zone ) = @_;
426 my @results;
427 my %nsnames_and_ip;
428 my %ns_sets;
429  
430 foreach
431 my $local_ns ( @{ Zonemaster::TestMethods->method4( $zone ) }, @{ Zonemaster::TestMethods->method5( $zone ) } )
432 {
433  
434 next if $nsnames_and_ip{ $local_ns->name->string . q{/} . $local_ns->address->short };
435  
436 if ( not Zonemaster->config->ipv6_ok and $local_ns->address->version == $IP_VERSION_6 ) {
437 push @results,
438 info(
439 IPV6_DISABLED => {
440 ns => "$local_ns",
441 type => q{SOA},
442 }
443 );
444 next;
445 }
446  
447 if ( not Zonemaster->config->ipv4_ok and $local_ns->address->version == $IP_VERSION_4 ) {
448 push @results,
449 info(
450 IPV4_DISABLED => {
451 ns => "$local_ns",
452 type => q{SOA},
453 }
454 );
455 next;
456 }
457  
458 my $p = $local_ns->query( $zone->name, q{NS} );
459  
460 if ( not $p ) {
461 push @results,
462 info(
463 NO_RESPONSE => {
464 ns => $local_ns->name,
465 address => $local_ns->address->short,
466 }
467 );
468 next;
469 }
470  
471 my ( @ns ) = sort map { lc($_->nsdname) } $p->get_records_for_name( q{NS}, $zone->name );
472  
473 if ( not scalar( @ns ) ) {
474 push @results,
475 info(
476 NO_RESPONSE_NS_QUERY => {
477 ns => $local_ns->name,
478 address => $local_ns->address->short,
479 }
480 );
481 next;
482 }
483 else {
484 push @{ $ns_sets{ join( q{,}, @ns ) } }, $local_ns->name->string . q{/} . $local_ns->address->short;
485 $nsnames_and_ip{ $local_ns->name->string . q{/} . $local_ns->address->short }++;
486 }
487 } ## end foreach my $local_ns ( @{ Zonemaster::TestMethods...})
488  
489 if ( scalar( keys %ns_sets ) == 1 ) {
490 push @results,
491 info(
492 ONE_NS_SET => {
493 nsset => ( keys %ns_sets )[0],
494 }
495 );
496 }
497 elsif ( scalar( keys %ns_sets ) ) {
498 push @results,
499 info(
500 MULTIPLE_NS_SET => {
501 count => scalar( keys %ns_sets ),
502 }
503 );
504 foreach my $ns_set ( keys %ns_sets ) {
505 push @results,
506 info(
507 NS_SET => {
508 nsset => $ns_set,
509 servers => join( q{;}, @{ $ns_sets{$ns_set} } ),
510 }
511 );
512 }
513 }
514  
515 return @results;
516 } ## end sub consistency04
517  
518 1;
519  
520 =head1 NAME
521  
522 Zonemaster::Test::Consistency - Consistency module showing the expected structure of Zonemaster test modules
523  
524 =head1 SYNOPSIS
525  
526 my @results = Zonemaster::Test::Consistency->all($zone);
527  
528 =head1 METHODS
529  
530 =over
531  
532 =item all($zone)
533  
534 Runs the default set of tests and returns a list of log entries made by the tests.
535  
536 =item metadata()
537  
538 Returns a reference to a hash, the keys of which are the names of all test methods in the module, and the corresponding values are references to
539 lists with all the tags that the method can use in log entries.
540  
541 =item translation()
542  
543 Returns a refernce to a hash with translation data. Used by the builtin translation system.
544  
545 =item version()
546  
547 Returns a version string for the module.
548  
549 =back
550  
551 =head1 TESTS
552  
553 =over
554  
555 =item consistency01($zone)
556  
557 Query all nameservers for SOA, and see that they all have the same SOA serial number.
558  
559 =item consistency02($zone)
560  
561 Query all nameservers for SOA, and see that they all have the same SOA rname.
562  
563 =item consistency03($zone)
564  
565 Query all nameservers for SOA, and see that they all have the same time parameters (REFRESH/RETRY/EXPIRE/MINIMUM).
566  
567 =item consistency04($zone)
568  
569 Query all nameservers for NS set, and see that they have all the same content.
570  
571 =back
572  
573 =cut