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

Remove some unintended network dependencies from the unit tests #1045

Merged
merged 9 commits into from
May 17, 2022

Conversation

mattias-p
Copy link
Member

@mattias-p mattias-p commented Mar 23, 2022

Purpose

This PR makes the unit tests don't autocomplete fake glue by sending out DNS requests.

Context

Fixes #888.

Changes

A new method Zonemaster::Engine->add_fake_delegation_raw() is factored out from Zonemaster::Engine->add_fake_delegation(). The new method performs the meat of things but without the bells and whistles like autocompleting fake glue and returning a boolean. (I don't think the return value is ever used and it's kind of nonsense anyway. Maybe I should have removed it altogether.)

How to test this PR

  1. In one terminal run sudo tcpdump -nn port 53 and keep it open.
  2. In another terminal run make test and wait for it to complete.
  3. Make sure tcpdump didn't list any DNS requests from the tests.

* Make unit tests not rely on fake glue for out-of-bailiwick nameservers
  being autocompleted.
* Make unit tests add fake delegation information using a method that
  never attempts to autocomplete glue.
@mattias-p mattias-p added this to the v2022.1 milestone Mar 23, 2022
@matsduf
Copy link
Contributor

matsduf commented Mar 25, 2022

If a "fake delegation" is something like

        'lysator.liu.se' => {
            'ns1.nic.fr' => [],
            'ns.nic.se'  => []
        }

then the IP address or addresses of ns1.nic.fr and ns.nic.se should be looked up on a resolver (built-in or external). As I read it add_fake_delegation_raw() will instead output 'FAKE_DELEGATION_NO_IP'. Do I read it wrong?

@matsduf matsduf self-requested a review March 25, 2022 08:42
@matsduf
Copy link
Contributor

matsduf commented Mar 25, 2022

In a second inspection, I think the idea is to use add_fake_delegation_raw() for unit tests and add_fake_delegation() else. Is that correct?

Copy link
Contributor

@matsduf matsduf left a comment

Choose a reason for hiding this comment

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

There is also a Zonemaster::Engine::Nameserver::add_fake_delegation() but I cannot see that it is used.

Comment on lines 135 to 137
if ( $incomplete_delegation ) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of this test? Does not add_fake_delegation_raw doing that job?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is one of the differences between add_fake_delegation() and add_fake_delegation_raw(). The former has a boolean return type and the latter has a void return type. I kept the return value semantics of add_fake_delegation() unchanged for compatibility reasons. However I can't see any use cases for the return value. Maybe it would be better to just remove it.

Copy link
Contributor

@matsduf matsduf left a comment

Choose a reason for hiding this comment

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

The two methods, add_fake_delegation_raw() and add_fake_delegation(), have very much overlap in logic. Why not have just one method and a input variable, say $raw, and if that is set it does not do any lookups for IP addresses? I think that would simplify the code and the understanding of the code.

@mattias-p
Copy link
Member Author

The two methods, add_fake_delegation_raw() and add_fake_delegation(), have very much overlap in logic. Why not have just one method and a input variable, say $raw, and if that is set it does not do any lookups for IP addresses?

Good point. I'll change it to use some kind of flag instead.

@matsduf matsduf modified the milestones: v2022.1, v2022.2 May 11, 2022
Comment on lines 330 to 336
The only recognized flag is C<fill_in_empty_ib>.
This flag is boolean and defaults to true.
If this flag is true, this method updates the given C<$data> by looking up and
filling in some glue addresses.
Specifically the glue addresses for any nameserver name that are out of
bailiwick of the given C<$domain> and that comes with an empty list of
addresses.
Copy link
Contributor

Choose a reason for hiding this comment

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

If the name sever name is an strict in-bailiwick then a missing address should never be looked up. What is "ib" in the flag name? Wouldn't "fill_in_empty_ob_glue" be better?

I suggest that the terms in-bailiwick and out-of-bailiwick (hyphened) are used (https://datatracker.ietf.org/doc/html/rfc8499)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll make updates.

Comment on lines 338 to 353
Returns `1` if all name servers in C<$data> have non-empty lists of
glue (after they've been filled in) or if `fill_in_empty_ib` is false.
Otherwise it returns `undef`.

Examples:

Zonemaster::Engine->add_fake_delegation(
'lysator.liu.se' => {
'ns1.nic.fr' => [ ],
'ns.nic.se' => [ '212.247.7.228', '2a00:801:f0:53::53' ],
'i.ns.se' => [ '194.146.106.22', '2001:67c:1010:5::53' ],
'ns3.nic.se' => [ '212.247.8.152', '2a00:801:f0:211::152' ]
}
},
);

will return 1.
returns 1.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the specification says that undef should be returned, depending on what you mean by glue. The se zone should never include glue for ns1.nic.fr in this case, but I am not sure that add_fake_delegation judge that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I don't think the return value is meaningful at all. I only kept it out of the principle to minimize API changes. And I only documented it out of a sense of duty. I was thinking I'd remove the return value entirely in a follow-up PR, but I might as well do it in this one. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Here I guess fail and success are the possible outcome, if anything is missing should be determined by the testing.

Fail: The data does not match the API for this method and cannot be loaded.

Success: The data matches the API for this method and can be loaded.

Data can be with or without IP address. I guess data can be with our without name server too.

Copy link
Member Author

@mattias-p mattias-p May 16, 2022

Choose a reason for hiding this comment

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

Do you know if we have other breaking changes in Engine? I looked but I couldn't see anything obvious. I'd rather not force a major version number bump just for this.

Comment on lines 125 to 137
if ( $fill_in_empty_ib ) {
foreach my $name ( keys %{$href} ) {
if ( !@{ $href->{$name} } ) {
if ( !$class->zone( $domain )->is_in_zone( $name ) ) {
my @ips = Zonemaster::LDNS->new->name2addr($name);
push @{ $href->{$name} }, @ips;
}
if ( !@{ $href->{$name} } ) {
$incomplete_delegation = 1;
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this fill in a strict in-bailiwick name server's IP address? It should not.

Copy link
Member Author

Choose a reason for hiding this comment

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

It does not. However misnamed the flag. I'll fix that.

@matsduf
Copy link
Contributor

matsduf commented May 16, 2022

The milestone is till set to v2022.2.

@mattias-p mattias-p modified the milestones: v2022.2, v2022.1 May 16, 2022
@mattias-p mattias-p requested a review from matsduf May 16, 2022 14:57
matsduf
matsduf previously approved these changes May 16, 2022
Copy link
Contributor

@tgreenx tgreenx left a comment

Choose a reason for hiding this comment

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

Two comments else lgtm, ready to approve afterwards

lib/Zonemaster/Engine.pm Outdated Show resolved Hide resolved
lib/Zonemaster/Engine.pm Show resolved Hide resolved
@mattias-p mattias-p merged commit 368e4d3 into zonemaster:develop May 17, 2022
@matsduf matsduf added the S-ReleaseTested Status: The PR has been successfully tested in release testing label Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-ReleaseTested Status: The PR has been successfully tested in release testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants