Skip to content

Commit

Permalink
Refactor of logging for undelegated tests
Browse files Browse the repository at this point in the history
- Rename ADDED_FAKE_DELEGATION to FAKE_DELEGATION_ADDED for consistency
- Rename FAKE_DELEGATION to FAKE_DELEGATION_RETURNED for consistency
- Rename FAKE_DS to FAKE_DS_ADDED for consistency
- Add messages IDs for FAKE_DS_ADDED and FAKE_DS_RETURNED
- Make FAKE_DS_RETURNED arguments consistent with FAKE_DELEGATION_RETURNED
- Return a FAKED_RETURN message when a fake DS exists (- relates to issue zonemaster#1169)
  • Loading branch information
tgreenx committed Jul 18, 2023
1 parent 76b9dd9 commit c50b3bb
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 27 deletions.
20 changes: 6 additions & 14 deletions lib/Zonemaster/Engine/Nameserver.pm
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ sub query {
}

my $res = Zonemaster::Engine::Packet->new( { packet => $p } );
Zonemaster::Engine->logger->add( FAKE_DS_RETURNED => { name => "$name", from => "$self" } );
Zonemaster::Engine->logger->add( FAKE_DS_RETURNED => { name => "$name", type => $type, class => $class, from => "$self" } );
Zonemaster::Engine->logger->add( FAKED_RETURN => { packet => $res->string } );
return $res;
}

