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 planned deprecated 'resolver.source' profile property #1343

Merged
merged 8 commits into from
Jun 17, 2024

Conversation

tgreenx
Copy link
Contributor

@tgreenx tgreenx commented May 7, 2024

Purpose

This PR removes the planned deprecated resolver.source profile property. It also adds a proper IP validation module (and functions) in Zonemaster::Engine::Validation.

Other related changes to the resolver.source{4,6} profile properties and Zonemaster::Engine::Nameserver source_address{4,6} attributes are made. See the Changes section.

Context

Fixes #1360
Also fixes Perl warnings from #1342

Changes

This PR removes the source_address{4,6} and source_address attributes of Zonemaster::Engine::Nameserver objects.

Other related changes:

  • Changes resolver.source_address{4,6} profile properties to not accept illegal values.
  • Removes now unused constant $RESOLVER_SOURCE_OS_DEFAULT
  • Removes now unused function Zonemaster::Engine::Profile::check_validity()
  • Rename Zonemaster::Engine::Nameserver::source_address() to Zonemaster::Engine::Nameserver::_build_source_address()
  • Add IP validation module and functions Zonemaster::Engine::Validation::validate_ipv{4,6}()
  • Refactoring
  • Add and updates documentation
  • Add and updates unit tests

How to test this PR

Unit tests are updated and should pass.

@tgreenx tgreenx added the V-Major Versioning: The change gives an update of major in version. label May 7, 2024
@tgreenx tgreenx added this to the v2024.1 milestone May 7, 2024
marc-vanderwal
marc-vanderwal previously approved these changes May 16, 2024
mattias-p
mattias-p previously approved these changes Jun 4, 2024
Copy link
Member

@mattias-p mattias-p left a comment

Choose a reason for hiding this comment

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

Looks great!

Once this is merged I'll rebase #1356 on top of it.

@mattias-p mattias-p mentioned this pull request Jun 4, 2024
lib/Zonemaster/Engine/Profile.pm Outdated Show resolved Hide resolved
@tgreenx tgreenx requested a review from matsduf June 4, 2024 16:49
@mattias-p mattias-p self-requested a review June 5, 2024 16:30
Copy link
Member

@mattias-p mattias-p left a comment

Choose a reason for hiding this comment

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

It seems I went too fast reviewing this the first time. When I had a look at it again I realized there is a problem with how the resolver.source4 and resolver.source6 properties are defined.

lib/Zonemaster/Engine/Profile.pm Outdated Show resolved Hide resolved
lib/Zonemaster/Engine/Profile.pm Outdated Show resolved Hide resolved
lib/Zonemaster/Engine/Profile.pm Outdated Show resolved Hide resolved
lib/Zonemaster/Engine/Profile.pm Outdated Show resolved Hide resolved
@mattias-p mattias-p self-requested a review June 5, 2024 16:55
@tgreenx tgreenx dismissed stale reviews from mattias-p and marc-vanderwal via f42aabd June 10, 2024 14:23
@tgreenx
Copy link
Contributor Author

tgreenx commented Jun 10, 2024

@matsduf @mattias-p @marc-vanderwal As discussed in the meeting, I added a proper IP validation function to Zonemaster::Engine::Util in this PR. Please re-review.

matsduf
matsduf previously approved these changes Jun 10, 2024
@@ -187,6 +189,22 @@ sub serial_gt {
);
}

