lib/XML/Compile/WSS.pm

filter: Statementstmt 94.5% 103 / 109 Branchbran 54.7% 23 / 42 Conditioncond 45.4% 5 / 11 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 92.0% 23 / 25 Podpod 76.9% 10 / 13 totaltotal 79.7% 165 / 207 CC 26 SCAR 15.5
CC
26
Cov
81%
prepare
13.1
init
6.8
__ANON__
6.5
CRAP 4.7
« lib/XML/Compile/WSS/BasicAuth.pm ↑ Summary blib/lib/XML/Compile/WSS/Timestamp.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 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 package XML::Compile::WSS;
9 7 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 $VERSION = '1.14';
11  
12  
13 7 ▶use Log::Report 'xml-compile-wss';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 7 ▶use XML::Compile::WSS::Util qw/:wss11/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 7 ▶use XML::Compile::Util qw/SCHEMA2001/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 7 ▶use XML::Compile::Schema::BuiltInTypes qw/builtin_type_info/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 7 ▶use File::Basename qw/dirname/;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 7 ▶use POSIX qw/strftime/;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 7 ▶use Scalar::Util qw/weaken/;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 7 my %prefixes10 =
24 ( ds => DSIG_NS, wsse => WSSE_10, wsu => WSU_10
25 );
26  
27 7 my %prefixes11 =
28 ( ds => DSIG_NS, wsse => WSSE_10, wsu => WSU_10
29 , wss => WSS_11, xenc => XENC_NS
30 );
31  
32 7 my %versions =
33 ( '1.0' => { xsddir => 'wss10', prefixes => \%prefixes10 }
34 , '1.1' => { xsddir => 'wss11', prefixes => \%prefixes11 }
35 );
36  
37  
38 sub new(@)
39 17 ▶{ my $class = shift;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
40 17 ▶ my $args = @_==1 ? shift : {@_};
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 3 14 17
41 17 my $self = (bless {}, $class)->init($args);
42 17 ▶ $self->prepare($args->{prepare} || 'ALL');
Condition50%1/2
$args->{'prepare'} || 'ALL'
l!l
017
MC/DC0%0/1
$args->{'prepare'} || 'ALL'
$args->{'prepare'}
Truth table50%1/2
A
A= $args->{'prepare'}
Aresult
11
00
43 17 $self;
44 }
45  
46 sub init($)
47 17 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=6 SCAR=19.2
Pod undocumented
48 my $version = $args->{wss_version} || $args->{version}
49 17 ▶ or error __x"explicit wss_version required";
Branch: 1 branch
BranchTrueFalseTotal
my $version = $args->{"wss_version"} || $args->{"version"} or &error(&__x("explicit wss_version required")) 17 0 17
Condition33%1/3
$args->{'wss_version'} || $args->{'version'}
l!l&&r!l&&!r
1700
MC/DC0%0/2
$args->{'wss_version'} || $args->{'version'}
$args->{'wss_version'} $args->{'version'}
Truth table33%1/3
A || B
A= $args->{'wss_version'}B= $args->{'version'}
ABresult
1X1
011
000
50 17 trace "initializing wss $version";
51  
52 17 ▶ $version = '1.1'
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd" 0 17 17
53 if $version eq WSS11MODULE;
54  
55 17 ▶ $versions{$version}
Branch: 1 branch
BranchTrueFalseTotal
$versions{$version} or &error(&__x("unknown wss version {v}, pick from {vs}", "v", $version, "vs", [keys %versions])) 17 0 17
56 or error __x"unknown wss version {v}, pick from {vs}"
57 , v => $version, vs => [keys %versions];
58 17 $self->{XCW_version} = $version;
59  
60 17 ▶ if(my $schema = $self->{XCW_schema} = $args->{schema})
Branch: 1 branch
BranchTrueFalseTotal
if (my $schema = $self->{"XCW_schema"} = $args->{"schema"}) 17 0 17
61 17 { weaken $self->{XCW_schema};
62 17 $self->loadSchemas($schema, $version);
63 }
64  
65 17 $self;
66 }
67  
68 sub prepare($)
69 17 ▶{ my ($self, $how) = @_;
Subroutine prepare: called CC=7 SCAR=25.7
Pod documented
70 17 my $schema = $self->schema;
71  
72 17 ▶ my ($r, $w)
Branch: 4 branches
BranchTrueFalseTotal
$how eq 'ALL' ? : 17 0 17
$how eq 'READER' ? : 0 0 0
$how eq 'WRITER' ? : 0 0 0
$how eq 'NONE' ? : 0 0 0
73 = $how eq 'ALL' ? (1, 1)
74 : $how eq 'READER' ? (1, 0)
75 : $how eq 'WRITER' ? (0, 1)
76 : $how eq 'NONE' ? (0, 0)
77 : panic $how;
78  
79 17 ▶ $self->prepareWriting($schema) if $w;
Branch: 1 branch
BranchTrueFalseTotal
if $w 17 0 17
80 17 ▶ $self->prepareReading($schema) if $r;
Branch: 1 branch
BranchTrueFalseTotal
if $r 17 0 17
81 17 $self;
82 }
83 17 ▶sub prepareWriting($) { $_[0]->{XCW_prepare_w}++; $_[0] }
Subroutine prepareWriting: called CC=1 SCAR=0.0
Pod undocumented
84 17 ▶sub prepareReading($) { $_[0]->{XCW_prepare_r}++; $_[0] }
Subroutine prepareReading: called CC=1 SCAR=0.0
Pod undocumented
85  
86 #-----------
87  
88 0 ▶sub version() {shift->{XCW_version}} # deprecated
Subroutine version: not called CC=1 SCAR=6.9
Pod documented
89 0 ▶sub wssVersion() {shift->{XCW_version}}
Subroutine wssVersion: not called CC=1 SCAR=6.9
Pod documented
90 21 ▶sub schema() {shift->{XCW_schema}}
Subroutine schema: called CC=1 SCAR=0.0
Pod documented
91  
92 #-----------
93  
94 sub create($$)
95 18 ▶{ my $self = shift;
Subroutine create: called CC=2 SCAR=7.1
Pod documented
96 panic __x"WSS plugin {name} is not prepared for writing", name => ref $self
97 18 ▶ unless $self->{XCW_prepare_w};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"XCW_prepare_w"} 0 18 18
98 18 $self;
99 }
100  
101  
102 sub check($)
103 4 ▶{ my $self = shift;
Subroutine check: called CC=2 SCAR=7.1
Pod documented
104 panic __x"WSS plugin {name} is not prepared for reading", name => ref $self
105 4 ▶ unless $self->{XCW_prepare_r};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"XCW_prepare_r"} 0 4 4
106 4 $self;
107 }
108  
109 #-----------
110  
111 # wsu had "allow anything" date fields, not type dateTime
112 sub dateTime($)
113 21 ▶{ my ($self, $time) = @_;
Subroutine dateTime: called CC=5 SCAR=16.4
Pod documented
114 21 ▶ return $time if !defined $time || ref $time;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $time or ref $time 1 20 21
Condition66%2/3
not defined $time or ref $time
l!l&&r!l&&!r
1020
MC/DC50%1/2
not defined $time or ref $time
not defined $time ref $time
Truth table66%2/3
not(A) or B
A= not defined $timeB= ref $time
ABresult
1X1
011
000
115  
116 20 my $dateTime = builtin_type_info 'dateTime';
117 20 ▶ if($time !~ m/[^0-9.]/) { $time = $dateTime->{format}->($time) }
Branch: 2 branches
BranchTrueFalseTotal
if (not $time =~ /[^0-9.]/) { } 4 16 20
elsif ($dateTime->{'check'}->($time)) { } 16 0 16
118 elsif($dateTime->{check}->($time)) {}
119 0 else {return $time}
120  
121 20 +{ _ => $time
122 , ValueType => SCHEMA2001.'/dateTime'
123 };
124 }
125  
126 #-----------
127  
128 sub loadSchemas($$)
129 21 ▶{ my ($thing, $schema, $version) = @_;
Subroutine loadSchemas: called CC=3 SCAR=11.0
Pod documented
130 21 ▶ return if $schema->{XCW_wss_loaded}++;
Branch: 1 branch
BranchTrueFalseTotal
if $schema->{"XCW_wss_loaded"}++ 15 6 21
131  
132 6 ▶ $schema->isa('XML::Compile::Cache')
Branch: 1 branch
BranchTrueFalseTotal
$schema->isa("XML::Compile::Cache") or &error(&__x("loadSchemas() requires a XML::Compile::Cache object")) 6 0 6
133 or error __x"loadSchemas() requires a XML::Compile::Cache object";
134  
135 6 my $def = $versions{$version};
136 6 my $prefixes = $def->{prefixes};
137 6 $schema->addPrefixes($prefixes);
138  
139 6 my $rewrite = join ',', sort keys %$prefixes;
140 6 $schema->addKeyRewrite("PREFIXED($rewrite)");
141  
142 6 (my $xsddir = __FILE__) =~ s! \.pm$ !/$def->{xsddir}!x;
143 7 ▶ my @xsd = glob "$xsddir/*.xsd";
Subroutine BEGIN: called CC=1 SCAR=0.0
144  
145 6 trace "loading wss schemas $version";
146  
147 6 $schema->importDefinitions
148 ( \@xsd
149  
150 # Missing from wss-secext-1.1.xsd (schema BUG) Gladly, all
151 # provided schemas have element_form qualified.
152 , element_form_default => 'qualified'
153 );
154  
155 # Another schema bug; attribute wsu:Id not declared qualified
156 # Besides, ValueType is often used on timestamps, which are declared
157 # as free-format fields (@*!&$#!&^ design committees!)
158 6 my ($wsu10, $xsd) = (WSU_10, SCHEMA2001);
159 6 $schema->importDefinitions( <<__PATCH );
160 <schema
161 xmlns="$xsd"
162 xmlns:wsu="$wsu10"
163 targetNamespace="$wsu10"
164 elementFormDefault="qualified"
165 attributeFormDefault="unqualified">
166 <attribute name="Id" type="ID" form="qualified" />
167  
168 <complexType name="AttributedDateTime">
169 <simpleContent>
170 <extension base="string">
171 <attribute name="ValueType" type="anyURI" />
172 <attributeGroup ref="wsu:commonAtts"/>
173 </extension>
174 </simpleContent>
175 </complexType>
176  
177 </schema>
178 __PATCH
179  
180 6 $schema->allowUndeclared(1);
181 6 $schema->addCompileOptions('RW'
182 , mixed_elements => 'STRUCTURAL'
183 , ignore_unused_tags => qr/^wsu_Id$/
184 );
185  
186 6 $schema->anyElement('ATTEMPT');
187 6 $schema;
188 }
189  
190  
191 sub writerHookWsuId($)
192 17 ▶{ my ($self, $type) = @_;
Subroutine writerHookWsuId: called CC=1 SCAR=0.4
Pod documented
193  
194 my $after = sub
195 18 ▶ { my ($doc, $node, $path, $val) = @_;
Subroutine __ANON__: called CC=5 SCAR=18.7
196  
197 18 my $id = $val->{wsu_Id};
198 18 ▶ defined $id or return $node;
Branch: 1 branch
BranchTrueFalseTotal
defined $id or return $node 7 11 18
199  
200 # Some schema explicitly list wsu:Id attributes, we shouldn't add
201 # the attribute again.
202 7 ▶ if(my $has = $node->getAttributeNS(WSU_10, 'Id')
Branch: 1 branch
BranchTrueFalseTotal
if (my $has = $node->getAttributeNS("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "Id") || $node->getAttribute("wsu:Id")) 7 0 7
Condition33%1/3
$node->getAttributeNS('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd', 'Id') || $node->getAttribute('wsu:Id')
l!l&&r!l&&!r
070
MC/DC0%0/2
$node->getAttributeNS('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd', 'Id') || $node->getAttribute('wsu:Id')
$node->getAttributeNS('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd', 'Id') $node->getAttribute('wsu:Id')
Truth table33%1/3
A || B
A= $node->getAttributeNS('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd', 'Id')B= $node->getAttribute('wsu:Id')
ABresult
1X1
011
000
203 || $node->getAttribute('wsu:Id'))
204 7 ▶ { $has eq $id or warning __x"two wsu:Id attributes: {one} and {two}"
Branch: 1 branch
BranchTrueFalseTotal
$has eq $id or &warning(&__x("two wsu:Id attributes: {one} and {two}", "one", $id, "two", $has)) 7 0 7
205 , one => $id, two => $has;
206  
207 7 return $node;
208 }
209  
210 0 $node->setNamespace(WSU_10, 'wsu', 0);
211 0 $node->setAttributeNS(WSU_10, 'Id', $id);
212 0 $node;
213 17 };
214  
215 17 +{ action => 'WRITER', type => $type, after => $after };
216 }
217  
218 #---------------------------
219  
220  
221 7 1;
« lib/XML/Compile/WSS/BasicAuth.pm ↑ Summary blib/lib/XML/Compile/WSS/Timestamp.pm »