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

Delegation02 delegation checks #400

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/Zonemaster/Engine.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use version; our $VERSION = version->declare("v2.0.6");

use 5.014002;
use Moose;
use Carp;

use Zonemaster::Engine::Nameserver;
use Zonemaster::Engine::Logger;
Expand Down Expand Up @@ -99,9 +100,17 @@ sub recurse {

sub add_fake_delegation {
my ( $class, $domain, $href ) = @_;
my $incomplete_delegation;

# Validate arguments
$domain =~ /[^.]$|^\.$/
or croak 'Argument $domain must omit the trailing dot, or it must be a single dot';
foreach my $name ( keys %{$href} ) {
$name =~ /[^.]$|^\.$/
or croak 'Each key of argument $href must omit the trailing dot, or it must be a single dot';
}

# Check fake delegation
my $incomplete_delegation;
foreach my $name ( keys %{$href} ) {
if ( not defined $href->{$name} or not scalar @{ $href->{$name} } ) {
if ( Zonemaster::Engine::Zone->new( { name => $domain } )->is_in_zone( $name ) ) {
Expand Down
11 changes: 11 additions & 0 deletions lib/Zonemaster/Engine/Test/Delegation.pm
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ sub metadata {
qw(
CHILD_DISTINCT_NS_IP
CHILD_NS_SAME_IP
DEL_DISTINCT_NS_IP
DEL_NS_SAME_IP
SAME_IP_ADDRESS
)
],
Expand Down Expand Up @@ -109,6 +111,8 @@ sub translation {
"NS_RR_IS_CNAME" => "Nameserver {ns} {address_type} RR point to CNAME.",
"CHILD_DISTINCT_NS_IP" => "All the IP addresses used by the nameservers in child are unique.",
"CHILD_NS_SAME_IP" => "IP {address} in child refers to multiple nameservers ({nss}).",
"DEL_DISTINCT_NS_IP" => "All the IP addresses used by the nameservers in parent are unique.",
"DEL_NS_SAME_IP" => "IP {address} in parent refers to multiple nameservers ({nss}).",
"SAME_IP_ADDRESS" => "IP {address} refers to multiple nameservers ({nss}).",
"DISTINCT_IP_ADDRESS" => "All the IP addresses used by the nameservers are unique",
"ENOUGH_NS_CHILD" => "Child lists enough ({count}) nameservers ({ns}). Lower limit set to {minimum}.",
Expand Down Expand Up @@ -222,6 +226,13 @@ sub delegation02 {
my @nss_del = @{ Zonemaster::Engine::TestMethods->method4( $zone ) };
my @nss_child = @{ Zonemaster::Engine::TestMethods->method5( $zone ) };

push @results,
_find_dup_ns(
duplicate_tag => 'DEL_NS_SAME_IP',
distinct_tag => 'DEL_DISTINCT_NS_IP',
nss => [@nss_del],
);

push @results,
_find_dup_ns(
duplicate_tag => 'CHILD_NS_SAME_IP',
Expand Down
4 changes: 3 additions & 1 deletion t/Test-delegation02-A.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if ( not $ENV{ZONEMASTER_RECORD} ) {
}

Zonemaster::Engine->add_fake_delegation(
'a.delegation02.exempelvis.se.' => {
'a.delegation02.exempelvis.se' => {
'ns1.a.delegation02.exempelvis.se' => [ '46.21.97.97', '2a02:750:12:77::97' ],
'ns2.a.delegation02.exempelvis.se' => [ '37.123.169.91', '2001:9b0:1:1c13::53' ],
},
Expand All @@ -25,7 +25,9 @@ my $zone = Zonemaster::Engine->zone( q{a.delegation02.exempelvis.se} );

my %res = map { $_->tag => $_ } Zonemaster::Engine::Test::Delegation->delegation02( $zone );

ok( !$res{DEL_NS_SAME_IP}, q{should not emit DEL_NS_SAME_IP} );
ok( !$res{CHILD_NS_SAME_IP}, q{should not emit CHILD_NS_SAME_IP} );
ok( $res{DEL_DISTINCT_NS_IP}, q{should emit DEL_DISTINCE_NS_IP} );
Copy link
Contributor

Choose a reason for hiding this comment

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

"should emit DEL_DISTINCE_NS_IP" => "should emit DEL_DISTINCT_NS_IP"

ok( $res{CHILD_DISTINCT_NS_IP}, q{should emit CHILD_DISTINCE_NS_IP} );
Copy link
Contributor

Choose a reason for hiding this comment

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

"should emit CHILD_DISTINCE_NS_IP" => "should emit CHILD_DISTINCT_NS_IP"


if ( $ENV{ZONEMASTER_RECORD} ) {
Expand Down
55 changes: 55 additions & 0 deletions t/Test-delegation02-B.data

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions t/Test-delegation02-B.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use Test::More;

BEGIN {
use_ok( q{Zonemaster::Engine} );
use_ok( q{Zonemaster::Engine::Test::Delegation} );
use_ok( q{Zonemaster::Engine::Util} );
}

my $datafile = q{t/Test-delegation02-B.data};

if ( not $ENV{ZONEMASTER_RECORD} ) {
die q{Stored data file missing} if not -r $datafile;
Zonemaster::Engine::Nameserver->restore( $datafile );
Zonemaster::Engine->config->no_network( 1 );
}

Zonemaster::Engine->add_fake_delegation(
'b.delegation02.exempelvis.se' => {
'ns1.b.delegation02.exempelvis.se' => [ '46.21.97.97', '2a02:750:12:77::97' ],
'ns2.b.delegation02.exempelvis.se' => [ '46.21.97.97', '2a02:750:12:77::97' ],
},
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why add that as undelegated instead of letting Zonemaster pick live data up?

Copy link
Member Author

Choose a reason for hiding this comment

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

Mostly because it reflects our use case. I guess it's not necessary. However, doing that is what unveiled the trailing dots problem.


my $zone = Zonemaster::Engine->zone( q{b.delegation02.exempelvis.se} );

my %res = map { $_->tag => $_ } Zonemaster::Engine::Test::Delegation->delegation02( $zone );

ok( $res{DEL_NS_SAME_IP}, q{should emit DEL_NS_SAME_IP} );
ok( !$res{CHILD_NS_SAME_IP}, q{should not emit CHILD_NS_SAME_IP} );
ok( !$res{DEL_DISTINCT_NS_IP}, q{should not emit DEL_DISTINCE_NS_IP} );
ok( $res{CHILD_DISTINCT_NS_IP}, q{should emit CHILD_DISTINCE_NS_IP} );

Copy link
Contributor

Choose a reason for hiding this comment

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

"should emit CHILD_DISTINCE_NS_IP" => "should emit CHILD_DISTINCT_NS_IP"

if ( $ENV{ZONEMASTER_RECORD} ) {
Zonemaster::Engine::Nameserver->save( $datafile );
}

done_testing;
4 changes: 3 additions & 1 deletion t/Test-delegation02-C.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if ( not $ENV{ZONEMASTER_RECORD} ) {
}

Zonemaster::Engine->add_fake_delegation(
'c.delegation02.exempelvis.se.' => {
'c.delegation02.exempelvis.se' => {
'ns1.c.delegation02.exempelvis.se' => [ '46.21.97.97', '2a02:750:12:77::97' ],
'ns2.c.delegation02.exempelvis.se' => [ '37.123.169.91', '2001:9b0:1:1c13::53' ],
},
Expand All @@ -26,7 +26,9 @@ my $zone = Zonemaster::Engine->zone( q{c.delegation02.exempelvis.se} );

my %res = map { $_->tag => $_ } Zonemaster::Engine::Test::Delegation->delegation02( $zone );

ok( !$res{DEL_NS_SAME_IP}, q{should not emit DEL_NS_SAME_IP} );
ok( $res{CHILD_NS_SAME_IP}, q{should emit CHILD_NS_SAME_IP} );
ok( $res{DEL_DISTINCT_NS_IP}, q{should emit DEL_DISTINCE_NS_IP} );
Copy link
Contributor

Choose a reason for hiding this comment

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

"should emit CHILD_DISTINCE_NS_IP" => "should emit CHILD_DISTINCT_NS_IP"

ok( !$res{CHILD_DISTINCT_NS_IP}, q{should not emit CHILD_DISTINCE_NS_IP} );

if ( $ENV{ZONEMASTER_RECORD} ) {
Expand Down
53 changes: 53 additions & 0 deletions t/Test-delegation02-D.data

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions t/Test-delegation02-D.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use strict;
use Test::More;

BEGIN {
use_ok( q{Zonemaster::Engine} );
use_ok( q{Zonemaster::Engine::Test::Delegation} );
use_ok( q{Zonemaster::Engine::Util} );
}

my $datafile = q{t/Test-delegation02-D.data};

if ( not $ENV{ZONEMASTER_RECORD} ) {
die q{Stored data file missing} if not -r $datafile;
Zonemaster::Engine::Nameserver->restore( $datafile );
Zonemaster::Engine->config->no_network( 1 );
}

Zonemaster::Engine->add_fake_delegation(
'd.delegation02.exempelvis.se' => {
'ns1.d.delegation02.exempelvis.se' => [ '46.21.97.97', '2a02:750:12:77::97' ],
'ns2.d.delegation02.exempelvis.se' => [ '46.21.97.97', '2a02:750:12:77::97' ],
},
);

my $zone = Zonemaster::Engine->zone( q{d.delegation02.exempelvis.se} );

my %res = map { $_->tag => $_ } Zonemaster::Engine::Test::Delegation->delegation02( $zone );

ok( $res{DEL_NS_SAME_IP}, q{should emit DEL_NS_SAME_IP} );
ok( $res{CHILD_NS_SAME_IP}, q{should emit CHILD_NS_SAME_IP} );
ok( !$res{DEL_DISTINCT_NS_IP}, q{should not emit DEL_DISTINCE_NS_IP} );
ok( !$res{CHILD_DISTINCT_NS_IP}, q{should not emit CHILD_DISTINCE_NS_IP} );
Copy link
Contributor

Choose a reason for hiding this comment

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

"should not emit DEL_DISTINCE_NS_IP" => "should not emit DEL_DISTINCT_NS_IP"

"should emit CHILD_DISTINCE_NS_IP" => "should emit CHILD_DISTINCT_NS_IP"


if ( $ENV{ZONEMASTER_RECORD} ) {
Zonemaster::Engine::Nameserver->save( $datafile );
}

done_testing;
8 changes: 4 additions & 4 deletions t/undelegated.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ isa_ok( $plain_p, 'Zonemaster::Engine::Packet' );
ok( $plain_p, 'Got answer' );

Zonemaster::Engine->add_fake_delegation(
'lysator.liu.se.' => {
'lysator.liu.se' => {
'ns-slave.lysator.liu.se' => [ '130.236.254.4', '130.236.255.2' ],
'ns-master.lysator.liu.se' => [ '130.236.254.2', '2001:6b0:17:f0a0::2' ],
'ns-slave-1.ifm.liu.se' => [ '130.236.160.2', '2001:6b0:17:f180::1001' ],
Expand Down Expand Up @@ -55,7 +55,7 @@ is( $ds->hexdigest, 'faceb00c', 'Correct digest' );

Zonemaster::Engine->logger->clear_history;
Zonemaster::Engine->add_fake_delegation(
'nic.se.' => {
'nic.se' => {
'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' ]
Expand All @@ -66,7 +66,7 @@ ok( !!( grep { $_->tag eq 'FAKE_DELEGATION_TO_SELF' } @{ Zonemaster::Engine->log

Zonemaster::Engine->logger->clear_history;
Zonemaster::Engine->add_fake_delegation(
'lysator.liu.se.' => {
'lysator.liu.se' => {
'frfr.sesefrfr' => [ ],
'i.ns.se' => [ '194.146.106.22', '2001:67c:1010:5::53' ],
'ns3.nic.se' => [ '212.247.8.152', '2a00:801:f0:211::152' ]
Expand All @@ -78,7 +78,7 @@ ok( !!( grep { $_->tag eq 'FAKE_DELEGATION_NO_IP' } @{ Zonemaster::Engine->logge

Zonemaster::Engine->logger->clear_history;
Zonemaster::Engine->add_fake_delegation(
'nic.se.' => {
'nic.se' => {
'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' ],
Expand Down