"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "t/71-TSIG-create.t" between
Net-DNS-1.23.tar.gz and Net-DNS-1.23_01.tar.gz

About: Net::DNS is a DNS resolver implemented in Perl. Development version.

71-TSIG-create.t  (Net-DNS-1.23):71-TSIG-create.t  (Net-DNS-1.23_01)
# $Id: 71-TSIG-create.t 1774 2020-03-18 07:49:22Z willem $ -*-perl-*- # $Id: 71-TSIG-create.t 1779 2020-05-11 09:11:17Z willem $ -*-perl-*-
use strict; use strict;
use Test::More; use Test::More;
use Net::DNS; use Net::DNS;
my %prerequisite = ( my %prerequisite = (
'Digest::HMAC' => 1.03, 'Digest::HMAC' => 1.03,
'Digest::MD5' => 2.13, 'Digest::MD5' => 2.13,
'Digest::SHA' => 5.23, 'Digest::SHA' => 5.23,
'MIME::Base64' => 2.13, 'MIME::Base64' => 2.13,
); );
foreach my $package ( sort keys %prerequisite ) { foreach my $package ( sort keys %prerequisite ) {
my @revision = grep $_, $prerequisite{$package}; my @revision = grep $_, $prerequisite{$package};
next if eval "use $package @revision; 1;"; next if eval "use $package @revision; 1;";
plan skip_all => "missing prerequisite $package @revision"; plan skip_all => "missing prerequisite $package @revision";
exit; exit;
} }
plan tests => 12; plan tests => 20;
my $tsig = new Net::DNS::RR( type => 'TSIG' ); my $tsig = new Net::DNS::RR( type => 'TSIG' );
my $class = ref($tsig); my $class = ref($tsig);
my $keyrr = new Net::DNS::RR <<'END'; my $tsigkey = 'HMAC-SHA256.key';
hmac-md5.example. IN KEY 512 3 157 ARDJZgtuTDzAWeSGYPAu9uJUkX0= END { unlink($tsigkey) if defined $tsigkey; }
open( KEY, '>', $tsigkey ) or die "$tsigkey $!";
print KEY <<'END';
key "HMAC-SHA256.example." {
algorithm hmac-sha256;
secret "f+JImRXRzLpKseG+bP+W9Vwb2QAgtFuIlRU80OA3NU8=";
};
END
close KEY;
my $keyrr = new Net::DNS::RR <<'END'; # dnssec-keygen k
ey pair
HMAC-SHA256.example. IN KEY 512 3 163 f+JImRXRzLpKseG+bP+W9Vwb2QAgtFuIlRU80OA3NU
8=
END END
my $publickey = 'Khmac-sha256.example.+163+52011.key';
END { unlink($publickey) if defined $publickey; }
open( KEY, ">", $publickey ) or die "$publickey $!";
print KEY $keyrr->string;
close KEY;
my $privatekey = $keyrr->privatekeyname; my $privatekey = $keyrr->privatekeyname;
END { unlink($privatekey) if defined $privatekey; } END { unlink($privatekey) if defined $privatekey; }
open( KEY, ">$privatekey" ) or die "$privatekey $!"; open( KEY, ">", $privatekey ) or die "$privatekey $!";
print KEY <<'END'; print KEY <<'END';
Private-key-format: v1.2 Private-key-format: v1.2
Algorithm: 157 (HMAC_MD5) Algorithm: 163 (HMAC_SHA256)
Key: ARDJZgtuTDzAWeSGYPAu9uJUkX0= Key: f+JImRXRzLpKseG+bP+W9Vwb2QAgtFuIlRU80OA3NU8=
END END
close KEY; close KEY;
{ SKIP: {
my $tsig = create $class($privatekey); my $tsig = create $class($tsigkey);
is( ref($tsig), $class, 'create TSIG from private key' ); skip( 'TSIG attribute test', 2 )
unless is( ref($tsig), $class, 'create TSIG from BIND tsi
g key' );
is( $tsig->name, $keyrr->name, 'TSIG key name' );
my $algorithm = $tsig->algorithm;
is( $algorithm, $tsig->algorithm( $keyrr->algorithm ), 'TSIG algorithm' )
;
} }
{ SKIP: {
my $tsig = create $class($keyrr); my $tsig = create $class($privatekey);
is( ref($tsig), $class, 'create TSIG from KEY RR' ); skip( 'TSIG attribute test', 2 )
unless is( ref($tsig), $class, 'create TSIG from BIND dns
sec private key' );
is( $tsig->name, lc( $keyrr->name ), 'TSIG key name' );
my $algorithm = $tsig->algorithm;
is( $algorithm, $tsig->algorithm( $keyrr->algorithm ), 'TSIG algorithm' )
;
} }
my $publickey = 'Khmac-sha1.example.+161+39562.key'; SKIP: {
END { unlink($publickey) if defined $publickey; }
open( KEY, ">$publickey" ) or die "$publickey $!";
print KEY <<'END';
HMAC-SHA1.example. IN KEY 512 3 161 xdX9m8UtQNbJUzUgQ4xDtUNZAmU=
END
close KEY;
{
my $tsig = create $class($publickey); my $tsig = create $class($publickey);
is( ref($tsig), $class, 'create TSIG from public key' ); skip( 'TSIG attribute test', 2 )
unless is( ref($tsig), $class, 'create TSIG from BIND dns
sec public key' );
is( $tsig->name, $keyrr->name, 'TSIG key name' );
my $algorithm = $tsig->algorithm;
is( $algorithm, $tsig->algorithm( $keyrr->algorithm ), 'TSIG algorithm' )
;
}
SKIP: {
my $tsig = create $class($keyrr);
skip( 'TSIG attribute test', 2 )
unless is( ref($tsig), $class, 'create TSIG from KEY RR'
);
is( $tsig->name, $keyrr->name, 'TSIG key name' );
my $algorithm = $tsig->algorithm;
is( $algorithm, $tsig->algorithm( $keyrr->algorithm ), 'TSIG algorithm' )
;
} }
{ {
my $packet = new Net::DNS::Packet('query.example'); my $packet = new Net::DNS::Packet('query.example');
$packet->sign_tsig($privatekey); $packet->sign_tsig($privatekey);
my $tsig = create $class($packet); my $tsig = create $class($packet);
is( ref($tsig), $class, 'create TSIG from signed packet' ); is( ref($tsig), $class, 'create TSIG from signed packet' );
} }
{ {
skipping to change at line 103 skipping to change at line 134
ok( $exception, "unexpected argument\t[$exception]" ); ok( $exception, "unexpected argument\t[$exception]" );
} }
{ {
my $packet = new Net::DNS::Packet('query.example'); my $packet = new Net::DNS::Packet('query.example');
eval { create $class($packet); }; eval { create $class($packet); };
my ($exception) = split /\n/, "$@\n"; my ($exception) = split /\n/, "$@\n";
ok( $exception, "no TSIG in packet\t[$exception]" ); ok( $exception, "no TSIG in packet\t[$exception]" );
} }
my $badprivatekey = 'K+161+39562.private';
END { unlink($badprivatekey) if defined $badprivatekey; }
open( KEY, ">$badprivatekey" ) or die "$badprivatekey $!";
print KEY <<'END';
Private-key-format: v1.2
Algorithm: 161 (HMAC_SHA1)
Key: xdX9m8UtQNbJUzUgQ4xDtUNZAmU=
END
close KEY;
{
eval { create $class($badprivatekey); };
my ($exception) = split /\n/, "$@\n";
ok( $exception, "misnamed private key\t[$exception]" );
}
my $dnskey = 'Kbad.example.+161+39562.key'; my $dnskey = 'Kbad.example.+161+39562.key';
END { unlink($dnskey) if defined $dnskey; } END { unlink($dnskey) if defined $dnskey; }
open( KEY, ">$dnskey" ) or die "$dnskey $!"; open( KEY, ">$dnskey" ) or die "$dnskey $!";
print KEY <<'END'; print KEY <<'END';
HMAC-SHA1.example. IN DNSKEY 512 3 161 xdX9m8UtQNbJUzUgQ4xDtUNZAmU= HMAC-SHA1.example. IN DNSKEY 512 3 161 xdX9m8UtQNbJUzUgQ4xDtUNZAmU=
END END
close KEY; close KEY;
{ {
 End of changes. 12 change blocks. 
42 lines changed or deleted 66 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)