blib/lib/Lemonldap/NG/Manager/Api/Providers/SamlSp.pm

filter: Statementstmt 99.4% 187 / 188 Branchbran 73.7% 90 / 122 Conditioncond 66.6% 16 / 24 MC/DCmcdc 33.3% 5 / 15 Subroutinesub 100% 16 / 16 Podpod 0.0% 0 / 7 totaltotal 84.4% 314 / 372 CC 77 SCAR 21.2
CC
77
Cov
88%
addSamlSp
13.2
_pushSamlSp
11.2
_readSamlSpExportedAttributes
11.1
CRAP 8.3
« blib/lib/Lemonldap/NG/Manager/Api/Misc.pm ↑ Summary blib/lib/Lemonldap/NG/Manager/Api/Providers/CasApp.pm »
1 package Lemonldap::NG::Manager::Api::Providers::SamlSp;
2  
3 28 our $VERSION = '2.23.0';
4  
5 package Lemonldap::NG::Manager::Api;
6  
7 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 28 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 28 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 28 extends 'Lemonldap::NG::Manager::Api::Common';
12  
13 16 ▶sub getSamlSpByConfKey {
Subroutine getSamlSpByConfKey: called CC=3 SCAR=11.2
Pod undocumented
14 16 my ( $self, $req ) = @_;
15  
16 16 ▶ my $confKey = $req->params('confKey')
Branch: 1 branch
BranchTrueFalseTotal
my $confKey = $req->params("confKey") or return $self->sendError($req, "confKey is missing", 400) 16 0 16
17 or return $self->sendError( $req, 'confKey is missing', 400 );
18  
19 16 $self->logger->debug("[API] SAML SP $confKey configuration requested");
20  
21 # Get latest configuration
22 16 my $conf = $self->_confAcc->getConf( { noCache => 1 } );
23 16 my $samlSp = $self->_getSamlSpByConfKey( $conf, $confKey );
24  
25 # Check if confKey is defined
26 16 ▶ return $self->sendError( $req,
Branch: 1 branch
BranchTrueFalseTotal
unless defined $samlSp 0 16 16
27 "SAML service Provider '$confKey' not found", 404 )
28 unless ( defined $samlSp );
29  
30 16 return $self->sendJSONresponse( $req, $samlSp );
31 }
32  
33 7 ▶sub findSamlSpByConfKey {
Subroutine findSamlSpByConfKey: called CC=6 SCAR=18.1
Pod undocumented
34 7 my ( $self, $req ) = @_;
35 7 ▶ my $pattern = (
Branch: 2 branches
BranchTrueFalseTotal
defined $req->params('uPattern') ? : 0 7 7
defined $req->params('pattern') ? : 7 0 7
36 defined $req->params('uPattern')
37 ? $req->params('uPattern')
38 : ( defined $req->params('pattern') ? $req->params('pattern') : undef )
39 );
40  
41 7 ▶ return $self->sendError( $req, 'Invalid input: pattern is missing', 400 )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pattern 0 7 7
42 unless ( defined $pattern );
43  
44 7 ▶ unless ( $pattern = $self->_getRegexpFromPattern($pattern) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pattern = $self->_getRegexpFromPattern($pattern)) 2 5 7
45 2 return $self->sendError( $req, 'Invalid input: pattern is invalid',
46 400 );
47 }
48  
49 $self->logger->debug(
50 5 "[API] Find SAML SPs by confKey regexp $pattern requested");
51  
52 # Get latest configuration
53 5 my $conf = $self->_confAcc->getConf( { noCache => 1 } );
54 my @samlSps =
55 10 ▶ map { $_ =~ $pattern ? $self->_getSamlSpByConfKey( $conf, $_ ) : () }
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /$pattern/ ? : 6 4 10
56 5 keys %{ $conf->{samlSPMetaDataXML} };
57  
58 5 return $self->sendJSONresponse( $req, [@samlSps] );
59 }
60  
61 3 ▶sub findSamlSpByEntityId {
Subroutine findSamlSpByEntityId: called CC=5 SCAR=16.4
Pod undocumented
62 3 my ( $self, $req ) = @_;
63 3 ▶ my $entityId = (
Branch: 2 branches
BranchTrueFalseTotal
defined $req->params('uEntityId') ? : 0 3 3
defined $req->params('entityId') ? : 3 0 3
64 defined $req->params('uEntityId') ? $req->params('uEntityId')
65 : (
66 defined $req->params('entityId') ? $req->params('entityId')
67 : undef
68 )
69 );
70  
71 3 ▶ return $self->sendError( $req, 'entityId is missing', 400 )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entityId 0 3 3
72 unless ( defined $entityId );
73  
74 3 $self->logger->debug("[API] Find SAML SPs by entityId $entityId requested");
75  
76 # Get latest configuration
77 3 my $conf = $self->_confAcc->getConf( { noCache => 1 } );
78 3 my $samlSp = $self->_getSamlSpByEntityId( $conf, $entityId );
79  
80 3 ▶ return $self->sendError( $req,
Branch: 1 branch
BranchTrueFalseTotal
unless defined $samlSp 1 2 3
81 "SAML service Provider with entityID '$entityId' not found", 404 )
82 unless ( defined $samlSp );
83 2 return $self->sendJSONresponse( $req, $samlSp );
84 }
85  
86 7 ▶sub addSamlSp {
Subroutine addSamlSp: called CC=12 SCAR=25.8
Pod undocumented
87 7 my ( $self, $req ) = @_;
88 7 my $add = $req->jsonBodyToObj;
89  
90 7 ▶ return $self->sendError( $req, "Invalid input: " . $req->error, 400 )
Branch: 1 branch
BranchTrueFalseTotal
unless $add 0 7 7
91 unless ($add);
92  
93 return $self->sendError( $req, 'Invalid input: confKey is missing', 400 )
94 7 ▶ unless ( defined $add->{confKey} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $add->{"confKey"} 0 7 7
95  
96 my $option_entityid =
97 7 ▶ $add->{options} ? $add->{options}->{federationEntityID} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$add->{'options'} ? : 7 0 7
98 return $self->sendError( $req, 'Invalid input: metadata is missing', 400 )
99 7 ▶ unless ( defined $add->{metadata} or $option_entityid );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $add->{"metadata"} or $option_entityid 0 7 7
Condition66%2/3
defined $add->{"metadata"} or $option_entityid
l!l&&r!l&&!r
520
MC/DC0%0/2
defined $add->{"metadata"} or $option_entityid
defined $add->{"metadata"} $option_entityid
Truth table66%2/3
A or B
A= defined $add->{"metadata"}B= $option_entityid
ABresult
1X1
011
000
100  
101 return $self->sendError( $req, 'Invalid input: confKey is empty', 400 )
102 7 ▶ unless ( $add->{confKey} );
Branch: 1 branch
BranchTrueFalseTotal
unless $add->{"confKey"} 0 7 7
103  
104 my $entityId =
105 7 ▶ $self->_readSamlSpEntityId( $add->{metadata} ) || $option_entityid;
Condition66%2/3
$self->_readSamlSpEntityId($add->{'metadata'}) || $option_entityid
l!l&&r!l&&!r
520
MC/DC0%0/2
$self->_readSamlSpEntityId($add->{'metadata'}) || $option_entityid
$self->_readSamlSpEntityId($add->{'metadata'}) $option_entityid
Truth table66%2/3
A || B
A= $self->_readSamlSpEntityId($add->{'metadata'})B= $option_entityid
ABresult
1X1
011
000
106  
107 7 ▶ return $self->sendError( $req,
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entityId 0 7 7
108 'Invalid input: entityID is missing in metadata', 400 )
109 unless ( defined $entityId );
110  
111 7 $self->logger->debug(
112 "[API] Add SAML SP with confKey $add->{confKey} and entityID $entityId requested"
113 );
114  
115 # Get latest configuration
116 7 my $conf = $self->_confAcc->getConf( { noCache => 1 } );
117  
118 return $self->sendError(
119 $req,
120 "Invalid input: A SAML SP with confKey $add->{confKey} already exists",
121 409
122 7 ▶ ) if ( defined $self->_getSamlSpByConfKey( $conf, $add->{confKey} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->_getSamlSpByConfKey($conf, $add->{"confKey"}) 1 6 7
123  
124 6 ▶ return $self->sendError( $req,
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->_getSamlSpByEntityId($conf, $entityId) 2 4 6
125 "Invalid input: A SAML SP with entityID $entityId already exists", 409 )
126 if ( defined $self->_getSamlSpByEntityId( $conf, $entityId ) );
127  
128 4 my $res = $self->_pushSamlSp( $conf, $add->{confKey}, $add, 1 );
129  
130 return $self->sendError( $req, $res->{msg}, 400 )
131 4 ▶ unless ( $res->{res} eq 'ok' );
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"res"} eq "ok" 1 3 4
132  
133 3 return $self->sendJSONresponse(
134 $req,
135 { message => "Successful operation" },
136 code => 201
137 );
138 }
139  
140 4 ▶sub replaceSamlSp {
Subroutine replaceSamlSp: called CC=7 SCAR=19.7
Pod undocumented
141 4 my ( $self, $req ) = @_;
142  
143 4 ▶ my $confKey = $req->params('confKey')
Branch: 1 branch
BranchTrueFalseTotal
my $confKey = $req->params("confKey") or return $self->sendError($req, "confKey is missing", 400) 4 0 4
144 or return $self->sendError( $req, 'confKey is missing', 400 );
145  
146 4 my $replace = $req->jsonBodyToObj;
147  
148 4 ▶ return $self->sendError( $req, "Invalid input: " . $req->error, 400 )
Branch: 1 branch
BranchTrueFalseTotal
unless $replace 0 4 4
149 unless ($replace);
150  
151 return $self->sendError( $req, 'Invalid input: metadata is missing', 400 )
152 4 ▶ unless ( defined $replace->{metadata} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $replace->{"metadata"} 0 4 4
153  
154 4 $self->logger->debug(
155 "[API] SAML SP $confKey configuration replace requested");
156  
157 # Get latest configuration
158 4 my $conf = $self->_confAcc->getConf( { noCache => 1 } );
159  
160 # Return 404 if not found
161  
162 4 ▶ return $self->sendError( $req,
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->_getSamlSpByConfKey($conf, $confKey) 1 3 4
163 "SAML service provider '$confKey' not found", 404 )
164 unless ( defined $self->_getSamlSpByConfKey( $conf, $confKey ) );
165  
166 # check if new entityId exists already
167 3 my $res = $self->_isNewSamlSpEntityIdUnique( $conf, $confKey, $replace );
168  
169 return $self->sendError( $req, $res->{msg}, 409 )
170 3 ▶ unless ( $res->{res} eq 'ok' );
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"res"} eq "ok" 0 3 3
171  
172 3 $res = $self->_pushSamlSp( $conf, $confKey, $replace, 1 );
173  
174 return $self->sendError( $req, $res->{msg}, 400 )
175 3 ▶ unless ( $res->{res} eq 'ok' );
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"res"} eq "ok" 2 1 3
176  
177 1 return $self->sendJSONresponse( $req, undef, code => 204 );
178 }
179  
180 4 ▶sub updateSamlSp {
Subroutine updateSamlSp: called CC=7 SCAR=19.6
Pod undocumented
181 4 my ( $self, $req ) = @_;
182 4 my $res;
183 4 ▶ my $confKey = $req->params('confKey')
Branch: 1 branch
BranchTrueFalseTotal
my $confKey = $req->params("confKey") or return $self->sendError($req, "confKey is missing", 400) 4 0 4
184 or return $self->sendError( $req, 'confKey is missing', 400 );
185  
186 4 my $update = $req->jsonBodyToObj;
187  
188 4 ▶ return $self->sendError( $req, "Invalid input: " . $req->error, 400 )
Branch: 1 branch
BranchTrueFalseTotal
unless $update 0 4 4
189 unless ($update);
190  
191 4 $self->logger->debug(
192 "[API] SAML SP $confKey configuration update requested");
193  
194 # Get latest configuration
195 4 my $conf = $self->_confAcc->getConf( { noCache => 1 } );
196 4 my $current = $self->_getSamlSpByConfKey( $conf, $confKey );
197  
198 # Return 404 if not found
199 4 ▶ return $self->sendError( $req,
Branch: 1 branch
BranchTrueFalseTotal
unless defined $current 1 3 4
200 "SAML service provider '$confKey' not found", 404 )
201 unless ( defined $current );
202  
203 3 ▶ if ( defined $update->{metadata} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $update->{"metadata"}) 3 0 3
204  
205 # check if new entityId exists already
206 3 $res = $self->_isNewSamlSpEntityIdUnique( $conf, $confKey, $update );
207  
208 return $self->sendError( $req, $res->{msg}, 409 )
209 3 ▶ unless ( $res->{res} eq 'ok' );
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"res"} eq "ok" 1 2 3
210  
211 }
212  
213 2 $res = $self->_pushSamlSp( $conf, $confKey, $update, 0 );
214 return $self->sendError( $req, $res->{msg}, 400 )
215 2 ▶ unless ( $res->{res} eq 'ok' );
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"res"} eq "ok" 1 1 2
216  
217 1 return $self->sendJSONresponse( $req, undef, code => 204 );
218 }
219  
220 3 ▶sub deleteSamlSp {
Subroutine deleteSamlSp: called CC=3 SCAR=11.0
Pod undocumented
221 3 my ( $self, $req ) = @_;
222  
223 3 ▶ my $confKey = $req->params('confKey')
Branch: 1 branch
BranchTrueFalseTotal
my $confKey = $req->params("confKey") or return $self->sendError($req, "confKey is missing", 400) 3 0 3
224 or return $self->sendError( $req, 'confKey is missing', 400 );
225  
226 # Get latest configuration
227 3 my $conf = $self->_confAcc->getConf( { noCache => 1 } );
228  
229 3 my $delete = $self->_getSamlSpByConfKey( $conf, $confKey );
230  
231 # Return 404 if not found
232  
233 3 ▶ return $self->sendError( $req,
Branch: 1 branch
BranchTrueFalseTotal
unless defined $delete 1 2 3
234 "SAML service provider '$confKey' not found", 404 )
235 unless ( defined $delete );
236  
237 2 delete $conf->{samlSPMetaDataXML}->{$confKey};
238 2 delete $conf->{samlSPMetaDataOptions}->{$confKey};
239 2 delete $conf->{samlSPMetaDataExportedAttributes}->{$confKey};
240 2 delete $conf->{samlSPMetaDataMacros}->{$confKey};
241  
242 # Save configuration
243 2 $self->_saveApplyConf($conf);
244  
245 2 return $self->sendJSONresponse( $req, undef, code => 204 );
246 }
247  
248 51 ▶sub _getSamlSpByConfKey {
Subroutine _getSamlSpByConfKey: called CC=10 SCAR=23.1
249 51 my ( $self, $conf, $confKey ) = @_;
250  
251 # Check if confKey is defined
252 51 ▶ return undef unless ( defined $conf->{samlSPMetaDataXML}->{$confKey} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $conf->{"samlSPMetaDataXML"}{$confKey} 9 42 51
253  
254 # Get metadata
255 42 my $metadata = $conf->{samlSPMetaDataXML}->{$confKey}->{samlSPMetaDataXML};
256  
257 # Get options
258 42 my $options = {};
259 42 for my $confOption ( keys %{ $conf->{samlSPMetaDataOptions}->{$confKey} } )
260 {
261 675 my $optionName = $self->_translateOptionConfToApi($confOption);
262 my $optionValue = $self->_translateValueConfToApi( $confOption,
263 675 $conf->{samlSPMetaDataOptions}->{$confKey}->{$confOption} );
264  
265 675 $options->{$optionName} = $optionValue;
266 }
267  
268 # Get macros
269 42 ▶ my $macros = $conf->{samlSPMetaDataMacros}->{$confKey} || {};
Condition50%1/2
$conf->{'samlSPMetaDataMacros'}{$confKey} || {}
l!l
420
MC/DC0%0/1
$conf->{'samlSPMetaDataMacros'}{$confKey} || {}
$conf->{'samlSPMetaDataMacros'}{$confKey}
Truth table50%1/2
A
A= $conf->{'samlSPMetaDataMacros'}{$confKey}
Aresult
11
00
270  
271 42 my $samlSp = {
272 confKey => $confKey,
273 metadata => $metadata,
274 exportedAttributes => {},
275 macros => $macros,
276 options => $options
277 };
278  
279 # Get exported attributes
280 42 foreach ( keys %{ $conf->{samlSPMetaDataExportedAttributes}->{$confKey} } )
281 {
282 # Extract fields from exportedAttr value
283 my ( $mandatory, $name, $format, $friendly_name ) =
284 split( /;/,
285 156 $conf->{samlSPMetaDataExportedAttributes}->{$confKey}->{$_} );
286  
287 156 ▶ $mandatory = !!$mandatory ? 'true' : 'false'; # ????????????
Branch: 1 branch
BranchTrueFalseTotal
!!$mandatory ? : 33 123 156
288  
289 156 $samlSp->{exportedAttributes}->{$_} = {
290 name => $name,
291 mandatory => $mandatory
292 };
293  
294 156 ▶ $samlSp->{exportedAttributes}->{$_}->{friendlyName} = $friendly_name
Branch: 1 branch
BranchTrueFalseTotal
if defined $friendly_name and $friendly_name ne "" 45 111 156
Condition66%2/3
defined $friendly_name and $friendly_name ne ""
!ll&&!rl&&r
011145
MC/DC50%1/2
defined $friendly_name and $friendly_name ne ""
defined $friendly_name $friendly_name ne ""
Truth table66%2/3
A and B
A= defined $friendly_nameB= $friendly_name ne ""
ABresult
0X0
100
111
295 if ( defined $friendly_name && $friendly_name ne '' );
296  
297 156 ▶ $samlSp->{exportedAttributes}->{$_}->{format} = $format
Branch: 1 branch
BranchTrueFalseTotal
if defined $format and $format ne "" 60 96 156
Condition66%2/3
defined $format and $format ne ""
!ll&&!rl&&r
09660
MC/DC50%1/2
defined $format and $format ne ""
defined $format $format ne ""
Truth table66%2/3
A and B
A= defined $formatB= $format ne ""
ABresult
0X0
100
111
298 if ( defined $format && $format ne '' );
299 }
300  
301 42 return $samlSp;
302 }
303  
304 10 ▶sub _getSamlSpByEntityId {
Subroutine _getSamlSpByEntityId: called CC=7 SCAR=19.5
305 10 my ( $self, $conf, $entityId ) = @_;
306  
307 10 foreach ( keys %{ $conf->{samlSPMetaDataXML} } ) {
308 my $metadata_entityId = $self->_readSamlSpEntityId(
309 $conf->{samlSPMetaDataXML}->{$_}->{samlSPMetaDataXML} )
310 15 ▶ || '';
Condition100%2/2
$self->_readSamlSpEntityId($conf->{'samlSPMetaDataXML'}{$_}{'samlSPMetaDataXML'}) || ''
l!l
141
MC/DC100%1/1
$self->_readSamlSpEntityId($conf->{'samlSPMetaDataXML'}{$_}{'samlSPMetaDataXML'}) || ''
$self->_readSamlSpEntityId($conf->{'samlSPMetaDataXML'}{$_}{'samlSPMetaDataXML'})
Truth table100%2/2
A
A= $self->_readSamlSpEntityId($conf->{'samlSPMetaDataXML'}{$_}{'samlSPMetaDataXML'})
Aresult
11
00
311 15 ▶ return $self->_getSamlSpByConfKey( $conf, $_ )
Branch: 1 branch
BranchTrueFalseTotal
if $metadata_entityId eq $entityId 4 11 15
312 if ( $metadata_entityId eq $entityId );
313 }
314  
315 6 foreach ( keys %{ $conf->{samlSPMetaDataOptions} } ) {
316 my $federated_entityId = $conf->{samlSPMetaDataOptions}->{$_}
317 8 ▶ ->{samlSPMetaDataOptionsFederationEntityID} || '';
Condition100%2/2
$conf->{'samlSPMetaDataOptions'}{$_}{'samlSPMetaDataOptionsFederationEntityID'} || ''
l!l
17
MC/DC100%1/1
$conf->{'samlSPMetaDataOptions'}{$_}{'samlSPMetaDataOptionsFederationEntityID'} || ''
$conf->{'samlSPMetaDataOptions'}{$_}{'samlSPMetaDataOptionsFederationEntityID'}
Truth table100%2/2
A
A= $conf->{'samlSPMetaDataOptions'}{$_}{'samlSPMetaDataOptionsFederationEntityID'}
Aresult
11
00
318 8 ▶ return $self->_getSamlSpByConfKey( $conf, $_ )
Branch: 1 branch
BranchTrueFalseTotal
if $federated_entityId eq $entityId 1 7 8
319 if ( $federated_entityId eq $entityId );
320 }
321  
322 5 return undef;
323 }
324  
325 34 ▶sub _readSamlSpEntityId {
Subroutine _readSamlSpEntityId: called CC=2 SCAR=6.9
326 34 my ( $self, $metadata ) = @_;
327  
328 34 ▶ return undef unless $metadata;
Branch: 1 branch
BranchTrueFalseTotal
unless $metadata 3 31 34
329 31 my ($entityID) = $metadata =~ /entityID=['"](.+?)['"]/;
330 31 return $entityID;
331 }
332  
333 6 ▶sub _readSamlSpExportedAttributes {
Subroutine _readSamlSpExportedAttributes: called CC=11 SCAR=24.1
334 6 my ( $self, $attrs, $mergeWith ) = @_;
335 6 my $allowedFormats = [
336 "urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified",
337 "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
338 "urn:oasis:names:tc:SAML:2.0:attrname-format:basic"
339 ];
340 6 foreach ( keys %{$attrs} ) {
341 15 ▶ if ( defined( $attrs->{$_} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attrs->{$_}) { } 11 4 15
342 return { res => "ko", msg => "Exported attribute $_ has no name" }
343 11 ▶ unless ( defined $attrs->{$_}->{name} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attrs->{$_}{"name"} 0 11 11
344 11 my $mandatory = 0;
345 11 my $name = $attrs->{$_}->{name};
346 11 my $format = '';
347 11 my $friendlyName = '';
348  
349 ( $mandatory, $name, $format, $friendlyName ) =
350 split( /;/, $mergeWith->{$_} )
351 11 ▶ if ( defined $mergeWith->{$_} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $mergeWith->{$_} 1 10 11
352  
353 11 ▶ if ( defined $attrs->{$_}->{mandatory} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attrs->{$_}{"mandatory"}) 11 0 11
354 $mandatory = (
355 $attrs->{$_}->{mandatory} eq '1'
356 11 ▶ or $attrs->{$_}->{mandatory} eq 'true'
Branch: 1 branch
BranchTrueFalseTotal
$attrs->{$_}{'mandatory'} eq '1' || $attrs->{$_}{'mandatory'} eq 'true' ? : 2 9 11
Condition66%2/3
$attrs->{$_}{"mandatory"} eq 1 or $attrs->{$_}{"mandatory"} eq "true"
l!l&&r!l&&!r
029
MC/DC50%1/2
$attrs->{$_}{"mandatory"} eq 1 or $attrs->{$_}{"mandatory"} eq "true"
$attrs->{$_}{"mandatory"} eq 1 $attrs->{$_}{"mandatory"} eq "true"
Truth table66%2/3
A or B
A= $attrs->{$_}{"mandatory"} eq 1B= $attrs->{$_}{"mandatory"} eq "true"
ABresult
1X1
011
000
357 ) ? 1 : 0;
358 }
359  
360 11 ▶ if ( defined $attrs->{$_}->{format} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attrs->{$_}{"format"}) 3 8 11
361 3 $format = $attrs->{$_}->{format};
362 return {
363 res => "ko",
364 msg => "Exported attribute $_ format does not exist."
365 }
366 3 ▶ unless ( length( grep { /^$format$/ } @{$allowedFormats} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length grep({/^$format$/;} @{$allowedFormats;}) 0 3 3
367 }
368  
369 $friendlyName = $attrs->{$_}->{friendlyName}
370 11 ▶ if ( defined $attrs->{$_}->{friendlyName} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $attrs->{$_}{"friendlyName"} 6 5 11
371 11 $mergeWith->{$_} = "$mandatory;$name;$format;$friendlyName";
372 }
373 else {
374 4 delete $mergeWith->{$_};
375 }
376 }
377  
378 6 return { res => "ok", exportedAttributes => $mergeWith };
379 }
380  
381 9 ▶sub _pushSamlSp {
Subroutine _pushSamlSp: called CC=11 SCAR=24.2
382 9 my ( $self, $conf, $confKey, $push, $replace ) = @_;
383  
384 9 my $translatedOptions = {};
385 9 ▶ if ($replace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($replace) 7 2 9
386 7 $conf->{samlSPMetaDataXML}->{$confKey} = {};
387 7 $conf->{samlSPMetaDataOptions}->{$confKey} = {};
388 7 $conf->{samlSPMetaDataMacros}->{$confKey} = {};
389 7 $conf->{samlSPMetaDataExportedAttributes}->{$confKey} = {};
390 7 $translatedOptions = $self->_getDefaultValues('samlSPMetaDataNode');
391 }
392  
393 $conf->{samlSPMetaDataXML}->{$confKey}->{samlSPMetaDataXML} =
394 $push->{metadata}
395 9 ▶ if defined $push->{metadata};
Branch: 1 branch
BranchTrueFalseTotal
if defined $push->{"metadata"} 8 1 9
396  
397 9 ▶ if ( defined $push->{options} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $push->{"options"}) 9 0 9
398  
399 9 foreach ( keys %{ $push->{options} } ) {
400 21 my $optionName = $self->_translateOptionApiToConf( $_, 'samlSP' );
401 my $optionValue =
402 $self->_translateValueApiToConf( $optionName,
403 21 $push->{options}->{$_} );
404 21 $translatedOptions->{$optionName} = $optionValue;
405 }
406  
407 9 my $res = $self->_hasAllowedAttributes( $translatedOptions,
408 'samlSPMetaDataNode' );
409 9 ▶ return $res unless ( $res->{res} eq 'ok' );
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"res"} eq "ok" 3 6 9
410 6 $self->_merge_hash( $conf, 'samlSPMetaDataOptions', $confKey,
411 $translatedOptions );
412  
413 }
414  
415 6 ▶ if ( defined $push->{macros} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $push->{"macros"}) 6 0 6
416 6 ▶ if ( $self->_isSimpleKeyValueHash( $push->{macros} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_isSimpleKeyValueHash($push->{'macros'})) { } 6 0 6
417 $self->_merge_hash( $conf, 'samlSPMetaDataMacros', $confKey,
418 6 $push->{macros} );
419 }
420 else {
421 return {
422 0 res => 'ko',
423 msg =>
424 "Invalid input: macros is not a hash object with \"key\":\"value\" attributes"
425 };
426 }
427 }
428  
429 6 ▶ if ( defined $push->{exportedAttributes} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $push->{"exportedAttributes"}) 6 0 6
430 my $res =
431 $self->_readSamlSpExportedAttributes( $push->{exportedAttributes},
432 6 $conf->{samlSPMetaDataExportedAttributes}->{$confKey} );
433 6 ▶ return $res unless ( $res->{res} eq 'ok' );
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"res"} eq "ok" 0 6 6
434  
435 $conf->{samlSPMetaDataExportedAttributes}->{$confKey} =
436 6 $res->{exportedAttributes};
437 }
438  
439 # Test new configuration
440 6 my $parser = Lemonldap::NG::Manager::Conf::Parser->new( {
441 refConf => $self->_confAcc->getConf( { noCache => 1 } ),
442 newConf => $conf,
443 req => {},
444 }
445 );
446 6 ▶ unless ( $parser->testNewConf( $self->p ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parser->testNewConf($self->p)) 1 5 6
447 return {
448 res => 'ko',
449 code => 400,
450 msg => "Configuration error: "
451 1 . join( ". ", map { $_->{message} } @{ $parser->errors } ),
452 };
453 }
454  
455 # Save configuration
456 5 $self->_saveApplyConf($conf);
457  
458 5 return { res => 'ok' };
459 }
460  
461 6 ▶sub _isNewSamlSpEntityIdUnique {
Subroutine _isNewSamlSpEntityIdUnique: called CC=5 SCAR=16.8
462 6 my ( $self, $conf, $confKey, $newSp ) = @_;
463  
464 my $option_entityid =
465 6 ▶ $newSp->{options} ? $newSp->{options}->{federationEntityID} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$newSp->{'options'} ? : 6 0 6
466 my $newEntityId =
467 6 ▶ $option_entityid || $self->_readSamlSpEntityId( $newSp->{metadata} );
Condition33%1/3
$option_entityid || $self->_readSamlSpEntityId($newSp->{'metadata'})
l!l&&r!l&&!r
060
MC/DC0%0/2
$option_entityid || $self->_readSamlSpEntityId($newSp->{'metadata'})
$option_entityid $self->_readSamlSpEntityId($newSp->{'metadata'})
Truth table33%1/3
A || B
A= $option_entityidB= $self->_readSamlSpEntityId($newSp->{'metadata'})
ABresult
1X1
011
000
468 my $curEntityId =
469 $self->_readSamlSpEntityId(
470 6 $self->_getSamlSpByConfKey( $conf, $confKey )->{metadata} );
471 6 ▶ if ( $newEntityId ne $curEntityId ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newEntityId ne $curEntityId) 1 5 6
472 return {
473 1 ▶ res => 'ko',
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->_getSamlSpByEntityId($conf, $newEntityId) 1 0 1
474 msg =>
475 "An SAML service provide with entityId '$newEntityId' already exists"
476 }
477 if ( defined $self->_getSamlSpByEntityId( $conf, $newEntityId ) );
478 }
479  
480 5 return { res => 'ok' };
481 }
482  
483 28 1;
« blib/lib/Lemonldap/NG/Manager/Api/Misc.pm ↑ Summary blib/lib/Lemonldap/NG/Manager/Api/Providers/CasApp.pm »