Blame t/05-SMIMEA.t

Packit Service f6e53a
# $Id: 05-SMIMEA.t 1449 2016-02-01 12:27:12Z willem $	-*-perl-*-
Packit Service f6e53a
Packit Service f6e53a
use strict;
Packit Service f6e53a
use Test::More tests => 19;
Packit Service f6e53a
Packit Service f6e53a
Packit Service f6e53a
use Net::DNS;
Packit Service f6e53a
Packit Service f6e53a
Packit Service f6e53a
my $name = 'c93f1e400f26708f98cb19d936620da35eec8f72e57f9eec01c1afd6._smimecert.example.com';
Packit Service f6e53a
my $type = 'SMIMEA';
Packit Service f6e53a
my $code = 53;
Packit Service f6e53a
my @attr = qw( usage selector matchingtype certificate );
Packit Service f6e53a
my @data = qw( 1 1 1 d2abde240d7cd3ee6b4b28c54df034b97983a1d16e8a410e4561cb106618e971 );
Packit Service f6e53a
my @also = qw( certbin babble );
Packit Service f6e53a
Packit Service f6e53a
my $wire = qw( 010101d2abde240d7cd3ee6b4b28c54df034b97983a1d16e8a410e4561cb106618e971 );
Packit Service f6e53a
Packit Service f6e53a
Packit Service f6e53a
{
Packit Service f6e53a
	my $typecode = unpack 'xn', new Net::DNS::RR(". $type")->encode;
Packit Service f6e53a
	is( $typecode, $code, "$type RR type code = $code" );
Packit Service f6e53a
Packit Service f6e53a
	my $hash = {};
Packit Service f6e53a
	@{$hash}{@attr} = @data;
Packit Service f6e53a
Packit Service f6e53a
	my $rr = new Net::DNS::RR(
Packit Service f6e53a
		name => $name,
Packit Service f6e53a
		type => $type,
Packit Service f6e53a
		%$hash
Packit Service f6e53a
		);
Packit Service f6e53a
Packit Service f6e53a
	my $string = $rr->string;
Packit Service f6e53a
	my $rr2	   = new Net::DNS::RR($string);
Packit Service f6e53a
	is( $rr2->string, $string, 'new/string transparent' );
Packit Service f6e53a
Packit Service f6e53a
	is( $rr2->encode, $rr->encode, 'new($string) and new(%hash) equivalent' );
Packit Service f6e53a
Packit Service f6e53a
	foreach (@attr) {
Packit Service f6e53a
		is( $rr->$_, $hash->{$_}, "expected result from rr->$_()" );
Packit Service f6e53a
	}
Packit Service f6e53a
Packit Service f6e53a
	foreach (@also) {
Packit Service f6e53a
		is( $rr2->$_, $rr->$_, "additional attribute rr->$_()" );
Packit Service f6e53a
	}
Packit Service f6e53a
Packit Service f6e53a
Packit Service f6e53a
	my $null    = new Net::DNS::RR("$name NULL")->encode;
Packit Service f6e53a
	my $empty   = new Net::DNS::RR("$name $type")->encode;
Packit Service f6e53a
	my $rxbin   = decode Net::DNS::RR( \$empty )->encode;
Packit Service f6e53a
	my $txtext  = new Net::DNS::RR("$name $type")->string;
Packit Service f6e53a
	my $rxtext  = new Net::DNS::RR($txtext)->encode;
Packit Service f6e53a
	my $encoded = $rr->encode;
Packit Service f6e53a
	my $decoded = decode Net::DNS::RR( \$encoded );
Packit Service f6e53a
	my $hex1    = unpack 'H*', $encoded;
Packit Service f6e53a
	my $hex2    = unpack 'H*', $decoded->encode;
Packit Service f6e53a
	my $hex3    = unpack 'H*', substr( $encoded, length $null );
Packit Service f6e53a
	is( $hex2,	     $hex1,	    'encode/decode transparent' );
Packit Service f6e53a
	is( $hex3,	     $wire,	    'encoded RDATA matches example' );
Packit Service f6e53a
	is( length($empty),  length($null), 'encoded RDATA can be empty' );
Packit Service f6e53a
	is( length($rxbin),  length($null), 'decoded RDATA can be empty' );
Packit Service f6e53a
	is( length($rxtext), length($null), 'string RDATA can be empty' )
Packit Service f6e53a
}
Packit Service f6e53a
Packit Service f6e53a
Packit Service f6e53a
{
Packit Service f6e53a
	my $rr = new Net::DNS::RR(". $type @data");
Packit Service f6e53a
	eval { $rr->certificate('123456789XBCDEF'); };
Packit Service f6e53a
	my $exception = $1 if $@ =~ /^(.+)\n/;
Packit Service f6e53a
	ok( $exception ||= '', "corrupt hexadecimal\t[$exception]" );
Packit Service f6e53a
}
Packit Service f6e53a
Packit Service f6e53a
Packit Service f6e53a
{
Packit Service f6e53a
	my $rr = new Net::DNS::RR(". $type");
Packit Service f6e53a
	foreach (@attr) {
Packit Service f6e53a
		ok( !$rr->$_(), "'$_' attribute of empty RR undefined" );
Packit Service f6e53a
	}
Packit Service f6e53a
}
Packit Service f6e53a
Packit Service f6e53a
Packit Service f6e53a
{
Packit Service f6e53a
	my $rr = new Net::DNS::RR("$name $type @data");
Packit Service f6e53a
	$rr->print;
Packit Service f6e53a
}
Packit Service f6e53a
Packit Service f6e53a
Packit Service f6e53a
exit;
Packit Service f6e53a