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

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