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

Fix alias (CNAME) handling in Address03 test case #1432

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ t/recursor-A.data
t/recursor-A.t
t/Test-address.data
t/Test-address.t
t/Test-address03.data
t/Test-address03.t
t/Test-basic.data
t/Test-basic.t
t/Test-basic01.data
Expand Down
10 changes: 1 addition & 9 deletions lib/Zonemaster/Engine/Test/Address.pm
Original file line number Diff line number Diff line change
Expand Up @@ -422,16 +422,8 @@ sub address03 {

my $p = Zonemaster::Engine::Recursor->recurse( $ptr_query, q{PTR} );

# In case of Classless IN-ADDR.ARPA delegation, query returns
# CNAME records. A PTR query is done on the CNAME.
if ( $p and $p->rcode eq q{NOERROR} and $p->get_records( q{CNAME}, q{answer} ) ) {
my ( $cname ) = $p->get_records( q{CNAME}, q{answer} );
$ptr_query = $cname->cname;
$p = Zonemaster::Engine::Recursor->recurse( $ptr_query, q{PTR} );
}

if ( $p ) {
my @ptr = $p->get_records_for_name( q{PTR}, $ptr_query );
my @ptr = $p->get_records( q{PTR}, 'answer' );
if ( $p->rcode eq q{NOERROR} and scalar @ptr ) {
if ( none { name( $_->ptrdname ) eq $local_ns->name->string . q{.} } @ptr ) {
push @results,
Expand Down
2 changes: 0 additions & 2 deletions t/Test-address.t
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,6 @@ ok( $res{NAMESERVER_IP_PRIVATE_NETWORK}, q{Nameserver address in non routable pu
my $torsasse = Zonemaster::Engine->zone( q{torsas.se} );
my @res = Zonemaster::Engine->test_method( q{Address}, q{address02}, $torsasse );
ok( !( grep { $_->tag eq 'NAMESERVER_IP_WITHOUT_REVERSE' } @res ), 'Classless in-addr.arpa properly handled when querying PTR.' );
@res = Zonemaster::Engine->test_method( q{Address}, q{address03}, $torsasse );
ok( !( grep { $_->tag eq 'NAMESERVER_IP_WITHOUT_REVERSE' } @res ), 'Classless in-addr.arpa properly handled when querying PTR.' );

if ( $ENV{ZONEMASTER_RECORD} ) {
Zonemaster::Engine::Nameserver->save( $datafile );
Expand Down
38 changes: 38 additions & 0 deletions t/Test-address03.data

Large diffs are not rendered by default.

145 changes: 145 additions & 0 deletions t/Test-address03.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
use strict;
use warnings;

use Test::More;
use File::Basename;
use File::Spec::Functions qw( rel2abs );
use lib dirname( rel2abs( $0 ) );

BEGIN {
use_ok( q{Zonemaster::Engine} );
use_ok( q{Zonemaster::Engine::Nameserver} );
use_ok( q{Zonemaster::Engine::Test::Address} );
use_ok( q{TestUtil}, qw( perform_testcase_testing ) );
}

my $test_module = q{Address};
my $test_case = q{address03};
my @all_tags = qw(NAMESERVER_IP_PTR_MATCH
NAMESERVER_IP_PTR_MISMATCH
NAMESERVER_IP_WITHOUT_REVERSE
NO_RESPONSE_PTR_QUERY);

# Common hint file (test-zone-data/COMMON/hintfile)
Zonemaster::Engine::Recursor->remove_fake_addresses( '.' );
Zonemaster::Engine::Recursor->add_fake_addresses( '.',
{ 'ns1' => [ '127.1.0.1', 'fda1:b2:c3::127:1:0:1' ],
'ns2' => [ '127.1.0.2', 'fda1:b2:c3::127:1:0:2' ],
}
);

# Test zone scenarios
# - Documentation: L<TestUtil/perform_testcase_testing()>
# - Format: { SCENARIO_NAME => [
# testable,
# zone_name,
# [ MANDATORY_MESSAGE_TAGS ],
# [ FORBIDDEN_MESSAGE_TAGS ],
# [ UNDELEGATED_NS ],
# [ UNDELEGATED_DS ],
# ] }
#
# - One of MANDATORY_MESSAGE_TAGS and FORBIDDEN_MESSAGE_TAGS may be undefined.
# See documentation for the meaning of that.

my %subtests = (
'ALL-NS-HAVE-PTR-1' => [
1,
q(all-ns-have-ptr-1.address03.xa),
[ qw(NAMESERVER_IP_PTR_MATCH) ],
undef,
[],
[]
],
'ALL-NS-HAVE-PTR-2' => [
1,
q(all-ns-have-ptr-2.address03.xa),
[ qw(NAMESERVER_IP_PTR_MATCH) ],
undef,
[],
[]
],
'NO-NS-HAVE-PTR' => [
1,
q(no-ns-have-ptr.address03.xa),
[ qw(NAMESERVER_IP_WITHOUT_REVERSE) ],
undef,
[],
[]
],
'INCOMPLETE-PTR-1' => [
1,
q(incomplete-ptr-1.address03.xa),
[ qw(NAMESERVER_IP_WITHOUT_REVERSE) ],
undef,
[],
[]
],
'INCOMPLETE-PTR-2' => [
1,
q(incomplete-ptr-2.address03.xa),
[ qw(NAMESERVER_IP_WITHOUT_REVERSE) ],
undef,
[],
[]
],
'NON-MATCHING-NAMES' => [
1,
q(non-matching-names.address03.xa),
[ qw(NAMESERVER_IP_PTR_MISMATCH) ],
undef,
[],
[]
],
'PTR-IS-GOOD-CNAME-1' => [
1,
q(ptr-is-good-cname-1.address03.xa),
[ qw(NAMESERVER_IP_PTR_MATCH) ],
undef,
[],
[]
],
'PTR-IS-GOOD-CNAME-2' => [
1,
q(ptr-is-good-cname-2.address03.xa),
[ qw(NAMESERVER_IP_PTR_MATCH) ],
undef,
[],
[]
],
'PTR-IS-DANGLING-CNAME' => [
1,
q(ptr-is-dangling-cname.address03.xa),
[ qw(NAMESERVER_IP_WITHOUT_REVERSE) ],
undef,
[],
[]
],
'PTR-IS-ILLEGAL-CNAME' => [
1,
q(ptr-is-illegal-cname.address03.xa),
[ qw(NAMESERVER_IP_WITHOUT_REVERSE) ],
[ qw(NAMESERVER_IP_PTR_MATCH) ],
[],
[]
]
);
###########

my $datafile = 't/' . basename ($0, '.t') . '.data';

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

Zonemaster::Engine::Profile->effective->merge( Zonemaster::Engine::Profile->from_json( qq({ "test_cases": [ "$test_case" ] }) ) );

perform_testcase_testing( $test_case, $test_module, \@all_tags, \%subtests, $ENV{ZONEMASTER_SINGLE_SCENARIO}, $ENV{ZONEMASTER_DISABLE_SCENARIO} );

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

done_testing;
Loading