lib/XML/Compile/SOAP/WSS.pm

filter: Statementstmt 90.4% 95 / 105 Branchbran 50.0% 16 / 32 Conditioncond 31.8% 7 / 22 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 91.3% 21 / 23 Podpod 75.0% 9 / 12 totaltotal 71.5% 148 / 207 CC 28 SCAR 24.9
CC
28
Cov
74%
signature
56.0
__ANON__
13.1
_start
4.2
CRAP 12.0
↑ Summary lib/XML/Compile/WSS/BasicAuth.pm »
1 # Copyrights 2011-2017 by [Mark Overmeer].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.02.
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 package XML::Compile::SOAP::WSS;
9 5 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 $VERSION = '1.14';
11  
12 5 ▶use base 'XML::Compile::SOAP::Extension';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 5 ▶use Log::Report 'xml-compile-wss';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 5 ▶use XML::Compile::WSS::Util qw/:wss11 :utp11/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use XML::Compile::WSS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use XML::Compile::SOAP::Util qw/SOAP11ENV/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 5 ▶use Scalar::Util qw/weaken/;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 sub init($)
24 4 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=2 SCAR=6.9
Pod undocumented
25 4 $self->SUPER::init($args);
26 4 $self->{XCSW_wss} = [];
27  
28 4 my $schema = $self->{XCSW_schema} = $args->{schema};
29 4 weaken $self->{XCSW_schema};
30  
31 # [1.0] to support backwards compat
32 4 ▶ XML::Compile::WSS->loadSchemas($schema, '1.1') if $schema;
Branch: 1 branch
BranchTrueFalseTotal
if $schema 3 1 4
33 4 $self;
34 }
35  
36 sub wsdl11Init($$)
37 1 ▶{ my ($self, $wsdl, $args) = @_;
Subroutine wsdl11Init: called CC=1 SCAR=0.0
Pod documented
38 1 $self->SUPER::wsdl11Init($wsdl, $args);
39  
40 1 $self->{XCSW_schema} = $wsdl;
41 1 weaken $self->{XCSW_schema};
42  
43 1 XML::Compile::WSS->loadSchemas($wsdl, '1.1');
44 1 $wsdl->addPrefixes('SOAP-ENV' => SOAP11ENV);
45  
46 1 $self;
47 }
48  
49 sub soap11OperationInit($$)
50 2 ▶{ my ($self, $op, $args) = @_;
Subroutine soap11OperationInit: called CC=3 SCAR=11.2
Pod documented
51  
52 2 ▶ my $schema = $self->schema
Branch: 1 branch
BranchTrueFalseTotal
my $schema = $self->schema or &error(&__x("WSS not connected to the WSDL: WSS needs to be instantiated\nbefore the WSDL because it influences its interpretation")) 2 0 2
53 or error __x"WSS not connected to the WSDL: WSS needs to be instantiated
54 before the WSDL because it influences its interpretation";
55  
56 # this is not a nice hack for apps where multiple ::WSDL or ::Schema
57 # objects are active https://rt.cpan.org/Ticket/Display.html?id=99735
58 2 ▶ $schema eq $op->schemas or return;
Branch: 1 branch
BranchTrueFalseTotal
$schema eq $op->schemas or return 2 0 2
59  
60 2 trace "adding wss header logic"; # get full type from any schema
61 2 my $sec = $schema->findName('wsse:Security');
62 2 $op->addHeader(INPUT => "wsse_Security" => $sec, mustUnderstand => 1);
63 2 $op->addHeader(OUTPUT => "wsse_Security" => $sec, mustUnderstand => 1);
64 }
65 5 *soap12OperationInit = \&soap11OperationInit;
66  
67 sub soap11ClientWrapper($$$)
68 2 ▶{ my ($self, $op, $call, $args) = @_;
Subroutine soap11ClientWrapper: called CC=2 SCAR=7.2
Pod documented
69  
70 2 ▶ $self->schema eq $op->schemas or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->schema eq $op->schemas or return 2 0 2
71  
72 4 ▶ sub {
Subroutine __ANON__: called CC=11 SCAR=25.7
73 4 ▶ my $data = @_==1 ? shift : {@_};
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 4 4
74 4 my $sec = $data->{wsse_Security};
75  
76 # Support pre-1.0 interface
77 4 ▶ return $call->($data)
Branch: 1 branch
BranchTrueFalseTotal
if ref $sec eq "HASH" 2 2 4
78 if ref $sec eq 'HASH';
79  
80 # select plugins
81 2 ▶ my $wss = $sec || $self->{XCSW_wss};
Condition66%2/3
$sec || $self->{'XCSW_wss'}
l!l&&r!l&&!r
110
MC/DC0%0/2
$sec || $self->{'XCSW_wss'}
$sec $self->{'XCSW_wss'}
Truth table66%2/3
A || B
A= $secB= $self->{'XCSW_wss'}
ABresult
1X1
011
000
82 2 ▶ my @wss = ref $wss eq 'ARRAY' ? @$wss : $wss;
Branch: 1 branch
BranchTrueFalseTotal
ref $wss eq 'ARRAY' ? : 2 0 2
83  
84 # Adding WSS headers to $secw
85 2 my $secw = $data->{wsse_Security} = {};
86 2 ▶ my $doc = $data->{_doc} ||= XML::LibXML::Document->new('1.0','UTF-8');
Condition33%1/3
$data->{"_doc"} ||= "XML::LibXML::Document"->new("1.0", "UTF-8")
l!l&&r!l&&!r
020
MC/DC0%0/2
$data->{"_doc"} ||= "XML::LibXML::Document"->new("1.0", "UTF-8")
$data->{"_doc"} "XML::LibXML::Document"->new("1.0", "UTF-8")
Truth table33%1/3
A ||= B
A= $data->{"_doc"}B= "XML::LibXML::Document"->new("1.0", "UTF-8")
ABresult
1X1
011
000
87 2 $_->create($doc, $secw) for @wss;
88
89 # The real work: SOAP message formatting and exchange
90 2 my ($answer, $trace) = $call->($data);
91  
92 2 ▶ if(defined $answer)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $answer) 2 0 2
93 2 ▶ { my $secr = $answer->{wsse_Security} ||= {};
Condition50%1/2
$answer->{"wsse_Security"} ||= {}
l!l
02
MC/DC0%0/1
$answer->{"wsse_Security"} ||= {}
$answer->{"wsse_Security"}
Truth table50%1/2
A
A= $answer->{"wsse_Security"}
Aresult
11
00
94 2 $_->check($secr) for @wss;
95 }
96
97 2 ▶ wantarray ? ($answer, $trace) : $answer;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 0 2
98 2 };
99 }
100 5 *soap12ClientWrapper = \&soap11ClientWrapper;
101  
102 #---------------------------
103  
104 16 ▶sub schema() { shift->{XCSW_schema} }
Subroutine schema: called CC=1 SCAR=0.0
Pod documented
105 0 ▶sub features() { @{shift->{XCSW_wss}} }
Subroutine features: not called CC=1 SCAR=6.9
Pod documented
106  
107 sub addFeature($)
108 3 ▶{ my ($self, $n) = @_;
Subroutine addFeature: called CC=2 SCAR=7.0
Pod documented
109 3 ▶ my $schema = $n->schema
Branch: 1 branch
BranchTrueFalseTotal
my $schema = $n->schema or &error(&__x("no schema yet. Instantiate ::WSS before ::WSDL")) 3 0 3
110 or error __x"no schema yet. Instantiate ::WSS before ::WSDL";
111  
112 3 push @{$self->{XCSW_wss}}, $n;
113 3 $n;
114 }
115  
116 #---------------------------
117  
118 sub _start($$)
119 3 ▶{ my ($self, $plugin, $args) = @_;
Subroutine _start: called CC=4 SCAR=14.5
120  
121 3 eval "require $plugin";
122 3 ▶ panic $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
123  
124 3 ▶ my $schema = $args->{schema} ||= $self->schema
Branch: 1 branch
BranchTrueFalseTotal
my $schema = ($args->{"schema"} ||= $self->schema) or &error(&__x("instantiate {pkg} before the wsdl, plugins after", "pkg", __PACKAGE__)) 3 0 3
Condition66%2/3
$args->{"schema"} ||= $self->schema
l!l&&r!l&&!r
120
MC/DC0%0/2
$args->{"schema"} ||= $self->schema
$args->{"schema"} $self->schema
Truth table66%2/3
A ||= B
A= $args->{"schema"}B= $self->schema
ABresult
1X1
011
000
125 or error __x"instantiate {pkg} before the wsdl, plugins after"
126 , pkg => __PACKAGE__;
127  
128 3 $self->addFeature($plugin->new($args));
129 }
130  
131  
132 sub basicAuth(%)
133 2 ▶{ my ($self, %args) = @_;
Subroutine basicAuth: called CC=1 SCAR=0.0
Pod documented
134 2 $self->_start('XML::Compile::WSS::BasicAuth', \%args);
135 }
136  
137  
138 sub timestamp(%)
139 1 ▶{ my ($self, %args) = @_;
Subroutine timestamp: called CC=1 SCAR=0.0
Pod documented
140 1 $self->_start('XML::Compile::WSS::Timestamp', \%args);
141 }
142  
143  
144 sub signature(%)
145 0 ▶{ my ($self, %args) = @_;
Subroutine signature: not called CC=7 SCAR=40.3
Pod documented
146 0 ▶ my $schema = $args{schema} || $self->schema;
Condition0%0/3
$args{'schema'} || $self->schema
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'schema'} || $self->schema
$args{'schema'} $self->schema
Truth table0%0/3
A || B
A= $args{'schema'}B= $self->schema
ABresult
1X1
011
000
147  
148 0 my $has12 = defined $schema->prefix('env12');
149 0 ▶ $args{sign_types} ||= ['SOAP-ENV:Body', ($has12 ? 'env12:Body' : ())];
Branch: 1 branch
BranchTrueFalseTotal
$has12 ? : 0 0 0
Condition0%0/2
$args{"sign_types"} ||= ["SOAP-ENV:Body", $has12 ? "env12:Body" : ()]
l!l
00
MC/DC0%0/1
$args{"sign_types"} ||= ["SOAP-ENV:Body", $has12 ? "env12:Body" : ()]
$args{"sign_types"}
Truth table0%0/2
A
A= $args{"sign_types"}
Aresult
11
00
150 0 ▶ $args{sign_put} ||= 'wsse:SecurityHeaderType';
Condition0%0/2
$args{"sign_put"} ||= "wsse:SecurityHeaderType"
l!l
00
MC/DC0%0/1
$args{"sign_put"} ||= "wsse:SecurityHeaderType"
$args{"sign_put"}
Truth table0%0/2
A
A= $args{"sign_put"}
Aresult
11
00
151 0 ▶ $args{sign_when} ||= ['SOAP-ENV:Envelope', ($has12 ? 'env12:Envelope':())];
Branch: 1 branch
BranchTrueFalseTotal
$has12 ? : 0 0 0
Condition0%0/2
$args{"sign_when"} ||= ["SOAP-ENV:Envelope", $has12 ? "env12:Envelope" : ()]
l!l
00
MC/DC0%0/1
$args{"sign_when"} ||= ["SOAP-ENV:Envelope", $has12 ? "env12:Envelope" : ()]
$args{"sign_when"}
Truth table0%0/2
A
A= $args{"sign_when"}
Aresult
11
00
152  
153 0 my $sig = $self->_start('XML::Compile::WSS::Signature', \%args);
154 0 $sig;
155 }
156  
157 #--------------------------------------
158 # [1.0] Expired interface
159 sub wsseBasicAuth($$$@)
160 7 ▶{ my ($self, $username, $password, $pwtype, %args) = @_;
Subroutine wsseBasicAuth: called CC=3 SCAR=11.2
Pod undocumented
161 # use XML::Compile::WSS::BasicAuth!!! This method will be removed!
162  
163 7 eval "require XML::Compile::WSS::BasicAuth";
164 7 ▶ panic $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 7 7
165  
166 7 ▶ my $auth = XML::Compile::WSS::BasicAuth->new
Condition50%1/2
$pwtype || 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'
l!l
70
MC/DC0%0/1
$pwtype || 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'
$pwtype
Truth table50%1/2
A
A= $pwtype
Aresult
11
00
167 ( username => $username
168 , password => $password
169 , pwformat => $pwtype || UTP11_PTEXT
170 , %args
171 , schema => $self->schema
172 );
173  
174 7 my $doc = XML::LibXML::Document->new('1.0', 'UTF-8');
175 7 $auth->create($doc, {});
176 }
177  
178 # [1.0] Expired interface
179 sub wsseTimestamp($$$@)
180 1 ▶{ my ($self, $created, $expires, %args) = @_;
Subroutine wsseTimestamp: called CC=2 SCAR=7.0
Pod undocumented
181 # use XML::Compile::WSS::Timestamp!!! This method will be removed!
182  
183 1 eval "require XML::Compile::WSS::Timestamp";
184 1 ▶ panic $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
185  
186 1 my $ts = XML::Compile::WSS::Timestamp->new
187 ( created => $created
188 , expires => $expires
189 , %args
190 , schema => $self->schema
191 );
192  
193 1 my $doc = XML::LibXML::Document->new('1.0', 'UTF-8');
194 1 $ts->create($doc, {});
195 }
196  
197 5 1;
↑ Summary lib/XML/Compile/WSS/BasicAuth.pm »