blib/lib/Lemonldap/NG/Portal/Main/Run.pm

filter: Statementstmt 57.0% 357 / 626 Branchbran 45.8% 131 / 286 Conditioncond 41.9% 91 / 217 MC/DCmcdc 15.1% 18 / 119 Subroutinesub 65.7% 48 / 73 Podpod 5.0% 3 / 60 totaltotal 46.9% 648 / 1381 CC 234 SCAR 34.4
CC
234
Cov
51%
registerLogin
182.0
_deleteSession
110.0
updatePersistentSession
72.0
CRAP 31.0
« blib/lib/Lemonldap/NG/Portal/Lib/RESTProxy.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/UserDB/WebID.pm »
1 ##@class Lemonldap::NG::Portal::Main::Run
2 # Serve request part of Lemonldap::NG portal
3 #
4 # Parts of this file:
5 # - response handler
6 # - main entry points
7 # - running methods
8 # - utilities
9 #
10 package Lemonldap::NG::Portal::Main::Run;
11  
12 429 our $VERSION = '2.22.2';
13  
14 package Lemonldap::NG::Portal::Main;
15  
16 429 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 429 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 429 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 429 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 429 ▶use Lemonldap::NG::Common::Util qw(getPSessionID getSameSite);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 423 ▶has trOverCache => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
23  
24 # The execution order between groups and macros can be
25 # modified in config (#1877)
26 sub groupsAndMacros {
27 return (
28 $_[0]->conf->{groupsBeforeMacros}
29 241 ▶ ? qw(setGroups setMacros)
Subroutine groupsAndMacros: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->conf->{'groupsBeforeMacros'} ? : 0 241 241
30 : qw(setMacros setGroups)
31 );
32 }
33  
34 # List constants
35 241 ▶sub authProcess { qw(extractFormInfo getUser authenticate) }
Subroutine authProcess: called CC=1 SCAR=0.0
Pod undocumented
36  
37 sub sessionData {
38 241 ▶ return qw(setAuthSessionInfo setSessionInfo), $_[0]->groupsAndMacros,
Subroutine sessionData: called CC=1 SCAR=0.0
Pod undocumented
39 qw(setPersistentSessionInfo setLocalGroups rememberBrowserCheck store secondFactor);
40 }
41  
42 sub validSession {
43 240 ▶ qw(storeHistory rememberBrowser buildCookie);
Subroutine validSession: called CC=1 SCAR=0.0
Pod undocumented
44 }
45  
46 # RESPONSE HANDLER
47 # ----------------
48 #
49 # - replace Lemonldap::NG::Common::PSGI::Request request by
50 # Lemonldap::NG::Portal::Main::Request
51 # - launch Lemonldap::NG::Common::PSGI::Request::handler()
52 sub handler {
53 2290 ▶ my ( $self, $req ) = @_;
Subroutine handler: called CC=15 SCAR=31.5
Pod undocumented
54  
55 2290 bless $req, 'Lemonldap::NG::Portal::Main::Request';
56 2290 $req->init( $self->conf );
57  
58 # Set portal URL dynamically
59 2290 $req->portal( HANDLER->tsv->{portal}->($req) );
60 2289 my $sp = 0;
61  
62 # Restore pdata
63 2289 ▶ if ( my $v = $req->cookies->{ $self->conf->{cookieName} . 'pdata' } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $v = $req->cookies->{$self->conf->{"cookieName"} . 'pdata'}) 2 2287 2289
64 2 $sp = 1;
65 2 eval { $req->pdata( JSON::from_json( uri_unescape($v) ) ); };
66 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
67 0 $self->logger->error("Bad JSON content in cookie pdata");
68 0 $req->pdata( {} );
69 }
70  
71 # Avoid fatal errors when using old keepPdata format
72 2 ▶ if ( $req->pdata->{keepPdata}
Branch: 1 branch
BranchTrueFalseTotal
if ($req->pdata->{"keepPdata"} and not ref $req->pdata->{"keepPdata"} eq "ARRAY") 0 2 2
Condition33%1/3
$req->pdata->{"keepPdata"} and not ref $req->pdata->{"keepPdata"} eq "ARRAY"
!ll&&!rl&&r
200
MC/DC0%0/2
$req->pdata->{"keepPdata"} and not ref $req->pdata->{"keepPdata"} eq "ARRAY"
$req->pdata->{"keepPdata"} not ref $req->pdata->{"keepPdata"} eq "ARRAY"
Truth table33%1/3
A and not(B)
A= $req->pdata->{"keepPdata"}B= not ref $req->pdata->{"keepPdata"} eq "ARRAY"
ABresult
0X0
100
111
73 and not( ref $req->pdata->{keepPdata} eq "ARRAY" ) )
74 {
75 0 $req->pdata->{keepPdata} = [];
76 }
77 }
78 2289 my $res = $self->Lemonldap::NG::Common::PSGI::Router::handler($req);
79  
80 # Avoid permanent loop 'Portal <-> _url' if pdata cookie is not removed
81 2255 ▶ if ( $req->userData->{_url}
Branch: 1 branch
BranchTrueFalseTotal
if ($req->userData->{"_url"} and not $req->pdata->{"keepPdata"} and $req->userData->{"_session_id"} and $req->{"env"}{"HTTP_COOKIE"} and $req->{"env"}{"HTTP_COOKIE"} eq &encode_base64($req->userData->{"_url"}, "")) 0 2255 2255
Condition33%4/12
$req->userData->{"_url"} and not $req->pdata->{"keepPdata"} and $req->userData->{"_session_id"} and $req->{"env"}{"HTTP_COOKIE"} and $req->{"env"}{"HTTP_COOKIE"} eq &encode_base64($req->userData->{"_url"}, "")
!ll&&!rl&&r
225500
$req->userData->{"_url"} and not $req->pdata->{"keepPdata"} and $req->userData->{"_session_id"} and $req->{"env"}{"HTTP_COOKIE"}
!ll&&!rl&&r
225500
$req->userData->{"_url"} and not $req->pdata->{"keepPdata"} and $req->userData->{"_session_id"}
!ll&&!rl&&r
225500
$req->userData->{"_url"} and not $req->pdata->{"keepPdata"}
!ll&&!rl&&r
225500
MC/DC0%0/5
$req->userData->{"_url"} and not $req->pdata->{"keepPdata"} and $req->userData->{"_session_id"} and $req->{"env"}{"HTTP_COOKIE"} and $req->{"env"}{"HTTP_COOKIE"} eq &encode_base64($req->userData->{"_url"}, "")
$req->userData->{"_url"} not $req->pdata->{"keepPdata"} $req->userData->{"_session_id"} $req->{"env"}{"HTTP_COOKIE"} $req->{"env"}{"HTTP_COOKIE"} eq &encode_base64($req->userData->{"_url"}, "")
Truth table16%1/6
A and not(B) and C and D and E
A= $req->userData->{"_url"}B= not $req->pdata->{"keepPdata"}C= $req->userData->{"_session_id"}D= $req->{"env"}{"HTTP_COOKIE"}E= $req->{"env"}{"HTTP_COOKIE"} eq &encode_base64($req->userData->{"_url"}, "")
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
82 and !$req->pdata->{keepPdata}
83 and $req->userData->{_session_id}
84 and $req->{env}->{HTTP_COOKIE}
85 and $req->{env}->{HTTP_COOKIE} eq
86 encode_base64( $req->userData->{_url}, '' ) )
87 {
88 0 $self->logger->info("Force cleaning pdata");
89 $self->logger->warn("pdata cookie domain must be set")
90 0 ▶ unless ( $self->conf->{pdataDomain} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->conf->{"pdataDomain"} 0 0 0
91 0 $req->pdata( {} );
92 }
93  
94 # Save pdata
95 2255 ▶ if ( $sp or %{ $req->pdata } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sp or %{$req->pdata;}) 22 2233 2255
Condition100%3/3
$sp or %{$req->pdata;}
l!l&&r!l&&!r
2202233
MC/DC100%2/2
$sp or %{$req->pdata;}
$sp %{$req->pdata;}
Truth table100%3/3
A or B
A= $spB= %{$req->pdata;}
ABresult
1X1
011
000
96 22 my %pdata_options = ();
97 $pdata_options{domain} = $self->conf->{pdataDomain}
98 22 ▶ if $self->conf->{pdataDomain};
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"pdataDomain"} 0 22 22
99  
100 22 ▶ if ( %{ $req->pdata } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$req->pdata;}) { } 21 1 22
101 21 push @{ $res->[1] }, 'Set-Cookie',
102 $self->cookie(
103 name => $self->conf->{cookieName} . 'pdata',
104 secure => $self->conf->{securedCookie},
105 21 value => uri_escape( JSON::to_json( $req->pdata ) ),
106 %pdata_options,
107 );
108  
109 }
110 else {
111 1 push @{ $res->[1] }, 'Set-Cookie',
112 $self->cookie(
113 name => $self->conf->{cookieName} . 'pdata',
114 secure => $self->conf->{securedCookie},
115 1 value => '',
116 expires => 'Wed, 21 Oct 2015 00:00:00 GMT',
117 %pdata_options,
118 );
119  
120 # Avoid regressions with #3228
121 1 push @{ $res->[1] }, 'Set-Cookie',
122 $self->genDomainCookie(
123 $req,
124 name => $self->conf->{cookieName} . 'pdata',
125 secure => $self->conf->{securedCookie},
126 1 value => '',
127 expires => 'Wed, 21 Oct 2015 00:00:00 GMT',
128 %pdata_options,
129 );
130 }
131 }
132 2255 return $res;
133 }
134  
135 # MAIN ENTRY POINTS (declared in Lemonldap::NG::Portal::Main::Init)
136 # -----------------
137 #
138 # Entry points:
139 # - "/ping": - authenticated() for already authenticated users
140 # - pleaseAuth() for others
141 # - "/": - login() ~first access
142 # - postLogin(), same for POST requests
143 # - authenticatedRequest() for authenticated users
144  
145 sub authenticated {
146 0 ▶ my ( $self, $req ) = @_;
Subroutine authenticated: not called CC=1 SCAR=6.9
Pod documented
147  
148 return $self->do(
149 $req,
150 [
151 'importHandlerData',
152 'controlUrl',
153 0 @{ $self->forAuthUser },
154 sub {
155 0 ▶ $req->response(
Subroutine __ANON__: not called CC=1 SCAR=6.9
156 $self->sendJSONresponse( $req, { status => 1 } ) );
157 0 return PE_SENDRESPONSE;
158 }
159 0 ]
160 );
161 }
162  
163 sub pleaseAuth {
164 1 ▶ my ( $self, $req ) = @_;
Subroutine pleaseAuth: called CC=1 SCAR=0.0
Pod undocumented
165 1 return $self->sendJSONresponse( $req, { status => 0 } );
166 }
167  
168 sub login {
169 192 ▶ my ( $self, $req ) = @_;
Subroutine login: called CC=1 SCAR=0.0
Pod undocumented
170 return $self->do(
171 $req,
172 [
173 'checkUnauthLogout', 'checkCancel',
174 192 'controlUrl', @{ $self->beforeAuth },
175 192 $self->authProcess, @{ $self->betweenAuthAndData },
176 192 $self->sessionData, @{ $self->afterData },
177 192 $self->validSession, @{ $self->endAuth }
178 ]
179 );
180 }
181  
182 sub postLogin {
183 39 ▶ my ( $self, $req ) = @_;
Subroutine postLogin: called CC=1 SCAR=0.0
Pod undocumented
184 return $self->do(
185 $req,
186 [
187 'checkUnauthLogout', 'restoreArgs', # Fix 2342
188 39 'controlUrl', @{ $self->beforeAuth },
189 39 $self->authProcess, @{ $self->betweenAuthAndData },
190 39 $self->sessionData, @{ $self->afterData },
191 39 $self->validSession, @{ $self->endAuth }
192 ]
193 );
194 }
195  
196 sub authenticatedRequest {
197 0 ▶ my ( $self, $req ) = @_;
Subroutine authenticatedRequest: not called CC=1 SCAR=6.9
Pod undocumented
198 return $self->do(
199 $req,
200 [
201 'importHandlerData', 'controlUrl',
202 0 'checkLogout', @{ $self->forAuthUser }
203 ]
204 );
205 }
206  
207 sub postAuthenticatedRequest {
208 0 ▶ my ( $self, $req ) = @_;
Subroutine postAuthenticatedRequest: not called CC=1 SCAR=6.9
Pod undocumented
209 return $self->do(
210 $req,
211 [
212 'importHandlerData', 'restoreArgs',
213 'controlUrl', 'checkLogout',
214 0 @{ $self->forAuthUser }
215 ]
216 );
217 }
218  
219 sub processRefreshSession {
220 0 ▶ my ( $self, $req ) = @_;
Subroutine processRefreshSession: not called CC=6 SCAR=37.4
Pod undocumented
221  
222 0 my %data = %{ $req->userData };
223 0 ▶ $req->user( $data{_user} || $data{ $self->conf->{whatToTrace} } );
Condition0%0/3
$data{'_user'} || $data{$self->conf->{'whatToTrace'}}
l!l&&r!l&&!r
000
MC/DC0%0/2
$data{'_user'} || $data{$self->conf->{'whatToTrace'}}
$data{'_user'} $data{$self->conf->{'whatToTrace'}}
Truth table0%0/3
A || B
A= $data{'_user'}B= $data{$self->conf->{'whatToTrace'}}
ABresult
1X1
011
000
224 0 $req->id( $data{_session_id} );
225  
226 0 $self->auditLog(
227 $req,
228 message => ( 'Refresh request for ' . $req->user ),
229 code => "SESSION_REFRESH",
230 user => $req->user,
231 );
232  
233 0 foreach ( keys %data ) {
234  
235 # Variables that start with _ are kept accross refresh
236 0 ▶ if (/^_/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^_/) { } 0 0 0
237  
238 # But not OIDC tokens, which can be refreshed
239 0 ▶ delete $data{$_}
Branch: 1 branch
BranchTrueFalseTotal
if /^(_oidc_access_token|_oidc_refresh_token|_oidc_access_token_eol)$/ 0 0 0
240 if (
241 /^(_oidc_access_token|_oidc_refresh_token|_oidc_access_token_eol)$/
242 );
243 }
244  
245 # Other variables should be refreshed
246 else {
247 # But not these two
248 0 ▶ if (/^(?:startTime|authenticationLevel)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(?:startTime|authenticationLevel)$/) { } 0 0 0
249 0 next;
250 }
251 else {
252 0 delete $data{$_};
253 }
254 }
255 }
256 0 $data{_updateTime} = strftime( "%Y%m%d%H%M%S", localtime() );
257 0 $self->logger->debug(
258 "Set session $req->{id} _updateTime with $data{_updateTime}");
259  
260 # Avoid interferences when refresh is run on multiple sessions
261 # in the same request
262 0 $req->sessionInfo( {} );
263  
264 # Transmit refreshed session data to setRefreshedSessionData
265 0 $req->data->{refreshedSessionData} = \%data;
266 $req->steps( [
267 0 'getUser', @{ $self->betweenAuthAndData },
268 'setSessionInfo', 'setRefreshedSessionData',
269 $self->groupsAndMacros, 'setLocalGroups',
270 ]
271 );
272 0 my $res = $self->process($req);
273 0 delete $req->data->{refreshedSessionData};
274  
275 0 return $res;
276 }
277  
278 sub setRefreshedSessionData {
279 0 ▶ my ( $self, $req ) = @_;
Subroutine setRefreshedSessionData: not called CC=2 SCAR=17.9
Pod undocumented
280 0 my %data = %{ $req->data->{refreshedSessionData} };
281  
282 0 $req->sessionInfo->{$_} = $data{$_} foreach ( keys %data );
283 0 $req->refresh(1);
284  
285 0 return PE_OK;
286 }
287  
288 sub refresh {
289 0 ▶ my ( $self, $req ) = @_;
Subroutine refresh: not called CC=3 SCAR=24.8
Pod undocumented
290 0 $req->mustRedirect(1);
291  
292 $self->userLogger->notice( 'Refresh request for '
293 0 . $req->userData->{ $self->conf->{whatToTrace} } );
294  
295 0 my $res = $self->processRefreshSession($req);
296  
297 # Run additional 'store' step We need to call process() here in case
298 # 'store' is hooked by aroundSub or afterSub
299 0 ▶ if ( $res == PE_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res == 0) 0 0 0
300 0 $req->steps( ['store'] );
301 0 $res = $self->process($req);
302 }
303  
304 0 $req->error($res);
305 0 ▶ if ($res) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res) 0 0 0
306 0 $req->info(
307 $self->loadTemplate(
308 $req,
309 'simpleInfo', params => { trspan => 'rightsReloadNeedsLogout' }
310 )
311 );
312 0 $req->urldc( $req->portal );
313 0 return $self->doPE( $req, PE_INFO );
314 }
315 0 return $self->doPE( $req, PE_OK );
316 }
317  
318 sub logout {
319 0 ▶ my ( $self, $req ) = @_;
Subroutine logout: not called CC=1 SCAR=6.9
Pod undocumented
320 return $self->do(
321 $req,
322 [
323 'importHandlerData', 'controlUrl',
324 0 @{ $self->beforeLogout }, 'authLogout',
325 'deleteSession'
326 ],
327 1, # No fail: logout should continue even if errors
328 );
329 }
330  
331 sub unauthLogout {
332 3 ▶ my ( $self, $req ) = @_;
Subroutine unauthLogout: called CC=2 SCAR=7.1
Pod undocumented
333 3 my $err = $self->_unauthLogout($req);
334 3 ▶ return $self->do( $req,
Branch: 1 branch
BranchTrueFalseTotal
$err > 0 ? : 0 3 3
335 [ 'controlUrl', [ returnPE => ( $err > 0 ? $err : PE_LOGOUT_OK ) ] ] );
336 }
337  
338 sub _unauthLogout {
339 31 ▶ my ( $self, $req ) = @_;
Subroutine _unauthLogout: called CC=1 SCAR=0.0
340 31 my $err = $self->processHook( $req, 'unauthLogout' );
341 31 $self->logger->debug('Unauthenticated logout request');
342 31 $self->logger->debug('Cleaning pdata');
343 31 $self->logger->debug("Removing $self->{conf}->{cookieName} cookie");
344 31 $req->pdata( {} );
345 $req->addCookie(
346 $self->genDomainCookie(
347 $req,
348 name => $self->conf->{cookieName},
349 secure => $self->conf->{securedCookie},
350 31 expires => 'Wed, 21 Oct 2015 00:00:00 GMT',
351 value => 0
352 )
353 );
354 31 return $err;
355 }
356  
357 # RUNNING METHODS
358 # ---------------
359  
360 sub do {
361 320 ▶ my ( $self, $req, $steps, $nofail ) = @_;
Subroutine do: called CC=27 SCAR=39.4
Pod undocumented
362 320 $req->steps($steps);
363 320 $req->data->{activeTimer} = $self->conf->{activeTimer};
364 320 my $err = $req->error( $self->process( $req, nofail => $nofail ) );
365  
366 # Update status
367 $self->HANDLER->publishStatus(
368 user => ( $req->user ? $req->user : $req->address ),
369 url => $req->{env}->{HTTP_HOST} . $req->{env}->{REQUEST_URI},
370 287 ▶ portalCode => $err,
Branch: 1 branch
BranchTrueFalseTotal
$req->user ? : 3 284 287
371 );
372  
373 # Update history
374 287 ▶ return $req->response if $err == PE_SENDRESPONSE;
Branch: 1 branch
BranchTrueFalseTotal
if $err == -4 3 284 287
375  
376 # Remove userData if authentication fails
377 284 ▶ $req->userData( {} ) if ( $err == PE_BADCREDENTIALS or $err == PE_BADOTP );
Branch: 1 branch
BranchTrueFalseTotal
if $err == 5 or $err == 96 1 283 284
Condition66%2/3
$err == 5 or $err == 96
l!l&&r!l&&!r
10283
MC/DC50%1/2
$err == 5 or $err == 96
$err == 5 $err == 96
Truth table66%2/3
A or B
A= $err == 5B= $err == 96
ABresult
1X1
011
000
378  
379 284 ▶ if ( !$self->conf->{noAjaxHook} and $req->wantJSON ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->conf->{'noAjaxHook'} and $req->wantJSON) { } 22 262 284
Condition66%2/3
not $self->conf->{"noAjaxHook"} and $req->wantJSON
!ll&&!rl&&r
026222
MC/DC50%1/2
not $self->conf->{"noAjaxHook"} and $req->wantJSON
not $self->conf->{"noAjaxHook"} $req->wantJSON
Truth table66%2/3
not(A) and B
A= not $self->conf->{"noAjaxHook"}B= $req->wantJSON
ABresult
0X0
100
111
380 22 $self->logger->debug('Processing to JSON response');
381 22 ▶ if ( ( $err > 0 and !$req->id and !( $err == PE_LOGOUT_OK ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($err > 0 and not $req->id and not $err == 47 or $err eq 41 or $err eq 1) { } 14 8 22
elsif ($err > 0 and $err != 35 and $err != 47) { } 0 8 8
Condition66%8/12
$err > 0 and not $req->id and not $err == 47 or $err eq 41 or $err eq 1
l!l&&r!l&&!r
1408
$err > 0 and not $req->id and not $err == 47 or $err eq 41
l!l&&r!l&&!r
1408
$err > 0 and not $req->id and not $err == 47
!ll&&!rl&&r
8014
$err > 0 and not $req->id
!ll&&!rl&&r
8014
MC/DC20%1/5
$err > 0 and not $req->id and not $err == 47 or $err eq 41 or $err eq 1
$err > 0 not $req->id not $err == 47 $err eq 41 $err eq 1
Truth table20%2/10
A and not(B) and not(C) or D or E
A= $err > 0B= not $req->idC= not $err == 47D= $err eq 41E= $err eq 1
ABCDEresult
111XX1
0XX1X1
10X1X1
1101X1
0XX011
10X011
110011
0XX000
10X000
110000
382 or $err eq PE_SESSIONNOTGRANTED
383 or $err eq PE_SESSIONEXPIRED )
384 {
385 14 my $json = { result => 0, error => $err };
386 14 ▶ if ( $req->wantErrorRender ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->wantErrorRender) 0 14 14
387 0 $json->{html} = $self->loadTemplate( $req, 'errormsg',
388 params => { $self->getErrorTplParams($req) } );
389 }
390 14 return $self->sendJSONresponse(
391 $req, $json,
392 code => 401,
393 headers => [
394 'WWW-Authenticate' => "SSO " . $req->portal,
395 "Content-Type" => "application/json"
396 ],
397 );
398 }
399 ▶ elsif ( $err > 0 and $err != PE_PASSWORD_OK and $err != PE_LOGOUT_OK ) {
Condition33%2/6
$err > 0 and $err != 35 and $err != 47
!ll&&!rl&&r
800
$err > 0 and $err != 35
!ll&&!rl&&r
800
MC/DC0%0/3
$err > 0 and $err != 35 and $err != 47
$err > 0 $err != 35 $err != 47
Truth table25%1/4
A and B and C
A= $err > 0B= $err != 35C= $err != 47
ABCresult
0XX0
10X0
1100
1111
400 0 ▶ return $self->sendJSONresponse(
Branch: 1 branch
BranchTrueFalseTotal
$err == 36 && $req->id ? : 0 0 0
Condition0%0/3
$err == 36 and $req->id
!ll&&!rl&&r
000
MC/DC0%0/2
$err == 36 and $req->id
$err == 36 $req->id
Truth table0%0/3
A and B
A= $err == 36B= $req->id
ABresult
0X0
100
111
401 $req,
402 {
403 result => 0,
404 error => $err,
405 (
406 $err == PE_NOTIFICATION && $req->id
407 ? ( ciphered_id => $req->id )
408 : ()
409 )
410 },
411 code => 400
412 );
413 }
414 else {
415 8 my $res = { result => 1, error => $err };
416 8 ▶ if ( $req->data->{newAuth} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->data->{"newAuth"}) 0 8 8
417 0 $res->{id} = $req->id;
418 $res->{id_http} = $req->sessionInfo->{_httpSession}
419 0 ▶ if $req->sessionInfo->{_httpSession};
Branch: 1 branch
BranchTrueFalseTotal
if $req->sessionInfo->{"_httpSession"} 0 0 0
420 }
421 8 return $self->sendJSONresponse( $req, $res );
422 }
423 }
424 else {
425 262 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($req->info or $err and $err != 47 and $err != -2 || $err == -2 && $req->data->{'redirectFormMethod'} && $req->data->{'redirectFormMethod'} eq 'post') { } 197 65 262
Condition66%12/18
$req->info or $err and $err != 47 and $err != -2 || $err == -2 && $req->data->{"redirectFormMethod"} && $req->data->{"redirectFormMethod"} eq "post"
l!l&&r!l&&!r
019765
$err and $err != 47 and $err != -2 || $err == -2 && $req->data->{"redirectFormMethod"} && $req->data->{"redirectFormMethod"} eq "post"
!ll&&!rl&&r
3134197
$err and $err != 47
!ll&&!rl&&r
229231
$err != -2 or $err == -2 and $req->data->{"redirectFormMethod"} and $req->data->{"redirectFormMethod"} eq "post"
l!l&&r!l&&!r
197034
$err == -2 and $req->data->{"redirectFormMethod"} and $req->data->{"redirectFormMethod"} eq "post"
!ll&&!rl&&r
3400
$err == -2 and $req->data->{"redirectFormMethod"}
!ll&&!rl&&r
0340
MC/DC42%3/7
$req->info or $err and $err != 47 and $err != -2 || $err == -2 && $req->data->{"redirectFormMethod"} && $req->data->{"redirectFormMethod"} eq "post"
$req->info $err $err != 47 $err != -2 $err == -2 $req->data->{"redirectFormMethod"} $req->data->{"redirectFormMethod"} eq "post"
Truth table50%4/8
A or B and C and D or E and F and G
A= $req->infoB= $errC= $err != 47D= $err != -2E= $err == -2F= $req->data->{"redirectFormMethod"}G= $req->data->{"redirectFormMethod"} eq "post"
ABCDEFGresult
1XXXXXX1
0111XXX1
01101111
00XXXXX0
010XXXX0
01100XX0
011010X0
01101100
426 $req->info
427 or (
428 $err
429 and $err != PE_LOGOUT_OK
430 and (
431 $err != PE_REDIRECT
432 or ( $err == PE_REDIRECT
433 and $req->data->{redirectFormMethod}
434 and $req->data->{redirectFormMethod} eq 'post' )
435 )
436 )
437 )
438 {
439 197 my ( $tpl, $prms ) = $self->display($req);
440 197 $self->logger->debug("Calling sendHtml with template $tpl");
441 197 return $self->sendHtml( $req, $tpl, params => $prms );
442 }
443 else {
444 65 $self->logger->debug('Calling autoredirect');
445 65 return $self->autoRedirect($req);
446 }
447 }
448 }
449  
450 # Utilities
451 # ---------
452  
453 sub doPE {
454 77 ▶ my ( $self, $req, $res ) = @_;
Subroutine doPE: called CC=1 SCAR=0.0
Pod undocumented
455 77 return $self->do( $req, [ [ returnPE => $res ] ] );
456 }
457  
458 sub getModule {
459 148 ▶ my ( $self, $req, $type ) = @_;
Subroutine getModule: called CC=5 SCAR=18.3
Pod undocumented
460 148 ▶ if ( my $val =
Branch: 1 branch
BranchTrueFalseTotal
if (my $val = $req->userData->{{"auth", "_auth", "user", "_userDB"}->{$type}}) 0 148 148
461 $req->userData->{ { auth => '_auth', user => '_userDB' }->{$type} } )
462 {
463 0 return $val;
464 }
465 148 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if (my $mod = {'auth', '_authentication', 'user', '_userDB', 'password', '_passwordDB'}->{$type}) { } 148 0 148
elsif ($type eq 'issuer') { } 0 0 0
466 my $mod = {
467 auth => '_authentication',
468 user => '_userDB',
469 password => '_passwordDB'
470 }->{$type}
471 )
472 {
473 148 ▶ if ( my $sub = $self->$mod->can('name') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $self->$mod->can('name')) { } 14 134 148
474 14 return $sub->( $self->$mod, $req, $type );
475 }
476 else {
477 134 my $s = ref( $self->$mod );
478 134 $s =~
479 s/^Lemonldap::NG::Portal::(?:(?:Issuer|UserDB|Auth|Password)::)?//;
480 134 return $s;
481 }
482 }
483 elsif ( $type eq 'issuer' ) {
484 0 return $req->{_activeIssuerDB};
485 }
486 else {
487 0 die "Unknown type $type";
488 }
489 }
490  
491 sub autoRedirect {
492 65 ▶ my ( $self, $req ) = @_;
Subroutine autoRedirect: called CC=13 SCAR=31.7
Pod undocumented
493  
494 # Set redirection URL if needed
495 65 ▶ if ( $req->mustRedirect and not( $req->info ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->mustRedirect and not $req->info) 2 63 65
Condition66%2/3
$req->mustRedirect and not $req->info
!ll&&!rl&&r
6302
MC/DC50%1/2
$req->mustRedirect and not $req->info
$req->mustRedirect not $req->info
Truth table66%2/3
A and not(B)
A= $req->mustRedirectB= not $req->info
ABresult
0X0
100
111
496 2 ▶ if ( $req->error == PE_LOGOUT_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->error == 47) { } 0 2 2
497 0 ▶ if ( !$req->urldc or !$self->_isExternalUrl( $req, $req->urldc ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->urldc and $self->_isExternalUrl($req, $req->urldc)) 0 0 0
Condition0%0/3
$req->urldc and $self->_isExternalUrl($req, $req->urldc)
!ll&&!rl&&r
000
MC/DC0%0/2
$req->urldc and $self->_isExternalUrl($req, $req->urldc)
$req->urldc $self->_isExternalUrl($req, $req->urldc)
Truth table0%0/3
A and B
A= $req->urldcB= $self->_isExternalUrl($req, $req->urldc)
ABresult
0X0
100
111
498 0 $req->urldc(
499 $self->buildUrl( $req->portal, { "logout" => 1 } ) );
500 }
501 }
502 else {
503 2 ▶ $req->{urldc} ||= $req->portal;
Condition66%2/3
$req->{"urldc"} ||= $req->portal
l!l&&r!l&&!r
110
MC/DC0%0/2
$req->{"urldc"} ||= $req->portal
$req->{"urldc"} $req->portal
Truth table66%2/3
A ||= B
A= $req->{"urldc"}B= $req->portal
ABresult
1X1
011
000
504 }
505 }
506  
507 # Redirection should be made if urldc defined
508 65 ▶ if ( $req->{urldc} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{"urldc"}) 37 28 65
509 37 ▶ if ( $req->{urldc} =~ /^\s*((?:java|vb)script|data):/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{'urldc'} =~ /^\s*((?:java|vb)script|data):/) { } 0 37 37
510 $self->auditLog(
511 $req,
512 message => "Redirection to $req->{urldc} blocked",
513 code => "UNAUTHORIZED_REDIRECT",
514 url => $req->{urldc},
515 user => $req->sessionInfo->{ $self->conf->{whatToTrace} }
516 0 ▶ || $req->user,
Condition0%0/3
$req->sessionInfo->{$self->conf->{'whatToTrace'}} || $req->user
l!l&&r!l&&!r
000
MC/DC0%0/2
$req->sessionInfo->{$self->conf->{'whatToTrace'}} || $req->user
$req->sessionInfo->{$self->conf->{'whatToTrace'}} $req->user
Truth table0%0/3
A || B
A= $req->sessionInfo->{$self->conf->{'whatToTrace'}}B= $req->user
ABresult
1X1
011
000
517 );
518 0 delete $req->{urldc};
519 }
520 else {
521 37 $self->logger->debug("Building redirection to $req->{urldc}");
522 37 ▶ if ( $req->{pdata}->{_url}
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{"pdata"}{"_url"} and $req->{"pdata"}{"_url"} eq &encode_base64($req->{"urldc"}, "")) 1 36 37
Condition66%2/3
$req->{"pdata"}{"_url"} and $req->{"pdata"}{"_url"} eq &encode_base64($req->{"urldc"}, "")
!ll&&!rl&&r
3601
MC/DC50%1/2
$req->{"pdata"}{"_url"} and $req->{"pdata"}{"_url"} eq &encode_base64($req->{"urldc"}, "")
$req->{"pdata"}{"_url"} $req->{"pdata"}{"_url"} eq &encode_base64($req->{"urldc"}, "")
Truth table66%2/3
A and B
A= $req->{"pdata"}{"_url"}B= $req->{"pdata"}{"_url"} eq &encode_base64($req->{"urldc"}, "")
ABresult
0X0
100
111
523 and $req->{pdata}->{_url} eq encode_base64( $req->{urldc}, '' )
524 )
525 {
526 1 $self->logger->info("Force cleaning pdata");
527 1 delete $req->{pdata}->{_url};
528 }
529 37 ▶ if ( $self->_jsRedirect->( $req, $req->sessionInfo ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_jsRedirect->($req, $req->sessionInfo)) { } 0 37 37
530 0 $req->error(PE_REDIRECT);
531 0 $req->data->{redirectFormMethod} = "get";
532 }
533 else {
534 return [
535 302,
536 [
537 37 Location => URI->new( $req->{urldc} )->as_string,
538 $req->spliceHdrs
539 ],
540 []
541 ];
542 }
543 }
544 }
545 28 my ( $tpl, $prms ) = $self->display($req);
546 28 $self->logger->debug("Calling sendHtml with template $tpl");
547 28 return $self->sendHtml( $req, $tpl, params => $prms );
548 }
549  
550 # Try to recover the session corresponding to id and return session data.
551 # If $id is set to undef or if $args{force} is true, return a new session.
552 sub getApacheSession {
553 35 ▶ my ( $self, $id, %args ) = @_;
Subroutine getApacheSession: called CC=18 SCAR=30.8
Pod undocumented
554 35 ▶ $args{kind} //= "SSO";
Condition100%2/2
$args{"kind"} //= "SSO"
l!l
2312
MC/DC100%1/1
$args{"kind"} //= "SSO"
$args{"kind"}
Truth table100%2/2
A
A= $args{"kind"}
Aresult
11
00
555 35 ▶ if ($id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id) { } 22 13 35
556 22 $self->logger->debug("Try to get $args{kind} session $id");
557 }
558 else {
559 13 $self->logger->debug("Try to get a new $args{kind} session");
560 }
561  
562 my $as = Lemonldap::NG::Common::Session->new( {
563  
564 # The $args{hashStore} permits one to override the
565 # hashedSessionStore parameter. It is used when sessions are given
566 # by searchOn (like in Refresh plugin)
567 hashStore => $args{hashStore} // $self->conf->{hashedSessionStore},
568 storageModule => $self->conf->{globalStorage},
569 storageModuleOptions => $self->conf->{globalStorageOptions},
570 cacheModule => $self->conf->{localSessionStorage},
571 cacheModuleOptions => $self->conf->{localSessionStorageOptions},
572 id => $id,
573 force => $args{force},
574 kind => $args{kind},
575 35 ▶ ( $args{info} ? ( info => $args{info} ) : () ),
Branch: 1 branch
BranchTrueFalseTotal
$args{'info'} ? : 17 18 35
Condition66%2/3
$args{"hashStore"} // $self->conf->{"hashedSessionStore"}
l!l&&r!l&&!r
0530
MC/DC50%1/2
$args{"hashStore"} // $self->conf->{"hashedSessionStore"}
$args{"hashStore"} $self->conf->{"hashedSessionStore"}
Truth table66%2/3
A // B
A= $args{"hashStore"}B= $self->conf->{"hashedSessionStore"}
ABresult
1X1
011
000
576 }
577 );
578  
579 35 ▶ if ( my $err = $as->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $as->error) 1 34 35
580 1 ▶ $self->lmLog(
Branch: 1 branch
BranchTrueFalseTotal
$err =~ /(?:Object does not exist|Invalid session ID|Session kind mismatch)/ ? : 1 0 1
581 $err,
582 (
583 $err =~
584 /(?:Object does not exist|Invalid session ID|Session kind mismatch)/
585 ? 'notice'
586 : 'error'
587 )
588 );
589 1 return;
590 }
591  
592 34 ▶ if ( $id and !$args{force} and !$as->data ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id and not $args{"force"} and not $as->data) 0 34 34
Condition66%4/6
$id and not $args{"force"} and not $as->data
!ll&&!rl&&r
13210
$id and not $args{"force"}
!ll&&!rl&&r
13021
MC/DC0%0/3
$id and not $args{"force"} and not $as->data
$id not $args{"force"} not $as->data
Truth table50%2/4
A and not(B) and not(C)
A= $idB= not $args{"force"}C= not $as->data
ABCresult
0XX0
10X0
1100
1111
593 0 $self->logger->debug("Session $args{kind} $id not found");
594 0 return;
595 }
596 34 ▶ $self->logger->debug("Get session $id from Portal::Main::Run")
Branch: 1 branch
BranchTrueFalseTotal
if $id 21 13 34
597 if ($id);
598 $self->logger->debug(
599 "Check session validity -> " . $self->conf->{timeoutActivity} . "s" )
600 34 ▶ if ( $self->conf->{timeoutActivity} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"timeoutActivity"} 0 34 34
601 34 my $now = time;
602 34 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($id and defined $as->data->{"_utime"} and $now - $as->data->{"_utime"} > $self->conf->{"timeout"} || $self->conf->{"timeoutActivity"} && $as->data->{"_lastSeen"} && $now - $as->data->{"_lastSeen"} > $self->conf->{"timeoutActivity"}) 5 29 34
Condition60%9/15
$id and defined $as->data->{"_utime"} and $now - $as->data->{"_utime"} > $self->conf->{"timeout"} || $self->conf->{"timeoutActivity"} && $as->data->{"_lastSeen"} && $now - $as->data->{"_lastSeen"} > $self->conf->{"timeoutActivity"}
!ll&&!rl&&r
21130
$id and defined $as->data->{"_utime"}
!ll&&!rl&&r
13813
$now - $as->data->{"_utime"} > $self->conf->{"timeout"} or $self->conf->{"timeoutActivity"} and $as->data->{"_lastSeen"} and $now - $as->data->{"_lastSeen"} > $self->conf->{"timeoutActivity"}
l!l&&r!l&&!r
508
$self->conf->{"timeoutActivity"} and $as->data->{"_lastSeen"} and $now - $as->data->{"_lastSeen"} > $self->conf->{"timeoutActivity"}
!ll&&!rl&&r
800
$self->conf->{"timeoutActivity"} and $as->data->{"_lastSeen"}
!ll&&!rl&&r
800
MC/DC0%0/6
$id and defined $as->data->{"_utime"} and $now - $as->data->{"_utime"} > $self->conf->{"timeout"} || $self->conf->{"timeoutActivity"} && $as->data->{"_lastSeen"} && $now - $as->data->{"_lastSeen"} > $self->conf->{"timeoutActivity"}
$id defined $as->data->{"_utime"} $now - $as->data->{"_utime"} > $self->conf->{"timeout"} $self->conf->{"timeoutActivity"} $as->data->{"_lastSeen"} $now - $as->data->{"_lastSeen"} > $self->conf->{"timeoutActivity"}
Truth table28%2/7
A and B and C or D and E and F
A= $idB= defined $as->data->{"_utime"}C= $now - $as->data->{"_utime"} > $self->conf->{"timeout"}D= $self->conf->{"timeoutActivity"}E= $as->data->{"_lastSeen"}F= $now - $as->data->{"_lastSeen"} > $self->conf->{"timeoutActivity"}
ABCDEFresult
0XXXXX0
10XXXX0
1100XX0
11010X0
1101100
111XXX1
1101111
603 $id
604 and defined $as->data->{_utime}
605 and (
606 ( ( $now - $as->data->{_utime} ) > $self->conf->{timeout} )
607 or (
608 $self->conf->{timeoutActivity}
609 and $as->data->{_lastSeen}
610 and ( ( $now - $as->data->{_lastSeen} ) >
611 $self->conf->{timeoutActivity} )
612 )
613 )
614 )
615 {
616 5 $self->logger->debug("Session $args{kind} $id expired");
617 5 return;
618 }
619  
620 29 $self->logger->debug( "Return $args{kind} session " . $as->id );
621  
622 29 return $as;
623 }
624  
625 # Try to recover the persistent session corresponding to uid and return session data.
626 sub getPersistentSession {
627 42 ▶ my ( $self, $uid, $info ) = @_;
Subroutine getPersistentSession: called CC=7 SCAR=20.4
Pod undocumented
628  
629 return
630 unless ( defined $uid
631 42 ▶ and !$self->conf->{disablePersistentStorage} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uid and not $self->conf->{"disablePersistentStorage"} 0 42 42
Condition33%1/3
defined $uid and not $self->conf->{"disablePersistentStorage"}
!ll&&!rl&&r
0042
MC/DC0%0/2
defined $uid and not $self->conf->{"disablePersistentStorage"}
defined $uid not $self->conf->{"disablePersistentStorage"}
Truth table33%1/3
A and not(B)
A= defined $uidB= not $self->conf->{"disablePersistentStorage"}
ABresult
0X0
100
111
632  
633 # Compute persistent identifier
634 42 my $pid = getPSessionID($uid);
635  
636 42 $info->{_session_uid} = $uid;
637  
638 my $ps = Lemonldap::NG::Common::Session->new( {
639 storageModule => $self->conf->{persistentStorage},
640 storageModuleOptions => $self->conf->{persistentStorageOptions},
641 42 ▶ id => $pid,
Branch: 1 branch
BranchTrueFalseTotal
$info ? : 42 0 42
642 force => 1,
643 kind => "Persistent",
644 ( $info ? ( info => $info ) : () ),
645 }
646 );
647  
648 42 ▶ if ( $ps->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ps->error) { } 1 41 42
649 1 $self->logger->debug( $ps->error );
650 }
651 else {
652  
653 # Set _session_uid if not already present
654 41 ▶ unless ( defined $ps->data->{_session_uid} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ps->data->{"_session_uid"}) 0 41 41
655 0 $ps->update( { _session_uid => $uid } );
656 }
657  
658 # Set _utime if not already present
659 41 ▶ unless ( defined $ps->data->{_utime} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ps->data->{"_utime"}) 36 5 41
660 36 $ps->update( { _utime => time } );
661 }
662 }
663  
664 42 return $ps;
665 }
666  
667 # Update persistent session.
668 # Call updateSession() and store %$infos in a persistent session.
669 # Note that if the session does not exists, it will be created.
670 # @param infos hash reference of information to update
671 # @param uid optional Unhashed persistent session ID
672 # @param id optional SSO session ID
673 # @return nothing
674 sub updatePersistentSession {
675 0 ▶ my ( $self, $req, $infos, $uid, $id ) = @_;
Subroutine updatePersistentSession: not called CC=8 SCAR=42.8
Pod undocumented
676  
677 # Return if no infos to update
678 return ()
679 unless ( ref $infos eq 'HASH'
680 and %$infos
681 0 ▶ and !$self->conf->{disablePersistentStorage} );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $infos eq "HASH" and %$infos and not $self->conf->{"disablePersistentStorage"} 0 0 0
Condition0%0/6
ref $infos eq "HASH" and %$infos and not $self->conf->{"disablePersistentStorage"}
!ll&&!rl&&r
000
ref $infos eq "HASH" and %$infos
!ll&&!rl&&r
000
MC/DC0%0/3
ref $infos eq "HASH" and %$infos and not $self->conf->{"disablePersistentStorage"}
ref $infos eq "HASH" %$infos not $self->conf->{"disablePersistentStorage"}
Truth table0%0/4
A and B and not(C)
A= ref $infos eq "HASH"B= %$infosC= not $self->conf->{"disablePersistentStorage"}
ABCresult
0XX0
10X0
1100
1111
682  
683 $uid ||= $req->{sessionInfo}->{ $self->conf->{whatToTrace} }
684 0 ▶ || $req->userData->{ $self->conf->{whatToTrace} };
Condition0%0/6
$uid ||= $req->{"sessionInfo"}{$self->conf->{"whatToTrace"}} || $req->userData->{$self->conf->{"whatToTrace"}}
l!l&&r!l&&!r
000
$req->{'sessionInfo'}{$self->conf->{'whatToTrace'}} || $req->userData->{$self->conf->{'whatToTrace'}}
l!l&&r!l&&!r
000
MC/DC0%0/3
$uid ||= $req->{"sessionInfo"}{$self->conf->{"whatToTrace"}} || $req->userData->{$self->conf->{"whatToTrace"}}
$uid $req->{'sessionInfo'}{$self->conf->{'whatToTrace'}} $req->userData->{$self->conf->{'whatToTrace'}}
Truth table0%0/4
A ||= B || C
A= $uidB= $req->{'sessionInfo'}{$self->conf->{'whatToTrace'}}C= $req->userData->{$self->conf->{'whatToTrace'}}
ABCresult
1XX1
01X1
0011
0000
685 0 $self->logger->debug("Found 'whatToTrace' -> $uid");
686 0 ▶ unless ($uid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($uid) 0 0 0
687 0 $self->logger->debug('No uid found, skipping updatePersistentSession');
688 0 return ();
689 }
690 0 $self->logger->debug("Update $uid persistent session");
691  
692 # Update current session
693 0 $self->updateSession( $req, $infos, $id );
694  
695 0 my $persistentSession = $self->getPersistentSession( $uid, $infos );
696  
697 0 ▶ if ( $persistentSession->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($persistentSession->error) 0 0 0
698 0 $self->logger->error(
699 "Cannot update persistent session " . getPSessionID($uid) );
700 0 $self->logger->error( $persistentSession->error );
701 }
702 }
703  
704 # Update session stored.
705 # If no id is given, try to get it from cookie.
706 # If the session is available, update data with $info.
707 # Note that outdated session data may remain some time on
708 # server local cache, if there are several LL::NG servers.
709 # @param infos hash reference of information to update
710 # @param id Session ID
711 # @return nothing
712 sub updateSession {
713 2 ▶ my ( $self, $req, $infos, $id ) = @_;
Subroutine updateSession: called CC=11 SCAR=30.5
Pod undocumented
714  
715 # Return if no infos to update
716 2 ▶ return () unless ( ref $infos eq 'HASH' and %$infos );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $infos eq "HASH" and %$infos 0 2 2
Condition33%1/3
ref $infos eq "HASH" and %$infos
!ll&&!rl&&r
002
MC/DC0%0/2
ref $infos eq "HASH" and %$infos
ref $infos eq "HASH" %$infos
Truth table33%1/3
A and B
A= ref $infos eq "HASH"B= %$infos
ABresult
0X0
100
111
717  
718 # Recover session ID unless given
719 2 ▶ $id ||= $req->id || $req->userData->{_session_id};
Condition16%1/6
$id ||= $req->id || $req->userData->{"_session_id"}
l!l&&r!l&&!r
200
$req->id || $req->userData->{'_session_id'}
l!l&&r!l&&!r
000
MC/DC0%0/3
$id ||= $req->id || $req->userData->{"_session_id"}
$id $req->id $req->userData->{'_session_id'}
Truth table0%0/4
A ||= B || C
A= $idB= $req->idC= $req->userData->{'_session_id'}
ABCresult
1XX1
01X1
0011
0000
720  
721 2 ▶ if ($id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id) 2 0 2
722  
723 # Update sessionInfo data
724 ## sessionInfo updated if $id defined : quite strange!!
725 ## See https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues/430
726 2 $self->logger->debug("Update session $id");
727 2 foreach ( keys %$infos ) {
728 2 $self->logger->debug("Update sessionInfo $_");
729 2 $self->_dump( $infos->{$_} );
730 2 $req->{sessionInfo}->{$_} = $infos->{$_};
731 2 ▶ if ( $self->HANDLER->data->{_session_id}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->HANDLER->data->{"_session_id"} and $id eq $self->HANDLER->data->{"_session_id"}) 0 2 2
Condition33%1/3
$self->HANDLER->data->{"_session_id"} and $id eq $self->HANDLER->data->{"_session_id"}
!ll&&!rl&&r
200
MC/DC0%0/2
$self->HANDLER->data->{"_session_id"} and $id eq $self->HANDLER->data->{"_session_id"}
$self->HANDLER->data->{"_session_id"} $id eq $self->HANDLER->data->{"_session_id"}
Truth table33%1/3
A and B
A= $self->HANDLER->data->{"_session_id"}B= $id eq $self->HANDLER->data->{"_session_id"}
ABresult
0X0
100
111
732 && $id eq $self->HANDLER->data->{_session_id} )
733 {
734 0 $self->HANDLER->data->{$_} = $infos->{$_};
735 }
736 }
737  
738 # Update session in global storage with _updateTime
739 2 $infos->{_updateTime} = strftime( "%Y%m%d%H%M%S", localtime() );
740 2 ▶ if ( my $apacheSession =
Branch: 1 branch
BranchTrueFalseTotal
if (my $apacheSession = $self->getApacheSession($id, "info", $infos)) 2 0 2
741 $self->getApacheSession( $id, info => $infos ) )
742 {
743 2 ▶ if ( $apacheSession->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($apacheSession->error) 0 2 2
744 0 $self->logger->error("Cannot update session $id");
745 0 $self->logger->error( $apacheSession->error );
746 }
747 }
748  
749 # remove the corresponding session from handler cache
750 2 HANDLER->publishEvent( $req, { action => 'unlog', id => $id } );
751 }
752 }
753  
754 # Delete an existing session. If "securedCookie" is set to 2, the http session
755 # will also be removed.
756 # @param h tied Apache::Session object
757 # @param preserveCookie do not delete cookie
758 # @return True if session has been deleted
759 sub _deleteSession {
760 0 ▶ my ( $self, $req, $session, $preserveCookie ) = @_;
Subroutine _deleteSession: not called CC=10 SCAR=47.0
761  
762 # Invalidate http cookie and session, if set
763 0 ▶ if ( $self->conf->{securedCookie} >= 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"securedCookie"} >= 2) 0 0 0
764  
765 # Try to find a linked http session (securedCookie == 2)
766 0 ▶ if ( $self->conf->{securedCookie} == 2
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"securedCookie"} == 2 and my $id2 = $session->data->{"_httpSession"}) 0 0 0
Condition0%0/3
$self->conf->{"securedCookie"} == 2 and my $id2 = $session->data->{"_httpSession"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->conf->{"securedCookie"} == 2 and my $id2 = $session->data->{"_httpSession"}
$self->conf->{"securedCookie"} == 2 my $id2 = $session->data->{"_httpSession"}
Truth table0%0/3
A and B
A= $self->conf->{"securedCookie"} == 2B= my $id2 = $session->data->{"_httpSession"}
ABresult
0X0
100
111
767 and my $id2 = $session->data->{_httpSession} )
768 {
769 0 ▶ if ( my $session2 = $self->getApacheSession($id2) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $session2 = $self->getApacheSession($id2)) 0 0 0
770 0 $session2->remove;
771 0 ▶ if ( $session2->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($session2->error) 0 0 0
772 0 $self->logger->debug(
773 "Unable to remove linked session $id2");
774 0 $self->logger->debug( $session2->error );
775 }
776 }
777 }
778  
779 # Create an obsolete cookie to remove it
780 $req->addCookie(
781 $self->genDomainCookie(
782 $req,
783 0 ▶ name => $self->conf->{cookieName} . 'http',
Branch: 1 branch
BranchTrueFalseTotal
unless $preserveCookie 0 0 0
784 value => 0,
785 secure => 0,
786 expires => 'Wed, 21 Oct 2015 00:00:00 GMT'
787 )
788 ) unless ($preserveCookie);
789 }
790  
791 # Publishing an "unlog" event will automatically remove the corresponding
792 # session from handler cache. See publishEvent into Handler::Main::Run
793 0 HANDLER->publishEvent( $req, { action => 'unlog', id => $session->id } );
794 0 $session->remove;
795  
796 # Create an obsolete cookie to remove it
797 $req->addCookie(
798 $self->genDomainCookie(
799 $req,
800 name => $self->conf->{cookieName},
801 value => 0,
802 secure => $self->conf->{securedCookie},
803 0 ▶ expires => 'Wed, 21 Oct 2015 00:00:00 GMT'
Branch: 1 branch
BranchTrueFalseTotal
unless $preserveCookie 0 0 0
804 )
805 ) unless ($preserveCookie);
806  
807 # Log
808 0 my $user = $req->{sessionInfo}->{ $self->conf->{whatToTrace} };
809 0 my $mod = $req->{sessionInfo}->{_auth};
810 0 ▶ if ($user) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user) 0 0 0
811 0 $self->auditLog(
812 $req,
813 message => (
814 "User $user has been disconnected from $mod ($req->{sessionInfo}->{ipAddr})"
815 ),
816 code => "LOGOUT",
817 user => $user,
818 auth => $mod,
819 );
820 }
821  
822 0 ▶ return $session->error ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$session->error ? : 0 0 0
823 }
824  
825 # Check if an URL's domain name is declared in LL::NG config or is declared as
826 # trusted domain
827 sub isTrustedUrl {
828 17 ▶ my ( $self, $url ) = @_;
Subroutine isTrustedUrl: called CC=2 SCAR=7.2
Pod undocumented
829 17 ▶ return $url =~ $self->trustedDomainsRe ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$url =~ $self->trustedDomainsRe ? : 17 0 17
830 }
831  
832 sub stamp {
833 3 ▶ my $self = shift;
Subroutine stamp: called CC=2 SCAR=7.0
Pod undocumented
834 my $res =
835 $self->conf->{cipher}
836 3 ▶ ? $self->conf->{cipher}->encrypt( time() )
Branch: 1 branch
BranchTrueFalseTotal
$self->conf->{'cipher'} ? : 3 0 3
837 : 1;
838 3 $res =~ s/\+/%2B/g;
839 3 return $res;
840 }
841  
842 # Transfer POST data with auto submit
843 # @return void
844 sub autoPost {
845 0 ▶ my ( $self, $req ) = @_;
Subroutine autoPost: not called CC=7 SCAR=40.3
Pod undocumented
846  
847 # Get URL and Form fields
848 0 $req->{urldc} = $req->postUrl;
849 0 ▶ if ( $req->{urldc} =~ /^\s*((?:java|vb)script|data):/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{"urldc"} =~ /^\s*((?:java|vb)script|data):/) 0 0 0
850 $self->auditLog(
851 $req,
852 message => "Redirection to $req->{urldc} blocked",
853 code => "UNAUTHORIZED_REDIRECT",
854 url => $req->{urldc},
855 user => $req->sessionInfo->{ $self->conf->{whatToTrace} }
856 0 ▶ || $req->user,
Condition0%0/3
$req->sessionInfo->{$self->conf->{'whatToTrace'}} || $req->user
l!l&&r!l&&!r
000
MC/DC0%0/2
$req->sessionInfo->{$self->conf->{'whatToTrace'}} || $req->user
$req->sessionInfo->{$self->conf->{'whatToTrace'}} $req->user
Truth table0%0/3
A || B
A= $req->sessionInfo->{$self->conf->{'whatToTrace'}}B= $req->user
ABresult
1X1
011
000
857 );
858 0 return PE_BADURL;
859 }
860 0 my $formFields = $req->postFields;
861  
862 0 $self->clearHiddenFormValue($req);
863 0 foreach ( keys %$formFields ) {
864 0 $self->setHiddenFormValue( $req, $_, $formFields->{$_}, "", 0 );
865 }
866  
867 # Display info before redirecting
868 0 ▶ if ( $req->info() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->info) 0 0 0
869 0 ▶ $req->data->{infoFormMethod} = $req->param('method') || "post";
Condition0%0/2
$req->param('method') || 'post'
l!l
00
MC/DC0%0/1
$req->param('method') || 'post'
$req->param('method')
Truth table0%0/2
A
A= $req->param('method')
Aresult
11
00
870 0 return PE_INFO;
871 }
872  
873 0 $req->data->{redirectFormMethod} = "post";
874  
875 # Case 2F wait
876 0 ▶ if ( $req->data->{sfWait} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->data->{"sfWait"}) 0 0 0
877 0 return PE_2FWAIT;
878 }
879  
880 # Default case -> redirect
881 0 return PE_REDIRECT;
882 }
883  
884 # Add element into $self->{portalHiddenFormValues}, those values could be
885 # used to hide values into HTML form.
886 # @param fieldname The field name which will contain the corresponding value
887 # @param value The associated value
888 # @param prefix Prefix of the field key
889 # @param base64 Encode value in base64
890 # @return nothing
891 sub setHiddenFormValue {
892 12 ▶ my ( $self, $req, $key, $val, $prefix, $base64 ) = @_;
Subroutine setHiddenFormValue: called CC=7 SCAR=21.5
Pod undocumented
893  
894 # Default values
895 12 ▶ $prefix = "lmhidden_" unless defined $prefix;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $prefix 0 12 12
896 12 ▶ $base64 = 1 unless defined $base64;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $base64 0 12 12
897 12 ▶ $val = '' unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 12 12
898  
899 # Store value
900 12 ▶ if ( defined $val or !( $val & ~$val ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val or not $val & ~$val) 12 0 12
Condition33%1/3
defined $val or not $val & ~$val
l!l&&r!l&&!r
1200
MC/DC0%0/2
defined $val or not $val & ~$val
defined $val not $val & ~$val
Truth table33%1/3
A or not(B)
A= defined $valB= not $val & ~$val
ABresult
1X1
011
000
901 12 $key = $prefix . $key;
902  
903 12 ▶ $val = encode_base64($val) if $base64;
Branch: 1 branch
BranchTrueFalseTotal
if $base64 0 12 12
904 12 $req->{portalHiddenFormValues}->{$key} = $val;
905 12 $self->logger->debug("Store $val in hidden key $key");
906 }
907 }
908  
909 ## @method public void getHiddenFormValue(string fieldname, string prefix, boolean base64)
910 # Get value into $self->{portalHiddenFormValues}.
911 # @param fieldname The existing field name which contains a value
912 # @param prefix Prefix of the field key
913 # @param base64 Decode value from base64
914 # @return string The associated value
915 sub getHiddenFormValue {
916 18 ▶ my ( $self, $req, $key, $prefix, $base64 ) = @_;
Subroutine getHiddenFormValue: called CC=5 SCAR=19.7
Pod undocumented
917  
918 # Default values
919 18 ▶ $prefix = "lmhidden_" unless defined $prefix;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $prefix 18 0 18
920 18 ▶ $base64 = 1 unless defined $base64;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $base64 18 0 18
921  
922 18 $key = $prefix . $key;
923  
924 # Get value
925 18 my $val = $req->param($key);
926 18 ▶ if ( defined $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 0 18 18
927 0 ▶ $val = decode_base64($val) if $base64;
Branch: 1 branch
BranchTrueFalseTotal
if $base64 0 0 0
928 0 $self->logger->debug("Hidden value $val found for key $key");
929 0 return $val;
930 }
931  
932 # No value found
933 18 return undef;
934 }
935  
936 ## @method protected void clearHiddenFormValue(arrayref keys)
937 # Clear values form stored hidden fields
938 # Delete all keys if no keys provided
939 # @param keys Array reference of keys
940 # @return nothing
941 sub clearHiddenFormValue {
942 0 ▶ my ( $self, $req, $keys ) = @_;
Subroutine clearHiddenFormValue: not called CC=3 SCAR=24.8
Pod undocumented
943  
944 0 ▶ unless ( defined $keys ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $keys) { } 0 0 0
945 0 delete $req->{portalHiddenFormValues};
946 0 $self->logger->debug("Delete all hidden values");
947 }
948 else {
949 0 foreach (@$keys) {
950 0 delete $req->{portalHiddenFormValues}->{$_};
951 0 $self->logger->debug("Delete hidden value for key $_");
952 }
953 }
954  
955 0 return;
956 }
957  
958 # Get the first value of a multivaluated session value
959 sub getFirstValue {
960 0 ▶ my ( $self, $value ) = @_;
Subroutine getFirstValue: not called CC=1 SCAR=6.9
Pod undocumented
961  
962 0 my @values = split /$self->{conf}->{multiValuesSeparator}/, $value;
963  
964 0 return $values[0];
965 }
966  
967 sub info {
968 0 ▶ my ( $self, $req, $info ) = @_;
Subroutine info: not called CC=1 SCAR=6.9
Pod undocumented
969 0 return $req->info($info);
970 }
971  
972 sub fullUrl {
973 44 ▶ my ( $self, $req ) = @_;
Subroutine fullUrl: called CC=1 SCAR=0.0
Pod undocumented
974 44 my $pHost = $req->portal;
975 44 $pHost =~ s#^(https?://[^/]+)(?:/.*)?$#$1#;
976 44 return $pHost . $req->env->{REQUEST_URI};
977 }
978  
979 # Generates a cookie header which can depend on the request
980 # If no domain was explicitely specified, use the default SSO domain
981 sub genDomainCookie {
982 40 ▶ my ( $self, $req, %h ) = @_;
Subroutine genDomainCookie: called CC=2 SCAR=6.9
Pod undocumented
983  
984 40 ▶ $h{domain} ||= $self->getCookieDomain($req);
Condition100%3/3
$h{"domain"} ||= $self->getCookieDomain($req)
l!l&&r!l&&!r
4351
MC/DC100%2/2
$h{"domain"} ||= $self->getCookieDomain($req)
$h{"domain"} $self->getCookieDomain($req)
Truth table100%3/3
A ||= B
A= $h{"domain"}B= $self->getCookieDomain($req)
ABresult
1X1
011
000
985 40 return $self->cookie(%h);
986 }
987  
988 # DEPRECATED, #3228
989 sub genCookie {
990 0 ▶ my ( $self, $req, %h ) = @_;
Subroutine genCookie: not called CC=1 SCAR=6.9
Pod undocumented
991 0 return $self->cookie(%h);
992 }
993  
994 # Generate a cookie header
995 # If no domain was explicitely specified, only the portal will see
996 # this cookie
997 sub cookie {
998 112 ▶ my ( $self, %h ) = @_;
Subroutine cookie: called CC=4 SCAR=15.9
Pod undocumented
999 112 ▶ $h{path} ||= '/';
Condition50%1/2
$h{"path"} ||= "/"
l!l
0112
MC/DC0%0/1
$h{"path"} ||= "/"
$h{"path"}
Truth table50%1/2
A
A= $h{"path"}
Aresult
11
00
1000 112 ▶ $h{HttpOnly} //= $self->conf->{httpOnly};
Condition33%1/3
$h{"HttpOnly"} //= $self->conf->{"httpOnly"}
l!l&&r!l&&!r
01120
MC/DC0%0/2
$h{"HttpOnly"} //= $self->conf->{"httpOnly"}
$h{"HttpOnly"} $self->conf->{"httpOnly"}
Truth table33%1/3
A //= B
A= $h{"HttpOnly"}B= $self->conf->{"httpOnly"}
ABresult
1X1
011
000
1001 112 ▶ $h{SameSite} ||= $self->cookieSameSite;
Condition33%1/3
$h{"SameSite"} ||= $self->cookieSameSite
l!l&&r!l&&!r
01120
MC/DC0%0/2
$h{"SameSite"} ||= $self->cookieSameSite
$h{"SameSite"} $self->cookieSameSite
Truth table33%1/3
A ||= B
A= $h{"SameSite"}B= $self->cookieSameSite
ABresult
1X1
011
000
1002  
1003 112 return $self->assemble_cookie(%h);
1004 }
1005  
1006 sub assemble_cookie {
1007 112 ▶ my ( $self, %h ) = @_;
Subroutine assemble_cookie: called CC=5 SCAR=16.2
Pod undocumented
1008  
1009 112 my @res;
1010 112 ▶ $res[0] = "$h{name}" or die("name required");
Branch: 1 branch
BranchTrueFalseTotal
$res[0] = qq[$h{"name"}] or die "name required" 0 112 112
1011 112 $res[0] .= "=$h{value}";
1012  
1013 112 foreach (qw(domain path expires max_age HttpOnly SameSite)) {
1014 672 my $f = $_;
1015 672 $f =~ s/_/-/g;
1016 672 ▶ push @res, "$f=$h{$_}" if ( $h{$_} );
Branch: 1 branch
BranchTrueFalseTotal
if $h{$_} 412 260 672
1017 }
1018 112 ▶ push @res, 'secure' if ( $h{secure} );
Branch: 1 branch
BranchTrueFalseTotal
if $h{"secure"} 0 112 112
1019 112 return join( '; ', @res );
1020 }
1021  
1022 sub _dump {
1023 2 ▶ my ( $self, $variable ) = @_;
Subroutine _dump: called CC=2 SCAR=9.9
1024 2 ▶ if ( $self->conf->{logLevel} eq 'debug' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"logLevel"} eq "debug") 0 2 2
1025 0 require Data::Dumper;
1026 0 $Data::Dumper::Indent = 0;
1027 0 $Data::Dumper::Useperl = 1;
1028 0 $self->logger->debug( "Dump: " . Data::Dumper::Dumper($variable) );
1029 }
1030 2 return;
1031 }
1032  
1033 sub getSkinTplDir {
1034 268 ▶ my ( $self, $skin ) = @_;
Subroutine getSkinTplDir: called CC=2 SCAR=7.6
Pod undocumented
1035  
1036 268 ▶ my $base = $self->conf->{skinTemplateDir} || $self->conf->{templateDir};
Condition33%1/3
$self->conf->{'skinTemplateDir'} || $self->conf->{'templateDir'}
l!l&&r!l&&!r
02680
MC/DC0%0/2
$self->conf->{'skinTemplateDir'} || $self->conf->{'templateDir'}
$self->conf->{'skinTemplateDir'} $self->conf->{'templateDir'}
Truth table33%1/3
A || B
A= $self->conf->{'skinTemplateDir'}B= $self->conf->{'templateDir'}
ABresult
1X1
011
000
1037 268 return ( $base . '/' . $skin );
1038 }
1039  
1040 # Warning: this function returns a JSON string
1041 sub getTrOver {
1042 228 ▶ my ( $self, $req, $templateDir ) = @_;
Subroutine getTrOver: called CC=9 SCAR=34.4
Pod undocumented
1043  
1044 228 ▶ $templateDir //= $self->getSkinTplDir( $self->getSkin($req) );
Condition33%1/3
$templateDir //= $self->getSkinTplDir($self->getSkin($req))
l!l&&r!l&&!r
22800
MC/DC0%0/2
$templateDir //= $self->getSkinTplDir($self->getSkin($req))
$templateDir $self->getSkinTplDir($self->getSkin($req))
Truth table33%1/3
A //= B
A= $templateDirB= $self->getSkinTplDir($self->getSkin($req))
ABresult
1X1
011
000
1045  
1046 228 ▶ unless ( $self->trOverCache->{$templateDir} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->trOverCache->{$templateDir}) 107 121 228
1047  
1048 # Override messages
1049 107 my $trOverMessages = JSON::from_json( $self->trOver );
1050  
1051 107 opendir( DIR, $templateDir );
1052 107 my @langfiles = grep( /\.json$/, readdir(DIR) );
1053 107 close(DIR);
1054  
1055 107 foreach my $file (@langfiles) {
1056 0 my ($lang) = ( $file =~ /^(\w+)\.json/ );
1057 0 $self->logger->debug("Use $file to override messages");
1058 0 ▶ if ( open my $json, "<", $templateDir . "/" . $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $json, '<', $templateDir . '/' . $file) { } 0 0 0
1059 0 my $trdata;
1060 0 eval {
1061 0 local $/ = undef;
1062 0 $trdata = JSON::from_json(<$json>);
1063 };
1064 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1065 0 $self->logger->warn("Ignoring $file because of error: $@");
1066 }
1067 0 ▶ if ( ref($trdata) eq "HASH" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $trdata eq "HASH") 0 0 0
1068 0 for my $msg ( keys %$trdata ) {
1069  
1070 # lemonldap-ng.ini has priority
1071 0 ▶ $trOverMessages->{$lang}->{$msg} //= $trdata->{$msg};
Condition0%0/3
$trOverMessages->{$lang}{$msg} //= $trdata->{$msg}
l!l&&r!l&&!r
000
MC/DC0%0/2
$trOverMessages->{$lang}{$msg} //= $trdata->{$msg}
$trOverMessages->{$lang}{$msg} $trdata->{$msg}
Truth table0%0/3
A //= B
A= $trOverMessages->{$lang}{$msg}B= $trdata->{$msg}
ABresult
1X1
011
000
1072 }
1073 }
1074 }
1075 else {
1076 0 $self->logger->error("Unable to read $file");
1077 }
1078 }
1079  
1080 107 $self->trOverCache->{$templateDir} = JSON::to_json($trOverMessages);
1081 }
1082  
1083 228 return $self->trOverCache->{$templateDir};
1084 }
1085  
1086 sub sendHtml {
1087 228 ▶ my ( $self, $req, $template, %args ) = @_;
Subroutine sendHtml: called CC=20 SCAR=38.1
Pod documented
1088 228 ▶ if ( $self->conf->{logParams} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"logParams"}) 0 228 228
1089 0 $self->_dump($req);
1090 0 $self->_dump( \%args );
1091 }
1092  
1093 228 my $skin_template_dir = $self->getSkinTplDir( $self->getSkin($req) );
1094  
1095 # Look for templates in skin subdirectories instead of templateDir
1096 $args{templateDir} =
1097 228 [ $skin_template_dir, $self->conf->{templateDir} . "/bootstrap" ];
1098  
1099 228 $args{params}->{TROVER} = $self->getTrOver( $req, $skin_template_dir );
1100  
1101 228 $self->processHook( $req, 'sendHtml', \$template, \%args );
1102  
1103 228 my $res = $self->SUPER::sendHtml( $req, $template, %args );
1104 228 push @{ $res->[1] },
1105 'X-Content-Type-Options' => 'nosniff',
1106 'Cache-Control' => 'no-cache, no-store, must-revalidate', # HTTP 1.1
1107 'Pragma' => 'no-cache', # HTTP 1.0
1108 'Expires' => '0'; # Proxies
1109  
1110 228 $self->setCorsHeaderFromConfig($res);
1111  
1112 228 ▶ if ( $self->conf->{strictTransportSecurityMax_Age}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"strictTransportSecurityMax_Age"} and $req->portal =~ /^https:/) 0 228 228
Condition66%2/3
$self->conf->{"strictTransportSecurityMax_Age"} and $req->portal =~ /^https:/
!ll&&!rl&&r
22710
MC/DC0%0/2
$self->conf->{"strictTransportSecurityMax_Age"} and $req->portal =~ /^https:/
$self->conf->{"strictTransportSecurityMax_Age"} $req->portal =~ /^https:/
Truth table66%2/3
A and B
A= $self->conf->{"strictTransportSecurityMax_Age"}B= $req->portal =~ /^https:/
ABresult
0X0
100
111
1113 and $req->portal =~ /^https:/ )
1114 {
1115 0 push @{ $res->[1] },
1116 'Strict-Transport-Security' =>
1117 "max-age=$self->{conf}->{strictTransportSecurityMax_Age}";
1118 0 $self->logger->debug(
1119 "Set Strict-Transport-Security with: $self->{conf}->{strictTransportSecurityMax_Age}"
1120 );
1121 }
1122  
1123 # Set authorized URL for POST
1124 228 my $csp = $self->csp . "form-action " . $self->conf->{cspFormAction};
1125 228 ▶ if ( my $url = $req->urldc ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $url = $req->urldc) 11 217 228
1126 11 $self->logger->debug("Required urldc: $url");
1127 11 my $host = $self->cspGetHost($url);
1128 11 ▶ if ($host) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host) 11 0 11
1129 11 $self->logger->debug("Set CSP form-action with urldc: $url");
1130 11 $csp .= " $host";
1131 }
1132 }
1133 228 my $url = $args{params}->{URL};
1134 228 ▶ if ( defined $url ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $url) 0 228 228
1135 0 $self->logger->debug("Required Params URL: $url");
1136 0 my $host = $self->cspGetHost($url);
1137 0 ▶ if ($host) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host) 0 0 0
1138 0 $self->logger->debug("Set CSP form-action with Params URL: $url");
1139 0 $csp .= " $host";
1140 }
1141 }
1142 228 ▶ if ( defined $req->data->{cspFormAction}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $req->data->{"cspFormAction"} and ref $req->data->{"cspFormAction"} eq "HASH") 14 214 228
Condition66%2/3
defined $req->data->{"cspFormAction"} and ref $req->data->{"cspFormAction"} eq "HASH"
!ll&&!rl&&r
214014
MC/DC50%1/2
defined $req->data->{"cspFormAction"} and ref $req->data->{"cspFormAction"} eq "HASH"
defined $req->data->{"cspFormAction"} ref $req->data->{"cspFormAction"} eq "HASH"
Truth table66%2/3
A and B
A= defined $req->data->{"cspFormAction"}B= ref $req->data->{"cspFormAction"} eq "HASH"
ABresult
0X0
100
111
1143 and ref( $req->data->{cspFormAction} ) eq "HASH" )
1144 {
1145 my $request_csp_form_action =
1146 14 join( " ", keys %{ $req->data->{cspFormAction} } );
1147 14 $self->logger->debug( "Set CSP form-action with request URL: "
1148 . $request_csp_form_action );
1149 14 $csp .= " " . $request_csp_form_action;
1150 }
1151  
1152 # Set SAML Discovery Protocol in form-action
1153 # See https://github.com/w3c/webappsec-csp/issues/8
1154 228 ▶ if ( $self->conf->{samlDiscoveryProtocolActivation}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"samlDiscoveryProtocolActivation"} and defined $self->conf->{"samlDiscoveryProtocolURL"}) 0 228 228
Condition33%1/3
$self->conf->{"samlDiscoveryProtocolActivation"} and defined $self->conf->{"samlDiscoveryProtocolURL"}
!ll&&!rl&&r
22800
MC/DC0%0/2
$self->conf->{"samlDiscoveryProtocolActivation"} and defined $self->conf->{"samlDiscoveryProtocolURL"}
$self->conf->{"samlDiscoveryProtocolActivation"} defined $self->conf->{"samlDiscoveryProtocolURL"}
Truth table33%1/3
A and B
A= $self->conf->{"samlDiscoveryProtocolActivation"}B= defined $self->conf->{"samlDiscoveryProtocolURL"}
ABresult
0X0
100
111
1155 and defined $self->conf->{samlDiscoveryProtocolURL} )
1156 {
1157 0 $self->logger->debug(
1158 "Add SAML Discovery Protocol URL in CSP form-action");
1159 0 $csp .= " " . $self->conf->{samlDiscoveryProtocolURL};
1160 }
1161 228 $csp .= ';';
1162  
1163 # Deny using portal in frame except if it is required
1164 228 ▶ unless ( $req->frame
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->frame or $self->conf->{"portalAntiFrame"} == 0 or $self->conf->{"cspFrameAncestors"}) 228 0 228
Condition33%2/6
$req->frame or $self->conf->{"portalAntiFrame"} == 0 or $self->conf->{"cspFrameAncestors"}
l!l&&r!l&&!r
00228
$req->frame or $self->conf->{"portalAntiFrame"} == 0
l!l&&r!l&&!r
00228
MC/DC0%0/3
$req->frame or $self->conf->{"portalAntiFrame"} == 0 or $self->conf->{"cspFrameAncestors"}
$req->frame $self->conf->{"portalAntiFrame"} == 0 $self->conf->{"cspFrameAncestors"}
Truth table25%1/4
A or B or C
A= $req->frameB= $self->conf->{"portalAntiFrame"} == 0C= $self->conf->{"cspFrameAncestors"}
ABCresult
1XX1
01X1
0011
0000
1165 or $self->conf->{portalAntiFrame} == 0
1166 or $self->conf->{cspFrameAncestors} )
1167 {
1168 228 push @{ $res->[1] }, 'X-Frame-Options' => 'DENY';
1169 228 $csp .= "frame-ancestors 'none';";
1170 }
1171 228 ▶ if ( $self->conf->{cspFrameAncestors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"cspFrameAncestors"}) 0 228 228
1172 0 push @{ $res->[1] }, 'X-Frame-Options' => 'ALLOW-FROM '
1173 . "$self->{conf}->{cspFrameAncestors};";
1174 0 $csp .= "frame-ancestors $self->{conf}->{cspFrameAncestors};";
1175 }
1176  
1177 # Check if frames need to be embedded
1178 # FIXME: we should use $req->data->{cspChildSrc} anywhere an iframe is
1179 # created in the code, and remove this
1180 228 my @url;
1181 228 ▶ if ( $req->info ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->info) 0 228 228
1182 0 @url = map { s#https?://([^/]+).*#$1#r }
1183 ( $req->info =~ /<iframe.*?src="(.*?)"/sg );
1184 }
1185  
1186 # Update child-src header from request data
1187 228 ▶ if ( ref( $req->data->{cspChildSrc} ) eq "HASH" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $req->data->{"cspChildSrc"} eq "HASH") 0 228 228
1188 0 push @url, keys %{ $req->data->{cspChildSrc} };
1189 }
1190 228 ▶ if (@url) {
Branch: 1 branch
BranchTrueFalseTotal
if (@url) 0 228 228
1191 0 $csp .= join( ' ', 'child-src', @url, "'self'" ) . ';';
1192 }
1193  
1194 # Set CSP header
1195 228 push @{ $res->[1] }, 'Content-Security-Policy' => $csp
1196 228 ▶ unless $req->data->{dropCsp};
Branch: 1 branch
BranchTrueFalseTotal
unless $req->data->{"dropCsp"} 228 0 228
1197 228 $self->logger->debug("Apply following CSP: $csp");
1198 228 return $res;
1199 }
1200  
1201 sub imgok {
1202 0 ▶ my ( $self, $req, ) = @_;
Subroutine imgok: not called CC=1 SCAR=6.9
Pod undocumented
1203 0 return $self->sendImage( $req, 'icons/ok.png' );
1204 }
1205  
1206 sub imgnok {
1207 0 ▶ my ( $self, $req, ) = @_;
Subroutine imgnok: not called CC=1 SCAR=6.9
Pod undocumented
1208 0 return $self->sendImage( $req, 'icons/warning.png' );
1209 }
1210  
1211 sub sendImage {
1212 0 ▶ my ( $self, $req, $img ) = @_;
Subroutine sendImage: not called CC=1 SCAR=6.9
Pod undocumented
1213 0 my $u = URI->new_abs( $self->staticPrefix . "/common/$img", $req->portal )
1214 ->as_string;
1215  
1216 return [
1217 0 302,
1218 [
1219 'Location' => $u,
1220 ],
1221 [],
1222 ];
1223 }
1224  
1225 sub sendCss {
1226 0 ▶ my ( $self, $req ) = @_;
Subroutine sendCss: not called CC=2 SCAR=17.9
Pod undocumented
1227 0 my $s = '/* LL::NG Portal CSS */';
1228 0 ▶ if ( $self->conf->{portalSkinBackground} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"portalSkinBackground"}) 0 0 0
1229 $s .=
1230 'html,body{background:url("'
1231 . $self->staticPrefix
1232 . '/common/backgrounds/'
1233 . $self->conf->{portalSkinBackground}
1234 0 . '") no-repeat center fixed;'
1235 . 'background-size:cover;}';
1236 }
1237 return [
1238 0 200,
1239 [
1240 'Content-Type' => 'text/css',
1241 'Content-Length' => length($s),
1242 'Cache-Control' => 'public,max-age=3600',
1243 ],
1244 [$s]
1245 ];
1246 }
1247  
1248 sub lmError {
1249 3 ▶ my ( $self, $req, $error ) = @_;
Subroutine lmError: called CC=6 SCAR=19.1
Pod undocumented
1250 3 ▶ my $httpError = $req->param('code') || $error;
Condition33%1/3
$req->param('code') || $error
l!l&&r!l&&!r
300
MC/DC0%0/2
$req->param('code') || $error
$req->param('code') $error
Truth table33%1/3
A || B
A= $req->param('code')B= $error
ABresult
1X1
011
000
1251  
1252 # Check URL
1253 3 $self->controlUrl($req);
1254 3 ▶ $req->pdata( {} ) unless ( $httpError == 404 );
Branch: 1 branch
BranchTrueFalseTotal
unless $httpError == 404 3 0 3
1255  
1256 3 ▶ if ( $req->wantJSON ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->wantJSON) 0 3 3
1257 0 return $self->sendJSONresponse(
1258 $req,
1259 { error => $httpError, result => 0 },
1260 code => $httpError
1261 );
1262 }
1263  
1264 my %templateParams = (
1265 MAIN_LOGO => $self->conf->{portalMainLogo},
1266 LANGS => $self->conf->{showLanguages},
1267 LOGOUT_URL => $self->buildUrl( $req->portal, { logout => 1 } ),
1268 URL => $req->{urldc},
1269 3 );
1270  
1271 # Error code
1272 $templateParams{"ERROR$_"} = ( $httpError == $_ ? 1 : 0 )
1273 3 ▶ foreach ( 403, 404, 500, 502, 503 );
Branch: 1 branch
BranchTrueFalseTotal
$httpError == $_ ? : 3 12 15
1274 3 return $self->sendHtml( $req, 'error', params => \%templateParams );
1275 }
1276  
1277 sub rebuildCookies {
1278 0 ▶ my ( $self, $req ) = @_;
Subroutine rebuildCookies: not called CC=3 SCAR=24.8
Pod undocumented
1279 0 my @tmp;
1280 0 ▶ for ( my $i = 0 ; $i < @{ $req->{respHeaders} } ; $i += 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$req->{"respHeaders"};}) 0 0 0
1281 0 ▶ push @tmp, $req->respHeaders->[$i], $req->respHeaders->[ $i + 1 ]
Branch: 1 branch
BranchTrueFalseTotal
unless $req->respHeaders->[$i] eq "Set-Cookie" 0 0 0
1282 unless ( $req->respHeaders->[$i] eq 'Set-Cookie' );
1283 }
1284 0 $req->{respHeaders} = \@tmp;
1285 0 $self->buildCookie($req);
1286 }
1287  
1288 sub tplParams {
1289 230 ▶ my ( $self, $req ) = @_;
Subroutine tplParams: called CC=7 SCAR=19.6
Pod undocumented
1290 230 my %templateParams;
1291  
1292 230 my $portalPath = $req->portal;
1293 230 $portalPath =~ s#^https?://[^/]+/?#/#;
1294 230 $portalPath =~ s#[^/]+\.fcgi$##;
1295  
1296 230 for my $session_key ( keys %{ $req->{sessionInfo} } ) {
1297 $templateParams{ "session_" . $session_key } =
1298 468 $req->{sessionInfo}->{$session_key};
1299 }
1300  
1301 230 for my $env_key ( keys %{ $req->env } ) {
1302 4925 $templateParams{ "env_" . $env_key } = $req->env->{$env_key};
1303 }
1304  
1305 230 for my $custom_key ( keys %{ $self->conf->{portalCustomTplParams} } ) {
1306 $templateParams{$custom_key} =
1307 0 $self->conf->{portalCustomTplParams}->{$custom_key};
1308 }
1309  
1310 return (
1311 CACHE_TAG => $self->cacheTag,
1312 PORTAL_URL => $req->portal,
1313 PORTAL_BASE => $portalPath,
1314 MAIN_LOGO => $self->conf->{portalMainLogo},
1315 LANGS => $self->conf->{showLanguages},
1316 SCROLL_TOP => $self->conf->{scrollTop},
1317 FLOATING_CAT => $self->conf->{floatingCategoryName},
1318 SKIN => $self->getSkin($req),
1319 SKIN_PATH => $portalPath . "skins",
1320 SAMESITE => getSameSite( $self->conf ),
1321 COOKIESECURE => ( $self->conf->{securedCookie} ? 1 : 0 ),
1322 SKIN_BG => $self->conf->{portalSkinBackground},
1323 FAVICON => $self->conf->{portalFavicon} || 'common/favicon.ico',
1324 LANGUAGE => $self->getLanguage($req),
1325 CUSTOM_CSS => $self->conf->{portalCustomCss},
1326 CUSTOM_JS => $self->conf->{portalCustomJs},
1327 (
1328 $self->customParameters
1329 230 ▶ ? ( %{ $self->customParameters } )
Branch: 2 branches
BranchTrueFalseTotal
$self->conf->{'securedCookie'} ? : 10 220 230
$self->customParameters ? : 230 0 230
Condition50%1/2
$self->conf->{'portalFavicon'} || 'common/favicon.ico'
l!l
2300
MC/DC0%0/1
$self->conf->{'portalFavicon'} || 'common/favicon.ico'
$self->conf->{'portalFavicon'}
Truth table50%1/2
A
A= $self->conf->{'portalFavicon'}
Aresult
11
00
1330 : ()
1331 ),
1332 %templateParams
1333 );
1334 }
1335  
1336 sub getErrorTplParams {
1337 225 ▶ my ( $self, $req ) = @_;
Subroutine getErrorTplParams: called CC=1 SCAR=0.0
Pod undocumented
1338  
1339 225 my $err = $req->error;
1340  
1341 return (
1342 225 AUTH_ERROR => $err,
1343 ( 'AUTH_ERROR_' . $err ) => 1,
1344 AUTH_ERROR_TYPE => $req->error_type,
1345 AUTH_ERROR_ROLE => $req->error_role,
1346 LOCKTIME => $req->lockTime(),
1347 );
1348 }
1349  
1350 sub registerLogin {
1351 0 ▶ my ( $self, $req ) = @_;
Subroutine registerLogin: not called CC=13 SCAR=52.0
Pod undocumented
1352 return
1353 unless ( $self->conf->{loginHistoryEnabled}
1354 0 ▶ and defined $req->authResult );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->conf->{"loginHistoryEnabled"} and defined $req->authResult 0 0 0
Condition0%0/3
$self->conf->{"loginHistoryEnabled"} and defined $req->authResult
!ll&&!rl&&r
000
MC/DC0%0/2
$self->conf->{"loginHistoryEnabled"} and defined $req->authResult
$self->conf->{"loginHistoryEnabled"} defined $req->authResult
Truth table0%0/3
A and B
A= $self->conf->{"loginHistoryEnabled"}B= defined $req->authResult
ABresult
0X0
100
111
1355  
1356 # Check old login history
1357 0 ▶ if ( $req->sessionInfo->{loginHistory} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->sessionInfo->{"loginHistory"}) 0 0 0
1358  
1359 0 ▶ if ( !$req->sessionInfo->{_loginHistory} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->sessionInfo->{"_loginHistory"}) 0 0 0
1360 0 $self->logger->debug("Restore old login history");
1361  
1362 # Restore success login
1363 $req->sessionInfo->{_loginHistory}->{successLogin} =
1364 0 $req->sessionInfo->{loginHistory}->{successLogin};
1365  
1366 # Restore failed login, with generic error
1367 0 ▶ if ( $req->sessionInfo->{loginHistory}->{failedLogin} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->sessionInfo->{"loginHistory"}{"failedLogin"}) 0 0 0
1368 0 $self->logger->debug("Restore old failed logins");
1369 0 $req->sessionInfo->{_loginHistory}->{failedLogin} = [];
1370 0 foreach (
1371 0 @{ $req->sessionInfo->{loginHistory}->{failedLogin} } )
1372 {
1373 $self->logger->debug(
1374 0 "Replace old failed login error " . $_->{error} );
1375 0 $_->{error} = 5;
1376 0 push @{ $req->sessionInfo->{_loginHistory}->{failedLogin} },
1377 $_;
1378 }
1379 }
1380 }
1381 0 $self->updatePersistentSession( $req, { 'loginHistory' => undef } );
1382 0 delete $req->sessionInfo->{loginHistory};
1383 }
1384  
1385 0 ▶ my $history = $req->sessionInfo->{_loginHistory} ||= {};
Condition0%0/2
$req->sessionInfo->{"_loginHistory"} ||= {}
l!l
00
MC/DC0%0/1
$req->sessionInfo->{"_loginHistory"} ||= {}
$req->sessionInfo->{"_loginHistory"}
Truth table0%0/2
A
A= $req->sessionInfo->{"_loginHistory"}
Aresult
11
00
1386 0 ▶ my $type = ( $req->authResult > 0 ? 'failed' : 'success' ) . 'Login';
Branch: 1 branch
BranchTrueFalseTotal
$req->authResult > 0 ? : 0 0 0
1387 0 ▶ $history->{$type} ||= [];
Condition0%0/2
$history->{$type} ||= []
l!l
00
MC/DC0%0/1
$history->{$type} ||= []
$history->{$type}
Truth table0%0/2
A
A= $history->{$type}
Aresult
11
00
1388 0 $self->logger->debug("Current login saved into $type");
1389  
1390 # Gather current login's parameters and force current time
1391 my $login =
1392 0 $self->_sumUpSession( { %{ $req->sessionInfo }, _utime => time }, 1 );
1393 0 ▶ $login->{error} = $self->error( $req->authResult )
Branch: 1 branch
BranchTrueFalseTotal
if $req->authResult 0 0 0
1394 if ( $req->authResult );
1395  
1396 $self->logger->debug( " Current login -> " . $login->{error} )
1397 0 ▶ if ( $login->{error} );
Branch: 1 branch
BranchTrueFalseTotal
if $login->{"error"} 0 0 0
1398  
1399 # Add current login into history
1400 0 unshift @{ $history->{$type} }, $login;
1401  
1402 # Forget oldest logins
1403 0 splice @{ $history->{$type} }, $self->conf->{ $type . "Number" }
1404 0 ▶ if ( scalar @{ $history->{$type} } > $self->conf->{ $type . "Number" } );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$history->{$type};} > $self->conf->{$type . 'Number'} 0 0 0
1405  
1406 # Save into persistent session
1407 0 $self->updatePersistentSession( $req, { _loginHistory => $history, } );
1408  
1409 0 PE_OK;
1410 }
1411  
1412 # Register access to protected app
1413 # @param Lemonldap::NG::Portal::Main::Request $req The request
1414 # @param string $uid The connected user ident
1415 # @param string $app The application client/RP namespaced with protocol
1416 sub registerProtectedAppAccess {
1417 0 ▶ my ( $self, $req, $uid, $app ) = @_;
Subroutine registerProtectedAppAccess: not called CC=3 SCAR=24.8
Pod undocumented
1418  
1419 0 ▶ return unless $self->conf->{appAccessHistoryEnabled};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->conf->{"appAccessHistoryEnabled"} 0 0 0
1420  
1421 0 $self->logger->debug("Registering $app access for user $uid");
1422  
1423 0 my $persistentSession = $self->getPersistentSession($uid);
1424 0 ▶ my $entry = $persistentSession->data->{_appHistory}->{$app} || {};
Condition0%0/2
$persistentSession->data->{'_appHistory'}{$app} || {}
l!l
00
MC/DC0%0/1
$persistentSession->data->{'_appHistory'}{$app} || {}
$persistentSession->data->{'_appHistory'}{$app}
Truth table0%0/2
A
A= $persistentSession->data->{'_appHistory'}{$app}
Aresult
11
00
1425  
1426 0 $entry->{access_time} = time();
1427 0 $entry->{access_count}++;
1428  
1429 $self->updatePersistentSession(
1430 $req,
1431 {
1432 _appHistory => {
1433 0 %{ $persistentSession->data->{_appHistory} }, $app => $entry
1434 }
1435 },
1436 $uid
1437 );
1438 }
1439  
1440 # put main session data into a hash ref
1441 # @param hashref $session The session to sum up
1442 # @return hashref
1443 sub _sumUpSession {
1444 0 ▶ my ( $self, $session, $withoutUser ) = @_;
Subroutine _sumUpSession: not called CC=3 SCAR=24.8
1445 my $res =
1446 $withoutUser
1447 ? {}
1448 0 ▶ : { user => $session->{ $self->conf->{whatToTrace} } };
Branch: 1 branch
BranchTrueFalseTotal
$withoutUser ? : 0 0 0
1449 $res->{$_} = $session->{$_}
1450 0 foreach (
1451 "_utime", "ipAddr",
1452 map {
1453 # Modifying key to remove ordering prefix
1454 0 $_ =~ s/(\d+_)?//;
1455 0 $_;
1456 0 } keys %{ $self->conf->{sessionDataToRemember} },
1457 0 keys %{ $self->pluginSessionDataToRemember }
1458 );
1459 0 return $res;
1460 }
1461  
1462 sub corsPreflight {
1463 1 ▶ my ( $self, $req ) = @_;
Subroutine corsPreflight: called CC=1 SCAR=0.0
Pod undocumented
1464 1 my @headers;
1465 1 my $res = [ 204, \@headers, [] ];
1466  
1467 1 $self->setCorsHeaderFromConfig($res);
1468  
1469 1 return $res;
1470 }
1471  
1472 sub sendJSONresponse {
1473 772 ▶ my ( $self, $req, $j, %args ) = @_;
Subroutine sendJSONresponse: called CC=5 SCAR=16.9
Pod documented
1474 772 ▶ $j->{token} = $req->token if $req->token;
Branch: 1 branch
BranchTrueFalseTotal
if $req->token 0 772 772
1475 772 my $res = Lemonldap::NG::Common::PSGI::sendJSONresponse(@_);
1476  
1477 # Handle caching
1478 772 ▶ if ( $args{ttl} and $args{ttl} =~ /^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'ttl'} and $args{'ttl'} =~ /^\d+$/) { } 0 772 772
Condition33%1/3
$args{"ttl"} and $args{"ttl"} =~ /^\d+$/
!ll&&!rl&&r
77200
MC/DC0%0/2
$args{"ttl"} and $args{"ttl"} =~ /^\d+$/
$args{"ttl"} $args{"ttl"} =~ /^\d+$/
Truth table33%1/3
A and B
A= $args{"ttl"}B= $args{"ttl"} =~ /^\d+$/
ABresult
0X0
100
111
1479 0 push @{ $res->[1] }, 'Cache-Control' => 'public, max-age=' . $args{ttl};
1480 }
1481 else {
1482 772 push @{ $res->[1] },
1483 'Cache-Control' => 'no-cache, no-store, must-revalidate',
1484 'Pragma' => 'no-cache',
1485 'Expires' => '0';
1486 }
1487  
1488 # If this is a cross-domain request from the portal itself
1489 # (Ajax SSL to a different VHost)
1490 # we allow CORS
1491 772 ▶ if ( $self->_checkSelfCors($req) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_checkSelfCors($req)) { } 2 770 772
1492 2 $self->logger->debug('AJAX request from portal, allowing CORS');
1493 2 push @{ $res->[1] },
1494 "Access-Control-Allow-Origin" => $req->origin,
1495 "Access-Control-Allow-Methods" => "*",
1496 "Access-Control-Allow-Credentials" => "true";
1497  
1498 }
1499 else {
1500 770 $self->setCorsHeaderFromConfig($res);
1501 }
1502 772 return $res;
1503 }
1504  
1505 sub _checkSelfCors {
1506 772 ▶ my ( $self, $req ) = @_;
Subroutine _checkSelfCors: called CC=5 SCAR=16.2
1507  
1508 772 ▶ if ( $req->origin ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->origin) 6 766 772
1509 6 my $origin = URI->new( $req->origin );
1510 6 my $portal = URI->new( $req->portal );
1511  
1512 6 ▶ return ( $origin->scheme
Condition77%7/9
$origin->scheme && $portal->scheme eq $origin->scheme && $origin->host_port && $origin->host_port eq $portal->host_port
!ll&&!rl&&r
132
$origin->scheme and $portal->scheme eq $origin->scheme and $origin->host_port
!ll&&!rl&&r
105
$origin->scheme and $portal->scheme eq $origin->scheme
!ll&&!rl&&r
015
MC/DC50%2/4
$origin->scheme && $portal->scheme eq $origin->scheme && $origin->host_port && $origin->host_port eq $portal->host_port
$origin->scheme $portal->scheme eq $origin->scheme $origin->host_port $origin->host_port eq $portal->host_port
Truth table60%3/5
A and B and C && D
A= $origin->schemeB= $portal->scheme eq $origin->schemeC= $origin->host_portD= $origin->host_port eq $portal->host_port
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1513 and $portal->scheme eq $origin->scheme
1514 and $origin->host_port
1515 and $origin->host_port eq $portal->host_port );
1516 }
1517 766 return;
1518 }
1519  
1520 sub sendRawHtml {
1521 1200 ▶ my ($self) = $_[0];
Subroutine sendRawHtml: called CC=1 SCAR=0.0
Pod undocumented
1522 1200 my $res = Lemonldap::NG::Common::PSGI::sendRawHtml(@_);
1523  
1524 1200 $self->setCorsHeaderFromConfig($res);
1525  
1526 1200 return $res;
1527 }
1528  
1529 sub setCorsHeaderFromConfig {
1530 2199 ▶ my ( $self, $response ) = @_;
Subroutine setCorsHeaderFromConfig: called CC=3 SCAR=11.0
Pod undocumented
1531  
1532 2199 ▶ if ( $self->conf->{corsEnabled} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"corsEnabled"}) 2199 0 2199
1533 2199 my @cors = split /;/, $self->cors;
1534 2199 push @{ $response->[1] }, @cors;
1535 2199 $self->logger->debug('Apply following CORS policy:');
1536 2199 $self->logger->debug(" $_") for @cors;
1537 }
1538 }
1539  
1540 # Temlate loader
1541 sub loadTemplate {
1542 0 ▶ my ( $self, $req, $name, %prm ) = @_;
Subroutine loadTemplate: not called CC=5 SCAR=34.0
Pod undocumented
1543  
1544 0 $self->processHook( $req, 'sendHtml', \$name, \%prm );
1545 0 $name .= '.tpl';
1546 my $tpl = HTML::Template->new(
1547 filename => $name,
1548 path => [
1549 $self->getSkinTplDir( $self->getSkin($req) ),
1550 $self->conf->{templateDir} . '/bootstrap/',
1551 $self->conf->{templateDir} . '/common/'
1552 ],
1553 search_path_on_include => 1,
1554 die_on_bad_params => 0,
1555 die_on_missing_include => 1,
1556 cache => ( defined $prm{cache} ? $prm{cache} : 1 ),
1557 global_vars => 0,
1558 0 ▶ ( $prm{filter} ? ( filter => $prm{filter} ) : () ),
Branch: 2 branches
BranchTrueFalseTotal
defined $prm{'cache'} ? : 0 0 0
$prm{'filter'} ? : 0 0 0
1559 );
1560 0 ▶ if ( $self->can('tplParams') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("tplParams")) 0 0 0
1561 0 $tpl->param( $self->tplParams($req) );
1562 }
1563 0 ▶ if ( $prm{params} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prm{"params"}) 0 0 0
1564 0 $tpl->param( %{ $prm{params} } );
1565 }
1566 0 return $tpl->output;
1567 }
1568  
1569 # This method extracts the scheme://host:port part of a URL for use in
1570 # Content-Security-Polity header
1571 sub cspGetHost {
1572 21 ▶ my ( $self, $url ) = @_;
Subroutine cspGetHost: called CC=8 SCAR=20.9
Pod undocumented
1573 21 ▶ return unless $url;
Branch: 1 branch
BranchTrueFalseTotal
unless $url 1 20 21
1574 20 my $uri = $url;
1575 20 ▶ unless ( blessed($uri) && $uri->isa("URI") ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($uri) and $uri->isa("URI")) 20 0 20
Condition33%1/3
builtin::blessed($uri) and $uri->isa("URI")
!ll&&!rl&&r
2000
MC/DC0%0/2
builtin::blessed($uri) and $uri->isa("URI")
builtin::blessed($uri) $uri->isa("URI")
Truth table33%1/3
A and B
A= builtin::blessed($uri)B= $uri->isa("URI")
ABresult
0X0
100
111
1576 20 $uri = URI->new($uri);
1577 }
1578 20 ▶ my $scheme = $uri->scheme || "";
Condition100%2/2
$uri->scheme || ''
l!l
173
MC/DC100%1/1
$uri->scheme || ''
$uri->scheme
Truth table100%2/2
A
A= $uri->scheme
Aresult
11
00
1579 20 ▶ if ( $scheme =~ /^https?/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($scheme =~ /^https?/) { } 16 4 20
elsif ($scheme) { } 1 3 4
1580 return (
1581 16 ▶ $scheme . "://"
Branch: 1 branch
BranchTrueFalseTotal
$uri->port == $uri->default_port ? : 15 1 16
1582 . (
1583 ( $uri->port == $uri->default_port )
1584 ? $uri->host
1585 : $uri->host_port
1586 )
1587 );
1588 }
1589 elsif ($scheme) {
1590 1 return ( $scheme . ":" );
1591 }
1592 3 return;
1593 }
1594  
1595 sub relativeUrl {
1596 4 ▶ my $self = shift;
Subroutine relativeUrl: called CC=1 SCAR=0.0
Pod undocumented
1597 4 my $req = shift;
1598  
1599 4 my $uri = $self->_buildUrlObj( $req->portal, @_ );
1600 4 return $uri->path_query;
1601 }
1602  
1603 sub buildUrl {
1604 336 ▶ my $self = shift;
Subroutine buildUrl: called CC=2 SCAR=6.9
Pod undocumented
1605 336 ▶ return $self->portal unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 335 336
1606  
1607 335 return $self->_buildUrlObj(@_)->as_string;
1608 }
1609  
1610 sub _buildUrlObj {
1611 339 ▶ my $self = shift;
Subroutine _buildUrlObj: called CC=6 SCAR=18.2
1612 339 ▶ return URI->new( $self->portal ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 339 339
1613  
1614 # URL base is $self->portal unless first arg is an URL
1615 339 ▶ my $uri =
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ m[^https?://] ? : 27 312 339
1616 URI->new( ( $_[0] =~ m#^https?://# ) ? shift(@_) : $self->portal );
1617 339 my @pathSg = grep { $_ ne '' } $uri->path_segments;
1618 339 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 348 339 687
1619 348 my $s = shift;
1620 348 ▶ if ( ref $s ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $s) { } 14 334 348
1621 14 $uri->query_form($s);
1622 14 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 14 14
1623 0 require Carp;
1624 0 Carp::confess('Query must be the last arg of buildUrl');
1625 }
1626 }
1627 else {
1628 334 push @pathSg, $s;
1629 }
1630 }
1631 339 $uri->path_segments(@pathSg);
1632 339 return $uri;
1633 }
1634  
1635 sub rememberBrowser {
1636 0 ▶ my ( $self, $req ) = @_;
Subroutine rememberBrowser: not called CC=3 SCAR=24.8
Pod undocumented
1637  
1638 0 ▶ if ( $self->getService('trustedBrowser')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getService('trustedBrowser') and $self->getService('trustedBrowser')->can('newDevice')) { } 0 0 0
Condition0%0/3
$self->getService("trustedBrowser") and $self->getService("trustedBrowser")->can("newDevice")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->getService("trustedBrowser") and $self->getService("trustedBrowser")->can("newDevice")
$self->getService("trustedBrowser") $self->getService("trustedBrowser")->can("newDevice")
Truth table0%0/3
A and B
A= $self->getService("trustedBrowser")B= $self->getService("trustedBrowser")->can("newDevice")
ABresult
0X0
100
111
1639 and $self->getService('trustedBrowser')->can("newDevice") )
1640 {
1641 0 return $self->getService('trustedBrowser')->newDevice($req);
1642 }
1643 else {
1644 0 return PE_OK;
1645 }
1646 }
1647  
1648 sub rememberBrowserCheck {
1649 33 ▶ my ( $self, $req ) = @_;
Subroutine rememberBrowserCheck: called CC=3 SCAR=13.3
Pod undocumented
1650  
1651 33 ▶ if ( $self->getService('trustedBrowser')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getService('trustedBrowser') and $self->getService('trustedBrowser')->can('check')) { } 0 33 33
Condition33%1/3
$self->getService("trustedBrowser") and $self->getService("trustedBrowser")->can("check")
!ll&&!rl&&r
3300
MC/DC0%0/2
$self->getService("trustedBrowser") and $self->getService("trustedBrowser")->can("check")
$self->getService("trustedBrowser") $self->getService("trustedBrowser")->can("check")
Truth table33%1/3
A and B
A= $self->getService("trustedBrowser")B= $self->getService("trustedBrowser")->can("check")
ABresult
0X0
100
111
1652 and $self->getService('trustedBrowser')->can("check") )
1653 {
1654 0 return $self->getService('trustedBrowser')->check($req);
1655 }
1656 else {
1657 33 return PE_OK;
1658 }
1659 }
1660  
1661 429 1;
« blib/lib/Lemonldap/NG/Portal/Lib/RESTProxy.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/UserDB/WebID.pm »