NAME

TestUtil - a set of methods to ease Zonemaster::Engine unit testing

SYNOPSIS

Because this package lies in the testing folder 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;

METHODS

perform_methodsv2_testing()
perform_methodsv2_testing( $href_subtests, $selected_scenarios, $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 MethodsV2 methods and checks for the presence (or absence) of specific nameservers data for each specified test scenario.

If $selected_scenarios has been set in the call to a comma separated list of names (or a single name), then only those scenarios will be run, and they will always be run even if they has been set as not testable.

If $disabled_scenarios 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:

  • a boolean (testable), 1 or 0

  • a string (zone name)

  • an array of strings (expected parent nameserver IPs), which could be empty, or undef

  • an array of strings (expected delegation nameserver expressions), which could be empty, or undef

  • an array of strings (expected zone nameserver expressions), which could be empty, or undef

  • an array of name server expressions for undelegated name servers

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 zonemaster-cli.

perform_testcase_testing()
perform_testcase_testing( $test_case, $test_module, $aref_alltags, $href_subtests, $selected_scenarios, $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 $selected_scenarios has been set in the call to a comma separated list of names of scenarios (or a single name) then only those scenarios will be run, and they will always be run even if they have been set as not testable.

If $disabled_scenarios 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:

  • a boolean (testable), 1 or 0

  • a string (zone name)

  • an array of strings (mandatory message tags), which could be empty, or undef

  • an array of strings (forbidden message tags), which could be empty, or undef

  • an array of name server expressions for undelegated name servers

  • an array of DS expressions for "undelegated" DS

If the array of mandatory message tags is undef, it means that any message tag in "alltags" not explicitly forbidden must be emitted.

If the array of forbidden message tags is undef, it means that any message tag in "alltags" not explicitly allowed must not be emitted.

Both of the above arrayrefs cannot be simultaneously 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 zonemaster-cli.

INTERNAL METHODS

_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).

_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).

_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).