Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreenx committed Nov 21, 2024
1 parent f4ea247 commit 06f5912
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions t/nameserver.t
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ isa_ok( $p2, 'Zonemaster::Engine::Packet' );
my ( $soa ) = grep { $_->type eq 'SOA' } $p1->answer;
is( scalar( $p1->answer ), 1, 'one answer RR present ' );
ok( $soa, 'it is a SOA RR' );
is( lc( $soa->rname ), 'hostmaster.iis.se.', 'RNAME has expected format' );
is( lc( $soa->rname ), 'hostmaster.nic.se.', 'RNAME has expected format' );
is( scalar( grep { $_->type eq 'SOA' or $_->type eq 'RRSIG' } $p2->answer ), 2, 'SOA and RRSIG RRs present' );
ok( !$nsv6->dns->dnssec, 'dnssec flag still unset' );
ok( $p3 eq $p2, 'Same packet object returned' );
ok( $p3 ne $p4, 'Same packet object not returned from other server' );
ok( $p3 ne $p1, 'Same packet object not returned with other flag' );
Expand Down Expand Up @@ -142,75 +141,75 @@ subtest 'dnssec, edns_size and edns_details{do, size} flags behavior for queries
my $ns = new_ok( 'Zonemaster::Engine::Nameserver' => [ { name => 'd.nic.fr', address => '194.0.9.1' } ] );

my $p = $ns->query( 'fr', 'SOA' );
is( $ns->dns->dnssec, 0, 'dnssec flag is unset' );
ok( !$ns->dns->dnssec, 'dnssec flag is unset' );
is( $ns->dns->edns_size, 0, 'edns_size flag is unset' );
ok( !$p->has_edns and !$p->do, 'non-EDNS response received on query with all default parameters' );

$p = $ns->query( 'fr', 'SOA', { "dnssec" => 0 } );
is( $ns->dns->dnssec, 0, 'dnssec flag is unset' );
ok( !$ns->dns->dnssec, 'dnssec flag is unset' );
is( $ns->dns->edns_size, 0, 'edns_size flag is unset' );
ok( !$p->has_edns and !$p->do, 'non-EDNS response received on query with dnssec unset' );

# Note that the following tests also implicitly test that flags are correctly re-evaluated between
# each consecutive queries.

$p = $ns->query( 'fr', 'SOA', { "dnssec" => 1 } );
is( $ns->dns->dnssec, 1, 'dnssec flag is set' );
ok( $ns->dns->dnssec, 'dnssec flag is set' );
is( $ns->dns->edns_size, $UDP_DNSSEC_QUERY_DEFAULT, 'edns_size uses default DNSSEC query value' );
ok( $p->has_edns and $p->do, 'DNSSEC response received on query with dnssec set' );

$p = $ns->query( 'fr', 'SOA', { "edns_size" => 1000 } );
is( $ns->dns->dnssec, 0, 'dnssec flag is unset' );
ok( !$ns->dns->dnssec, 'dnssec flag is unset' );
is( $ns->dns->edns_size, 1000, 'edns_size uses given value' );
ok( $p->has_edns and !$p->do, 'non-DNSSEC EDNS response received on query with edns_size set' );

$p = $ns->query( 'fr', 'SOA', { "dnssec" => 0, "edns_size" => 1001 } );
is( $ns->dns->dnssec, 0, 'dnssec flag is unset' );
ok( !$ns->dns->dnssec, 'dnssec flag is unset' );
is( $ns->dns->edns_size, 1001, 'edns_size uses given value instead of default for non-DNSSEC EDNS queries' );
ok( $p->has_edns and !$p->do, 'non-DNSSEC EDNS response received on query with dnssec unset and edns_size set' );

$p = $ns->query( 'fr', 'SOA', { "dnssec" => 1, "edns_size" => 1002 } );
is( $ns->dns->dnssec, 1, 'dnssec flag is set' );
is( $ns->dns->edns_size, 1002, 'edns_size uses given value instead of default for DNSSEC EDNS queries' );
ok( $ns->dns->dnssec, 'dnssec flag is set' );
is( $ns->dns->edns_size, 1002, 'edns_size uses given value instead of default for DNSSEC queries' );
ok( $p->has_edns and $p->do, 'DNSSEC response received on query with dnssec set and edns_size set' );

