Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MethodsV2 unit testing #1350

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

tgreenx
Copy link
Contributor

@tgreenx tgreenx commented May 22, 2024

Purpose

This PR adds MethodsV2 unit testing, based on test zone specification from zonemaster/zonemaster#1254. All external methods are covered.

Context

Test zone specification: zonemaster/zonemaster#1254

Changes

  • Add unit testing for MethodsV2
  • Minor fix in Zonemaster::Engine::TestMethodsV2

How to test this PR

Unit tests are updated and should pass.

@tgreenx tgreenx added FA-MethodV2 Focus Area: Implementing and migrating to MethodNT for test cases. V-Patch Versioning: The change gives an update of patch in version. labels May 22, 2024
@tgreenx tgreenx added this to the v2024.1 milestone May 22, 2024
@tgreenx tgreenx requested a review from matsduf May 22, 2024 09:52
@tgreenx
Copy link
Contributor Author

tgreenx commented May 22, 2024

TODO in this PR:

  • Discuss the current implementation design
  • Add data checks
  • Add documentation

@matsduf
Copy link
Contributor

matsduf commented May 22, 2024

I disagree that only testing "Get zone NS names and IP addresses" gives a full coverage. The extraction of parent IPs is not tested. Delegation and zone do not need to match. Delegation can be with or without glue or parts of glue.

@matsduf
Copy link
Contributor

matsduf commented May 22, 2024

We could limit the data in the t file to be

  • Get parent NS IP addresses
  • Get delegation NS names and IP addresses
  • Get zone NS names and IP addresses

From "Get delegation NS names and IP addresses" the following two can be extracted:

  • Get delegation NS names
  • Get delegation NS IP addresses

From "Get zone NS names and IP addresses" the following two can be extracted:

  • Get zone NS names
  • Get zone NS IP addresses

We should verify that MethodsV2 do that extraction correctly, but maybe not for every scenario.

@tgreenx
Copy link
Contributor Author

tgreenx commented May 23, 2024

TODO in this PR:

* [x]  Discuss the current implementation design

* [x]  Add data checks

* [x]  Add documentation

All done in latest commit 2ba293c. I'm marking this PR as ready for review. @matsduf your comments have been addressed.

@tgreenx tgreenx marked this pull request as ready for review May 23, 2024 14:25
- Expand unit test coverage to all external Zonemaster::Engine::Test::TestMethodsV2 methods
- Add input data checks
- Update unit test data
- Update documentation
- Minor fixes and refactoring
Copy link
Contributor

@marc-vanderwal marc-vanderwal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine, though I have some minor suggestions.

Comment on lines +109 to +112
The arrays of mandatory message tags and forbidden message tags, but not both, could be undefined.
If the mandatory message tag array is undefined, then it will be generated to contain all message
tags not included in the forbidden message tag array. The same mechanism is used if the forbidden
message tag array is undefined.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change supposed to be part of this pull request? I seem to have reviewed a similar passage before and suggesting an improvement. After sleeping on it, I think I’ve come up with something better still.

Suggested change
The arrays of mandatory message tags and forbidden message tags, but not both, could be undefined.
If the mandatory message tag array is undefined, then it will be generated to contain all message
tags not included in the forbidden message tag array. The same mechanism is used if the forbidden
message tag array is undefined.
It is possible to pass C<undef> instead of the mandatory message tag or forbidden message tag arrayref.
In that case, it is equivalent to an arrayref containing C<@$aref_alltags> minus the tags in the other array.
In other words, passing C<undef> as the forbidden message tag arrayref means that any tag not explicitly
allowed must not be emitted, while passing C<undef> as the mandatory message tag arrayref means
that any tag not explicitly forbidden must be emitted.
It is an error if both of the aforementioned arrayrefs are simultaneously undefined or simultaneously empty.

