XML-Compile-WSS-Signature
view release on metacpan or search on metacpan
t/31keyinfo.t view on Meta::CPAN
#!/usr/bin/env perl
# This code is part of distribution XML-Compile-WSS-Signature.
# Meta-POD processed with OODoc into POD and HTML manual-pages. See README.md
# Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
# Check processing of KeyInfo structures.
use warnings;
use strict;
use lib '../XML-Compile-WSS/lib', 'lib';
use Log::Report mode => 2;
use Test::More tests => 45;
use Data::Dumper;
$Data::Dumper::Indent = 1;
$Data::Dumper::Quotekeys = 0;
$Data::Dumper::Sortkeys = 1;
use XML::LibXML ();
use XML::Compile::WSS::Util qw/:xtp10 :wsm10/;
use XML::Compile::Tester qw/compare_xml/;
use MIME::Base64 qw/encode_base64/;
my $certfn = 't/20cert.pem';
my $privkey_fn = 't/20privkey.pem';
sub newdoc() { XML::LibXML::Document->new('1.0', 'UTF8') }
use_ok('XML::Compile::Cache');
use_ok('XML::Compile::WSS::KeyInfo');
use_ok('XML::Compile::WSS::Signature');
my $schema = XML::Compile::Cache->new;
ok(defined $schema);
my $wss = XML::Compile::WSS::Signature->new
( version => '1.1'
, schema => $schema
, token => 'dummy'
, sign_types => []
, sign_put => []
, private_key => $privkey_fn
);
isa_ok($wss, 'XML::Compile::WSS');
isa_ok($wss, 'XML::Compile::WSS::Signature');
### top-level KeyInfo readers and writers
use_ok('XML::Compile::WSS::KeyInfo');
my $ki = XML::Compile::WSS::KeyInfo->new;
isa_ok($ki, 'XML::Compile::WSS::KeyInfo');
my $ki_reader = $schema->reader('ds:KeyInfo');
isa_ok($ki_reader, 'CODE', 'ki_reader');
my $ki_tokens = $ki->getTokens($wss);
isa_ok($ki_tokens, 'CODE', 'ki_tokens');
my $ki_writer = $schema->writer('ds:KeyInfo');
isa_ok($ki_writer, 'CODE', 'ki_writer');
my $sec_reader = $schema->reader('wsse:Security');
isa_ok($sec_reader, 'CODE', 'sec_reader');
### learn some tokens
use_ok('XML::Compile::WSS::SecToken::X509v3');
my $x509 = XML::Compile::WSS::SecToken::X509v3->fromFile($certfn);
ok(defined $x509, 'created x509v3 token');
my @t = $ki->tokens;
cmp_ok(scalar @t, '==', 0);
$ki->addToken($x509);
@t = $ki->tokens;
cmp_ok(scalar @t, '==', 1);
is($t[0], $x509);
my $x509fp = $x509->fingerprint;
ok(defined $x509fp, 'got fingerprint');
my $x509fp64 = encode_base64 $x509fp;
### SECTOKREF_KEYID
ok(1, 'testing SECTOKREF_KEYID');
my $keyinfo1 = <<__KEYINFO__;
<?xml version="1.0"?>
<ds:KeyInfo
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
>
<wsse:SecurityTokenReference>
<wsse:KeyIdentifier
EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
ValueType="http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#ThumbprintSHA1">$x509fp64</wsse:KeyIdentifier>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
__KEYINFO__
my $keyhash1 = $ki_reader->($keyinfo1);
#warn Dumper $keyhash1;
( run in 1.851 second using v1.01-cache-2.11-cpan-0d23b851a93 )