Expand Down Expand Up @@ -318,15 +319,7 @@ sub query {
$p->rd( $recurse );
$p->answerfrom( $self->address->ip );

Zonemaster::Engine->logger->add(
'FAKE_DELEGATION',
{
name => "$name",
type => $type,
class => $class,
from => "$self",
}
);
Zonemaster::Engine->logger->add( FAKE_DELEGATION_RETURNED => { name => "$name", type => $type, class => $class, from => "$self" } );

my $res = Zonemaster::Engine::Packet->new( { packet => $p } );
Zonemaster::Engine->logger->add( FAKED_RETURN => { packet => $res->string } );
Expand Down Expand Up @@ -382,8 +375,7 @@ sub add_fake_delegation {
push @{ $delegation{authority} }, Zonemaster::LDNS::RR->new( sprintf( '%s IN NS %s', $domain, $name ) );
foreach my $ip ( @{ $href->{$name} } ) {
if ( Net::IP::XS->new( $ip )->ip eq $self->address->ip ) {
Zonemaster::Engine->logger->add(
FAKE_DELEGATION_TO_SELF => { ns => "$self", domain => $domain, data => $href } );
Zonemaster::Engine->logger->add( FAKE_DELEGATION_TO_SELF => { ns => "$self", domain => $domain, data => $href } );
return;
}

Expand All @@ -393,7 +385,7 @@ sub add_fake_delegation {
}

$self->fake_delegations->{$domain} = \%delegation;
Zonemaster::Engine->logger->add( ADDED_FAKE_DELEGATION => { ns => "$self", domain => $domain, data => $href } );
Zonemaster::Engine->logger->add( FAKE_DELEGATION_ADDED => { ns => "$self", domain => $domain, data => $href } );

# We're changing the world, so the cache can't be trusted
Zonemaster::Engine::Recursor->clear_cache;
Expand All @@ -409,7 +401,6 @@ sub add_fake_ds {
$domain = Zonemaster::Engine::DNSName->new( $domain );
}

Zonemaster::Engine->logger->add( FAKE_DS => { domain => lc( "$domain" ), data => $aref, ns => "$self" } );
foreach my $href ( @{$aref} ) {
push @ds,
Zonemaster::LDNS::RR->new(
Expand All @@ -421,6 +412,7 @@ sub add_fake_ds {
}

$self->fake_ds->{ lc( "$domain" ) } = \@ds;
Zonemaster::Engine->logger->add( FAKE_DS_ADDED => { domain => lc( "$domain" ), data => $aref, ns => "$self" } );

# We're changing the world, so the cache can't be trusted
Zonemaster::Engine::Recursor->clear_cache;
Expand Down
16 changes: 12 additions & 4 deletions lib/Zonemaster/Engine/Translator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ Readonly my %TAG_DESCRIPTIONS => (
__x # SYSTEM:SKIP_IPV6_DISABLED
"IPv6 is disabled, not sending \"{rrtype}\" query to {ns}.", @_;
},
FAKE_DELEGATION => sub {
__x # SYSTEM:FAKE_DELEGATION
FAKE_DELEGATION_RETURNED => sub {
__x # SYSTEM:FAKE_DELEGATION_RETURNED
"Followed a fake delegation.";
},
ADDED_FAKE_DELEGATION => sub {
__x # SYSTEM:ADDED_FAKE_DELEGATION
FAKE_DELEGATION_ADDED => sub {
__x # SYSTEM:FAKE_DELEGATION_ADDED
"Added a fake delegation for domain {domain} to name server {ns}.", @_;
},
FAKE_DELEGATION_TO_SELF => sub {
Expand All @@ -103,6 +103,14 @@ Readonly my %TAG_DESCRIPTIONS => (
. "that cannot be resolved to any IP address.",
@_;
},
FAKE_DS_ADDED => sub {
__x # SYSTEM:FAKE_DS_ADDED
"Added a fake DS for domain {domain} to name server {ns}.", @_;
},
FAKE_DS_RETURNED => sub {
__x # SYSTEM:FAKE_DS_RETURNED
"Returned a fake DS.";
},
PACKET_BIG => sub {
__x # SYSTEM:PACKET_BIG
"Big packet size ({size}) (try with \"{command}\").", @_;
Expand Down
8 changes: 5 additions & 3 deletions share/profile.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,19 +402,21 @@
"TEST_CASE_START" : "DEBUG"
},
"SYSTEM" : {
"ADDED_FAKE_DELEGATION" : "DEBUG",
"CACHE_CREATED" : "DEBUG2",
"CACHE_FETCHED" : "DEBUG2",
"CACHED_RETURN" : "DEBUG3",
"CANNOT_CONTINUE" : "CRITICAL",
"DEPENDENCY_VERSION" : "DEBUG",
"EMPTY_RETURN" : "DEBUG3",
"EXTERNAL_RESPONSE" : "DEBUG3",
"FAKED_RETURN" : "DEBUG2",
"FAKE_DELEGATION" : "DEBUG2",
"FAKE_DELEGATION_ADDED" : "DEBUG",
"FAKE_DELEGATION_IN_ZONE_NO_IP" : "ERROR",
"FAKE_DELEGATION_NO_IP" : "ERROR",
"FAKE_DELEGATION_RETURNED" : "DEBUG2",
"FAKE_DELEGATION_TO_SELF" : "DEBUG",
"FAKE_DS_ADDED" : "DEBUG",
"FAKE_DS_RETURNED" : "DEBUG2",
"FAKED_RETURN" : "DEBUG2",
"GLOBAL_VERSION" : "INFO",
"IPV4_BLOCKED" : "DEBUG2",
"IPV6_BLOCKED" : "DEBUG2",
Expand Down
8 changes: 5 additions & 3 deletions share/profile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -440,19 +440,21 @@ test_levels:
TEST_CASE_END: DEBUG
TEST_CASE_START: DEBUG
SYSTEM:
ADDED_FAKE_DELEGATION: DEBUG
CACHED_RETURN: DEBUG3
CACHE_CREATED: DEBUG2
CACHE_FETCHED: DEBUG2
CANNOT_CONTINUE: CRITICAL
DEPENDENCY_VERSION: DEBUG
EMPTY_RETURN: DEBUG3
EXTERNAL_RESPONSE: DEBUG3
FAKED_RETURN: DEBUG2
FAKE_DELEGATION: DEBUG2
FAKE_DELEGATION_ADDED: DEBUG
FAKE_DELEGATION_IN_ZONE_NO_IP: ERROR
FAKE_DELEGATION_NO_IP: ERROR
FAKE_DELEGATION_RETURNED: DEBUG2
FAKE_DELEGATION_TO_SELF: DEBUG
FAKE_DS_ADDED: DEBUG
FAKE_DS_RETURNED: DEBUG2
FAKED_RETURN: DEBUG2
GLOBAL_VERSION: INFO
IPV4_BLOCKED: DEBUG2
IPV6_BLOCKED: DEBUG2
Expand Down
8 changes: 6 additions & 2 deletions t/profiles/Test-all-levels.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,14 @@
"DEPENDENCY_VERSION" : "DEBUG",
"EMPTY_RETURN" : "DEBUG3",
"EXTERNAL_RESPONSE" : "DEBUG3",
"FAKED_RETURN" : "DEBUG2",
"FAKE_DELEGATION" : "DEBUG2",
"FAKE_DELEGATION_ADDED" : "DEBUG",
"FAKE_DELEGATION_IN_ZONE_NO_IP" : "ERROR",
"FAKE_DELEGATION_NO_IP" : "ERROR",
"FAKE_DELEGATION_RETURNED" : "DEBUG2",
"FAKE_DELEGATION_TO_SELF" : "DEBUG",
"FAKE_DS_ADDED" : "DEBUG",
"FAKE_DS_RETURNED" : "DEBUG2",
"FAKED_RETURN" : "DEBUG2",
"GLOBAL_VERSION" : "INFO",
"IPV4_BLOCKED" : "DEBUG2",
"IPV6_BLOCKED" : "DEBUG2",
Expand Down
2 changes: 1 addition & 1 deletion t/undelegated.t
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Zonemaster::Engine->add_fake_delegation(
my $fake_happened = 0;
Zonemaster::Engine->logger->callback(
sub {
$fake_happened = 1 if $_[0]->tag eq 'FAKE_DELEGATION';
$fake_happened = 1 if $_[0]->tag eq 'FAKE_DELEGATION_RETURNED';
}
);

Expand Down

0 comments on commit c50b3bb

Please sign in to comment.