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

filter: Statementstmt 55.9% 221 / 395 Branchbran 40.8% 80 / 196 Conditioncond 29.7% 25 / 84 MC/DCmcdc 9.6% 5 / 52 Subroutinesub 75.6% 28 / 37 Podpod 0.0% 0 / 30 totaltotal 45.2% 359 / 794 CC 137 SCAR 42.4
CC
137
Cov
48%
deleteSession
380.0
controlUrl
82.5
process
56.5
CRAP 69.4
« blib/lib/Lemonldap/NG/Portal/Plugins/OIDCNativeSso.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Auth/_WebForm.pm »
1 package Lemonldap::NG::Portal::Main::Process;
2  
3 429 our $VERSION = '2.22.2';
4  
5 package Lemonldap::NG::Portal::Main;
6  
7 429 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 429 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 429 ▶use POSIX qw(strftime);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 429 ▶use Lemonldap::NG::Common::Util qw(isHiddenAttr);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 429 ▶use Lemonldap::NG::Portal::Main::Constants qw(portalConsts);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 429 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # Main method
15 # -----------
16 # Launch all methods declared in request "steps" array. Methods can be
17 # declared by their name (in Lemonldap::NG::Portal::Main namespace) or point
18 # to a subroutine (see Lemonldap::NG::Portal::Main::Run.pm)
19  
20 sub process {
21 325 ▶ my ( $self, $req, %args ) = @_;
Subroutine process: called CC=27 SCAR=40.3
Pod undocumented
22  
23 # Store ipAddr in env
24 325 $req->env->{ipAddr} = $req->address;
25 325 my $err = PE_OK;
26 325 my $nofail = delete $args{nofail};
27 325 ▶ if ( grep { ref $_ eq "CODE" } @{ $req->steps } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {ref $_ eq "CODE";} @{$req->steps;}) 1 324 325
28 1 $self->logger->debug(
29 "Warning: process pipeline contains non-serializable step");
30 }
31 325 ▶ while ( my $sub = shift @{ $req->steps } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = shift @{$req->steps;}) 1391 6 1397
32 1391 ▶ $nofail = 1 if $req->data->{nofail};
Branch: 1 branch
BranchTrueFalseTotal
if $req->data->{"nofail"} 0 1391 1391
33 1391 my @args_array;
34  
35 # This lets you transmit arguments by storing
36 # [ "method_name", @args_array ] in steps
37 1391 ▶ if ( ref($sub) eq "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sub eq "ARRAY") 107 1284 1391
38 107 my $sub_name = shift @$sub;
39 107 @args_array = @$sub;
40 107 $sub = $sub_name;
41 }
42 1391 ▶ if ( ref $sub eq "CODE" ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $sub eq 'CODE') { } 2 1389 1391
elsif (() = $sub =~ /(.*)::(.*)/) { } 60 1329 1389
43 2 $self->logger->debug("Processing code ref");
44 2 my $tmp = $sub->( $req, %args );
45 2 ▶ if ($tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp) 0 2 2
46 0 ▶ $err = $tmp unless $err > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $err > 0 0 0 0
47 0 ▶ last unless $nofail and $err != PE_SENDRESPONSE;
Branch: 1 branch
BranchTrueFalseTotal
unless $nofail and $err != -4 0 0 0
Condition0%0/3
$nofail and $err != -4
!ll&&!rl&&r
000
MC/DC0%0/2
$nofail and $err != -4
$nofail $err != -4
Truth table0%0/3
A and B
A= $nofailB= $err != -4
ABresult
0X0
100
111
48 }
49 }
50 elsif ( my ( $plugin, $callback ) = $sub =~ /(.*)::(.*)/ ) {
51 60 $self->logger->debug("Processing ${plugin}::${callback}");
52 60 my $plugin = $self->loadedModules->{$plugin};
53 60 ▶ if ( ref($plugin) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $plugin) { } 60 0 60
54 60 my $tmp = $plugin->$callback( $req, @args_array, %args );
55 60 ▶ if ($tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp) 4 56 60
56 4 ▶ $err = $tmp unless $err > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $err > 0 4 0 4
57 4 ▶ last unless $nofail and $err != PE_SENDRESPONSE;
Branch: 1 branch
BranchTrueFalseTotal
unless $nofail and $err != -4 4 0 4
Condition33%1/3
$nofail and $err != -4
!ll&&!rl&&r
400
MC/DC0%0/2
$nofail and $err != -4
$nofail $err != -4
Truth table33%1/3
A and B
A= $nofailB= $err != -4
ABresult
0X0
100
111
58 }
59 }
60 else {
61 0 $self->logger->error("Plugin $plugin is not loaded");
62 }
63 }
64 else {
65 1329 $self->logger->debug("Processing $sub");
66 1329 ▶ if ( my $as = $self->aroundSub->{$sub} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $as = $self->aroundSub->{$sub}) { } 0 1329 1329
67 0 my $tmp = $as->( $req, @args_array, %args );
68 0 ▶ if ($tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp) 0 0 0
69 0 ▶ $err = $tmp unless $err > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $err > 0 0 0 0
70 0 ▶ last unless $nofail and $err != PE_SENDRESPONSE;
Branch: 1 branch
BranchTrueFalseTotal
unless $nofail and $err != -4 0 0 0
Condition0%0/3
$nofail and $err != -4
!ll&&!rl&&r
000
MC/DC0%0/2
$nofail and $err != -4
$nofail $err != -4
Truth table0%0/3
A and B
A= $nofailB= $err != -4
ABresult
0X0
100
111
71 }
72 }
73 else {
74 1329 my $tmp = $self->$sub( $req, @args_array, %args );
75 1295 ▶ if ($tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp) 281 1014 1295
76 281 ▶ $err = $tmp unless $err > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $err > 0 281 0 281
77 281 ▶ last unless $nofail and $err != PE_SENDRESPONSE;
Branch: 1 branch
BranchTrueFalseTotal
unless $nofail and $err != -4 281 0 281
Condition33%1/3
$nofail and $err != -4
!ll&&!rl&&r
28100
MC/DC0%0/2
$nofail and $err != -4
$nofail $err != -4
Truth table33%1/3
A and B
A= $nofailB= $err != -4
ABresult
0X0
100
111
78 }
79 }
80 1014 ▶ if ( $self->afterSub->{$sub} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->afterSub->{$sub}) 2 1012 1014
81 2 unshift @{ $req->steps }, @{ $self->afterSub->{$sub} };
82 }
83 }
84 }
85 291 ▶ $self->logger->debug( "Returned " . $self->_formatProcessResult($err) )
Branch: 1 branch
BranchTrueFalseTotal
if $err 285 6 291
86 if $err;
87 291 return $err;
88 }
89  
90 sub processHook {
91 272 ▶ my ( $self, $req, $hookName, @args ) = @_;
Subroutine processHook: called CC=6 SCAR=22.4
Pod undocumented
92  
93 272 $self->logger->debug("Calling hook $hookName");
94 272 my $err = PE_OK;
95 272 for my $sub ( @{ $self->hook->{$hookName} } ) {
96 8 ▶ if ( ref $sub eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sub eq 'CODE') { } 8 0 8
97  
98 # If return code is not PE_OK (0), stop processing
99 8 ▶ last if ( $err = $sub->( $req, @args ) );
Branch: 1 branch
BranchTrueFalseTotal
if $err = &$sub($req, @args) 0 8 8
100 }
101 else {
102 0 $self->logger->debug("Not a code ref: $sub");
103 }
104 }
105 272 ▶ if ( $err != PE_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err != 0) 0 272 272
106 0 my $msg = "Hook $hookName returned $err (" . portalConsts->{$err} . ")";
107 0 ▶ if ( $err > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err > 0) { } 0 0 0
108 0 $self->logger->warn($msg);
109 }
110 else {
111 # <0 error codes are normal in some use cases
112 0 $self->logger->debug($msg);
113 }
114 }
115 272 return $err;
116 }
117  
118 sub _formatProcessResult {
119 285 ▶ my ( $self, $err ) = @_;
Subroutine _formatProcessResult: called CC=2 SCAR=6.9
120 return ( ( $err > 0 ? "error" : "status" )
121 . ": $err ("
122 285 ▶ . portalConsts->{$err}
Branch: 1 branch
BranchTrueFalseTotal
$err > 0 ? : 237 48 285
123 . ")" );
124 }
125  
126 # First process block: check args
127 # -------------------------------
128  
129 # For post requests, parse data
130 sub restoreArgs {
131 39 ▶ my ( $self, $req ) = @_;
Subroutine restoreArgs: called CC=1 SCAR=0.0
Pod undocumented
132 39 $req->mustRedirect(1);
133 39 return PE_OK;
134 }
135  
136 sub importHandlerData {
137 0 ▶ my ( $self, $req ) = @_;
Subroutine importHandlerData: not called CC=1 SCAR=6.9
Pod undocumented
138 0 $req->{sessionInfo} = $req->userData;
139 0 $req->id( $req->sessionInfo->{_session_id} );
140 0 $req->user( $req->sessionInfo->{ $self->conf->{whatToTrace} } );
141 0 return PE_OK;
142 }
143  
144 # Verify url and confirm parameter
145 sub controlUrl {
146 245 ▶ my ( $self, $req ) = @_;
Subroutine controlUrl: called CC=22 SCAR=44.1
Pod undocumented
147 245 ▶ if ( my $c = $req->param('confirm') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $req->param("confirm")) 0 245 245
148  
149 # Replace confirm stamp by 1 or -1
150 0 $c =~ s/^(-?)(.*)$/${1}1/;
151  
152 # Decrypt confirm stamp if cipher available
153 # and confirm not already decrypted
154 0 ▶ if ( $self->conf->{cipher} and $2 ne "1" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"cipher"} and $2 ne 1) 0 0 0
Condition0%0/3
$self->conf->{"cipher"} and $2 ne 1
!ll&&!rl&&r
000
MC/DC0%0/2
$self->conf->{"cipher"} and $2 ne 1
$self->conf->{"cipher"} $2 ne 1
Truth table0%0/3
A and B
A= $self->conf->{"cipher"}B= $2 ne 1
ABresult
0X0
100
111
155 0 my $time = time() - $self->conf->{cipher}->decrypt($2);
156 0 ▶ if ( $time < 600 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($time < 600) { } 0 0 0
157 0 $self->logger->debug("Confirm parameter accepted $c");
158 0 $req->set_param( 'confirm', $c );
159 }
160 else {
161 0 $self->logger->notice('Confirmation too old, refused');
162 0 $req->set_param( 'confirm', 0 );
163 }
164 }
165 }
166 245 ▶ $req->{data}->{_url} ||= '';
Condition50%1/2
$req->{"data"}{"_url"} ||= ""
l!l
0245
MC/DC0%0/1
$req->{"data"}{"_url"} ||= ""
$req->{"data"}{"_url"}
Truth table50%1/2
A
A= $req->{"data"}{"_url"}
Aresult
11
00
167 245 ▶ my $url = $req->param('url') || $req->pdata->{_url};
Condition100%3/3
$req->param('url') || $req->pdata->{'_url'}
l!l&&r!l&&!r
89228
MC/DC100%2/2
$req->param('url') || $req->pdata->{'_url'}
$req->param('url') $req->pdata->{'_url'}
Truth table100%3/3
A || B
A= $req->param('url')B= $req->pdata->{'_url'}
ABresult
1X1
011
000
168 245 ▶ if ($url) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url) 17 228 245
169  
170 # REJECT NON BASE64 URL
171 17 ▶ if ( $req->urlNotBase64 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->urlNotBase64) { } 0 17 17
172 0 $req->{urldc} = $url;
173 }
174 else {
175 17 ▶ if ( $url =~ m#[^A-Za-z0-9\+/=]# ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ m[[^A-Za-z0-9\+/=]]) { } 0 17 17
176 0 ▶ unless ( $req->maybeNotBase64 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->maybeNotBase64) 0 0 0
177 0 $self->logger->error(
178 "Value must be BASE64 encoded (param: url | value: $url)"
179 );
180 0 return PE_BADURL;
181 }
182 0 $req->{urldc} = $url;
183 }
184 else {
185 17 $req->{urldc} = decode_base64($url);
186 17 $req->{urldc} =~ s/[\r\n]//sg;
187 }
188 }
189 17 $req->{urldc} = URI->new( $req->{urldc} )->as_string;
190  
191 17 my $tmp = $req->urldc;
192  
193 # XSS attack
194 17 ▶ if ( $self->checkXSSAttack( 'urldc', $req->{urldc} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->checkXSSAttack("urldc", $req->{"urldc"})) 0 17 17
195 0 delete $req->{urldc};
196 0 return PE_BADURL;
197 }
198  
199 # Unprotected hosts
200 17 ▶ if ( $tmp and ( $tmp !~ URIRE ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp and not $tmp =~ m[(((?^:https?))://((?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)|(?:[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)))(?::((?:[0-9]*)))?(/(((?:(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:/(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))(?:[?]((?:(?:[;/?:\@&=+\$,a-zA-Z0-9\-_.!~*'()]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)))?))?)]) 0 17 17
Condition33%1/3
$tmp and not $tmp =~ m[(((?^:https?))://((?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)|(?:[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)))(?::((?:[0-9]*)))?(/(((?:(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:/(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))(?:[?]((?:(?:[;/?:\@&=+\$,a-zA-Z0-9\-_.!~*'()]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)))?))?)]
!ll&&!rl&&r
0170
MC/DC0%0/2
$tmp and not $tmp =~ m[(((?^:https?))://((?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)|(?:[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)))(?::((?:[0-9]*)))?(/(((?:(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:/(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))(?:[?]((?:(?:[;/?:\@&=+\$,a-zA-Z0-9\-_.!~*'()]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)))?))?)]
$tmp not $tmp =~ m[(((?^:https?))://((?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)|(?:[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)))(?::((?:[0-9]*)))?(/(((?:(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:/(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))(?:[?]((?:(?:[;/?:\@&=+\$,a-zA-Z0-9\-_.!~*'()]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)))?))?)]
Truth table33%1/3
A and not(B)
A= $tmpB= not $tmp =~ m[(((?^:https?))://((?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)|(?:[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)))(?::((?:[0-9]*)))?(/(((?:(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:/(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))(?:[?]((?:(?:[;/?:\@&=+\$,a-zA-Z0-9\-_.!~*'()]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)))?))?)]
ABresult
0X0
100
111
201 0 $self->auditLog(
202 $req,
203 message => "Bad URL $tmp",
204 code => "UNAUTHORIZED_REDIRECT",
205 url => $tmp,
206 );
207 0 delete $req->{urldc};
208 0 return PE_BADURL;
209 }
210 17 my ( $proto, $vhost, $appuri );
211 17 ▶ if ($tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp) 17 0 17
212 17 my $u = URI->new($tmp);
213 17 ▶ if ( $u->scheme =~ /^https?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($u->scheme =~ /^https?$/) 17 0 17
214 17 $proto = $u->scheme;
215 17 ▶ $vhost = $u->host if $u->can("host");
Branch: 1 branch
BranchTrueFalseTotal
if $u->can("host") 17 0 17
216 17 $appuri = $u->path_query;
217 }
218 }
219  
220 # Try to resolve alias
221 17 my $originalVhost = $self->HANDLER->resolveAlias($vhost);
222 17 $vhost = "$proto://$originalVhost";
223 17 ▶ $self->logger->debug( 'Required URL (param: urldc'
Branch: 1 branch
BranchTrueFalseTotal
$tmp ? : 17 0 17
224 . ( $tmp ? " | value: $tmp | alias: $vhost)" : ')' ) );
225  
226 # If the target URL has an authLevel set in config, remember it.
227 17 my $level = $self->HANDLER->getLevel( $req, $appuri, $originalVhost );
228  
229 17 ▶ if ($level) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level) 0 17 17
230 0 $self->logger->debug( "VirtualHost $originalVhost requires"
231 . " authentication level $level" );
232 0 $req->pdata->{targetAuthnLevel} = $level;
233 }
234  
235 17 ▶ if ( $tmp
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp and not $self->isTrustedUrl($tmp) and not $self->isTrustedUrl($vhost)) 0 17 17
Condition33%2/6
$tmp and not $self->isTrustedUrl($tmp) and not $self->isTrustedUrl($vhost)
!ll&&!rl&&r
1700
$tmp and not $self->isTrustedUrl($tmp)
!ll&&!rl&&r
0170
MC/DC0%0/3
$tmp and not $self->isTrustedUrl($tmp) and not $self->isTrustedUrl($vhost)
$tmp not $self->isTrustedUrl($tmp) not $self->isTrustedUrl($vhost)
Truth table25%1/4
A and not(B) and not(C)
A= $tmpB= not $self->isTrustedUrl($tmp)C= not $self->isTrustedUrl($vhost)
ABCresult
0XX0
10X0
1100
1111
236 and !$self->isTrustedUrl($tmp)
237 and !$self->isTrustedUrl($vhost) )
238 {
239 0 $self->auditLog(
240 $req,
241 message => (
242 "URL contains an unprotected host (param: urldc"
243 . " | value: $tmp | alias: $vhost)"
244 ),
245 code => "UNAUTHORIZED_REDIRECT",
246 url => $tmp,
247 );
248 0 delete $req->{urldc};
249 0 return PE_UNPROTECTEDURL;
250 }
251  
252 17 $req->env->{urldc} = $req->{urldc};
253 17 $req->env->{_url} = $req->{_url};
254 $req->data->{_url} = $req->pdata->{_url} =
255 17 encode_base64( $req->{urldc}, '' ); # Avoid \n or \r
256 }
257 245 return PE_OK;
258 }
259  
260 sub cleanPdata {
261 0 ▶ my ( $self, $req ) = @_;
Subroutine cleanPdata: not called CC=6 SCAR=37.4
Pod undocumented
262 0 ▶ my $tmp = $req->pdata->{keepPdata} //= [];
Condition0%0/2
$req->pdata->{"keepPdata"} //= []
l!l
00
MC/DC0%0/1
$req->pdata->{"keepPdata"} //= []
$req->pdata->{"keepPdata"}
Truth table0%0/2
A
A= $req->pdata->{"keepPdata"}
Aresult
11
00
263 0 foreach my $k ( keys %{ $req->pdata } ) {
264 0 ▶ unless ( grep { $_ eq $k } @$tmp ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ eq $k;} @$tmp) 0 0 0
265 0 $self->logger->debug("Removing $k from pdata");
266 0 delete $req->pdata->{$k};
267 }
268 }
269 0 my $user_log = $req->{sessionInfo}->{ $self->conf->{whatToTrace} };
270 0 my $auth_module = $req->{sessionInfo}->{_auth};
271 0 my $ipAddr = $req->{sessionInfo}->{ipAddr};
272  
273 0 ▶ if ($user_log) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user_log) 0 0 0
274 0 $self->auditLog(
275 $req,
276 message => (
277 "User " . $user_log . " connected from $auth_module ($ipAddr)"
278 ),
279 code => "LOGIN",
280 user => $user_log,
281 );
282 }
283 0 ▶ if (@$tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tmp) 0 0 0
284 0 $self->logger->debug( 'Add ' . join( ',', @$tmp ) . ' in keepPdata' );
285 0 $req->pdata->{keepPdata} = $tmp;
286 }
287 0 return PE_OK;
288 }
289  
290 sub checkLogout {
291 0 ▶ my ( $self, $req ) = @_;
Subroutine checkLogout: not called CC=2 SCAR=17.9
Pod undocumented
292 0 ▶ if ( defined $req->param('logout') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $req->param("logout")) 0 0 0
293 0 $req->data->{nofail} = 1;
294 $req->steps(
295 0 [ @{ $self->beforeLogout }, 'authLogout', 'deleteSession' ] );
296 }
297 0 return PE_OK;
298 }
299  
300 sub checkUnauthLogout {
301 231 ▶ my ( $self, $req ) = @_;
Subroutine checkUnauthLogout: called CC=2 SCAR=6.9
Pod undocumented
302 231 ▶ if ( defined $req->param('logout') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $req->param("logout")) 26 205 231
303 26 $self->_unauthLogout($req);
304 26 $req->steps( [ 'controlUrl', [ returnPE => PE_LOGOUT_OK ] ] );
305 }
306 231 return PE_OK;
307 }
308  
309 sub returnPE {
310 107 ▶ my ( $self, $req, $code ) = @_;
Subroutine returnPE: called CC=1 SCAR=0.0
Pod undocumented
311  
312 107 return $code;
313 }
314  
315 sub eventLogout {
316 2 ▶ my ( $self, $req, $msg ) = @_;
Subroutine eventLogout: called CC=3 SCAR=16.0
Pod undocumented
317 2 bless $req, 'Lemonldap::NG::Portal::Main::Request';
318 2 $self->logger->debug("Receive a logout event");
319 2 $self->processHook( $req, 'eventLogout', $msg );
320 2 ▶ if ( $msg->{id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg->{'id'}) { } 0 2 2
321 0 $self->logger->debug(" -> logout asked for $msg->{id}");
322 0 ▶ if ( my $session = HANDLER->retrieveSession( $req, $msg->{id} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $session = 'Lemonldap::NG::Handler::PSGI::Main'->retrieveSession($req, $msg->{'id'})) { } 0 0 0
323 0 $req->sessionInfo( $req->userData($session) );
324 0 $req->id( $session->{_session_id} );
325 0 $req->pdata( {} );
326 $self->do( $req,
327 0 [ @{ $self->beforeLogout }, 'authLogout', 'deleteSession' ],
328 1 );
329 }
330 else {
331 0 $self->logger->debug('Session not found');
332 0 $self->_unauthLogout($req);
333 }
334 }
335 else {
336 2 $self->logger->debug('Logout event without id');
337 2 $self->_unauthLogout($req);
338 }
339 }
340  
341 sub checkCancel {
342 166 ▶ my ( $self, $req ) = @_;
Subroutine checkCancel: called CC=2 SCAR=6.9
Pod undocumented
343 166 ▶ if ( $req->param('cancel') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->param("cancel")) 1 165 166
344 1 $self->logger->debug('Cancel called, run authCancel calls');
345 1 $req->mustRedirect(1);
346 1 $req->steps( [ @{ $self->authCancel }, [ returnPE => PE_OK ] ] );
347 1 return PE_OK;
348 }
349 165 return PE_OK;
350 }
351  
352 sub authLogout {
353 0 ▶ my ( $self, $req ) = @_;
Subroutine authLogout: not called CC=5 SCAR=34.0
Pod undocumented
354 0 my $res = $self->_authentication->authLogout($req);
355 0 $self->logger->debug('Cleaning pdata');
356 0 ▶ my $tmp = $req->pdata->{keepPdata} //= [];
Condition0%0/2
$req->pdata->{"keepPdata"} //= []
l!l
00
MC/DC0%0/1
$req->pdata->{"keepPdata"} //= []
$req->pdata->{"keepPdata"}
Truth table0%0/2
A
A= $req->pdata->{"keepPdata"}
Aresult
11
00
357 0 foreach my $k ( keys %{ $req->pdata } ) {
358 0 ▶ delete $req->pdata->{$k} unless ( grep { $_ eq $k } @$tmp );
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $k;} @$tmp 0 0 0
359 }
360 0 ▶ $req->pdata->{keepPdata} = $tmp if @$tmp;
Branch: 1 branch
BranchTrueFalseTotal
if @$tmp 0 0 0
361 0 return $res;
362 }
363  
364 sub deleteSession {
365 0 ▶ my ( $self, $req ) = @_;
Subroutine deleteSession: not called CC=19 SCAR=59.4
Pod undocumented
366 0 ▶ if ( my $id = $req->id || $req->userData->{_session_id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $id = $req->id || $req->userData->{"_session_id"}) 0 0 0
Condition0%0/3
$req->id || $req->userData->{'_session_id'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$req->id || $req->userData->{'_session_id'}
$req->id $req->userData->{'_session_id'}
Truth table0%0/3
A || B
A= $req->idB= $req->userData->{'_session_id'}
ABresult
1X1
011
000
367 0 my $apacheSession = $self->getApacheSession($id);
368 0 ▶ unless ($apacheSession) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($apacheSession) 0 0 0
369 0 $self->logger->debug("Session $id already deleted");
370 0 return PE_OK;
371 }
372 0 ▶ unless ( $self->_deleteSession( $req, $apacheSession ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_deleteSession($req, $apacheSession)) { } 0 0 0
373 0 $self->logger->error("Unable to delete session $id");
374 0 $self->logger->error( $apacheSession->error );
375 0 return PE_ERROR;
376 }
377 else {
378 0 $self->logger->debug("Session $id deleted from global storage");
379 }
380 }
381  
382 # Merge logoutServices from user context (for example CAS logoutServices
383 # url) and from global configuration
384 0 ▶ if ( $self->conf->{logoutServices}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"logoutServices"} and %{$self->conf->{"logoutServices"};}) 0 0 0
Condition0%0/3
$self->conf->{"logoutServices"} and %{$self->conf->{"logoutServices"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->conf->{"logoutServices"} and %{$self->conf->{"logoutServices"};}
$self->conf->{"logoutServices"} %{$self->conf->{"logoutServices"};}
Truth table0%0/3
A and B
A= $self->conf->{"logoutServices"}B= %{$self->conf->{"logoutServices"};}
ABresult
0X0
100
111
385 0 and %{ $self->conf->{logoutServices} } )
386 {
387  
388 # Initialize logoutServices (if not already done)
389 0 ▶ $req->data->{logoutServices} ||= {};
Condition0%0/2
$req->data->{"logoutServices"} ||= {}
l!l
00
MC/DC0%0/1
$req->data->{"logoutServices"} ||= {}
$req->data->{"logoutServices"}
Truth table0%0/2
A
A= $req->data->{"logoutServices"}
Aresult
11
00
390 $req->data->{logoutServices} = {
391 0 %{ $req->data->{logoutServices} },
392 0 %{ $self->conf->{logoutServices} }
393 };
394 }
395  
396 # Collect logout services and build hidden iFrames
397 0 ▶ if ( $req->data->{logoutServices}
Branch: 1 branch
BranchTrueFalseTotal
if ($req->data->{"logoutServices"} and %{$req->data->{"logoutServices"};}) 0 0 0
Condition0%0/3
$req->data->{"logoutServices"} and %{$req->data->{"logoutServices"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$req->data->{"logoutServices"} and %{$req->data->{"logoutServices"};}
$req->data->{"logoutServices"} %{$req->data->{"logoutServices"};}
Truth table0%0/3
A and B
A= $req->data->{"logoutServices"}B= %{$req->data->{"logoutServices"};}
ABresult
0X0
100
111
398 0 and %{ $req->data->{logoutServices} } )
399 {
400  
401 0 $self->logger->debug("Create iFrames to forward logout to services");
402  
403 0 $req->info(
404 $self->loadTemplate(
405 $req, 'simpleInfo',
406 params => { trspan => 'logoutFromOtherApp' }
407 )
408 );
409  
410 0 foreach ( keys %{ $req->data->{logoutServices} } ) {
411 0 my $logoutServiceUrl = $req->data->{logoutServices}->{$_};
412  
413 0 $self->logger->debug("Find logout service $_ ($logoutServiceUrl)");
414  
415 0 my $iframe =
416 qq'<iframe src="$logoutServiceUrl" alt="$_"'
417 . ' marginwidth="0" marginheight="0" scrolling="no"'
418 . ' class="hiddenFrame" width="0" height="0"'
419 . ' frameborder="0"></iframe>';
420  
421 0 $req->info($iframe);
422 }
423  
424 # Redirect on logout page if no other target defined
425 0 ▶ if ( !$req->urldc and !$req->postUrl ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->urldc or $req->postUrl) 0 0 0
Condition0%0/3
$req->urldc or $req->postUrl
l!l&&r!l&&!r
000
MC/DC0%0/2
$req->urldc or $req->postUrl
$req->urldc $req->postUrl
Truth table0%0/3
A or B
A= $req->urldcB= $req->postUrl
ABresult
1X1
011
000
426 0 $self->logger->debug('No other target defined, redirect on logout');
427 0 $req->urldc( $self->buildUrl( $req->portal, { logout => 1 } ) );
428 }
429 }
430 0 $req->userData( {} );
431  
432 # Redirect or Post if asked by authLogout
433 0 ▶ if ( $req->postUrl ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->postUrl) 0 0 0
434 0 $req->steps( ['autoPost'] );
435 0 return PE_OK;
436 }
437  
438 0 ▶ if ( $req->urldc and $req->urldc ne $req->portal ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->urldc and $req->urldc ne $req->portal) 0 0 0
Condition0%0/3
$req->urldc and $req->urldc ne $req->portal
!ll&&!rl&&r
000
MC/DC0%0/2
$req->urldc and $req->urldc ne $req->portal
$req->urldc $req->urldc ne $req->portal
Truth table0%0/3
A and B
A= $req->urldcB= $req->urldc ne $req->portal
ABresult
0X0
100
111
439 0 $req->steps( [] );
440 0 return PE_REDIRECT;
441 }
442  
443 # If logout redirects to another URL, just remove next steps for the
444 # request so autoRedirect will be called
445 0 ▶ if ( $req->{urldc} and $req->{urldc} ne $req->portal ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{"urldc"} and $req->{"urldc"} ne $req->portal) 0 0 0
Condition0%0/3
$req->{"urldc"} and $req->{"urldc"} ne $req->portal
!ll&&!rl&&r
000
MC/DC0%0/2
$req->{"urldc"} and $req->{"urldc"} ne $req->portal
$req->{"urldc"} $req->{"urldc"} ne $req->portal
Truth table0%0/3
A and B
A= $req->{"urldc"}B= $req->{"urldc"} ne $req->portal
ABresult
0X0
100
111
446 0 $req->steps( [] );
447 0 return PE_OK;
448 }
449  
450 # You can use the _continueLogout variable to continue the current flow
451 # after deleteSession
452 0 ▶ return PE_OK if $req->data->{_continueLogout};
Branch: 1 branch
BranchTrueFalseTotal
if $req->data->{"_continueLogout"} 0 0 0
453  
454 # Else display "error"
455 0 return PE_LOGOUT_OK;
456 }
457  
458 # Check value to detect XSS attack
459 # @param name Parameter name
460 # @param value Parameter value
461 # @return 1 if attack detected, 0 else
462 sub checkXSSAttack {
463 26 ▶ my ( $self, $name, $value ) = @_;
Subroutine checkXSSAttack: called CC=3 SCAR=11.6
Pod undocumented
464  
465 # Empty values are not bad
466 26 ▶ return 0 unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 2 24 26
467  
468 # Test value
469 24 $value =~ s/\%25/\%/g;
470 24 ▶ if ( $value =~ m/(?:\0|<|'|"|`|\%(?:00|3C|22|27))/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /(?:\0|<|'|"|`|\%(?:00|3C|22|27))/) 0 24 24
471 0 $self->logger->error(
472 "XSS attack detected (param: $name | value: $value)");
473 0 return $self->conf->{checkXSS};
474 }
475 24 return 0;
476 }
477  
478 # Relaxed version that doesn't look at URL escaped character
479 # This is meant to be used for checking urldc until we find a better solution
480 sub checkXSSAttackUrldc {
481 9 ▶ my ( $self, $name, $value ) = @_;
Subroutine checkXSSAttackUrldc: called CC=3 SCAR=11.8
Pod undocumented
482  
483 # Empty values are not bad
484 9 ▶ return 0 unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 2 7 9
485  
486 # Test value
487 7 ▶ if ( $value =~ m/(?:\0|<|'|"|`)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /(?:\0|<|'|"|`)/) 0 7 7
488 0 $self->userLogger->error(
489 "XSS attack detected (param: $name | value: $value)");
490 0 return $self->conf->{checkXSS};
491 }
492 7 return 0;
493 }
494  
495 # Second block: auth process (call auth or userDB object)
496 # -------------------------------------------------------
497  
498 sub extractFormInfo {
499 210 ▶ my ( $self, $req ) = @_;
Subroutine extractFormInfo: called CC=8 SCAR=27.2
Pod undocumented
500 210 ▶ return PE_ERROR unless ( $self->_authentication );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_authentication 0 210 210
501 210 my $ret = $self->_authentication->extractFormInfo($req);
502 210 ▶ if ( $ret == PE_OK and not( $req->user or $req->continue ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ret == 0 and not $req->user || $req->continue) { } 0 210 210
elsif ($ret == 9 and $req->cookies->{$self->conf->{'cookieName'}}) { } 0 384 384
Condition66%4/6
$ret == 0 and not $req->user || $req->continue
!ll&&!rl&&r
172380
$req->user || $req->continue
l!l&&r!l&&!r
3710
MC/DC0%0/3
$ret == 0 and not $req->user || $req->continue
$ret == 0 $req->user $req->continue
Truth table75%3/4
A and not(B || C)
A= $ret == 0B= $req->userC= $req->continue
ABCresult
0XX0
11X0
1010
1001
503 0 $self->logger->error(
504 'Authentication module succeed but has not set $req->user');
505 0 return PE_ERROR;
506 }
507 ▶ elsif ( $ret == PE_FIRSTACCESS
Condition66%2/3
$ret == 9 and $req->cookies->{$self->conf->{"cookieName"}}
!ll&&!rl&&r
174360
MC/DC0%0/2
$ret == 9 and $req->cookies->{$self->conf->{"cookieName"}}
$ret == 9 $req->cookies->{$self->conf->{"cookieName"}}
Truth table66%2/3
A and B
A= $ret == 9B= $req->cookies->{$self->conf->{"cookieName"}}
ABresult
0X0
100
111
508 and $req->cookies->{ $self->conf->{cookieName} } )
509 {
510 $req->addCookie(
511 $self->genDomainCookie(
512 $req,
513 name => $self->conf->{cookieName},
514 value => 0,
515 secure => $self->conf->{securedCookie},
516 0 expires => 'Wed, 21 Oct 2015 00:00:00 GMT'
517 )
518 );
519 0 ▶ if ( $self->conf->{portalErrorOnExpiredSession} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"portalErrorOnExpiredSession"}) 0 0 0
520 0 $ret = PE_SESSIONEXPIRED;
521 }
522 }
523 210 return $ret;
524 }
525  
526 sub getUser {
527 37 ▶ my ( $self, $req, %args ) = @_;
Subroutine getUser: called CC=2 SCAR=7.1
Pod undocumented
528 37 ▶ return PE_ERROR unless ( $self->_userDB );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_userDB 0 37 37
529 37 return $self->_userDB->getUser( $req, %args );
530 }
531  
532 sub findUser {
533 0 ▶ my ( $self, $req, %args ) = @_;
Subroutine findUser: not called CC=2 SCAR=17.9
Pod undocumented
534 0 ▶ return PE_ERROR unless ( $self->_userDB );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_userDB 0 0 0
535 0 return $self->_userDB->findUser( $req, %args );
536 }
537  
538 sub authenticate {
539 33 ▶ my ( $self, $req ) = @_;
Subroutine authenticate: called CC=3 SCAR=16.3
Pod undocumented
540 33 my $ret = $req->authResult( $self->_authentication->authenticate($req) );
541 33 $self->logger->debug( " -> authResult = " . $req->authResult );
542 33 ▶ return $ret if $ret == PE_OK;
Branch: 1 branch
BranchTrueFalseTotal
if $ret == 0 33 0 33
543  
544 # Store failed login into history
545 $req->steps( [
546 'setSessionInfo', 'setMacros',
547 'setPersistentSessionInfo', 'storeHistory',
548 0 @{ $self->afterData }, [ returnPE => PE_BADCREDENTIALS ],
549 ]
550 );
551  
552 # Ignore result, process will end at least with PE_BADCREDENTIALS
553 0 my $tmp = $self->process($req);
554 0 ▶ $ret = $tmp if ( $tmp == PE_WAIT );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp == 86 0 0 0
555 0 return $ret;
556 }
557  
558 # Third block: Session data providing
559 # -----------------------------------
560  
561 sub setAuthSessionInfo {
562 33 ▶ my ( $self, $req ) = @_;
Subroutine setAuthSessionInfo: called CC=3 SCAR=12.3
Pod undocumented
563 33 $req->{sessionInfo}->{_lastAuthnUTime} = time();
564 33 my $ret = $self->_authentication->setAuthSessionInfo($req);
565 33 ▶ if ( $ret == PE_OK
Branch: 1 branch
BranchTrueFalseTotal
if ($ret == 0 and not defined $req->sessionInfo->{"authenticationLevel"}) 0 33 33
Condition33%1/3
$ret == 0 and not defined $req->sessionInfo->{"authenticationLevel"}
!ll&&!rl&&r
0330
MC/DC0%0/2
$ret == 0 and not defined $req->sessionInfo->{"authenticationLevel"}
$ret == 0 not defined $req->sessionInfo->{"authenticationLevel"}
Truth table33%1/3
A and not(B)
A= $ret == 0B= not defined $req->sessionInfo->{"authenticationLevel"}
ABresult
0X0
100
111
566 and not( defined $req->sessionInfo->{authenticationLevel} ) )
567 {
568 0 $self->logger->error('Authentication level is not set by auth module');
569 }
570 33 return $ret;
571 }
572  
573 sub setSessionInfo {
574 33 ▶ my ( $self, $req ) = @_;
Subroutine setSessionInfo: called CC=5 SCAR=17.3
Pod undocumented
575  
576 # Set _user
577 33 ▶ $req->{sessionInfo}->{_user} //= $req->user;
Condition33%1/3
$req->{"sessionInfo"}{"_user"} //= $req->user
l!l&&r!l&&!r
0330
MC/DC0%0/2
$req->{"sessionInfo"}{"_user"} //= $req->user
$req->{"sessionInfo"}{"_user"} $req->user
Truth table33%1/3
A //= B
A= $req->{"sessionInfo"}{"_user"}B= $req->user
ABresult
1X1
011
000
578  
579 # Get the current user module
580 33 $req->{sessionInfo}->{_auth} = $self->getModule( $req, "auth" );
581 33 $req->{sessionInfo}->{_userDB} = $self->getModule( $req, "user" );
582  
583 # Store IP address from remote address or X-FORWARDED-FOR header
584 33 $req->{sessionInfo}->{ipAddr} = $req->address;
585  
586 # Date and time
587 33 ▶ if ( $self->conf->{updateSession} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{'updateSession'}) { } 0 33 33
588 $req->{sessionInfo}->{_updateTime} =
589 0 strftime( "%Y%m%d%H%M%S", localtime() );
590 }
591 else {
592 33 ▶ $req->{sessionInfo}->{_utime} ||= time();
Condition33%1/3
$req->{"sessionInfo"}{"_utime"} ||= &CORE::GLOBAL::time()
l!l&&r!l&&!r
0330
MC/DC0%0/2
$req->{"sessionInfo"}{"_utime"} ||= &CORE::GLOBAL::time()
$req->{"sessionInfo"}{"_utime"} &CORE::GLOBAL::time()
Truth table33%1/3
A ||= B
A= $req->{"sessionInfo"}{"_utime"}B= &CORE::GLOBAL::time()
ABresult
1X1
011
000
593 $req->{sessionInfo}->{_startTime} =
594 33 strftime( "%Y%m%d%H%M%S", localtime() );
595 $req->{sessionInfo}->{_lastSeen} = time()
596 33 ▶ if $self->conf->{timeoutActivity};
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"timeoutActivity"} 0 33 33
597 }
598  
599 # Currently selected language
600 33 $req->{sessionInfo}->{_language} = $self->getLanguage($req);
601  
602 # Store URL origin in session
603 33 $req->{sessionInfo}->{_url} = $req->{urldc};
604  
605 # Share sessionInfo with underlying handler (needed for safe jail)
606 33 $req->userData( $req->sessionInfo );
607  
608 # Call UserDB setSessionInfo
609 33 return $self->_userDB->setSessionInfo($req);
610 }
611  
612 sub setMacros {
613 33 ▶ my ( $self, $req ) = @_;
Subroutine setMacros: called CC=2 SCAR=6.9
Pod undocumented
614 33 foreach ( sort keys %{ $self->_macros } ) {
615 $req->{sessionInfo}->{$_} =
616 132 $self->_macros->{$_}->( $req, $req->sessionInfo );
617 }
618 33 return PE_OK;
619 }
620  
621 sub setGroups {
622 33 ▶ my ( $self, $req ) = @_;
Subroutine setGroups: called CC=1 SCAR=0.0
Pod undocumented
623 33 return $self->_userDB->setGroups($req);
624 }
625  
626 sub setPersistentSessionInfo {
627 33 ▶ my ( $self, $req ) = @_;
Subroutine setPersistentSessionInfo: called CC=6 SCAR=18.3
Pod undocumented
628  
629 33 my $key = $req->{sessionInfo}->{ $self->conf->{whatToTrace} };
630  
631 33 ▶ return PE_OK unless ( $key and length($key) );
Branch: 1 branch
BranchTrueFalseTotal
unless $key and length $key 0 33 33
Condition33%1/3
$key and length $key
!ll&&!rl&&r
0033
MC/DC0%0/2
$key and length $key
$key length $key
Truth table33%1/3
A and B
A= $keyB= length $key
ABresult
0X0
100
111
632  
633 33 my $persistentSession = $self->getPersistentSession($key);
634 33 ▶ if ($persistentSession) {
Branch: 1 branch
BranchTrueFalseTotal
if ($persistentSession) 33 0 33
635 33 $self->logger->debug("Persistent session found for $key");
636 33 foreach my $k ( keys %{ $persistentSession->data } ) {
637  
638 # Do not restore some parameters
639 131 ▶ next if $k =~ /^_(?:utime|session_(?:u?id|kind))$/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^_(?:utime|session_(?:u?id|kind))$/ 130 1 131
640 1 $self->logger->debug("Restore persistent parameter $k");
641 1 $req->{sessionInfo}->{$k} = $persistentSession->data->{$k};
642 }
643 }
644 33 return PE_OK;
645 }
646  
647 sub setLocalGroups {
648 33 ▶ my ( $self, $req ) = @_;
Subroutine setLocalGroups: called CC=6 SCAR=17.9
Pod undocumented
649 33 ▶ $req->{sessionInfo}->{groups} //= '';
Condition100%2/2
$req->{"sessionInfo"}{"groups"} //= ""
l!l
321
MC/DC100%1/1
$req->{"sessionInfo"}{"groups"} //= ""
$req->{"sessionInfo"}{"groups"}
Truth table100%2/2
A
A= $req->{"sessionInfo"}{"groups"}
Aresult
11
00
650 33 ▶ $req->{sessionInfo}->{hGroups} //= {};
Condition100%2/2
$req->{"sessionInfo"}{"hGroups"} //= {}
l!l
321
MC/DC100%1/1
$req->{"sessionInfo"}{"hGroups"} //= {}
$req->{"sessionInfo"}{"hGroups"}
Truth table100%2/2
A
A= $req->{"sessionInfo"}{"hGroups"}
Aresult
11
00
651 33 foreach ( sort keys %{ $self->_groups } ) {
652 99 ▶ if ( $self->_groups->{$_}->( $req, $req->sessionInfo ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_groups->{$_}->($req, $req->sessionInfo)) 25 74 99
653 $req->{sessionInfo}->{groups} .=
654 25 $self->conf->{multiValuesSeparator} . $_;
655 25 $req->{sessionInfo}->{hGroups}->{$_}->{name} = $_;
656 }
657 }
658  
659 # Clear values separator at the beginning
660 33 ▶ if ( $req->{sessionInfo}->{groups} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{"sessionInfo"}{"groups"}) 32 1 33
661 $req->{sessionInfo}->{groups} =~
662 32 s/^$self->{conf}->{multiValuesSeparator}//o;
663 }
664 33 return PE_OK;
665 }
666  
667 sub store {
668 33 ▶ my ( $self, $req ) = @_;
Subroutine store: called CC=11 SCAR=34.9
Pod undocumented
669  
670 # Now, user is authenticated => inform handler
671 33 $req->userData( $req->sessionInfo );
672  
673 # Create second session for unsecure cookie
674 33 ▶ if ( $self->conf->{securedCookie} == 2 and !$req->refresh ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"securedCookie"} == 2 and not $req->refresh) 1 32 33
Condition66%2/3
$self->conf->{"securedCookie"} == 2 and not $req->refresh
!ll&&!rl&&r
3201
MC/DC50%1/2
$self->conf->{"securedCookie"} == 2 and not $req->refresh
$self->conf->{"securedCookie"} == 2 not $req->refresh
Truth table66%2/3
A and not(B)
A= $self->conf->{"securedCookie"} == 2B= not $req->refresh
ABresult
0X0
100
111
675 1 my %infos = %{ $req->{sessionInfo} };
676 1 $infos{_updateTime} = strftime( "%Y%m%d%H%M%S", localtime() );
677 1 $self->logger->debug("Set _updateTime with $infos{_updateTime}");
678 1 $infos{_httpSessionType} = 1;
679  
680 1 my $session2 = $self->getApacheSession( undef, info => \%infos );
681 1 $self->logger->debug("Create second session for unsecured cookie");
682 1 $req->{sessionInfo}->{_httpSession} = $session2->id;
683 1 $self->logger->debug( " -> Cookie value: " . $session2->id );
684 }
685  
686 # Fill session
687 33 my $infos = {};
688 33 foreach my $k ( sort keys %{ $req->{sessionInfo} } ) {
689 33 ▶ next unless defined $req->{sessionInfo}->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $req->{"sessionInfo"}{$k} 0 33 33
690 33 my $displayValue = $req->{sessionInfo}->{$k};
691 $displayValue = '****'
692 33 ▶ if isHiddenAttr( $self->conf->{hiddenAttributes}, $k );
Branch: 1 branch
BranchTrueFalseTotal
if isHiddenAttr($self->conf->{"hiddenAttributes"}, $k) 0 0 0
693 0 $self->logger->debug("Store $displayValue in session key $k");
694 0 ▶ $self->_dump($displayValue) if ref($displayValue);
Branch: 1 branch
BranchTrueFalseTotal
if ref $displayValue 0 0 0
695 0 $infos->{$k} = $req->{sessionInfo}->{$k};
696 }
697  
698 # Main session
699 my $session = $self->getApacheSession(
700 $req->id,
701 hashStore => $req->data->{hashStore},
702 force => $req->{force},
703 0 info => $infos
704 );
705 0 ▶ return PE_APACHESESSIONERROR unless $session;
Branch: 1 branch
BranchTrueFalseTotal
unless $session 0 0 0
706  
707 # Update current request
708 0 $req->id( $session->id );
709 0 ▶ unless ( $self->_sfEngine->searchForAuthorized2Fmodules($req) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_sfEngine->searchForAuthorized2Fmodules($req)) 0 0 0
710 0 $self->logger->debug(
711 "No 2F module authorized -> Update current request");
712 0 $req->{sessionInfo}->{_session_id} = $session->{id};
713 0 $req->{sessionInfo}->{_session_kind} = $session->{kind};
714 }
715  
716 # Compute unsecured cookie value if needed
717 0 ▶ if ( $self->conf->{securedCookie} == 3 and !$req->refresh ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"securedCookie"} == 3 and not $req->refresh) 0 0 0
Condition0%0/3
$self->conf->{"securedCookie"} == 3 and not $req->refresh
!ll&&!rl&&r
000
MC/DC0%0/2
$self->conf->{"securedCookie"} == 3 and not $req->refresh
$self->conf->{"securedCookie"} == 3 not $req->refresh
Truth table0%0/3
A and not(B)
A= $self->conf->{"securedCookie"} == 3B= not $req->refresh
ABresult
0X0
100
111
718 $req->{sessionInfo}->{_httpSession} =
719 0 $self->conf->{cipher}->encryptHex( $req->id, "http" );
720 $self->logger->debug( " -> Compute unsecured cookie value : "
721 0 . $req->{sessionInfo}->{_httpSession} );
722 }
723 0 $req->refresh(0);
724 0 return PE_OK;
725 }
726  
727 sub buildCookie {
728 0 ▶ my ( $self, $req ) = @_;
Subroutine buildCookie: not called CC=6 SCAR=37.4
Pod undocumented
729 0 ▶ if ( $req->id ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->id) 0 0 0
730 $req->addCookie(
731 $self->genDomainCookie(
732 $req,
733 name => $self->conf->{cookieName},
734 value => $req->id,
735 secure => $self->conf->{securedCookie},
736 $self->conf->{cookieExpiration}
737 ? ( max_age => $self->conf->{cookieExpiration} )
738 0 ▶ : (),
Branch: 1 branch
BranchTrueFalseTotal
$self->conf->{'cookieExpiration'} ? : 0 0 0
739 )
740 );
741 0 ▶ if ( $self->conf->{securedCookie} >= 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"securedCookie"} >= 2) 0 0 0
742 $req->addCookie(
743 $self->genDomainCookie(
744 $req,
745 name => $self->conf->{cookieName} . "http",
746 value => $req->{sessionInfo}->{_httpSession},
747 secure => 0,
748 $self->conf->{cookieExpiration}
749 ? ( max_age => $self->conf->{cookieExpiration} )
750 0 ▶ : (),
Branch: 1 branch
BranchTrueFalseTotal
$self->conf->{'cookieExpiration'} ? : 0 0 0
751 )
752 );
753 }
754 }
755 my $ref = (
756 0 %{ $req->{sessionInfo} }
757 ? $req->{sessionInfo}
758 : $req->{userData}
759 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
%{$req->{'sessionInfo'};} ? : 0 0 0
760 0 $req->data->{newAuth} = 1;
761 $self->auditLog(
762 $req,
763 message => (
764 'User '
765 . $ref->{ $self->conf->{whatToTrace} }
766 . " successfully authenticated at level $ref->{authenticationLevel}"
767 ),
768 code => "AUTHENTICATED",
769 user => $ref->{ $self->conf->{whatToTrace} },
770 level => $ref->{authenticationLevel},
771 0 );
772 0 return PE_OK;
773 }
774  
775 sub secondFactor {
776 0 ▶ my ( $self, $req ) = @_;
Subroutine secondFactor: not called CC=1 SCAR=6.9
Pod undocumented
777 0 return $self->_sfEngine->run($req);
778 }
779  
780 sub storeHistory {
781 0 ▶ my ( $self, $req ) = @_;
Subroutine storeHistory: not called CC=2 SCAR=17.9
Pod undocumented
782 0 ▶ if ( $self->conf->{loginHistoryEnabled} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"loginHistoryEnabled"}) 0 0 0
783 0 $self->registerLogin($req);
784 }
785 0 return PE_OK;
786 }
787  
788 # This method returns the domain for a new cookie
789 # In modern browsers:
790 # - an empty value means the cookie is only valid on the portal itself
791 # - in other situations, the cookie is sent to all subdomains
792 # and a leading dot is added for compatibility
793 sub getCookieDomain {
794 36 ▶ my ( $self, $req ) = @_;
Subroutine getCookieDomain: called CC=4 SCAR=13.9
Pod undocumented
795  
796 36 ▶ if ( my $domain = $self->conf->{domain} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $domain = $self->conf->{"domain"}) 35 1 36
797 35 ▶ if ( $domain eq '#PORTALDOMAIN#' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($domain eq '#PORTALDOMAIN#') { } 1 34 35
elsif ($domain eq '#PORTAL#') { } 1 33 34
798 1 my $host = URI->new( $req->portal )->host;
799 1 return $host =~ s/^([^\.]*)//r;
800 }
801 elsif ( $domain eq '#PORTAL#' ) {
802 1 my $host = URI->new( $req->portal )->host;
803 1 return ".$host";
804 }
805 else {
806 33 return $domain =~ s/^(?!\.)/./r;
807 }
808 }
809 1 return;
810 }
811  
812 429 1;
« blib/lib/Lemonldap/NG/Portal/Plugins/OIDCNativeSso.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Auth/_WebForm.pm »