$p = $ns->query( 'fr', 'SOA', { "edns_details" => {} } );
is( $ns->dns->dnssec, 0, 'dnssec flag is unset' );
ok( !$ns->dns->dnssec, 'dnssec flag is unset' );
is( $ns->dns->edns_size, $UDP_EDNS_QUERY_DEFAULT, 'edns_size uses default EDNS query value for non-DNSSEC EDNS queries' );
ok( $p->has_edns and !$p->do, 'non-DNSSEC EDNS response received on query with edns_details set' );

$p = $ns->query( 'fr', 'SOA', { "edns_details" => { "do" => 1 } } );
is( $ns->dns->dnssec, 1, 'dnssec flag is also set via edns_details{do}' );
ok( $ns->dns->dnssec, 'dnssec flag is also set via edns_details{do}' );
is( $ns->dns->edns_size, $UDP_DNSSEC_QUERY_DEFAULT, 'edns_size also uses default DNSSEC query value when set with edns_details{do}' );
ok( $p->has_edns and $p->do, 'DNSSEC response received on query with edns_details{do} set' );

$p = $ns->query( 'fr', 'SOA', { "edns_details" => { "size" => 900 } } );
is( $ns->dns->dnssec, 0, 'dnssec flag is unset' );
ok( !$ns->dns->dnssec, 'dnssec flag is unset' );
is( $ns->dns->edns_size, 900, 'edns_size also uses given value when set with edns_details{size}' );
ok( $p->has_edns and !$p->do, 'non-DNSSEC EDNS response received on query with edns_details{size} set' );

$p = $ns->query( 'fr', 'SOA', { "edns_details" => { "size" => 0 } } );
is( $ns->dns->dnssec, 0, 'dnssec flag is unset' );
ok( !$ns->dns->dnssec, 'dnssec flag is unset' );
is( $ns->dns->edns_size, 0, 'edns_size also uses given value when set with edns_details{size}' );
ok( $p->has_edns and !$p->do, 'non-DNSSEC EDNS response received on query even with edns_details{size} set to 0' );

$p = $ns->query( 'fr', 'SOA', { "dnssec" => 1, "edns_details" => { "do" => 0 } } );
is( $ns->dns->dnssec, 0, 'edns_details{do} takes precedence over dnssec for setting the dnssec flag' );
ok( !$ns->dns->dnssec, 'edns_details{do} takes precedence over dnssec for (un)setting the dnssec flag' );
is( $ns->dns->edns_size, $UDP_EDNS_QUERY_DEFAULT, 'edns_size uses default EDNS query value when dnssec flag is unset by edns_details{do}' );
ok( $p->has_edns and !$p->do, 'non-DNSSEC EDNS response received on query with dnssec unset by edns_details{do}' );

$p = $ns->query( 'fr', 'SOA', { "edns_size" => 1003, "edns_details" => { "size" => 901 } } );
is( $ns->dns->dnssec, 0, 'dnssec flag is unset' );
ok( !$ns->dns->dnssec, 'dnssec flag is unset' );
is( $ns->dns->edns_size, 901, 'edns_details{size} takes precedence over edns_size for setting the edns_size flag' );
ok( $p->has_edns and !$p->do, 'non-DNSSEC EDNS response received on query with edns_size and edns_details{size} set' );

$p = $ns->query( 'fr', 'SOA', { "dnssec" => 1, "edns_size" => 1004, "edns_details" => { "size" => 0 } } );
is( $ns->dns->dnssec, 1, 'dnssec flag is set' );
ok( $ns->dns->dnssec, 'dnssec flag is set' );
is( $ns->dns->edns_size, 0, 'edns_size is unset' );
ok( $p->has_edns and $p->do, 'DNSSEC response received on query with dnssec set and even with edns_details{size} set to 0' );

$p = $ns->query( 'fr', 'SOA', { "dnssec" => 0, "edns_size" => 1005, "edns_details" => { "do" => 1, "size" => 0 } } );
is( $ns->dns->dnssec, 1, 'dnssec flag is set' );
ok( $ns->dns->dnssec, 'dnssec flag is set' );
is( $ns->dns->edns_size, 0, 'edns_size is unset' );
ok( $p->has_edns and $p->do, 'DNSSEC response received on query with dnssec set by edns_details{do} and even with edns_details{size} set to 0' );

Expand Down

0 comments on commit 06f5912

Please sign in to comment.