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

filter: Statementstmt 85.2% 340 / 399 Branchbran 67.6% 134 / 198 Conditioncond 51.1% 43 / 84 MC/DCmcdc 25.0% 13 / 52 Subroutinesub 97.3% 36 / 37 Podpod 0.0% 0 / 30 totaltotal 70.7% 566 / 800 CC 138 SCAR 30.2
CC
138
Cov
76%
controlUrl
53.0
process
49.5
deleteSession
26.0
CRAP 20.5
« blib/lib/Lemonldap/NG/Portal/Lib/SOAPProxy.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/2F/Register/Base.pm »
1 package Lemonldap::NG::Portal::Main::Process;
2  
3 442 our $VERSION = '2.23.0';
4  
5 package Lemonldap::NG::Portal::Main;
6  
7 442 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 442 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 442 ▶use POSIX qw(strftime);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 442 ▶use Lemonldap::NG::Common::Util qw(isHiddenAttr);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 442 ▶use Lemonldap::NG::Portal::Main::Constants qw(portalConsts);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 442 ▶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 728 ▶ my ( $self, $req, %args ) = @_;
Subroutine process: called CC=27 SCAR=39.0
Pod undocumented
22  
23 # Store ipAddr in env
24 728 $req->env->{ipAddr} = $req->address;
25 728 my $err = PE_OK;
26 728 my $nofail = delete $args{nofail};
27 728 ▶ if ( grep { ref $_ eq "CODE" } @{ $req->steps } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {ref $_ eq "CODE";} @{$req->steps;}) 23 705 728
28 23 $self->logger->debug(
29 "Warning: process pipeline contains non-serializable step");
30 }
31 728 ▶ while ( my $sub = shift @{ $req->steps } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = shift @{$req->steps;}) 4876 232 5108
32 4876 ▶ $nofail = 1 if $req->data->{nofail};
Branch: 1 branch
BranchTrueFalseTotal
if $req->data->{"nofail"} 128 4748 4876
33 4876 my @args_array;
34  
35 # This lets you transmit arguments by storing
36 # [ "method_name", @args_array ] in steps
37 4876 ▶ if ( ref($sub) eq "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sub eq "ARRAY") 218 4658 4876
38 218 my $sub_name = shift @$sub;
39 218 @args_array = @$sub;
40 218 $sub = $sub_name;
41 }
42 4876 ▶ if ( ref $sub eq "CODE" ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $sub eq 'CODE') { } 56 4820 4876
elsif (() = $sub =~ /(.*)::(.*)/) { } 610 4210 4820
43 56 $self->logger->debug("Processing code ref");
44 56 my $tmp = $sub->( $req, %args );
45 56 ▶ if ($tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp) 0 56 56
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 610 $self->logger->debug("Processing ${plugin}::${callback}");
52 610 my $plugin = $self->loadedModules->{$plugin};
53 610 ▶ if ( ref($plugin) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $plugin) { } 610 0 610
54 610 my $tmp = $plugin->$callback( $req, @args_array, %args );
55 610 ▶ if ($tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp) 39 571 610
56 39 ▶ $err = $tmp unless $err > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $err > 0 39 0 39
57 39 ▶ last unless $nofail and $err != PE_SENDRESPONSE;
Branch: 1 branch
BranchTrueFalseTotal
unless $nofail and $err != -4 39 0 39
Condition33%1/3
$nofail and $err != -4
!ll&&!rl&&r
3900
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 4210 $self->logger->debug("Processing $sub");
66 4210 ▶ if ( my $as = $self->aroundSub->{$sub} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $as = $self->aroundSub->{$sub}) { } 0 4210 4210
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 4210 my $tmp = $self->$sub( $req, @args_array, %args );
75 4209 ▶ if ($tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp) 495 3714 4209
76 495 ▶ $err = $tmp unless $err > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $err > 0 495 0 495
77 495 ▶ last unless $nofail and $err != PE_SENDRESPONSE;
Branch: 1 branch
BranchTrueFalseTotal
unless $nofail and $err != -4 456 39 495
Condition66%2/3
$nofail and $err != -4
!ll&&!rl&&r
456039
MC/DC50%1/2
$nofail and $err != -4
$nofail $err != -4
Truth table66%2/3
A and B
A= $nofailB= $err != -4
ABresult
0X0
100
111
78 }
79 }
80 3753 ▶ if ( $self->afterSub->{$sub} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->afterSub->{$sub}) 2 3751 3753
81 2 unshift @{ $req->steps }, @{ $self->afterSub->{$sub} };
82 }
83 }
84 }
85 727 ▶ $self->logger->debug( "Returned " . $self->_formatProcessResult($err) )
Branch: 1 branch
BranchTrueFalseTotal
if $err 534 193 727
86 if $err;
87 727 return $err;
88 }
89  
90 sub processHook {
91 655 ▶ my ( $self, $req, $hookName, @args ) = @_;
Subroutine processHook: called CC=6 SCAR=18.3
Pod undocumented
92  
93 655 $self->logger->debug("Calling hook $hookName");
94 655 my $err = PE_OK;
95 655 for my $sub ( @{ $self->hook->{$hookName} } ) {
96 17 ▶ if ( ref $sub eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sub eq 'CODE') { } 17 0 17
97  
98 # If return code is not PE_OK (0), stop processing
99 17 ▶ last if ( $err = $sub->( $req, @args ) );
Branch: 1 branch
BranchTrueFalseTotal
if $err = &$sub($req, @args) 4 13 17
100 }
101 else {
102 0 $self->logger->debug("Not a code ref: $sub");
103 }
104 }
105 655 ▶ if ( $err != PE_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err != 0) 4 651 655
106 4 my $msg = "Hook $hookName returned $err (" . portalConsts->{$err} . ")";
107 4 ▶ if ( $err > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err > 0) { } 0 4 4
108 0 $self->logger->warn($msg);
109 }
110 else {
111 # <0 error codes are normal in some use cases
112 4 $self->logger->debug($msg);
113 }
114 }
115 655 return $err;
116 }
117  
118 sub _formatProcessResult {
119 534 ▶ my ( $self, $err ) = @_;
Subroutine _formatProcessResult: called CC=2 SCAR=6.9
120 return ( ( $err > 0 ? "error" : "status" )
121 . ": $err ("
122 534 ▶ . portalConsts->{$err}
Branch: 1 branch
BranchTrueFalseTotal
$err > 0 ? : 458 76 534
123 . ")" );
124 }
125  
126 # First process block: check args
127 # -------------------------------
128  
129 # For post requests, parse data
130 sub restoreArgs {
131 148 ▶ my ( $self, $req ) = @_;
Subroutine restoreArgs: called CC=1 SCAR=0.0
Pod undocumented
132 148 $req->mustRedirect(1);
133 148 return PE_OK;
134 }
135  
136 sub importHandlerData {
137 110 ▶ my ( $self, $req ) = @_;
Subroutine importHandlerData: called CC=1 SCAR=0.0
Pod undocumented
138 110 $req->{sessionInfo} = $req->userData;
139 110 $req->id( $req->sessionInfo->{_session_id} );
140 110 $req->user( $req->sessionInfo->{ $self->conf->{whatToTrace} } );
141 110 return PE_OK;
142 }
143  
144 # Verify url and confirm parameter
145 sub controlUrl {
146 562 ▶ my ( $self, $req ) = @_;
Subroutine controlUrl: called CC=22 SCAR=39.7
Pod undocumented
147 562 ▶ if ( my $c = $req->param('confirm') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $req->param("confirm")) 0 562 562
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 562 ▶ $req->{data}->{_url} ||= '';
Condition50%1/2
$req->{"data"}{"_url"} ||= ""
l!l
0562
MC/DC0%0/1
$req->{"data"}{"_url"} ||= ""
$req->{"data"}{"_url"}
Truth table50%1/2
A
A= $req->{"data"}{"_url"}
Aresult
11
00
167 562 ▶ my $url = $req->param('url') || $req->pdata->{_url};
Condition100%3/3
$req->param('url') || $req->pdata->{'_url'}
l!l&&r!l&&!r
3016516
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 562 ▶ if ($url) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url) 46 516 562
169  
170 # REJECT NON BASE64 URL
171 46 ▶ if ( $req->urlNotBase64 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->urlNotBase64) { } 0 46 46
172 0 $req->{urldc} = $url;
173 }
174 else {
175 46 ▶ if ( $url =~ m#[^A-Za-z0-9\+/=]# ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ m[[^A-Za-z0-9\+/=]]) { } 8 38 46
176 8 ▶ unless ( $req->maybeNotBase64 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->maybeNotBase64) 0 8 8
177 0 $self->logger->error(
178 "Value must be BASE64 encoded (param: url | value: $url)"
179 );
180 0 return PE_BADURL;
181 }
182 8 $req->{urldc} = $url;
183 }
184 else {
185 38 $req->{urldc} = decode_base64($url);
186 38 $req->{urldc} =~ s/[\r\n]//sg;
187 }
188 }
189 46 $req->{urldc} = URI->new( $req->{urldc} )->as_string;
190  
191 46 my $tmp = $req->urldc;
192  
193 # XSS attack
194 46 ▶ if ( $self->checkXSSAttack( 'urldc', $req->{urldc} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->checkXSSAttack("urldc", $req->{"urldc"})) 0 46 46
195 0 delete $req->{urldc};
196 0 return PE_BADURL;
197 }
198  
199 # Unprotected hosts
200 46 ▶ 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 46 46
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
0460
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 46 my ( $proto, $vhost, $appuri );
211 46 ▶ if ($tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp) 46 0 46
212 46 my $u = URI->new($tmp);
213 46 ▶ if ( $u->scheme =~ /^https?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($u->scheme =~ /^https?$/) 46 0 46
214 46 $proto = $u->scheme;
215 46 ▶ $vhost = $u->host if $u->can("host");
Branch: 1 branch
BranchTrueFalseTotal
if $u->can("host") 46 0 46
216 46 $appuri = $u->path_query;
217 }
218 }
219  
220 # Try to resolve alias
221 46 my $originalVhost = $self->HANDLER->resolveAlias($vhost);
222 46 $vhost = "$proto://$originalVhost";
223 46 ▶ $self->logger->debug( 'Required URL (param: urldc'
Branch: 1 branch
BranchTrueFalseTotal
$tmp ? : 46 0 46
224 . ( $tmp ? " | value: $tmp | alias: $vhost)" : ')' ) );
225  
226 # If the target URL has an authLevel set in config, remember it.
227 46 my $level = $self->HANDLER->getLevel( $req, $appuri, $originalVhost );
228  
229 46 ▶ if ($level) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level) 0 46 46
230 0 $self->logger->debug( "VirtualHost $originalVhost requires"
231 . " authentication level $level" );
232 0 $req->pdata->{targetAuthnLevel} = $level;
233 }
234  
235 46 ▶ if ( $tmp
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp and not $self->isTrustedUrl($tmp) and not $self->isTrustedUrl($vhost)) 4 42 46
Condition66%4/6
$tmp and not $self->isTrustedUrl($tmp) and not $self->isTrustedUrl($vhost)
!ll&&!rl&&r
4204
$tmp and not $self->isTrustedUrl($tmp)
!ll&&!rl&&r
0424
MC/DC33%1/3
$tmp and not $self->isTrustedUrl($tmp) and not $self->isTrustedUrl($vhost)
$tmp not $self->isTrustedUrl($tmp) not $self->isTrustedUrl($vhost)
Truth table50%2/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 4 $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 4 delete $req->{urldc};
249 4 return PE_UNPROTECTEDURL;
250 }
251  
252 42 $req->env->{urldc} = $req->{urldc};
253 42 $req->env->{_url} = $req->{_url};
254 $req->data->{_url} = $req->pdata->{_url} =
255 42 encode_base64( $req->{urldc}, '' ); # Avoid \n or \r
256 }
257 558 return PE_OK;
258 }
259  
260 sub cleanPdata {
261 127 ▶ my ( $self, $req ) = @_;
Subroutine cleanPdata: called CC=6 SCAR=17.9
Pod undocumented
262 127 ▶ my $tmp = $req->pdata->{keepPdata} //= [];
Condition100%2/2
$req->pdata->{"keepPdata"} //= []
l!l
6121
MC/DC100%1/1
$req->pdata->{"keepPdata"} //= []
$req->pdata->{"keepPdata"}
Truth table100%2/2
A
A= $req->pdata->{"keepPdata"}
Aresult
11
00
263 127 foreach my $k ( keys %{ $req->pdata } ) {
264 174 ▶ unless ( grep { $_ eq $k } @$tmp ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ eq $k;} @$tmp) 162 12 174
265 162 $self->logger->debug("Removing $k from pdata");
266 162 delete $req->pdata->{$k};
267 }
268 }
269 127 my $user_log = $req->{sessionInfo}->{ $self->conf->{whatToTrace} };
270 127 my $auth_module = $req->{sessionInfo}->{_auth};
271 127 my $ipAddr = $req->{sessionInfo}->{ipAddr};
272  
273 127 ▶ if ($user_log) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user_log) 127 0 127
274 127 $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 127 ▶ if (@$tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tmp) 6 121 127
284 6 $self->logger->debug( 'Add ' . join( ',', @$tmp ) . ' in keepPdata' );
285 6 $req->pdata->{keepPdata} = $tmp;
286 }
287 127 return PE_OK;
288 }
289  
290 sub checkLogout {
291 64 ▶ my ( $self, $req ) = @_;
Subroutine checkLogout: called CC=2 SCAR=6.9
Pod undocumented
292 64 ▶ if ( defined $req->param('logout') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $req->param("logout")) 29 35 64
293 29 $req->data->{nofail} = 1;
294 $req->steps(
295 29 [ @{ $self->beforeLogout }, 'authLogout', 'deleteSession' ] );
296 }
297 64 return PE_OK;
298 }
299  
300 sub checkUnauthLogout {
301 426 ▶ my ( $self, $req ) = @_;
Subroutine checkUnauthLogout: called CC=2 SCAR=6.9
Pod undocumented
302 426 ▶ if ( defined $req->param('logout') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $req->param("logout")) 28 398 426
303 28 $self->_unauthLogout($req);
304 28 $req->steps( [ 'controlUrl', [ returnPE => PE_LOGOUT_OK ] ] );
305 }
306 426 return PE_OK;
307 }
308  
309 sub returnPE {
310 170 ▶ my ( $self, $req, $code ) = @_;
Subroutine returnPE: called CC=1 SCAR=0.0
Pod undocumented
311  
312 170 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 261 ▶ my ( $self, $req ) = @_;
Subroutine checkCancel: called CC=2 SCAR=6.9
Pod undocumented
343 261 ▶ if ( $req->param('cancel') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->param("cancel")) 1 260 261
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 260 return PE_OK;
350 }
351  
352 sub authLogout {
353 39 ▶ my ( $self, $req ) = @_;
Subroutine authLogout: called CC=5 SCAR=16.8
Pod undocumented
354 39 my $res = $self->_authentication->authLogout($req);
355 39 $self->logger->debug('Cleaning pdata');
356 39 ▶ my $tmp = $req->pdata->{keepPdata} //= [];
Condition50%1/2
$req->pdata->{"keepPdata"} //= []
l!l
039
MC/DC0%0/1
$req->pdata->{"keepPdata"} //= []
$req->pdata->{"keepPdata"}
Truth table50%1/2
A
A= $req->pdata->{"keepPdata"}
Aresult
11
00
357 39 foreach my $k ( keys %{ $req->pdata } ) {
358 39 ▶ delete $req->pdata->{$k} unless ( grep { $_ eq $k } @$tmp );
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $k;} @$tmp 39 0 39
359 }
360 39 ▶ $req->pdata->{keepPdata} = $tmp if @$tmp;
Branch: 1 branch
BranchTrueFalseTotal
if @$tmp 0 39 39
361 39 return $res;
362 }
363  
364 sub deleteSession {
365 39 ▶ my ( $self, $req ) = @_;
Subroutine deleteSession: called CC=19 SCAR=32.6
Pod undocumented
366 39 ▶ if ( my $id = $req->id || $req->userData->{_session_id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $id = $req->id || $req->userData->{"_session_id"}) 39 0 39
Condition33%1/3
$req->id || $req->userData->{'_session_id'}
l!l&&r!l&&!r
3900
MC/DC0%0/2
$req->id || $req->userData->{'_session_id'}
$req->id $req->userData->{'_session_id'}
Truth table33%1/3
A || B
A= $req->idB= $req->userData->{'_session_id'}
ABresult
1X1
011
000
367 39 my $apacheSession = $self->getApacheSession($id);
368 39 ▶ unless ($apacheSession) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($apacheSession) 0 39 39
369 0 $self->logger->debug("Session $id already deleted");
370 0 return PE_OK;
371 }
372 39 ▶ unless ( $self->_deleteSession( $req, $apacheSession ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_deleteSession($req, $apacheSession)) { } 38 1 39
373 1 $self->logger->error("Unable to delete session $id");
374 1 $self->logger->error( $apacheSession->error );
375 1 return PE_ERROR;
376 }
377 else {
378 38 $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 38 ▶ if ( $self->conf->{logoutServices}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"logoutServices"} and %{$self->conf->{"logoutServices"};}) 1 37 38
Condition66%2/3
$self->conf->{"logoutServices"} and %{$self->conf->{"logoutServices"};}
!ll&&!rl&&r
0371
MC/DC50%1/2
$self->conf->{"logoutServices"} and %{$self->conf->{"logoutServices"};}
$self->conf->{"logoutServices"} %{$self->conf->{"logoutServices"};}
Truth table66%2/3
A and B
A= $self->conf->{"logoutServices"}B= %{$self->conf->{"logoutServices"};}
ABresult
0X0
100
111
385 38 and %{ $self->conf->{logoutServices} } )
386 {
387  
388 # Initialize logoutServices (if not already done)
389 1 ▶ $req->data->{logoutServices} ||= {};
Condition50%1/2
$req->data->{"logoutServices"} ||= {}
l!l
01
MC/DC0%0/1
$req->data->{"logoutServices"} ||= {}
$req->data->{"logoutServices"}
Truth table50%1/2
A
A= $req->data->{"logoutServices"}
Aresult
11
00
390 $req->data->{logoutServices} = {
391 1 %{ $req->data->{logoutServices} },
392 1 %{ $self->conf->{logoutServices} }
393 };
394 }
395  
396 # Collect logout services and build hidden iFrames
397 38 ▶ if ( $req->data->{logoutServices}
Branch: 1 branch
BranchTrueFalseTotal
if ($req->data->{"logoutServices"} and %{$req->data->{"logoutServices"};}) 1 37 38
Condition66%2/3
$req->data->{"logoutServices"} and %{$req->data->{"logoutServices"};}
!ll&&!rl&&r
3701
MC/DC50%1/2
$req->data->{"logoutServices"} and %{$req->data->{"logoutServices"};}
$req->data->{"logoutServices"} %{$req->data->{"logoutServices"};}
Truth table66%2/3
A and B
A= $req->data->{"logoutServices"}B= %{$req->data->{"logoutServices"};}
ABresult
0X0
100
111
398 1 and %{ $req->data->{logoutServices} } )
399 {
400  
401 1 $self->logger->debug("Create iFrames to forward logout to services");
402  
403 1 $req->info(
404 $self->loadTemplate(
405 $req, 'simpleInfo',
406 params => { trspan => 'logoutFromOtherApp' }
407 )
408 );
409  
410 1 foreach ( keys %{ $req->data->{logoutServices} } ) {
411 1 my $logoutServiceUrl = $req->data->{logoutServices}->{$_};
412  
413 1 $self->logger->debug("Find logout service $_ ($logoutServiceUrl)");
414  
415 1 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 1 $req->info($iframe);
422 }
423  
424 # Redirect on logout page if no other target defined
425 1 ▶ if ( !$req->urldc and !$req->postUrl ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->urldc or $req->postUrl) 1 0 1
Condition33%1/3
$req->urldc or $req->postUrl
l!l&&r!l&&!r
001
MC/DC0%0/2
$req->urldc or $req->postUrl
$req->urldc $req->postUrl
Truth table33%1/3
A or B
A= $req->urldcB= $req->postUrl
ABresult
1X1
011
000
426 1 $self->logger->debug('No other target defined, redirect on logout');
427 1 $req->urldc( $self->buildUrl( $req->portal, { logout => 1 } ) );
428 }
429 }
430 38 $req->userData( {} );
431  
432 # Redirect or Post if asked by authLogout
433 38 ▶ if ( $req->postUrl ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->postUrl) 0 38 38
434 0 $req->steps( ['autoPost'] );
435 0 return PE_OK;
436 }
437  
438 38 ▶ if ( $req->urldc and $req->urldc ne $req->portal ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->urldc and $req->urldc ne $req->portal) 1 37 38
Condition66%2/3
$req->urldc and $req->urldc ne $req->portal
!ll&&!rl&&r
3701
MC/DC50%1/2
$req->urldc and $req->urldc ne $req->portal
$req->urldc $req->urldc ne $req->portal
Truth table66%2/3
A and B
A= $req->urldcB= $req->urldc ne $req->portal
ABresult
0X0
100
111
439 1 $req->steps( [] );
440 1 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 37 ▶ if ( $req->{urldc} and $req->{urldc} ne $req->portal ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{"urldc"} and $req->{"urldc"} ne $req->portal) 0 37 37
Condition33%1/3
$req->{"urldc"} and $req->{"urldc"} ne $req->portal
!ll&&!rl&&r
3700
MC/DC0%0/2
$req->{"urldc"} and $req->{"urldc"} ne $req->portal
$req->{"urldc"} $req->{"urldc"} ne $req->portal
Truth table33%1/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 37 ▶ return PE_OK if $req->data->{_continueLogout};
Branch: 1 branch
BranchTrueFalseTotal
if $req->data->{"_continueLogout"} 0 37 37
453  
454 # Else display "error"
455 37 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 72 ▶ my ( $self, $name, $value ) = @_;
Subroutine checkXSSAttack: called CC=3 SCAR=11.6
Pod undocumented
464  
465 # Empty values are not bad
466 72 ▶ return 0 unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 4 68 72
467  
468 # Test value
469 68 $value =~ s/\%25/\%/g;
470 68 ▶ if ( $value =~ m/(?:\0|<|'|"|`|\%(?:00|3C|22|27))/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /(?:\0|<|'|"|`|\%(?:00|3C|22|27))/) 0 68 68
471 0 $self->logger->error(
472 "XSS attack detected (param: $name | value: $value)");
473 0 return $self->conf->{checkXSS};
474 }
475 68 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 67 ▶ my ( $self, $name, $value ) = @_;
Subroutine checkXSSAttackUrldc: called CC=3 SCAR=11.8
Pod undocumented
482  
483 # Empty values are not bad
484 67 ▶ return 0 unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 34 33 67
485  
486 # Test value
487 33 ▶ if ( $value =~ m/(?:\0|<|'|"|`)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /(?:\0|<|'|"|`)/) 0 33 33
488 0 $self->userLogger->error(
489 "XSS attack detected (param: $name | value: $value)");
490 0 return $self->conf->{checkXSS};
491 }
492 33 return 0;
493 }
494  
495 # Second block: auth process (call auth or userDB object)
496 # -------------------------------------------------------
497  
498 sub extractFormInfo {
499 417 ▶ my ( $self, $req ) = @_;
Subroutine extractFormInfo: called CC=8 SCAR=22.1
Pod undocumented
500 417 ▶ return PE_ERROR unless ( $self->_authentication );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_authentication 0 417 417
501 417 my $ret = $self->_authentication->extractFormInfo($req);
502 417 ▶ 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 417 417
elsif ($ret == 9 and $req->cookies->{$self->conf->{'cookieName'}}) { } 32 712 744
Condition66%4/6
$ret == 0 and not $req->user || $req->continue
!ll&&!rl&&r
2651520
$req->user || $req->continue
l!l&&r!l&&!r
14930
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
Condition100%3/3
$ret == 9 and $req->cookies->{$self->conf->{"cookieName"}}
!ll&&!rl&&r
3275832
MC/DC100%2/2
$ret == 9 and $req->cookies->{$self->conf->{"cookieName"}}
$ret == 9 $req->cookies->{$self->conf->{"cookieName"}}
Truth table100%3/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 32 expires => 'Wed, 21 Oct 2015 00:00:00 GMT'
517 )
518 );
519 32 ▶ if ( $self->conf->{portalErrorOnExpiredSession} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"portalErrorOnExpiredSession"}) 32 0 32
520 32 $ret = PE_SESSIONEXPIRED;
521 }
522 }
523 417 return $ret;
524 }
525  
526 sub getUser {
527 153 ▶ my ( $self, $req, %args ) = @_;
Subroutine getUser: called CC=2 SCAR=7.1
Pod undocumented
528 153 ▶ return PE_ERROR unless ( $self->_userDB );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_userDB 0 153 153
529 153 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 131 ▶ my ( $self, $req ) = @_;
Subroutine authenticate: called CC=3 SCAR=11.0
Pod undocumented
540 131 my $ret = $req->authResult( $self->_authentication->authenticate($req) );
541 131 $self->logger->debug( " -> authResult = " . $req->authResult );
542 131 ▶ return $ret if $ret == PE_OK;
Branch: 1 branch
BranchTrueFalseTotal
if $ret == 0 130 1 131
543  
544 # Store failed login into history
545 $req->steps( [
546 'setSessionInfo', 'setMacros',
547 'setPersistentSessionInfo', 'storeHistory',
548 1 @{ $self->afterData }, [ returnPE => PE_BADCREDENTIALS ],
549 ]
550 );
551  
552 # Ignore result, process will end at least with PE_BADCREDENTIALS
553 1 my $tmp = $self->process($req);
554 1 ▶ $ret = $tmp if ( $tmp == PE_WAIT );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp == 86 0 1 1
555 1 return $ret;
556 }
557  
558 # Third block: Session data providing
559 # -----------------------------------
560  
561 sub setAuthSessionInfo {
562 131 ▶ my ( $self, $req ) = @_;
Subroutine setAuthSessionInfo: called CC=3 SCAR=12.3
Pod undocumented
563 131 $req->{sessionInfo}->{_lastAuthnUTime} = time();
564 131 my $ret = $self->_authentication->setAuthSessionInfo($req);
565 131 ▶ if ( $ret == PE_OK
Branch: 1 branch
BranchTrueFalseTotal
if ($ret == 0 and not defined $req->sessionInfo->{"authenticationLevel"}) 0 131 131
Condition33%1/3
$ret == 0 and not defined $req->sessionInfo->{"authenticationLevel"}
!ll&&!rl&&r
01310
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 131 return $ret;
571 }
572  
573 sub setSessionInfo {
574 134 ▶ my ( $self, $req ) = @_;
Subroutine setSessionInfo: called CC=5 SCAR=16.8
Pod undocumented
575  
576 # Set _user
577 134 ▶ $req->{sessionInfo}->{_user} //= $req->user;
Condition33%1/3
$req->{"sessionInfo"}{"_user"} //= $req->user
l!l&&r!l&&!r
01340
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 134 $req->{sessionInfo}->{_auth} = $self->getModule( $req, "auth" );
581 134 $req->{sessionInfo}->{_userDB} = $self->getModule( $req, "user" );
582  
583 # Store IP address from remote address or X-FORWARDED-FOR header
584 134 $req->{sessionInfo}->{ipAddr} = $req->address;
585  
586 # Date and time
587 134 ▶ if ( $self->conf->{updateSession} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{'updateSession'}) { } 0 134 134
588 $req->{sessionInfo}->{_updateTime} =
589 0 strftime( "%Y%m%d%H%M%S", localtime() );
590 }
591 else {
592 134 ▶ $req->{sessionInfo}->{_utime} ||= time();
Condition33%1/3
$req->{"sessionInfo"}{"_utime"} ||= &CORE::GLOBAL::time()
l!l&&r!l&&!r
01340
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 134 strftime( "%Y%m%d%H%M%S", localtime() );
595 $req->{sessionInfo}->{_lastSeen} = time()
596 134 ▶ if $self->conf->{timeoutActivity};
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"timeoutActivity"} 3 131 134
597 }
598  
599 # Currently selected language
600 134 $req->{sessionInfo}->{_language} = $self->getLanguage($req);
601  
602 # Store URL origin in session
603 134 $req->{sessionInfo}->{_url} = $req->{urldc};
604  
605 # Share sessionInfo with underlying handler (needed for safe jail)
606 134 $req->userData( $req->sessionInfo );
607  
608 # Call UserDB setSessionInfo
609 134 return $self->_userDB->setSessionInfo($req);
610 }
611  
612 sub setMacros {
613 135 ▶ my ( $self, $req ) = @_;
Subroutine setMacros: called CC=2 SCAR=6.9
Pod undocumented
614 135 foreach ( sort keys %{ $self->_macros } ) {
615 $req->{sessionInfo}->{$_} =
616 540 $self->_macros->{$_}->( $req, $req->sessionInfo );
617 }
618 135 return PE_OK;
619 }
620  
621 sub setGroups {
622 133 ▶ my ( $self, $req ) = @_;
Subroutine setGroups: called CC=1 SCAR=0.0
Pod undocumented
623 133 return $self->_userDB->setGroups($req);
624 }
625  
626 sub setPersistentSessionInfo {
627 130 ▶ my ( $self, $req ) = @_;
Subroutine setPersistentSessionInfo: called CC=6 SCAR=18.3
Pod undocumented
628  
629 130 my $key = $req->{sessionInfo}->{ $self->conf->{whatToTrace} };
630  
631 130 ▶ return PE_OK unless ( $key and length($key) );
Branch: 1 branch
BranchTrueFalseTotal
unless $key and length $key 0 130 130
Condition33%1/3
$key and length $key
!ll&&!rl&&r
00130
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 130 my $persistentSession = $self->getPersistentSession($key);
634 130 ▶ if ($persistentSession) {
Branch: 1 branch
BranchTrueFalseTotal
if ($persistentSession) 130 0 130
635 130 $self->logger->debug("Persistent session found for $key");
636 130 foreach my $k ( keys %{ $persistentSession->data } ) {
637  
638 # Do not restore some parameters
639 519 ▶ next if $k =~ /^_(?:utime|session_(?:u?id|kind))$/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^_(?:utime|session_(?:u?id|kind))$/ 518 1 519
640 1 $self->logger->debug("Restore persistent parameter $k");
641 1 $req->{sessionInfo}->{$k} = $persistentSession->data->{$k};
642 }
643 }
644 130 return PE_OK;
645 }
646  
647 sub setLocalGroups {
648 134 ▶ my ( $self, $req ) = @_;
Subroutine setLocalGroups: called CC=6 SCAR=17.9
Pod undocumented
649 134 ▶ $req->{sessionInfo}->{groups} //= '';
Condition100%2/2
$req->{"sessionInfo"}{"groups"} //= ""
l!l
11420
MC/DC100%1/1
$req->{"sessionInfo"}{"groups"} //= ""
$req->{"sessionInfo"}{"groups"}
Truth table100%2/2
A
A= $req->{"sessionInfo"}{"groups"}
Aresult
11
00
650 134 ▶ $req->{sessionInfo}->{hGroups} //= {};
Condition100%2/2
$req->{"sessionInfo"}{"hGroups"} //= {}
l!l
11420
MC/DC100%1/1
$req->{"sessionInfo"}{"hGroups"} //= {}
$req->{"sessionInfo"}{"hGroups"}
Truth table100%2/2
A
A= $req->{"sessionInfo"}{"hGroups"}
Aresult
11
00
651 134 foreach ( sort keys %{ $self->_groups } ) {
652 402 ▶ if ( $self->_groups->{$_}->( $req, $req->sessionInfo ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_groups->{$_}->($req, $req->sessionInfo)) 121 281 402
653 $req->{sessionInfo}->{groups} .=
654 121 $self->conf->{multiValuesSeparator} . $_;
655 121 $req->{sessionInfo}->{hGroups}->{$_}->{name} = $_;
656 }
657 }
658  
659 # Clear values separator at the beginning
660 134 ▶ if ( $req->{sessionInfo}->{groups} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{"sessionInfo"}{"groups"}) 114 20 134
661 $req->{sessionInfo}->{groups} =~
662 114 s/^$self->{conf}->{multiValuesSeparator}//o;
663 }
664 134 return PE_OK;
665 }
666  
667 sub store {
668 129 ▶ my ( $self, $req ) = @_;
Subroutine store: called CC=11 SCAR=24.1
Pod undocumented
669  
670 # Now, user is authenticated => inform handler
671 129 $req->userData( $req->sessionInfo );
672  
673 # Create second session for unsecure cookie
674 129 ▶ if ( $self->conf->{securedCookie} == 2 and !$req->refresh ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"securedCookie"} == 2 and not $req->refresh) 1 128 129
Condition66%2/3
$self->conf->{"securedCookie"} == 2 and not $req->refresh
!ll&&!rl&&r
12801
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 129 my $infos = {};
688 129 foreach my $k ( sort keys %{ $req->{sessionInfo} } ) {
689 2593 ▶ next unless defined $req->{sessionInfo}->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $req->{"sessionInfo"}{$k} 241 2352 2593
690 2352 my $displayValue = $req->{sessionInfo}->{$k};
691 2352 ▶ $displayValue = '****' if isHiddenAttr( $self->conf, $k );
Branch: 1 branch
BranchTrueFalseTotal
if isHiddenAttr($self->conf, $k) 2 2350 2352
692 2352 $self->logger->debug("Store $displayValue in session key $k");
693 2352 ▶ $self->_dump($displayValue) if ref($displayValue);
Branch: 1 branch
BranchTrueFalseTotal
if ref $displayValue 129 2223 2352
694 2352 $infos->{$k} = $req->{sessionInfo}->{$k};
695 }
696  
697 # Main session
698 my $session = $self->getApacheSession(
699 $req->id,
700 hashStore => $req->data->{hashStore},
701 force => $req->{force},
702 129 info => $infos
703 );
704 129 ▶ return PE_APACHESESSIONERROR unless $session;
Branch: 1 branch
BranchTrueFalseTotal
unless $session 1 128 129
705  
706 # Update current request
707 128 $req->id( $session->id );
708 128 ▶ unless ( $self->_sfEngine->searchForAuthorized2Fmodules($req) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_sfEngine->searchForAuthorized2Fmodules($req)) 126 2 128
709 126 $self->logger->debug(
710 "No 2F module authorized -> Update current request");
711 126 $req->{sessionInfo}->{_session_id} = $session->{id};
712 126 $req->{sessionInfo}->{_session_kind} = $session->{kind};
713 }
714  
715 # Compute unsecured cookie value if needed
716 128 ▶ if ( $self->conf->{securedCookie} == 3 and !$req->refresh ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"securedCookie"} == 3 and not $req->refresh) 0 128 128
Condition33%1/3
$self->conf->{"securedCookie"} == 3 and not $req->refresh
!ll&&!rl&&r
12800
MC/DC0%0/2
$self->conf->{"securedCookie"} == 3 and not $req->refresh
$self->conf->{"securedCookie"} == 3 not $req->refresh
Truth table33%1/3
A and not(B)
A= $self->conf->{"securedCookie"} == 3B= not $req->refresh
ABresult
0X0
100
111
717 $req->{sessionInfo}->{_httpSession} =
718 0 $self->conf->{cipher}->encryptHex( $req->id, "http" );
719 $self->logger->debug( " -> Compute unsecured cookie value : "
720 0 . $req->{sessionInfo}->{_httpSession} );
721 }
722 128 $req->refresh(0);
723 128 return PE_OK;
724 }
725  
726 sub buildCookie {
727 126 ▶ my ( $self, $req ) = @_;
Subroutine buildCookie: called CC=7 SCAR=20.7
Pod undocumented
728 126 ▶ if ( $req->id ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->id) 126 0 126
729 $req->addCookie(
730 $self->genDomainCookie(
731 $req,
732 name => $self->conf->{cookieName},
733 value => $req->id,
734 secure => $self->conf->{securedCookie},
735 $self->conf->{cookieExpiration}
736 ? ( max_age => $self->conf->{cookieExpiration} )
737 126 ▶ : (),
Branch: 1 branch
BranchTrueFalseTotal
$self->conf->{'cookieExpiration'} ? : 0 126 126
738 )
739 );
740 126 ▶ if ( $self->conf->{securedCookie} >= 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"securedCookie"} >= 2) 1 125 126
741 $req->addCookie(
742 $self->genDomainCookie(
743 $req,
744 name => $self->conf->{cookieName} . "http",
745 value => $req->{sessionInfo}->{_httpSession},
746 secure => 0,
747 $self->conf->{cookieExpiration}
748 ? ( max_age => $self->conf->{cookieExpiration} )
749 1 ▶ : (),
Branch: 1 branch
BranchTrueFalseTotal
$self->conf->{'cookieExpiration'} ? : 0 1 1
750 )
751 );
752 }
753 }
754 my $ref = (
755 126 %{ $req->{sessionInfo} }
756 ? $req->{sessionInfo}
757 126 ▶ : $req->userData
Branch: 1 branch
BranchTrueFalseTotal
%{$req->{'sessionInfo'};} ? : 126 0 126
758 );
759 126 $req->data->{newAuth} = 1;
760  
761 126 my $whatToTrace = $ref->{ $self->conf->{whatToTrace} };
762 126 ▶ if ( !$whatToTrace ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($whatToTrace) 0 126 126
763 $self->logger->error( "Could not obtain main identifier ("
764 . $self->conf->{whatToTrace}
765 0 . ") of user. Aborting authentication" );
766 0 return PE_ERROR;
767  
768 }
769  
770 $self->auditLog(
771 $req,
772 message => (
773 "User $whatToTrace "
774 . " successfully authenticated at level $ref->{authenticationLevel}"
775 ),
776 code => "AUTHENTICATED",
777 user => $whatToTrace,
778 level => $ref->{authenticationLevel},
779 126 );
780 126 return PE_OK;
781 }
782  
783 sub secondFactor {
784 128 ▶ my ( $self, $req ) = @_;
Subroutine secondFactor: called CC=1 SCAR=0.0
Pod undocumented
785 128 return $self->_sfEngine->run($req);
786 }
787  
788 sub storeHistory {
789 128 ▶ my ( $self, $req ) = @_;
Subroutine storeHistory: called CC=2 SCAR=7.6
Pod undocumented
790 128 ▶ if ( $self->conf->{loginHistoryEnabled} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"loginHistoryEnabled"}) 0 128 128
791 0 $self->registerLogin($req);
792 }
793 128 return PE_OK;
794 }
795  
796 # This method returns the domain for a new cookie
797 # In modern browsers:
798 # - an empty value means the cookie is only valid on the portal itself
799 # - in other situations, the cookie is sent to all subdomains
800 # and a leading dot is added for compatibility
801 sub getCookieDomain {
802 251 ▶ my ( $self, $req ) = @_;
Subroutine getCookieDomain: called CC=4 SCAR=13.9
Pod undocumented
803  
804 251 ▶ if ( my $domain = $self->conf->{domain} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $domain = $self->conf->{"domain"}) 250 1 251
805 250 ▶ if ( $domain eq '#PORTALDOMAIN#' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($domain eq '#PORTALDOMAIN#') { } 3 247 250
elsif ($domain eq '#PORTAL#') { } 1 246 247
806 3 my $host = URI->new( $req->portal )->host;
807 3 return $host =~ s/^([^\.]*)//r;
808 }
809 elsif ( $domain eq '#PORTAL#' ) {
810 1 my $host = URI->new( $req->portal )->host;
811 1 return ".$host";
812 }
813 else {
814 246 return $domain =~ s/^(?!\.)/./r;
815 }
816 }
817 1 return;
818 }
819  
820 442 1;
« blib/lib/Lemonldap/NG/Portal/Lib/SOAPProxy.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/2F/Register/Base.pm »