Comment on lines +40 to +43
[ qw( 127.40.3.21 fda1:b2:c3:0:127:40:3:21 127.40.3.22 fda1:b2:c3:0:127:40:3:22 ) ],
[ qw( ns1.child.parent.good-1.methodsv2.xa/127.40.4.21 ns1.child.parent.good-1.methodsv2.xa/fda1:b2:c3:0:127:40:4:21 ns2.child.parent.good-1.methodsv2.xa/127.40.4.22 ns2.child.parent.good-1.methodsv2.xa/fda1:b2:c3:0:127:40:4:22 ) ],
[ qw( ns1.child.parent.good-1.methodsv2.xa/127.40.4.21 ns1.child.parent.good-1.methodsv2.xa/fda1:b2:c3:0:127:40:4:21 ns2.child.parent.good-1.methodsv2.xa/127.40.4.22 ns2.child.parent.good-1.methodsv2.xa/fda1:b2:c3:0:127:40:4:22 ) ],
[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be much nicer to read if this data is on multiple lines, like this:

Suggested change
[ qw( 127.40.3.21 fda1:b2:c3:0:127:40:3:21 127.40.3.22 fda1:b2:c3:0:127:40:3:22 ) ],
[ qw( ns1.child.parent.good-1.methodsv2.xa/127.40.4.21 ns1.child.parent.good-1.methodsv2.xa/fda1:b2:c3:0:127:40:4:21 ns2.child.parent.good-1.methodsv2.xa/127.40.4.22 ns2.child.parent.good-1.methodsv2.xa/fda1:b2:c3:0:127:40:4:22 ) ],
[ qw( ns1.child.parent.good-1.methodsv2.xa/127.40.4.21 ns1.child.parent.good-1.methodsv2.xa/fda1:b2:c3:0:127:40:4:21 ns2.child.parent.good-1.methodsv2.xa/127.40.4.22 ns2.child.parent.good-1.methodsv2.xa/fda1:b2:c3:0:127:40:4:22 ) ],
[]
[ qw( 127.40.3.21 fda1:b2:c3:0:127:40:3:21
127.40.3.22 fda1:b2:c3:0:127:40:3:22 ) ],
[ qw( ns1.child.parent.good-1.methodsv2.xa/127.40.4.21
ns1.child.parent.good-1.methodsv2.xa/fda1:b2:c3:0:127:40:4:21
ns2.child.parent.good-1.methodsv2.xa/127.40.4.22
ns2.child.parent.good-1.methodsv2.xa/fda1:b2:c3:0:127:40:4:22 ) ],
[ qw( ns1.child.parent.good-1.methodsv2.xa/127.40.4.21
ns1.child.parent.good-1.methodsv2.xa/fda1:b2:c3:0:127:40:4:21
ns2.child.parent.good-1.methodsv2.xa/127.40.4.22
ns2.child.parent.good-1.methodsv2.xa/fda1:b2:c3:0:127:40:4:22 ) ],
[]

@matsduf
Copy link
Contributor

matsduf commented May 26, 2024

I have realized that I have done less optimal selection of IP addresses for the scenarios. The selection principle is also different for the test scenarios for test cases. I am about to renumber, both in zonemaster/zonemaster#1254 and as a PR to this PR.

@matsduf
Copy link
Contributor

matsduf commented May 26, 2024

For scenarios for test cases it is possible to test and trouble shoot with the help of zonemaster-cli, but that is not possible for the MethodsV2 scenarios. Would it be possible to at a "verbose" mode for the t file in which only one scenario is run and verbose information is outputted, e.g. expected name servers and found name servers, respectively?

@matsduf
Copy link
Contributor

matsduf commented May 26, 2024

I have created tgreenx#2 to update this PR with the new IP addresses from an update of zonemaster/zonemaster#1254. A new data file is also created.

@matsduf
Copy link
Contributor

matsduf commented May 27, 2024

I tested by changing the correct to an incorrect. I tested scenario GOOD-1.

In EXPECTED_PARENT_IP I changed "127.40.1.41" to "127.40.2.41". ("1" to "2".) In EXPECTED_DEL_NS I changed "ns1.child.parent.good-1.methodsv2.xa/127.40.1.51" to "ns1.childs.parent.good-1.methodsv2.xa/127.40.1.51". ("child" to "childs".)

I got the following output:

        #   Failed test 'Nameserver IP '127.40.2.41' is present'
        #   at /home/ubuntu/git/zonemaster-engine/t/TestUtil.pm line 270.
        # Nameserver IP '127.40.2.41' should have been present, but wasn't
        # Looks like you failed 1 test of 6.

    #   Failed test 'get_parent_ns_ips'
    #   at /home/ubuntu/git/zonemaster-engine/t/TestUtil.pm line 278.

I expects it to say that the look-up data gives "127.40.1.41" that was not found in the expected data.

        #   Failed test 'Nameserver 'ns1.childs.parent.good-1.methodsv2.xa/127.40.1.51' is present'
        #   at /home/ubuntu/git/zonemaster-engine/t/TestUtil.pm line 291.
        # Nameserver 'ns1.childs.parent.good-1.methodsv2.xa/127.40.1.51' should have been present, but wasn't
        # Looks like you failed 1 test of 6.

    #   Failed test 'get_del_ns_names_and_ips'
    #   at /home/ubuntu/git/zonemaster-engine/t/TestUtil.pm line 299.

Same here. "ns1.child.parent.good-1.methodsv2.xa/127.40.1.51" is what we get from the look-up, but we do find it in the expected data.

@matsduf
Copy link
Contributor

matsduf commented May 27, 2024

I removed one IP address from EXPECTED_PARENT_IP and got the following error message:

        #   Failed test at /home/ubuntu/git/zonemaster-engine/t/TestUtil.pm line 273.
        # Number of nameserver IP addresses in both arrays does not match
        # Looks like you failed 1 test of 5.

    #   Failed test 'get_parent_ns_ips'
    #   at /home/ubuntu/git/zonemaster-engine/t/TestUtil.pm line 278.
    # Looks like you failed 1 test of 7.
t/methodsv2.t .. 4/? 
#   Failed test 'GOOD-1'

It is not very helpful. Are there too many in EXPECTED_PARENT_IP or too few? Which is the problematic IP address?

Then I also changed one address in EXPECTED_PARENT_IP but that information is not provided.

        #   Failed test at /home/ubuntu/git/zonemaster-engine/t/TestUtil.pm line 273.
        # Number of nameserver IP addresses in both arrays does not match
        # Looks like you failed 1 test of 5.

    #   Failed test 'get_parent_ns_ips'
    #   at /home/ubuntu/git/zonemaster-engine/t/TestUtil.pm line 278.
    # Looks like you failed 1 test of 7.

#   Failed test 'GOOD-1'

@matsduf
Copy link
Contributor

matsduf commented May 27, 2024

Scenario GOOD-6 fails. See #1351.

@matsduf
Copy link
Contributor

matsduf commented May 30, 2024

IB-NOT-IN-ZONE-1 fails and also triggers "Use of uninitialized value".

t/methodsv2.t .. 11/? 
        #   Failed test 'Nameserver 'ns1.child.parent.ib-not-in-zone-1.methodsv2.xa' is present'
        #   at /home/ubuntu/git/zonemaster-engine/t/TestUtil.pm line 291.
        # Nameserver 'ns1.child.parent.ib-not-in-zone-1.methodsv2.xa' should have been present, but wasn't

        #   Failed test 'Nameserver 'ns2.child.parent.ib-not-in-zone-1.methodsv2.xa' is present'
        #   at /home/ubuntu/git/zonemaster-engine/t/TestUtil.pm line 291.
        # Nameserver 'ns2.child.parent.ib-not-in-zone-1.methodsv2.xa' should have been present, but wasn't

        #   Failed test at /home/ubuntu/git/zonemaster-engine/t/TestUtil.pm line 294.
        # Number of nameservers in both arrays does not match
        # Looks like you failed 3 tests of 4.

    #   Failed test 'get_zone_ns_names_and_ips'
    #   at /home/ubuntu/git/zonemaster-engine/t/TestUtil.pm line 299.
Use of uninitialized value $expected_ip in concatenation (.) or string at /home/ubuntu/git/zonemaster-engine/t/TestUtil.pm line 339.

        #   Failed test 'Nameserver IP '' is present'
        #   at /home/ubuntu/git/zonemaster-engine/t/TestUtil.pm line 339.
Use of uninitialized value $expected_ip in concatenation (.) or string at /home/ubuntu/git/zonemaster-engine/t/TestUtil.pm line 339.
        # Nameserver IP '' should have been present, but wasn't

        #   Failed test at /home/ubuntu/git/zonemaster-engine/t/TestUtil.pm line 342.
        # Number of nameserver IPs in both arrays does not match
        # Looks like you failed 2 tests of 3.

    #   Failed test 'get_zone_ns_ips'
    #   at /home/ubuntu/git/zonemaster-engine/t/TestUtil.pm line 347.
    # Looks like you failed 2 tests of 7.
t/methodsv2.t .. 14/? 
#   Failed test 'IB-NOT-IN-ZONE-1'

@matsduf
Copy link
Contributor

matsduf commented Jun 3, 2024

I suggest that the error message is something like:

Unexpected: 127.40.3.21 
Unexpected: fda1:b2:c3:0:127:40:3:21
Missing: 127.40.3.22
Missing: fda1:b2:c3:0:127:40:3:22

"Unexpected" when not in the expected set, but given by the method. "Missing" when in the expected set, but not given by the method.

Comment on lines +180 to +185
sub perform_methodsv2_testing {
my ( %subtests ) = @_;

my @untested_scenarios = ();

for my $scenario ( sort ( keys %subtests ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest the following to support testing one scenario:

sub perform_methodsv2_testing {
    my ( $href_subtests, $single_scenario ) = @_;

    my %subtests = %$href_subtests;

    my @untested_scenarios = ();

    for my $scenario ( sort ( keys %subtests ) ) {
        next if $single_scenario and $scenario ne $single_scenario;

This will require changes to the methodsv2.t too. See that.

The documentation should be updated too.

Comment on lines +214 to +217
if ( $testable != 1 and $testable != 0 ) {
croak "Scenario $scenario: Value of testable must be 0 or 1";
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on the change above, and will test a single scenario even if not testable. Change to:

        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;

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 } ), "Nameserver IP '$expected_ip' is present" )
or diag "Nameserver IP '$expected_ip' should have been present, but wasn't";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If change to the following it will be much easier to read:

                            or diag "Missing: $expected_ip";

However, what is missing from the error messages are the IP addresses found but are not in the expected set.

Zonemaster::Engine::Profile->effective->set( q{no_network}, 1 );
}

perform_methodsv2_testing( %subtests );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This depends on the changes in t/TestUtil.t. See those.

perform_methodsv2_testing( \%subtests, $ENV{ZONEMASTER_MOTHODSV2_SCENARIO} );

The documentation should also be updated.

@tgreenx tgreenx linked an issue Jun 11, 2024 that may be closed by this pull request
@tgreenx tgreenx removed this from the v2024.1 milestone Jun 11, 2024
@tgreenx tgreenx added this to the v2024.2 milestone Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FA-MethodV2 Focus Area: Implementing and migrating to MethodNT for test cases. V-Patch Versioning: The change gives an update of patch in version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create test zones and test data for MethodsV2.
3 participants