Subject: | Calling wsseBasicAuth produces something illegible |
While looking at something else, it seemed that when I called
wsseBasicAuth twice in a row with a "created" element, the second
UsernameToken lacks xmlns:wsu=..., so the Created element can't be
understood.
I tried to reproduce the problem using just XML::Compile::Cache
(thinking it was the writer causing the problems) but couldn't test to fail.
But the attached script gives the following output, where it's "clear"
that the second instance just uses "wsu:Created" without declaring that
namespace.
--
ok 1 - First basic auth returns something sensible
ok 2 - First basic auth is legible
# Good string: <wsse:UsernameToken
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsse:Username>username</wsse:Username><wsu:Created>2012-08-31T05:21:44Z</wsu:Created><wsse:Password
Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">rf/31fRgiHE6rAYMpqoxswL6bAo=</wsse:Password></wsse:UsernameToken>
ok 3 - Second basic auth returns something sensible
not ok 4 - Second basic auth is legible
# Failed test 'Second basic auth is legible'
# at t/05double_basic_auth.t line 49.
# :1: namespace error : Namespace prefix wsu on Created is not defined
#
s-wssecurity-secext-1.0.xsd"><wsse:Username>username</wsse:Username><wsu:Created
#
^
# Bad string: <wsse:UsernameToken
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsse:Username>username</wsse:Username><wsu:Created>2012-08-31T05:21:44Z</wsu:Created><wsse:Password
Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">rf/31fRgiHE6rAYMpqoxswL6bAo=</wsse:Password></wsse:UsernameToken>
# Looks like you failed 1 test of 4.
--
My versions of the packages that show up in the script are
Test::More version 0.98
XML::Compile version 1.27
XML::Compile::Cache version 0.991
XML::Compile::SOAP version 2.29
XML::Compile::C14N version 0.10
XML::Compile::WSDL11 version 2.29
XML::Compile::SOAP11 version 2.29
XML::Compile::Transport::SOAPHTTP version 2.29
XML::Compile::SOAP::WSS version 0.90
XML::Compile::WSS::Util version 0.90
Subject: | 05double_basic_auth.t |
#!/usr/bin/env perl
#
# Is it true that calling wsseBasicAuth twice causes an error?
#
use strict ;
use warnings ;
use Carp qw/cluck/ ;
use Data::Dumper ;
# use Log::Report mode => 3;
# use Digest::SHA1 qw/sha1_base64/;
# use Encode qw/encode/;
# use MIME::Base64 qw/encode_base64 decode_base64/ ;
use Test::More tests => 4 ;
use XML::Compile::WSDL11;
use XML::Compile::SOAP11;
use XML::Compile::Transport::SOAPHTTP;
use XML::Compile::SOAP::WSS;
use XML::Compile::WSS::Util qw/:wss11 :utp11/;
my ($username, $password) = qw/username password/;
my $wsdl = XML::Compile::WSDL11->new( 'examples/wsse/example.wsdl');
my $wss = XML::Compile::SOAP::WSS->new( version => 1.1, schema => $wsdl);
my $untype = $wss->schema->findName('wsse:UsernameToken');
my $unreader = $wss->schema->reader($untype) ;
my $now = time() ;
my $ut1 = $wss->wsseBasicAuth($username, $password, UTP11_PDIGEST
, created => $now
);
ok( $ut1, 'First basic auth returns something sensible' ) ;
my $ut1String = $ut1->{$untype}->toString() ;
ok( $unreader->( $ut1String ), 'First basic auth is legible' )
and diag( "Good string: $ut1String" ) ;
my $ut2 = $wss->wsseBasicAuth($username, $password, UTP11_PDIGEST
, created => $now
);
ok( $ut2, 'Second basic auth returns something sensible' ) ;
my $ut2String = $ut2->{$untype}->toString() ;
ok( eval { $unreader->( $ut2String ) }, 'Second basic auth is legible' )
or do { diag( $@ ) ;diag( "Bad string: $ut2String" ) ; }