1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
|
package TestUtil;
use 5.014002;
use strict;
use warnings;
use Test::More;
use Zonemaster::Engine;
use Exporter 'import';
use List::MoreUtils qw[ uniq ];
use Zonemaster::Engine::Validation qw( validate_ipv4 validate_ipv6 );
use Carp qw( croak );
BEGIN {
our @EXPORT_OK = qw[ perform_testcase_testing perform_methodsv2_testing ];
our %EXPORT_TAGS = ( all => \@EXPORT_OK );
## no critic (Modules::ProhibitAutomaticExportation)
our @EXPORT = qw[ perform_testcase_testing perform_methodsv2_testing ];
}
=head1 NAME
TestUtil - a set of methods to ease Zonemaster::Engine unit testing
=head1 SYNOPSIS
Because this package lies in the testing folder C<t/> and that folder is
unknown to the include path @INC, it can be including using the following code:
use File::Basename qw( dirname );
use File::Spec::Functions qw( rel2abs );
use lib dirname( rel2abs( $0 ) );
use TestUtil;
=head1 METHODS
=over
=item perform_methodsv2_testing()
perform_methodsv2_testing( $href_subtests, $single_scenario, $disabled_scenarios );
This method loads unit test data (test scenarios) and, after some data checks and if the test scenario is testable,
it runs all external L<MethodsV2|Zonemaster::Engine::Test::TestMethodsV2> methods and checks for the presence (or absence) of
specific nameservers data for each specified test scenario.
If C<$single_scenario> has been set in the call to the name of a scenario then only that
scenario will be run, and it will always be run even if it has been set as not testable.
If C<$disabled_scenario> has been set in the call to the name of a scenario or to a
comma separated list of scenarios then that or those scenarios will be
temporarily disabled.
Takes a reference to a hash - the keys of which are scenario names (in all uppercase), and their corresponding values are an array of:
=over
=item *
a boolean (testable), 1 or 0
=item *
a string (zone name)
=item *
an array of strings (expected parent nameserver IPs), which could be empty, or undef
=item *
an array of strings (expected delegation nameserver expressions), which could be empty, or undef
=item *
an array of strings (expected zone nameserver expressions), which could be empty, or undef
=item *
an array of name server expressions for undelegated name servers
=back
The name server expression has the format "name-server-name/IP" or only "name-server-name". This is the same format
as the data for the --ns option in I<zonemaster-cli>.
=item perform_testcase_testing()
perform_testcase_testing( $test_case, $test_module, $aref_alltags, $href_subtests, $single_scenario, $disabled_scenarios );
This method loads unit test data (test case name, test module name, array of all message tags and test scenarios) and,
after some data checks and if the test scenario is testable, it runs the specified test case and checks for the presence
(or absence) of specific message tags for each specified test scenario.
If C<$single_scenario> has been set in the call to the name of a scenario then only that
scenario will be run, and it will always be run even if it has been set as not testable.
If C<$disabled_scenario> has been set in the call to the name of a scenario or to a
comma separated list of scenarios then that or those scenarios will be
temporarily disabled.
Takes a string (test case name), a string (test module name) and a reference to a hash - the keys of which are scenario names
(in all uppercase), and their corresponding values are an array of:
=over
=item *
a boolean (testable), 1 or 0
=item *
a string (zone name)
=item *
an array of strings (mandatory message tags), which could be empty, or undef
=item *
an array of strings (forbidden message tags), which could be empty, or undef
=item *
an array of name server expressions for undelegated name servers
=item *
an array of DS expressions for "undelegated" DS
=back
If the array of mandatory message tags is C<undef>, it means that any message tag
in "alltags" not explicitly forbidden must be emitted.
If the array of forbidden message tags is C<undef>, it means that any message tag
in "alltags" not explicitly allowed must not be emitted.
Both of the above arrayrefs cannot be simultaneously C<undef>.
The arrays of mandatory message tags and forbidden message tags, respectively, can be empty, but not
both. At least one of the arrays must be non-empty.
The name server expression has the format "name-server-name/IP" or only "name-server-name". The DS expression
has the format "keytag,algorithm,type,digest". Those two expressions have the same format as the data for the
--ns and --ds options, respectively, in I<zonemaster-cli>.
=back
=head1 INTERNAL METHODS
=over
=item _check_ip_addresses()
_check_ip_addresses( $scenario_name, @ip_addresses );
Helper method that checks if the given ip address(es) are valid.
Takes a string (scenario name) and a reference to an array of strings (IP addresses).
=item _check_ns_expressions()
_check_ns_expressions( $scenario_name, @ns_expressions );
Helper method that checks if the given nameserver expression(s) are valid.
Takes a string (scenario name) and a reference to an array of strings (nameserver expressions).
=item _check_ds_expressions()
_check_ds_expressions( $scenario_name, @ds_expressions );
Helper method that checks if the given delegation signer (DS) expression(s) are valid.
Takes a string (scenario name) and a reference to an array of strings (delegation signer expressions).
=back
=cut
sub _check_ip_addresses {
my ( $scenario, $ip_addresses ) = @_;
return if ! defined $ip_addresses;
foreach my $ip ( @{ $ip_addresses } ) {
croak "Scenario $scenario: IP address '$ip' is not valid"
unless validate_ipv4( $ip ) or validate_ipv6( $ip );
}
}
sub _check_ns_expressions {
my ( $scenario, $ns_expressions ) = @_;
return if ! defined $ns_expressions;
foreach my $nsexp ( @{ $ns_expressions } ) {
my ( $ns, $ip ) = split m(/), $nsexp;
croak "Scenario $scenario: Name server name '$ns' in '$nsexp' is not valid" if $ns !~ /^[0-9A-Za-z-.]+$/;
if ( $ip ) {
croak "Scenario $scenario: IP address '$ip' in '$nsexp' is not valid"
unless validate_ipv4( $ip ) or validate_ipv6( $ip );
}
}
}
sub _check_ds_expressions {
my ( $scenario, $ds_expressions ) = @_;
return if ! defined $ds_expressions;
foreach my $str ( @{ $ds_expressions } ) {
my ( $tag, $algo, $type, $digest ) = split( /,/, $str );
croak "Scenario $scenario: DS expression '$str' is not valid" if
$tag !~ /^[0-9]+$/ or $algo !~ /^[0-9]+$/ or $type !~ /^[0-9]+$/ or $digest !~ /^[0-9a-fA-F]{4,}/;
}
}
sub perform_methodsv2_testing {
my ( $href_subtests, $single_scenario, $disabled_scenarios ) = @_;
my %subtests = %$href_subtests;
$single_scenario = uc( $single_scenario ) if $single_scenario;
my @disabled_scenarios = map {uc} split(/, */, $disabled_scenarios) if $disabled_scenarios;
my @untested_scenarios = ();
if ( $single_scenario and not grep /^$single_scenario$/, keys %subtests ) {
croak "Scenario $single_scenario does not exist";
}
for my $scenario ( sort ( keys %subtests ) ) {
next if $single_scenario and $scenario ne $single_scenario;
if ( @disabled_scenarios and grep /^$scenario$/, @disabled_scenarios ) {
push @untested_scenarios, $scenario;
next;
}
if ( ref( $scenario ) ne '' or $scenario ne uc($scenario) ) {
croak "Scenario $scenario: Key must (i) not be a reference and (ii) be in all uppercase";
}
if ( scalar @{ $subtests{$scenario} } != 6 ) {
croak "Scenario $scenario: Incorrect number of values. " .
"Correct format is: { SCENARIO_NAME => [" .
"testable " .
"zone_name, " .
"[ EXPECTED_PARENT_IP ], " .
"[ EXPECTED_DEL_NS ], " .
"[ EXPECTED_ZONE_NS ], " .
"[ UNDELEGATED_NS ], " .
" ] }";
}
my ( $testable,
$zone_name,
$expected_parent_ip,
$expected_del_ns,
$expected_zone_ns,
$undelegated_ns,
) = @{ $subtests{$scenario} };
if ( ref( $testable ) ne '' ) {
croak "Scenario $scenario: Type of testable must not be a reference";
}
if ( $testable != 1 and $testable != 0 ) {
croak "Scenario $scenario: Value of testable must be 0 or 1";
}
$testable = 1 if $single_scenario and $scenario eq $single_scenario;
if ( ref( $zone_name ) ne '' ) {
croak "Scenario $scenario: Type of zone name must not be a reference";
}
if ( $zone_name !~ m(^[A-Za-z0-9/_.-]+$) ) {
croak "Scenario $scenario: Zone name '$zone_name' is not valid";
}
if ( defined( $expected_parent_ip ) and ref( $expected_parent_ip ) ne 'ARRAY' ) {
croak "Scenario $scenario: Incorrect reference type of expected parent IPs. Expected: ARRAY";
}
if ( defined( $expected_del_ns ) and ref( $expected_del_ns ) ne 'ARRAY' ) {
croak "Scenario $scenario: Incorrect reference type of expected delegation name servers. Expected: ARRAY";
}
if ( defined( $expected_zone_ns ) and ref( $expected_zone_ns ) ne 'ARRAY' ) {
croak "Scenario $scenario: Incorrect reference type of expected zone name servers. Expected: ARRAY";
}
if ( ref( $undelegated_ns ) ne 'ARRAY' ) {
croak "Scenario $scenario: Incorrect reference type of undelegated name servers expressions. Expected: ARRAY";
}
_check_ip_addresses( $scenario, $expected_parent_ip );
_check_ns_expressions( $scenario, $expected_del_ns );
_check_ns_expressions( $scenario, $expected_zone_ns );
_check_ns_expressions( $scenario, $undelegated_ns );
if ( not $testable ) {
push @untested_scenarios, $scenario;
next;
}
subtest $scenario => sub {
if ( @$undelegated_ns ) {
my %undel_ns;
foreach my $nsexp ( @$undelegated_ns ) {
my ( $ns, $ip ) = split m(/), $nsexp;
$undel_ns{$ns} //= [];
push @{ $undel_ns{$ns} }, $ip if $ip;
}
Zonemaster::Engine->add_fake_delegation( $zone_name => \%undel_ns, fill_in_empty_oob_glue => 0 );
}
# Method: get_parent_ns_ips()
my $method = 'get_parent_ns_ips';
subtest $method => sub {
my $res = Zonemaster::Engine::TestMethodsV2->$method( Zonemaster::Engine->zone( $zone_name ) );
if ( defined $expected_parent_ip ) {
ok( defined $res, "Result is defined" ) or diag "Unexpected undefined result";
foreach my $expected_ip ( @{ $expected_parent_ip } ) {
ok( grep( /^$expected_ip$/, uniq map { $_->address->short } @{ $res } ), "Name server IP '$expected_ip' is present" )
or diag "Expected but missing: $expected_ip";
}
ok( scalar @{ $res } == scalar @{ $expected_parent_ip }, "Number of name server IPs in both arrays match" )
or diag "Number of name server IPs in both arrays does not match (found ". scalar @{ $res } . ", expected " . @{ $expected_parent_ip } . ")";
}
else {
ok( ! defined $res, "Result is undefined" ) or diag "Unexpected defined result";
}
};
# Methods: get_del_ns_names_and_ips() and get_zone_ns_names_and_ips()
my @method_names = qw( get_del_ns_names_and_ips get_zone_ns_names_and_ips );
my @expected_all_ns = ( $expected_del_ns, $expected_zone_ns );
foreach my $i ( 0..$#method_names ) {
my $method = $method_names[$i];
subtest $method => sub {
my $expected_res = $expected_all_ns[$i];
my $res = Zonemaster::Engine::TestMethodsV2->$method( Zonemaster::Engine->zone( $zone_name ) );
if ( defined $expected_res ) {
ok( defined $res, "Result is defined" ) or diag "Unexpected undefined result";
foreach my $expected_ns ( @{ $expected_res } ) {
ok( grep( /^$expected_ns$/, @{ $res } ), "Name server '$expected_ns' is present" )
or diag "Expected but missing: $expected_ns";
}
foreach my $ns ( @{ $res } ) {
ok( grep( /^$ns$/, @{ $expected_res } ), "Name server '$ns' is expected" )
or diag "Present but not expected: $ns";
}
ok( scalar @{ $res } == scalar @{ $expected_res }, "Number of name server in both arrays match" )
or diag "Number of name servers in both arrays does not match (found " . scalar @{ $res } . ", expected " . scalar @{ $expected_res }.")";
}
else {
ok( ! defined $res, "Result is undefined" ) or diag "Unexpected defined result";
}
};
}
# Methods: get_del_ns_names() and get_zone_ns_names()
@method_names = qw( get_del_ns_names get_zone_ns_names );
my $expected_del_ns_names = defined $expected_del_ns ?
[ uniq map { (split( m(/), $_ ))[0] } @{ $expected_del_ns } ] : undef;
my $expected_zone_ns_names = defined $expected_zone_ns ?
[ uniq map { (split( m(/), $_ ))[0] } @{ $expected_zone_ns } ] : undef;
my @expected_ns_names = ( $expected_del_ns_names, $expected_zone_ns_names );
foreach my $i ( 0..$#method_names ) {
my $method = $method_names[$i];
subtest $method => sub {
my $expected_res = $expected_ns_names[$i];
my $res = Zonemaster::Engine::TestMethodsV2->$method( Zonemaster::Engine->zone( $zone_name ) );
if ( defined $expected_res ) {
ok( defined $res, "Result is defined" ) or diag "Unexpected undefined result";
foreach my $expected_name ( @{ $expected_res } ) {
ok( grep( /^$expected_name$/, @{ $res } ), "Name server name '$expected_name' is present" )
or diag "Expected but missing: $expected_name";
}
foreach my $name ( @{ $res } ) {
ok( grep( /^$name$/, @{ $expected_res } ), "Name server name '$name' is expected" )
or diag "Present but not expected: $name";
}
ok( scalar @{ $res } == scalar @{ $expected_res }, "Number of name server names in both arrays match" )
or diag "Number of name server names in both arrays does not match (found " . scalar @{ $res } . ", expected " . scalar @{ $expected_res }.")";
}
else {
ok( ! defined $res, "Result is undefined" ) or diag "Unexpected defined result";
}
};
}
# Methods: get_del_ns_ips() and get_zone_ns_ips()
@method_names = qw( get_del_ns_ips get_zone_ns_ips );
my $expected_del_ns_ips = defined $expected_del_ns ?
[ uniq grep { $_ ne '' } map { (split( m(/), $_ ))[1] ? (split( m(/), $_ ))[1] : '' } @{ $expected_del_ns } ] : undef;
my $expected_zone_ns_ips = defined $expected_zone_ns ?
[ uniq grep { $_ ne '' } map { (split( m(/), $_ ))[1] ? (split( m(/), $_ ))[1] : '' } @{ $expected_zone_ns } ] : undef;
my @expected_ns_ips = ( $expected_del_ns_ips, $expected_zone_ns_ips );
foreach my $i ( 0..$#method_names ) {
my $method = $method_names[$i];
subtest $method => sub {
my $expected_res = $expected_ns_ips[$i];
my $res = Zonemaster::Engine::TestMethodsV2->$method( Zonemaster::Engine->zone( $zone_name ) );
if ( defined $expected_res ) {
ok( defined $res, "Result is defined" ) or diag "Unexpected undefined result";
foreach my $expected_ip ( @{ $expected_res } ) {
ok( grep( /^$expected_ip$/, @{ $res } ), "Name server IP '$expected_ip' is present" )
or diag "Expected but missing: $expected_ip";
}
foreach my $ip ( @{ $res } ) {
ok( grep( /^$ip$/, @{ $expected_res } ), "Name server IP '$ip' is expected" )
or diag "Present but not expected: $ip";
}
ok( scalar @{ $res } == scalar @{ $expected_res }, "Number of name server IPs in both arrays match" )
or diag "Number of name server IPs in both arrays does not match (found " . scalar @{ $res } . ", expected " . scalar @{ $expected_res }.")";
}
else {
ok( ! defined $res, "Result is undefined" ) or diag "Unexpected defined result";
}
};
}
}
}
if ( @untested_scenarios ) {
warn "Untested scenarios:\n";
warn "\tScenario $_ has been disabled from testing.\n" for @untested_scenarios;
}
}
sub perform_testcase_testing {
my ( $test_case, $test_module, $aref_alltags, $href_subtests, $single_scenario, $disabled_scenarios ) = @_;
my %subtests = %$href_subtests;
$single_scenario = uc( $single_scenario ) if $single_scenario;
my @disabled_scenarios = map {uc} split(/, */, $disabled_scenarios) if $disabled_scenarios;
my @untested_scenarios = ();
if ( $single_scenario and not grep /^$single_scenario$/, keys %subtests ) {
croak "Scenario $single_scenario does not exist";
}
if ( ref( $aref_alltags ) ne 'ARRAY' ) {
croak 'All tags array variable must be an array ref'
}
foreach my $t ( @$aref_alltags ) {
croak "Invalid tag in 'all tags': '$t'" unless $t =~ /^[A-Z]+[A-Z0-9_]*[A-Z0-9]$/;
}
for my $scenario ( sort ( keys %subtests ) ) {
next if $single_scenario and $scenario ne $single_scenario;
if ( @disabled_scenarios and grep /^$scenario$/, @disabled_scenarios ) {
push @untested_scenarios, $scenario;
next;
}
if ( ref( $scenario ) ne '' or $scenario ne uc($scenario) ) {
croak "Scenario $scenario: Key must (i) not be a reference and (ii) be in all uppercase";
}
if ( scalar @{ $subtests{$scenario} } != 6 ) {
croak "Scenario $scenario: Incorrect number of values. " .
"Correct format is: { SCENARIO_NAME => [" .
"testable " .
"zone_name, " .
"[ MANDATORY_MESSAGE_TAGS ], " .
"[ FORBIDDEN_MESSAGE_TAGS ], " .
"[ UNDELEGATED_NS ], " .
"[ UNDELEGATED_DS ], " .
" ] }";
}
my ( $testable,
$zone_name,
$mandatory_message_tags,
$forbidden_message_tags,
$undelegated_ns,
$undelegated_ds
) = @{ $subtests{$scenario} };
if ( ref( $testable ) ne '' ) {
croak "Scenario $scenario: Type of testable must not be a reference";
}
if ( $testable != 1 and $testable != 0 ) {
croak "Scenario $scenario: Value of testable must be 0 or 1";
}
$testable = 1 if $single_scenario and $scenario eq $single_scenario;
if ( ref( $zone_name ) ne '' ) {
croak "Scenario $scenario: Type of zone name must not be a reference";
}
if ( $zone_name !~ m(^[A-Za-z0-9/_.-]+$) ) {
croak "Scenario $scenario: Zone name '$zone_name' is not valid";
}
if ( ! defined( $mandatory_message_tags ) and ! defined( $forbidden_message_tags ) ) {
croak "Scenario $scenario: Not both array of mandatory tags and array of forbidden tags can be undefined";
}
if ( defined( $mandatory_message_tags ) and defined( $forbidden_message_tags ) and
not scalar @{ $mandatory_message_tags } and not scalar @{ $forbidden_message_tags } ) {
croak "Scenario $scenario: Not both arrays of mandatory message tags and forbidden message tags, respectively, can be empty";
}
if ( defined( $mandatory_message_tags ) and ref( $mandatory_message_tags ) ne 'ARRAY' ) {
croak "Scenario $scenario: Incorrect reference type of mandatory message tags. Expected: ARRAY";
}
if ( defined( $forbidden_message_tags ) and ref( $forbidden_message_tags ) ne 'ARRAY' ) {
croak "Scenario $scenario: Incorrect reference type of forbidden message tags. Expected: ARRAY";
}
if ( ! defined( $mandatory_message_tags ) ) {
my @tags;
foreach my $t ( @$aref_alltags ) {
push @tags, $t unless grep( /^$t$/, @$forbidden_message_tags );
}
$mandatory_message_tags = \@tags;
}
if ( ! defined( $forbidden_message_tags ) ) {
my @tags;
foreach my $t ( @$aref_alltags ) {
push @tags, $t unless grep( /^$t$/, @$mandatory_message_tags );
}
$forbidden_message_tags = \@tags;
}
foreach my $tag ( @$mandatory_message_tags ) {
croak "Scenario $scenario: Invalid message tag in 'mandatory_message_tags': '$tag'" unless $tag =~ /^[A-Z]+[A-Z0-9_]*[A-Z0-9]$/;
}
foreach my $tag ( @$mandatory_message_tags ) {
unless ( grep( /^$tag$/, @$aref_alltags ) ) {
croak "Scenario $scenario: Message tag '$tag' in 'mandatory_message_tags' is missing in 'all_tags'";
}
}
foreach my $tag ( @$forbidden_message_tags ) {
croak "Scenario $scenario: Invalid message tag in 'forbidden_message_tags': '$tag'" unless $tag =~ /^[A-Z]+[A-Z0-9_]*[A-Z0-9]$/;
}
foreach my $tag ( @$forbidden_message_tags ) {
unless ( grep( /^$tag$/, @$aref_alltags ) ) {
croak "Scenario $scenario: Message tag '$tag' in 'forbidden_message_tags' is missing in 'all_tags'";
}
}
if ( ref( $undelegated_ns ) ne 'ARRAY' ) {
croak "Scenario $scenario: Incorrect reference type of undelegated name servers expressions. Expected: ARRAY";
}
if ( ref( $undelegated_ds ) ne 'ARRAY' ) {
croak "Scenario $scenario: Incorrect reference type of undelegated DS expressions. Expected: ARRAY";
}
_check_ns_expressions( $scenario, $undelegated_ns );
_check_ds_expressions( $scenario, $undelegated_ds );
if ( not $testable ) {
push @untested_scenarios, $scenario;
next;
}
subtest $scenario => sub {
if ( @$undelegated_ns ) {
my %undel_ns;
foreach my $nsexp ( @$undelegated_ns ) {
my ($ns, $ip) = split m(/), $nsexp;
$undel_ns{$ns} //= [];
push @{ $undel_ns{$ns} }, $ip if $ip;
}
Zonemaster::Engine->add_fake_delegation( $zone_name => \%undel_ns, fill_in_empty_oob_glue => 0 );
}
if ( @$undelegated_ds ) {
my @data;
foreach my $str ( @$undelegated_ds ) {
my ( $tag, $algo, $type, $digest ) = split( /,/, $str );
push @data, { keytag => $tag, algorithm => $algo, type => $type, digest => $digest };
}
Zonemaster::Engine->add_fake_ds( $zone_name => \@data );
}
my @messages = Zonemaster::Engine->test_method( $test_module, $test_case, Zonemaster::Engine->zone( $zone_name ) );
my %res = map { $_->tag => 1 } @messages;
if ( my ( $error ) = grep { $_->tag eq 'MODULE_ERROR' } @messages ) {
diag("Module died with error: " . $error->args->{"msg"});
fail("Test case executes properly");
}
else {
for my $tag ( @{ $mandatory_message_tags } ) {
ok( exists $res{$tag}, "Tag $tag is outputted" )
or diag "Tag '$tag' should have been outputted, but wasn't";
}
for my $tag ( @{ $forbidden_message_tags } ) {
ok( !exists $res{$tag}, "Tag $tag is not outputted" )
or diag "Tag '$tag' was not supposed to be outputted, but it was";
}
}
};
}
if ( @untested_scenarios ) {
warn "Untested scenarios:\n";
warn "\tScenario $_ cannot be tested.\n" for @untested_scenarios;
}
}
1;
|