sub validate_ip {
Copy link
Member

Choose a reason for hiding this comment

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

IMHO, having separate function for IPv4 and IPv6 would make for a better API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't do that, because I couldn't see a major benefit. However, to go in that direction I renamed this function from validate_ip() to validate_ip_for_version().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed in group meeting, it is now done (in commit f29f884).

lib/Zonemaster/Engine/Constants.pm Outdated Show resolved Hide resolved
lib/Zonemaster/Engine/Profile.pm Outdated Show resolved Hide resolved
@tgreenx
Copy link
Contributor Author

tgreenx commented Jun 11, 2024

@mattias-p I'm integrating your comments, but I have one problem.

I see now that I get a Undefined subroutine &Zonemaster::Engine::Util::validate_ip called at zonemaster-engine/lib/Zonemaster/Engine/Profile.pm line 87. error when adding the source{4,6} property in the profile. I suspect it has to do with how Perl modules and imports work (compile and run times): currently Zonemaster::Engine::Util already has a use Zonemaster::Engine::Profile import, and now in this PR I added a use Zonemaster::Engine::Util qw( validate_ip ) import in the Zonemaster::Engine::Profile module.

Do you have any clue on how to solve this issue (mutual/circular module imports)?

Copy link
Member

@mattias-p mattias-p left a comment

Choose a reason for hiding this comment

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

I had another look at this PR and started questioning the use of an accessor for the source address. The following review comments are this topic.

lib/Zonemaster/Engine/Nameserver.pm Outdated Show resolved Hide resolved
lib/Zonemaster/Engine/Nameserver.pm Outdated Show resolved Hide resolved
lib/Zonemaster/Engine/Nameserver.pm Outdated Show resolved Hide resolved
lib/Zonemaster/Engine/Nameserver.pm Outdated Show resolved Hide resolved
lib/Zonemaster/Engine/Nameserver.pm Outdated Show resolved Hide resolved
@mattias-p
Copy link
Member

Do you have any clue on how to solve this issue (mutual/circular module imports)?

Oh, this again. In general I think we should try to avoid circular module dependencies as much as possible, but I we do have a lot of them already. Zonemaster::Engine and Zonemaster::Engine::Util seem to be the worst offenders in this respect. As I refactor code to clean up or make room for other features I try to reduce the amount of circular dependencies. Maybe we should come up with some plan to reduce circular dependencies to sane levels. I'm sure that would involve deprecating a fair number of public methods.

For this particular case maybe we could introduce a new Zonemaster::Engine::Validation module that doesn't import any other modules. Zonemaster::Engine::Profile would be able to import that module without problem.

@tgreenx
Copy link
Contributor Author

tgreenx commented Jun 11, 2024

Do you have any clue on how to solve this issue (mutual/circular module imports)?
[ ... ]
For this particular case maybe we could introduce a new Zonemaster::Engine::Validation module that doesn't import any other modules. Zonemaster::Engine::Profile would be able to import that module without problem.

Now done. And your other comments have been addressed as well. Thanks for the good feedback !

@mattias-p @matsduf @marc-vanderwal please re-review.

tgreenx and others added 4 commits June 12, 2024 11:07
This commit also removes the 'source_address{4,6}' attributes of Zonemaster::Engine::Nameserver objects by using an unified one, 'source_address'.
I believe the change that introduced them was unecessary, as Zonemaster::Engine::Nameserver objects are tied to only one IP address (protocol).

Other tied changes:
- Changes 'resolver.source_address{4,6}' profile properties to not accept illegal values such as undefined or empty values.
- Removes now unused constant '$RESOLVER_SOURCE_OS_DEFAULT'
- Removes now unused function Zonemaster::Engine::Profile::check_validity()
- Rename Zonemaster::Engine::Nameserver::source_address() to Zonemaster::Engine::Nameserver::_build_source_address()
- Refactoring
- Updates documentation
- Updates unit tests
Co-authored-by: Mattias Päivärinta <mattias@paivarinta.se>
- Add constants IPV{4,6}_RE
- Add function Zonemaster::Engine::Util->validate_ip()
- Update documentation
- Update unit tests
marc-vanderwal
marc-vanderwal previously approved these changes Jun 12, 2024
@tgreenx tgreenx force-pushed the remove-deprecated branch 2 times, most recently from fab619f to cb03801 Compare June 12, 2024 09:35
…w IP address validation module

- Remove 'source_address' attribute in Zonemaster::Engine::Nameserver
- Rename function '_build_source_address()' to 'source_address()' and make it a public instance method
- Move IP address validation from Zonemaster::Engine::Util to a new module, Zonemaster::Engine::Validation
- Fixes for 'resolver.source{4,6}' properties in Zonemaster::Engine::Profile
- Update and add documentation
- Update unit tests for Zonemaster::Engine::Profile
- Add unit tests for Zonemaster::Engine::Validation
@tgreenx tgreenx force-pushed the remove-deprecated branch from cb03801 to 2dd7139 Compare June 12, 2024 09:39
marc-vanderwal
marc-vanderwal previously approved these changes Jun 12, 2024
Copy link
Member

@mattias-p mattias-p left a comment

Choose a reason for hiding this comment

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

I reviewing the test code I found one place where relevant tests are removed and a couple of places of missing tests that we should add. I feel bad about asking you to fix stuff in this PR that you didn't introduce. If you don't feel like fixing those, just say so and I'll make my own PR.

t/profiles.t Outdated
Comment on lines 162 to 170
# JSON representation of an example profile where all set values are sentinels
Readonly my $EXAMPLE_PROFILE_3 => qq(
{
"resolver": {
"source": "$RESOLVER_SOURCE_OS_DEFAULT"
}
}
);

Copy link
Member

Choose a reason for hiding this comment

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

The empty strings for resolver.source4 and resolver.source6 are also sentinel values, so we need an example profile where those values are present.

# JSON representation of an example profile where all set values are sentinels
Readonly my $EXAMPLE_PROFILE_3 => qq(
  {
    "resolver": {
      "source4": "",
      "source6": ""
    }
  }
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

t/profiles.t Outdated
Comment on lines 280 to 284
subtest 'from_json() parses sentinel values from a string' => sub {
my $profile = Zonemaster::Engine::Profile->from_json( $EXAMPLE_PROFILE_3 );

is $profile->get( 'resolver.source' ), $RESOLVER_SOURCE_OS_DEFAULT, 'resolver.source was parsed from JSON';
};
Copy link
Member

Choose a reason for hiding this comment

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

We should test parsing of the sentinel values for resolver.source4 and resolver.source6 too.

subtest 'from_json() parses sentinel values from a string' => sub {
    my $profile = Zonemaster::Engine::Profile->from_json( $EXAMPLE_PROFILE_3 );

    is $profile->get( 'resolver.source4' ), '', 'resolver.source4 was parsed from JSON';
    is $profile->get( 'resolver.source6' ), '', 'resolver.source6 was parsed from JSON';
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

t/profiles.t Outdated
Comment on lines 588 to 600
subtest 'set() accepts sentinel values' => sub {
my $profile = Zonemaster::Engine::Profile->new;

$profile->set( 'resolver.source', $RESOLVER_SOURCE_OS_DEFAULT );
is $profile->get( 'resolver.source' ), $RESOLVER_SOURCE_OS_DEFAULT, 'resolver.source was updated';

$profile->set( 'resolver.source4', '' );
is $profile->get( 'resolver.source4' ), '', 'resolver.source4 was updated';

$profile->set( 'resolver.source6', '' );
is $profile->get( 'resolver.source6' ), '', 'resolver.source6 was updated';
};

Copy link
Member

Choose a reason for hiding this comment

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

We should keep the checks for resolver.source4 and resolver.source6.

subtest 'set() accepts sentinel values' => sub {
    my $profile = Zonemaster::Engine::Profile->new;

    $profile->set( 'resolver.source4', '' );
    is $profile->get( 'resolver.source4' ), '', 'resolver.source4 was updated';

    $profile->set( 'resolver.source6', '' );
    is $profile->get( 'resolver.source6' ), '', 'resolver.source6 was updated';
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@tgreenx
Copy link
Contributor Author

tgreenx commented Jun 12, 2024

@mattias-p @matsduf @marc-vanderwal Comments have been addressed, please re-review.

@matsduf matsduf added the P-High Priority: Issue to be solved before other label Jun 13, 2024
@tgreenx tgreenx merged commit 3501cc1 into zonemaster:develop Jun 17, 2024
3 checks passed
@tgreenx tgreenx deleted the remove-deprecated branch June 17, 2024 09:31
@tgreenx tgreenx mentioned this pull request Jun 17, 2024
@matsduf
Copy link
Contributor

matsduf commented Jun 27, 2024

Release testing for v2024.1

I have verified that there is no more resolver.source support.

@matsduf matsduf added the S-ReleaseTested Status: The PR has been successfully tested in release testing label Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-High Priority: Issue to be solved before other S-ReleaseTested Status: The PR has been successfully tested in release testing V-Major Versioning: The change gives an update of major in version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move IP address validation to Zonemaster::Engine::Util
4 participants