| 1 | package Net::DNS::Resolver::Mock; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 3 | our $VERSION = '1.20220817'; # VERSION | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use base 'Net::DNS::Resolver'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Net::DNS::Packet; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Net::DNS::Question; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Net::DNS::ZoneFile; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 3 | my $die_on = {}; | |||||||||||||||||||||||||||||||
| 15 | { | ||||||||||||||||||||||||||||||||
| 16 | 3 | my @_debug_output; | |||||||||||||||||||||||||||||||
| 17 | sub enable_debug { | ||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
enable_debug: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 19 | 1 | $self->{_mock_debug} = 1; | |||||||||||||||||||||||||||||||
| 20 | 1 | $self->_add_debug( "Net::DNS::Resolver::Mock Debugging enabled" ); | |||||||||||||||||||||||||||||||
| 21 | 1 | return; | |||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||
| 23 | sub disable_debug { | ||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
disable_debug: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 25 | 1 | $self->clear_debug(); | |||||||||||||||||||||||||||||||
| 26 | 1 | delete $self->{_mock_debug}; | |||||||||||||||||||||||||||||||
| 27 | 1 | return; | |||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||
| 29 | sub _add_debug { | ||||||||||||||||||||||||||||||||
| 30 | 4 | ▶ | my ( $self, $debug ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_add_debug: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 31 | 4 | push @_debug_output, $debug; | |||||||||||||||||||||||||||||||
| 32 | 4 | warn $debug; | |||||||||||||||||||||||||||||||
| 33 | 4 | return; | |||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||
| 35 | sub clear_debug { | ||||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
clear_debug: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 37 | 1 | @_debug_output = (); | |||||||||||||||||||||||||||||||
| 38 | 1 | return; | |||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||
| 40 | sub get_debug { | ||||||||||||||||||||||||||||||||
| 41 | 5 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
get_debug: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 42 | 5 | return @_debug_output; | |||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 3 | sub die_on { | |||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | my ( $self, $name, $type, $error ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
die_on: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 48 | 1 | $die_on->{ "$name $type" } = $error; | |||||||||||||||||||||||||||||||
| 49 | 1 | return; | |||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | sub zonefile_read { | ||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | my ( $self, $zonefile ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
zonefile_read: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 54 | 1 | $self->{ 'zonefile' } = Net::DNS::ZoneFile->read( $zonefile ); | |||||||||||||||||||||||||||||||
| 55 | 1 | return; | |||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | sub zonefile_parse { | ||||||||||||||||||||||||||||||||
| 59 | 3 | ▶ | my ( $self, $zonefile ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
zonefile_parse: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 60 | 3 | $self->{ 'zonefile' } = Net::DNS::ZoneFile->parse( $zonefile ); | |||||||||||||||||||||||||||||||
| 61 | 3 | return; | |||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | sub send { | ||||||||||||||||||||||||||||||||
| 65 | 16 | ▶ | my ( $self, $name, $type ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
send: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 16 | ▶ | $self->_add_debug( "DNS Lookup '$name' '$type'" ) if $self->{_mock_debug}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 16 | ▶ | if ( exists ( $die_on->{ "$name $type" } ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 70 | 1 | die $die_on->{ "$name $type" }; | |||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 15 | ▶ | $name =~ s/\.$// unless $name eq '.'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 15 | my $FakeZone = $self->{ 'zonefile' }; | |||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 15 | my $origname = $name; | |||||||||||||||||||||||||||||||
| 78 | 15 | ▶ | if ( lc $type eq 'ptr' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 79 | 4 | ▶ | if ( index( lc $name, '.in-addr.arpa' ) == -1 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 80 | 3 | ▶ | if ( $name =~ /^\d+\.\d+\.\d+\.\d+$/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 81 | 2 | $name = join( '.', reverse( split( /\./, $name ) ) ); | |||||||||||||||||||||||||||||||
| 82 | 2 | $name .= '.in-addr.arpa'; | |||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||
| 86 | 15 | my $Packet = Net::DNS::Packet->new(); | |||||||||||||||||||||||||||||||
| 87 | 15 | $Packet->push( 'question' => Net::DNS::Question->new( $origname, $type, 'IN' ) ); | |||||||||||||||||||||||||||||||
| 88 | 15 | foreach my $Item ( @$FakeZone ) { | |||||||||||||||||||||||||||||||
| 89 | 32 | my $itemname = $Item->name(); | |||||||||||||||||||||||||||||||
| 90 | 32 | my $itemtype = $Item->type(); | |||||||||||||||||||||||||||||||
| 91 | 32 | ▶ | if ( ( lc $itemname eq lc $name ) && ( lc $itemtype eq lc $type ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
lc $itemname eq lc $name and lc $itemtype eq lc $type
MC/DC100%2/2
lc $itemname eq lc $name and lc $itemtype eq lc $type
lc $itemname eq lc $name
lc $itemtype eq lc $type
Truth table100%3/3
A and B
A= lc $itemname eq lc $nameB= lc $itemtype eq lc $type
| |||||||||||||||||||||||||||||||||
| 92 | 6 | $Packet->push( 'answer' => $Item ); | |||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||
| 94 | ▶ | elsif ( ( lc $itemname eq lc $name ) && ( lc $itemtype eq lc 'cname' ) ) { | |||||||||||||||||||||||||||||||
|
Condition66%2/3
lc $itemname eq lc $name and lc $itemtype eq "cname"
MC/DC50%1/2
lc $itemname eq lc $name and lc $itemtype eq "cname"
lc $itemname eq lc $name
lc $itemtype eq "cname"
Truth table66%2/3
A and B
A= lc $itemname eq lc $nameB= lc $itemtype eq "cname"
| |||||||||||||||||||||||||||||||||
| 95 | 1 | $Packet->push( 'answer' => $Item ); | |||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||
| 98 | 15 | $Packet->{ 'answerfrom' } = '127.0.0.1'; | |||||||||||||||||||||||||||||||
| 99 | 15 | $Packet->{ 'status' } = 33152; | |||||||||||||||||||||||||||||||
| 100 | 15 | return $Packet; | |||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | 3 | 1; | |||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | __END__ | ||||||||||||||||||||||||||||||||