Zonemaster/Engine/Test/Connectivity.pm untested

filter: Statementstmt 0.0% 0 / 289 Branchbran 0.0% 0 / 90 Conditioncond 0.0% 0 / 40 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 0.0% 0 / 24 Podpod 0.0% 0 / 11 totaltotal 0.0% 0 / 480 CC 46 SCAR 46.8
CC
46
Cov
0%
connectivity03
240.0
connectivity04
182.0
_connectivity_loop
110.0
CRAP 107.8
1 package Zonemaster::Engine::Test::Connectivity;
2  
3 use v5.16.0;
4 use warnings;
5  
6 use version; our $VERSION = version->declare("v1.1.0");
7  
8 use Carp;
9 use List::MoreUtils qw[uniq];
10 use Locale::TextDomain qw[Zonemaster-Engine];
11 use Readonly;
12  
13 use Zonemaster::Engine::Profile;
14 use Zonemaster::Engine::ASNLookup;
15 use Zonemaster::Engine::Constants qw[:ip];
16 use Zonemaster::Engine::TestMethods;
17 use Zonemaster::Engine::TestMethodsV2;
18 use Zonemaster::Engine::Util;
19  
20 =head1 NAME
21  
22 Zonemaster::Engine::Test::Connectivity - Module implementing tests focused on name servers reachability
23  
24 =head1 SYNOPSIS
25  
26 my @results = Zonemaster::Engine::Test::Connectivity->all( $zone );
27  
28 =head1 METHODS
29  
30 =over
31  
32 =item all()
33  
34 my @array = all( $zone );
35  
36 Runs the default set of tests for that module, i.e. L<four tests|/TESTS>.
37  
38 Takes a L<Zonemaster::Engine::Zone> object.
39  
40 Returns a list of L<Zonemaster::Engine::Logger::Entry> objects.
41  
42 =back
43  
44 =cut
45  
46 sub all {
47 my ( $class, $zone ) = @_;
48 my @results;
49  
50 if ( Zonemaster::Engine::Util::should_run_test( q{connectivity01} ) ) {
51 push @results, $class->connectivity01( $zone );
52 }
53 if ( Zonemaster::Engine::Util::should_run_test( q{connectivity02} ) ) {
54 push @results, $class->connectivity02( $zone );
55 }
56 if ( Zonemaster::Engine::Util::should_run_test( q{connectivity03} ) ) {
57 push @results, $class->connectivity03( $zone );
58 }
59 if ( Zonemaster::Engine::Util::should_run_test( q{connectivity04} ) ) {
60 push @results, $class->connectivity04( $zone );
61 }
62  
63 return @results;
64 }
65  
66 =over
67  
68 =item metadata()
69  
70 my $hash_ref = metadata();
71  
72 Returns a reference to a hash, the keys of which are the names of all Test Cases in the module, and the corresponding values are references to
73 an array containing all the message tags that the Test Case can use in L<log entries|Zonemaster::Engine::Logger::Entry>.
74  
75 =back
76  
77 =cut
78  
79 sub metadata {
80 my ( $class ) = @_;
81  
82 return {
83 connectivity01 => [
84 qw(
85 CN01_IPV4_DISABLED
86 CN01_IPV6_DISABLED
87 CN01_MISSING_NS_RECORD_UDP
88 CN01_MISSING_SOA_RECORD_UDP
89 CN01_NO_RESPONSE_NS_QUERY_UDP
90 CN01_NO_RESPONSE_SOA_QUERY_UDP
91 CN01_NO_RESPONSE_UDP
92 CN01_NS_RECORD_NOT_AA_UDP
93 CN01_SOA_RECORD_NOT_AA_UDP
94 CN01_UNEXPECTED_RCODE_NS_QUERY_UDP
95 CN01_UNEXPECTED_RCODE_SOA_QUERY_UDP
96 CN01_WRONG_NS_RECORD_UDP
97 CN01_WRONG_SOA_RECORD_UDP
98 IPV4_DISABLED
99 IPV6_DISABLED
100 TEST_CASE_END
101 TEST_CASE_START
102 )
103 ],
104 connectivity02 => [
105 qw(
106 CN02_MISSING_NS_RECORD_TCP
107 CN02_MISSING_SOA_RECORD_TCP
108 CN02_NO_RESPONSE_NS_QUERY_TCP
109 CN02_NO_RESPONSE_SOA_QUERY_TCP
110 CN02_NO_RESPONSE_TCP
111 CN02_NS_RECORD_NOT_AA_TCP
112 CN02_SOA_RECORD_NOT_AA_TCP
113 CN02_UNEXPECTED_RCODE_NS_QUERY_TCP
114 CN02_UNEXPECTED_RCODE_SOA_QUERY_TCP
115 CN02_WRONG_NS_RECORD_TCP
116 CN02_WRONG_SOA_RECORD_TCP
117 IPV4_DISABLED
118 IPV6_DISABLED
119 TEST_CASE_END
120 TEST_CASE_START
121 )
122 ],
123 connectivity03 => [
124 qw(
125 ASN_INFOS_RAW
126 ASN_INFOS_ANNOUNCE_BY
127 ASN_INFOS_ANNOUNCE_IN
128 EMPTY_ASN_SET
129 ERROR_ASN_DATABASE
130 IPV4_DIFFERENT_ASN
131 IPV4_ONE_ASN
132 IPV4_SAME_ASN
133 IPV6_DIFFERENT_ASN
134 IPV6_ONE_ASN
135 IPV6_SAME_ASN
136 TEST_CASE_END
137 TEST_CASE_START
138 )
139 ],
140 connectivity04 => [
141 qw(
142 ASN_INFOS_RAW
143 ASN_INFOS_ANNOUNCE_IN
144 CN04_EMPTY_PREFIX_SET
145 CN04_ERROR_PREFIX_DATABASE
146 CN04_IPV4_DIFFERENT_PREFIX
147 CN04_IPV4_SAME_PREFIX
148 CN04_IPV4_SINGLE_PREFIX
149 CN04_IPV6_DIFFERENT_PREFIX
150 CN04_IPV6_SAME_PREFIX
151 CN04_IPV6_SINGLE_PREFIX
152 TEST_CASE_END
153 TEST_CASE_START
154 )
155 ],
156 };
157 } ## end sub metadata
158  
159 Readonly my %TAG_DESCRIPTIONS => (
160 CONNECTIVITY01 => sub {
161 __x # CONNECTIVITY:CONNECTIVITY01
162 'UDP connectivity';
163 },
164 CONNECTIVITY02 => sub {
165 __x # CONNECTIVITY:CONNECTIVITY02
166 'TCP connectivity';
167 },
168 CONNECTIVITY03 => sub {
169 __x # CONNECTIVITY:CONNECTIVITY03
170 'AS Diversity';
171 },
172 CONNECTIVITY04 => sub {
173 __x # CONNECTIVITY:CONNECTIVITY04
174 'IP Prefix Diversity';
175 },
176 CN01_IPV4_DISABLED => sub {
177 __x # CONNECTIVITY:CN01_IPV4_DISABLED
178 'IPv4 is disabled. No DNS queries are sent to these name servers: "{ns_list}".', @_;
179 },
180 CN01_IPV6_DISABLED => sub {
181 __x # CONNECTIVITY:CN01_IPV6_DISABLED
182 'IPv6 is disabled. No DNS queries are sent to these name servers: "{ns_list}".', @_;
183 },
184 CN01_MISSING_NS_RECORD_UDP => sub {
185 __x # CONNECTIVITY:CN01_MISSING_NS_RECORD_UDP
186 'Nameserver {ns} responds to a NS query with no NS records in the answer section over UDP.', @_;
187 },
188 CN01_MISSING_SOA_RECORD_UDP => sub {
189 __x # CONNECTIVITY:CN01_MISSING_SOA_RECORD_UDP
190 'Nameserver {ns} responds to a SOA query with no SOA records in the answer section over UDP.', @_;
191 },
192 CN01_NO_RESPONSE_NS_QUERY_UDP => sub {
193 __x # CONNECTIVITY:CN01_NO_RESPONSE_NS_QUERY_UDP
194 'Nameserver {ns} does not respond to NS queries over UDP.', @_;
195 },
196 CN01_NO_RESPONSE_SOA_QUERY_UDP => sub {
197 __x # CONNECTIVITY:CN01_NO_RESPONSE_SOA_QUERY_UDP
198 'Nameserver {ns} does not respond to SOA queries over UDP.', @_;
199 },
200 CN01_NO_RESPONSE_UDP => sub {
201 __x # CONNECTIVITY:CN01_NO_RESPONSE_UDP
202 'Nameserver {ns} does not respond to any queries over UDP.', @_;
203 },
204 CN01_NS_RECORD_NOT_AA_UDP => sub {
205 __x # CONNECTIVITY:CN01_NS_RECORD_NOT_AA_UDP
206 'Nameserver {ns} does not give an authoritative response on an NS query over UDP.', @_;
207 },
208 CN01_SOA_RECORD_NOT_AA_UDP => sub {
209 __x # CONNECTIVITY:CN01_SOA_RECORD_NOT_AA_UDP
210 'Nameserver {ns} does not give an authoritative response on an SOA query over UDP.', @_;
211 },
212 CN01_UNEXPECTED_RCODE_NS_QUERY_UDP => sub {
213 __x # CONNECTIVITY:CN01_UNEXPECTED_RCODE_NS_QUERY_UDP
214 'Nameserver {ns} responds with an unexpected RCODE ({rcode}) on an NS query over UDP.', @_;
215 },
216 CN01_UNEXPECTED_RCODE_SOA_QUERY_UDP => sub {
217 __x # CONNECTIVITY:CN01_UNEXPECTED_RCODE_SOA_QUERY_UDP
218 'Nameserver {ns} responds with an unexpected RCODE ({rcode}) on an SOA query over UDP.', @_;
219 },
220 CN01_WRONG_NS_RECORD_UDP => sub {
221 __x # CONNECTIVITY:CN01_WRONG_NS_RECORD_UDP
222 'Nameserver {ns} responds with a wrong owner name ({domain_found} instead of {domain_expected}) on NS queries over UDP.', @_;
223 },
224 CN01_WRONG_SOA_RECORD_UDP => sub {
225 __x # CONNECTIVITY:CN01_WRONG_SOA_RECORD_UDP
226 'Nameserver {ns} responds with a wrong owner name ({domain_found} instead of {domain_expected}) on SOA queries over UDP.', @_;
227 },
228 CN02_MISSING_NS_RECORD_TCP => sub {
229 __x # CONNECTIVITY:CN02_MISSING_NS_RECORD_TCP
230 'Nameserver {ns} responds to a NS query with no NS records in the answer section over TCP.', @_;
231 },
232 CN02_MISSING_SOA_RECORD_TCP => sub {
233 __x # CONNECTIVITY:CN02_MISSING_SOA_RECORD_TCP
234 'Nameserver {ns} responds to a SOA query with no SOA records in the answer section over TCP.', @_;
235 },
236 CN02_NO_RESPONSE_NS_QUERY_TCP => sub {
237 __x # CONNECTIVITY:CN02_NO_RESPONSE_NS_QUERY_TCP
238 'Nameserver {ns} does not respond to NS queries over TCP.', @_;
239 },
240 CN02_NO_RESPONSE_SOA_QUERY_TCP => sub {
241 __x # CONNECTIVITY:CN02_NO_RESPONSE_SOA_QUERY_TCP
242 'Nameserver {ns} does not respond to SOA queries over TCP.', @_;
243 },
244 CN02_NO_RESPONSE_TCP => sub {
245 __x # CONNECTIVITY:CN02_NO_RESPONSE_TCP
246 'Nameserver {ns} does not respond to any queries over TCP.', @_;
247 },
248 CN02_NS_RECORD_NOT_AA_TCP => sub {
249 __x # CONNECTIVITY:CN02_NS_RECORD_NOT_AA_TCP
250 'Nameserver {ns} does not give an authoritative response on an NS query over TCP.', @_;
251 },
252 CN02_SOA_RECORD_NOT_AA_TCP => sub {
253 __x # CONNECTIVITY:CN02_SOA_RECORD_NOT_AA_TCP
254 'Nameserver {ns} does not give an authoritative response on an SOA query over TCP.', @_;
255 },
256 CN02_UNEXPECTED_RCODE_NS_QUERY_TCP => sub {
257 __x # CONNECTIVITY:CN02_UNEXPECTED_RCODE_NS_QUERY_TCP
258 'Nameserver {ns} responds with an unexpected RCODE ({rcode}) on an NS query over TCP.', @_;
259 },
260 CN02_UNEXPECTED_RCODE_SOA_QUERY_TCP => sub {
261 __x # CONNECTIVITY:CN02_UNEXPECTED_RCODE_SOA_QUERY_TCP
262 'Nameserver {ns} responds with an unexpected RCODE ({rcode}) on an SOA query over TCP.', @_;
263 },
264 CN02_WRONG_NS_RECORD_TCP => sub {
265 __x # CONNECTIVITY:CN02_WRONG_NS_RECORD_TCP
266 'Nameserver {ns} responds with a wrong owner name ({domain_found} instead of {domain_expected}) on NS queries over TCP.', @_;
267 },
268 CN02_WRONG_SOA_RECORD_TCP => sub {
269 __x # CONNECTIVITY:CN02_WRONG_SOA_RECORD_TCP
270 'Nameserver {ns} responds with a wrong owner name ({domain_found} instead of {domain_expected}) on SOA queries over TCP.', @_;
271 },
272 CN04_ASN_INFOS_ANNOUNCE_IN => sub {
273 __x # CONNECTIVITY:ASN_INFOS_ANNOUNCE_IN
274 'Name server IP address "{ns_ip}" is announced in prefix "{prefix}".', @_;
275 },
276 CN04_ASN_INFOS_RAW => sub {
277 __x # CONNECTIVITY:ASN_INFOS_RAW
278 'The ASN data for name server IP address "{ns_ip}" is "{data}".', @_;
279 },
280 CN04_EMPTY_PREFIX_SET => sub {
281 __x # CONNECTIVITY:CN04_EMPTY_PREFIX_SET
282 'Prefix database returned no information for IP address {ns_ip}.', @_;
283 },
284 CN04_ERROR_PREFIX_DATABASE => sub {
285 __x # CONNECTIVITY:CN04_ERROR_PREFIX_DATABASE
286 'Prefix database error for IP address {ns_ip}.', @_;
287 },
288 CN04_IPV4_DIFFERENT_PREFIX => sub {
289 __x # CONNECTIVITY:CN04_IPV4_DIFFERENT_PREFIX
290 'The following name server(s) are announced in unique IPv4 prefix(es): "{ns_list}"', @_;
291 },
292 CN04_IPV4_SAME_PREFIX => sub {
293 __x # CONNECTIVITY:CN04_IPV4_SAME_PREFIX
294 'The following name server(s) are announced in the same IPv4 prefix ({ip_prefix}): "{ns_list}"', @_;
295 },
296 CN04_IPV4_SINGLE_PREFIX => sub {
297 __x # CONNECTIVITY:CN04_IPV4_SINGLE_PREFIX
298 'All name server(s) IPv4 address(es) are announced in the same IPv4 prefix.';
299 },
300 CN04_IPV6_DIFFERENT_PREFIX => sub {
301 __x # CONNECTIVITY:CN04_IPV6_DIFFERENT_PREFIX
302 'The following name server(s) are announced in unique IPv6 prefix(es): "{ns_list}"', @_;
303 },
304 CN04_IPV6_SAME_PREFIX => sub {
305 __x # CONNECTIVITY:CN04_IPV6_SAME_PREFIX
306 'The following name server(s) are announced in the same IPv6 prefix ({ip_prefix}): "{ns_list}"', @_;
307 },
308 CN04_IPV6_SINGLE_PREFIX => sub {
309 __x # CONNECTIVITY:CN04_IPV6_SINGLE_PREFIX
310 'All name server(s) IPv6 address(es) are announced in the same IPv6 prefix.';
311 },
312 ERROR_ASN_DATABASE => sub {
313 __x # CONNECTIVITY:ERROR_ASN_DATABASE
314 'ASN Database error. No data to analyze for {ns_ip}.', @_;
315 },
316 EMPTY_ASN_SET => sub {
317 __x # CONNECTIVITY:EMPTY_ASN_SET
318 'AS database returned no informations for IP address {ns_ip}.', @_;
319 },
320 IPV4_SAME_ASN => sub {
321 __x # CONNECTIVITY:IPV4_SAME_ASN
322 'All authoritative nameservers have their IPv4 addresses in the same AS set ({asn_list}).', @_;
323 },
324 IPV4_ONE_ASN => sub {
325 __x # CONNECTIVITY:IPV4_ONE_ASN
326 'All authoritative nameservers have their IPv4 addresses in the same AS ({asn}).', @_;
327 },
328 IPV4_DIFFERENT_ASN => sub {
329 __x # CONNECTIVITY:IPV4_DIFFERENT_ASN
330 'At least two IPv4 addresses of the authoritative nameservers are announced by different AS sets. '
331 . 'A merged list of all AS: ({asn_list}).', @_;
332 },
333 IPV6_SAME_ASN => sub {
334 __x # CONNECTIVITY:IPV6_SAME_ASN
335 'All authoritative nameservers have their IPv6 addresses in the same AS set ({asn_list}).', @_;
336 },
337 IPV6_ONE_ASN => sub {
338 __x # CONNECTIVITY:IPV6_ONE_ASN
339 'All authoritative nameservers have their IPv6 addresses in the same AS ({asn}).', @_;
340 },
341 IPV6_DIFFERENT_ASN => sub {
342 __x # CONNECTIVITY:IPV6_DIFFERENT_ASN
343 'At least two IPv6 addresses of the authoritative nameservers are announced by different AS sets. '
344 . 'A merged list of all AS: ({asn_list}).', @_;
345 },
346 IPV4_DISABLED => sub {
347 __x # CONNECTIVITY:IPV4_DISABLED
348 'IPv4 is disabled, not sending "{rrtype}" query to {ns}.', @_;
349 },
350 IPV6_DISABLED => sub {
351 __x # CONNECTIVITY:IPV6_DISABLED
352 'IPv6 is disabled, not sending "{rrtype}" query to {ns}.', @_;
353 },
354 IPV4_ASN => sub {
355 __x # CONNECTIVITY:IPV4_ASN
356 'Name servers have IPv4 addresses in the following ASs: {asn}.', @_;
357 },
358 IPV6_ASN => sub {
359 __x # CONNECTIVITY:IPV6_ASN
360 'Name servers have IPv6 addresses in the following ASs: {asn}.', @_;
361 },
362 ASN_INFOS_RAW => sub {
363 __x # CONNECTIVITY:ASN_INFOS_RAW
364 'The ASN data for name server IP address "{ns_ip}" is "{data}".', @_;
365 },
366 ASN_INFOS_ANNOUNCE_BY => sub {
367 __x # CONNECTIVITY:ASN_INFOS_ANNOUNCE_BY
368 'Name server IP address "{ns_ip}" is announced by ASN {asn}.', @_;
369 },
370 ASN_INFOS_ANNOUNCE_IN => sub {
371 __x # CONNECTIVITY:ASN_INFOS_ANNOUNCE_IN
372 'Name server IP address "{ns_ip}" is announced in prefix "{prefix}".', @_;
373 },
374 TEST_CASE_END => sub {
375 __x # CONNECTIVITY:TEST_CASE_END
376 'TEST_CASE_END {testcase}.', @_;
377 },
378 TEST_CASE_START => sub {
379 __x # CONNECTIVITY:TEST_CASE_START
380 'TEST_CASE_START {testcase}.', @_;
381 },
382 );
383  
384 =over
385  
386 =item tag_descriptions()
387  
388 my $hash_ref = tag_descriptions();
389  
390 Used by the L<built-in translation system|Zonemaster::Engine::Translator>.
391  
392 Returns a reference to a hash, the keys of which are the message tags and the corresponding values are strings (message ids).
393  
394 =back
395  
396 =cut
397  
398 sub tag_descriptions {
399 return \%TAG_DESCRIPTIONS;
400 }
401  
402 =over
403  
404 =item version()
405  
406 my $string = version();
407  
408 Returns a string containing the version of the current module.
409  
410 =back
411  
412 =cut
413  
414 sub version {
415 return "$Zonemaster::Engine::Test::Connectivity::VERSION";
416 }
417  
418 =head1 INTERNAL METHODS
419  
420 =over
421  
422 =item _emit_log()
423  
424 my $log_entry = _emit_log( $message_tag_string, $hash_ref );
425  
426 Adds a message to the L<logger|Zonemaster::Engine::Logger> for this module.
427 See L<Zonemaster::Engine::Logger::Entry/add($tag, $argref, $module, $testcase)> for more details.
428  
429 Takes a string (message tag) and a reference to a hash (arguments).
430  
431 Returns a L<Zonemaster::Engine::Logger::Entry> object.
432  
433 =back
434  
435 =cut
436  
437 sub _emit_log { my ( $tag, $argref ) = @_; return Zonemaster::Engine->logger->add( $tag, $argref, 'Connectivity' ); }
438  
439 =over
440  
441 =item _ip_disabled_message()
442  
443 my $bool = _ip_disabled_message( $logentry_array_ref, $ns, @query_type_array );
444  
445 Checks if the IP version of a given name server is allowed to be queried. If not, it adds a logging message and returns true. Else, it returns false.
446  
447 Takes a reference to an array of L<Zonemaster::Engine::Logger::Entry> objects, a L<Zonemaster::Engine::Nameserver> object and an array of strings (query type).
448  
449 Returns a boolean.
450  
451 =back
452  
453 =cut
454  
455 sub _ip_disabled_message {
456 my ( $results_array, $ns, @rrtypes ) = @_;
457  
458 if ( not Zonemaster::Engine::Profile->effective->get(q{net.ipv6}) and $ns->address->version == $IP_VERSION_6 ) {
459 push @$results_array, map {
460 _emit_log(
461 IPV6_DISABLED => {
462 ns => $ns->string,
463 rrtype => $_
464 }
465 )
466 } @rrtypes;
467 return 1;
468 }
469  
470 if ( not Zonemaster::Engine::Profile->effective->get(q{net.ipv4}) and $ns->address->version == $IP_VERSION_4 ) {
471 push @$results_array, map {
472 _emit_log(
473 IPV4_DISABLED => {
474 ns => $ns->string,
475 rrtype => $_,
476 }
477 )
478 } @rrtypes;
479 return 1;
480 }
481 return 0;
482 }
483  
484 =over
485  
486 =item _connectivity_loop()
487  
488 _connectivity_loop( $testcase_string, $zone_name, $ns_array_ref, $logentry_array_ref );
489  
490 Verifies name servers reachability. Used as an helper function for Test Cases L<Connectivity01/connectivity01()>
491 and L<Connectivity02/connectivity02()>.
492  
493 Takes a string (test case identifier), a L<Zonemaster::Engine::DNSName> object, a reference to an array of L<Zonemaster::Engine::Nameserver>
494 objects and a reference to an array of L<Zonemaster::Engine::Logger::Entry> objects.
495  
496 =back
497  
498 =cut
499  
500 sub _connectivity_loop {
501 my ( $testcase, $name, $ns_list, $results ) = @_;
502  
503 my ( $testcase_prefix, $use_tcp, $protocol );
504 if ( $testcase eq 'connectivity01' ) {
505 ( $testcase_prefix, $use_tcp, $protocol ) = ( "CN01", 0, "UDP" );
506 } elsif ( $testcase eq 'connectivity02' ) {
507 ( $testcase_prefix, $use_tcp, $protocol ) = ( "CN02", 1, "TCP" );
508 }
509  
510 foreach my $ns ( @$ns_list ) {
511 if ( _ip_disabled_message( $results, $ns, qw{SOA NS} ) ) {
512 next;
513 }
514  
515 my %packets = (
516 'SOA' => $ns->query( $name, q{SOA}, { usevc => $use_tcp } ),
517 'NS' => $ns->query( $name, q{NS}, { usevc => $use_tcp } )
518 );
519  
520 if ( not $packets{SOA} and not $packets{NS} ) {
521 push @$results, _emit_log( "${testcase_prefix}_NO_RESPONSE_${protocol}" => { ns => $ns->string } );
522 next;
523 }
524  
525 foreach my $qtype ( qw{SOA NS} ) {
526 my $pkt = $packets{$qtype};
527  
528 if ( not $pkt ) {
529 push @$results, _emit_log( "${testcase_prefix}_NO_RESPONSE_${qtype}_QUERY_${protocol}" => { ns => $ns->string } );
530 }
531 elsif ( $pkt->rcode ne q{NOERROR} ) {
532 push @$results, _emit_log( "${testcase_prefix}_UNEXPECTED_RCODE_${qtype}_QUERY_${protocol}" => {
533 ns => $ns->string,
534 rcode => $pkt->rcode
535 }
536 );
537 }
538 else {
539 my ( $rr ) = $pkt->get_records( $qtype, q{answer} );
540 if ( not $rr ) {
541 push @$results, _emit_log( "${testcase_prefix}_MISSING_${qtype}_RECORD_${protocol}" => { ns => $ns->string } );
542 }
543 elsif ( lc($rr->owner) ne lc($name->fqdn) ) {
544 push @$results, _emit_log( "${testcase_prefix}_WRONG_${qtype}_RECORD_${protocol}" => {
545 ns => $ns->string,
546 domain_found => lc($rr->owner),
547 domain_expected => lc($name->fqdn)
548 }
549 );
550 }
551 elsif ( not $pkt->aa ) {
552 push @$results, _emit_log( "${testcase_prefix}_${qtype}_RECORD_NOT_AA_${protocol}" => { ns => $ns->string } );
553 }
554 }
555 }
556 }
557 }
558  
559 =head1 TESTS
560  
561 =over
562  
563 =item connectivity01()
564  
565 my @logentry_array = connectivity01( $zone );
566  
567 Runs the L<Connectivity01 Test Case|https://github.com/zonemaster/zonemaster/blob/master/docs/public/specifications/tests/Connectivity-TP/connectivity01.md>.
568  
569 Takes a L<Zonemaster::Engine::Zone> object.
570  
571 Returns a list of L<Zonemaster::Engine::Logger::Entry> objects.
572  
573 =back
574  
575 =cut
576  
577 sub connectivity01 {
578 my ( $class, $zone ) = @_;
579  
580 local $Zonemaster::Engine::Logger::TEST_CASE_NAME = 'Connectivity01';
581 push my @results, _emit_log( TEST_CASE_START => { testcase => $Zonemaster::Engine::Logger::TEST_CASE_NAME } );
582 my $name = name( $zone );
583 my @ns_list = @{ Zonemaster::Engine::TestMethods->method4and5( $zone ) };
584  
585 my @ns_ipv4 = ();
586 my @ns_ipv6 = ();
587 foreach my $ns ( @ns_list ) {
588 if ( $ns->address->version == $IP_VERSION_4 and not Zonemaster::Engine::Profile->effective->get(q{net.ipv4}) ) {
589 push @ns_ipv4, $ns;
590 }
591 elsif ( $ns->address->version == $IP_VERSION_6 and not Zonemaster::Engine::Profile->effective->get(q{net.ipv6}) ) {
592 push @ns_ipv6, $ns;
593 }
594 }
595 if ( @ns_ipv4 ) {
596 push @results, _emit_log( "CN01_IPV4_DISABLED" => { ns_list => join( ';', @ns_ipv4 ) } );
597 }
598 if ( @ns_ipv6 ) {
599 push @results, _emit_log( "CN01_IPV6_DISABLED" => { ns_list => join( ';', @ns_ipv6 ) } );
600 }
601  
602 _connectivity_loop("connectivity01", $name, \@ns_list, \@results);
603  
604 return ( @results, _emit_log( TEST_CASE_END => { testcase => $Zonemaster::Engine::Logger::TEST_CASE_NAME } ) );
605 } ## end sub connectivity01
606  
607 =over
608  
609 =item connectivity02()
610  
611 my @logentry_array = connectivity02( $zone );
612  
613 Runs the L<Connectivity02 Test Case|https://github.com/zonemaster/zonemaster/blob/master/docs/public/specifications/tests/Connectivity-TP/connectivity02.md>.
614  
615 Takes a L<Zonemaster::Engine::Zone> object.
616  
617 Returns a list of L<Zonemaster::Engine::Logger::Entry> objects.
618  
619 =back
620  
621 =cut
622  
623 sub connectivity02 {
624 my ( $class, $zone ) = @_;
625  
626 local $Zonemaster::Engine::Logger::TEST_CASE_NAME = 'Connectivity02';
627 push my @results, _emit_log( TEST_CASE_START => { testcase => $Zonemaster::Engine::Logger::TEST_CASE_NAME } );
628 my $name = name( $zone );
629 my @ns_list = @{ Zonemaster::Engine::TestMethods->method4and5( $zone ) };
630  
631 _connectivity_loop("connectivity02", $name, \@ns_list, \@results);
632  
633 return ( @results, _emit_log( TEST_CASE_END => { testcase => $Zonemaster::Engine::Logger::TEST_CASE_NAME } ) );
634 } ## end sub connectivity02
635  
636 =over
637  
638 =item connectivity03()
639  
640 my @logentry_array = connectivity03( $zone );
641  
642 Runs the L<Connectivity03 Test Case|https://github.com/zonemaster/zonemaster/blob/master/docs/public/specifications/tests/Connectivity-TP/connectivity03.md>.
643  
644 Takes a L<Zonemaster::Engine::Zone> object.
645  
646 Returns a list of L<Zonemaster::Engine::Logger::Entry> objects.
647  
648 =back
649  
650 =cut
651  
652 sub connectivity03 {
653 my ( $class, $zone ) = @_;
654  
655 local $Zonemaster::Engine::Logger::TEST_CASE_NAME = 'Connectivity03';
656 push my @results, _emit_log( TEST_CASE_START => { testcase => $Zonemaster::Engine::Logger::TEST_CASE_NAME } );
657  
658 my %ips = ( $IP_VERSION_4 => {}, $IP_VERSION_6 => {} );
659  
660 foreach my $ns ( @{ Zonemaster::Engine::TestMethods->method4and5( $zone ) } ) {
661 my $addr = $ns->address;
662 $ips{ $addr->version }{ $addr->ip } = $addr;
663 }
664  
665 my @v4ips = values %{ $ips{$IP_VERSION_4} };
666 my @v6ips = values %{ $ips{$IP_VERSION_6} };
667  
668 my @v4asns;
669 my @v4asnsets;
670 my @v6asns;
671 my @v6asnsets;
672  
673 foreach my $v4ip ( @v4ips ) {
674 my ( $asnref, $prefix, $raw, $ret_code ) = Zonemaster::Engine::ASNLookup->get_with_prefix( $v4ip );
675 if ( defined $ret_code and ( $ret_code eq q{ERROR_ASN_DATABASE} or $ret_code eq q{EMPTY_ASN_SET} ) ) {
676 push @results, _emit_log( $ret_code => { ns_ip => $v4ip->short } );
677 }
678 else {
679 if ( $raw ) {
680 push @results,
681 _emit_log(
682 ASN_INFOS_RAW => {
683 ns_ip => $v4ip->short,
684 data => $raw,
685 }
686 );
687 }
688 if ( $asnref ) {
689 push @results,
690 _emit_log(
691 ASN_INFOS_ANNOUNCE_BY => {
692 ns_ip => $v4ip->short,
693 asn => join( q{,}, sort @{$asnref} ),
694 }
695 );
696 push @v4asns, @{$asnref};
697 push @v4asnsets, join( q{,}, sort { $a <=> $b } @{$asnref} );
698 }
699 if ( $prefix ) {
700 push @results,
701 _emit_log(
702 ASN_INFOS_ANNOUNCE_IN => {
703 ns_ip => $v4ip->short,
704 prefix => sprintf "%s/%d",
705 $prefix->ip, $prefix->prefixlen,
706 }
707 );
708 }
709 }
710 } ## end foreach my $v4ip ( @v4ips )
711 foreach my $v6ip ( @v6ips ) {
712 my ( $asnref, $prefix, $raw, $ret_code ) = Zonemaster::Engine::ASNLookup->get_with_prefix( $v6ip );
713 if ( defined $ret_code and ( $ret_code eq q{ERROR_ASN_DATABASE} or $ret_code eq q{EMPTY_ASN_SET} ) ) {
714 push @results, _emit_log( $ret_code => { ns_ip => $v6ip->short } );
715 }
716 else {
717 if ( $raw ) {
718 push @results,
719 _emit_log(
720 ASN_INFOS_RAW => {
721 ns_ip => $v6ip->short,
722 data => $raw,
723 }
724 );
725 }
726 if ( $asnref ) {
727 push @results,
728 _emit_log(
729 ASN_INFOS_ANNOUNCE_BY => {
730 ns_ip => $v6ip->short,
731 asn => join( q{,}, sort @{$asnref} ),
732 }
733 );
734 push @v6asns, @{$asnref};
735 push @v6asnsets, join( q{,}, sort { $a <=> $b } @{$asnref} );
736 }
737 if ( $prefix ) {
738 push @results,
739 _emit_log(
740 ASN_INFOS_ANNOUNCE_IN => {
741 ns_ip => $v6ip->short,
742 prefix => sprintf "%s/%d",
743 $prefix->short, $prefix->prefixlen,
744 }
745 );
746 }
747 }
748 } ## end foreach my $v6ip ( @v6ips )
749  
750 @v4asns = uniq sort { $a <=> $b } @v4asns;
751 @v4asnsets = uniq sort @v4asnsets;
752 @v6asns = uniq sort { $a <=> $b } @v6asns;
753 @v6asnsets = uniq sort @v6asnsets;
754  
755 if ( scalar @v4asns ) {
756 if ( @v4asns == 1 ) {
757 push @results, _emit_log( IPV4_ONE_ASN => { asn => $v4asns[0] } );
758 }
759 elsif ( @v4asnsets == 1 ) {
760 push @results, _emit_log( IPV4_SAME_ASN => { asn_list => $v4asnsets[0] } );
761 }
762 else {
763 push @results, _emit_log( IPV4_DIFFERENT_ASN => { asn_list => join( q{,}, @v4asns ) } );
764 }
765 }
766  
767 if ( scalar @v6asns ) {
768 if ( @v6asns == 1 ) {
769 push @results, _emit_log( IPV6_ONE_ASN => { asn => $v6asns[0] } );
770 }
771 elsif ( @v6asnsets == 1 ) {
772 push @results, _emit_log( IPV6_SAME_ASN => { asn_list => $v6asnsets[0] } );
773 }
774 else {
775 push @results, _emit_log( IPV6_DIFFERENT_ASN => { asn_list => join( q{,}, @v6asns ) } );
776 }
777 }
778  
779 return ( @results, _emit_log( TEST_CASE_END => { testcase => $Zonemaster::Engine::Logger::TEST_CASE_NAME } ) );
780 } ## end sub connectivity03
781  
782 =over
783  
784 =item connectivity04()
785  
786 my @logentry_array = connectivity04( $zone );
787  
788 Runs the L<Connectivity04 Test Case|https://github.com/zonemaster/zonemaster/blob/master/docs/public/specifications/tests/Connectivity-TP/connectivity04.md>.
789  
790 Takes a L<Zonemaster::Engine::Zone> object.
791  
792 Returns a list of L<Zonemaster::Engine::Logger::Entry> objects.
793  
794 =back
795  
796 =cut
797  
798 sub connectivity04 {
799 my ( $class, $zone ) = @_;
800  
801 local $Zonemaster::Engine::Logger::TEST_CASE_NAME = 'Connectivity04';
802 push my @results, _emit_log( TEST_CASE_START => { testcase => $Zonemaster::Engine::Logger::TEST_CASE_NAME } );
803  
804 my %prefixes;
805 my %ip_already_processed;
806  
807 my @nss = grep { $_->isa('Zonemaster::Engine::Nameserver') } (
808 @{ Zonemaster::Engine::TestMethodsV2->get_del_ns_names_and_ips( $zone ) // [] },
809 @{ Zonemaster::Engine::TestMethodsV2->get_zone_ns_names_and_ips( $zone ) // [] }
810 );
811  
812 foreach my $ns ( @nss ) {
813 my $ip = $ns->address;
814  
815 next if exists $ip_already_processed{$ip->version}{$ip->short};
816 $ip_already_processed{$ip->version}{$ip->short} = 1;
817  
818 my ( $asnref, $prefix, $raw, $ret_code ) = Zonemaster::Engine::ASNLookup->get_with_prefix( $ip );
819  
820 if ( defined $ret_code and ( $ret_code eq q{ERROR_ASN_DATABASE} or $ret_code eq q{EMPTY_ASN_SET} ) ) {
821 if ( $ret_code eq 'ERROR_ASN_DATABASE' ) {
822 $ret_code = 'CN04_ERROR_PREFIX_DATABASE';
823 }
824 elsif ( $ret_code eq 'EMPTY_ASN_SET' ) {
825 $ret_code = 'CN04_EMPTY_PREFIX_SET';
826 }
827  
828 push @results, _emit_log( $ret_code => { ns_ip => $ip->short } );
829 }
830 else {
831 if ( $raw ) {
832 push @results,
833 _emit_log(
834 CN04_ASN_INFOS_RAW => {
835 ns_ip => $ip->short,
836 data => $raw,
837 }
838 );
839 }
840  
841 if ( $prefix ) {
842 my $prefix_str;
843  
844 if ( $prefix->version == 4 ) {
845 $prefix_str = $prefix->prefix;
846 }
847 elsif ( $prefix->version == 6 ) {
848 $prefix_str = $prefix->short . '/' . $prefix->prefixlen;
849 }
850 else {
851 next;
852 }
853  
854 push @results,
855 _emit_log(
856 CN04_ASN_INFOS_ANNOUNCE_IN => {
857 ns_ip => $ip->short,
858 prefix => sprintf "%s", $prefix_str,
859 }
860 );
861  
862 push @{ $prefixes{$prefix->version}{$prefix_str} }, $ns;
863 }
864 }
865 }
866  
867 foreach my $ip_version ( sort keys %prefixes ) {
868 my @combined_ns;
869  
870 foreach my $prefix ( keys %{ $prefixes{$ip_version} } ) {
871 if ( scalar @{ $prefixes{$ip_version}{$prefix} } == 1 ) {
872 push @combined_ns, @{ $prefixes{$ip_version}{$prefix} };
873 }
874 elsif ( scalar @{ $prefixes{$ip_version}{$prefix} } >= 2 ) {
875 push @results,
876 _emit_log(
877 "CN04_IPV${ip_version}_SAME_PREFIX" => {
878 ip_prefix => $prefix,
879 ns_list => join( q{;}, sort @{ $prefixes{$ip_version}{$prefix} } )
880 }
881 );
882 }
883 }
884  
885 if ( scalar @combined_ns ) {
886 push @results,
887 _emit_log(
888 "CN04_IPV${ip_version}_DIFFERENT_PREFIX" => {
889 ns_list => join( q{;}, uniq sort @combined_ns )
890 }
891 );
892 }
893  
894 push @results, _emit_log( "CN04_IPV${ip_version}_SINGLE_PREFIX" => {} ) if scalar keys %{ $prefixes{$ip_version} } == 1
895 and scalar @{ (values %{ $prefixes{$ip_version} })[0] } == scalar keys %{ $ip_already_processed{$ip_version} };
896 }
897  
898 return ( @results, _emit_log( TEST_CASE_END => { testcase => $Zonemaster::Engine::Logger::TEST_CASE_NAME } ) );
899 } ## end sub connectivity04
900  
901 1;