blib/lib/Lemonldap/NG/Portal/Plugins/Upgrade.pm

filter: Statementstmt 23.3% 18 / 77 Branchbran 3.5% 1 / 28 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 38.4% 5 / 13 Podpod 0.0% 0 / 9 totaltotal 14.9% 24 / 161 CC 23 SCAR 43.6
CC
23
Cov
15%
confirm
156.0
ask
90.0
handleAuthRequests
12.0
CRAP 78.2
« blib/lib/Lemonldap/NG/Portal/2F/Register/WebAuthn.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Plugins/BruteForceProtection.pm »
1 package Lemonldap::NG::Portal::Plugins::Upgrade;
2  
3 93 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 93 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 93 use Lemonldap::NG::Portal::Main::Constants qw(
6 PE_OK
7 PE_CONFIRM
8 PE_TOKENEXPIRED
9 PE_SENDRESPONSE
10 93 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 93 our $VERSION = '2.22.0';
13  
14 93 extends 'Lemonldap::NG::Portal::Main::Plugin';
15  
16 169 ▶sub forAuthUser { 'handleAuthRequests' }
Subroutine forAuthUser: called CC=1 SCAR=0.0
Pod undocumented
17  
18 # INITIALIZATION
19  
20 has ott => (
21 is => 'rw',
22 lazy => 1,
23 default => sub {
24 my $ott =
25 0 ▶ $_[0]->{p}->loadModule('Lemonldap::NG::Portal::Lib::OneTimeToken');
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 0 $ott->timeout( $_[0]->{conf}->{formTimeout} );
27 0 return $ott;
28 }
29 93 );
30  
31 sub init {
32 169 ▶ my ($self) = @_;
Subroutine init: called CC=2 SCAR=7.9
Pod undocumented
33 169 ▶ if ( $self->conf->{forceGlobalStorageUpgradeOTT} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"forceGlobalStorageUpgradeOTT"}) 0 169 169
34 0 $self->logger->debug(
35 "-> Upgrade tokens will be stored into global storage");
36 0 $self->ott->cache(undef);
37 }
38 169 $self->addAuthRoute( upgradesession => 'askUpgrade', ['GET'] )
39 ->addAuthRoute( upgradesession => 'confirmUpgrade', ['POST'] )
40 ->addAuthRoute( renewsession => 'askRenew', ['GET'] )
41 ->addAuthRoute( renewsession => 'confirmRenew', ['POST'] );
42  
43 169 return 1;
44 }
45  
46 sub askUpgrade {
47 0 ▶ my ( $self, $req ) = @_;
Subroutine askUpgrade: not called CC=1 SCAR=6.9
Pod undocumented
48 0 $self->ask( $req, '/upgradesession', 'askToUpgrade', 'upgradeSession' );
49 }
50  
51 sub askRenew {
52 0 ▶ my ( $self, $req ) = @_;
Subroutine askRenew: not called CC=1 SCAR=6.9
Pod undocumented
53 0 $self->ask( $req, '/renewsession', 'askToRenew', 'renewSession' );
54 }
55  
56 sub confirmUpgrade {
57 0 ▶ my ( $self, $req ) = @_;
Subroutine confirmUpgrade: not called CC=1 SCAR=6.9
Pod undocumented
58  
59 0 $req->data->{discardChoiceForCurrentSession} = 1;
60  
61 # sfOnlyUpgrade feature can only be used during session renew
62 0 return $self->confirm( $req, $self->conf->{sfOnlyUpgrade} );
63 }
64  
65 sub confirmRenew {
66 0 ▶ my ( $self, $req ) = @_;
Subroutine confirmRenew: not called CC=1 SCAR=6.9
Pod undocumented
67 0 return $self->confirm($req);
68 }
69  
70 # RUNNING METHOD
71  
72 sub ask {
73 0 ▶ my ( $self, $req, $form_action, $message, $buttonlabel ) = @_;
Subroutine ask: not called CC=9 SCAR=45.0
Pod undocumented
74  
75 # Check if auth is already running
76 # and verify token
77 0 ▶ return $self->confirm($req)
Branch: 1 branch
BranchTrueFalseTotal
if $req->param("upgrading") or $req->param("kerberos") 0 0 0
Condition0%0/3
$req->param("upgrading") or $req->param("kerberos")
l!l&&r!l&&!r
000
MC/DC0%0/2
$req->param("upgrading") or $req->param("kerberos")
$req->param("upgrading") $req->param("kerberos")
Truth table0%0/3
A or B
A= $req->param("upgrading")B= $req->param("kerberos")
ABresult
1X1
011
000
78 if ( $req->param('upgrading') or $req->param('kerberos') );
79  
80 0 ▶ my $url = $req->param('url') || '';
Condition0%0/2
$req->param('url') || ''
l!l
00
MC/DC0%0/1
$req->param('url') || ''
$req->param('url')
Truth table0%0/2
A
A= $req->param('url')
Aresult
11
00
81 0 ▶ my $forceUpgrade = $req->param('forceUpgrade') || '';
Condition0%0/2
$req->param('forceUpgrade') || ''
l!l
00
MC/DC0%0/1
$req->param('forceUpgrade') || ''
$req->param('forceUpgrade')
Truth table0%0/2
A
A= $req->param('forceUpgrade')
Aresult
11
00
82 0 my $action = ( $message =~ /^askTo(\w+)$/ )[0];
83 0 $self->logger->debug(" -> $action required");
84 $self->logger->debug(" -> Skip confirmation is enabled")
85 0 ▶ if $self->conf->{"skip${action}Confirmation"};
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"skip${action}Confirmation"} 0 0 0
86  
87 0 ▶ $url = '' if $self->p->checkXSSAttack('url', $url);
Branch: 1 branch
BranchTrueFalseTotal
if $self->p->checkXSSAttack("url", $url) 0 0 0
88 0 ▶ $forceUpgrade = '' if $self->p->checkXSSAttack('forceUpgrade', $forceUpgrade);
Branch: 1 branch
BranchTrueFalseTotal
if $self->p->checkXSSAttack("forceUpgrade", $forceUpgrade) 0 0 0
89  
90 0 my $cacheTag = $self->p->cacheTag;
91 # Display form
92 return $self->p->sendHtml(
93 $req,
94 'upgradesession',
95 params => {
96 FORMACTION => $form_action,
97 PORTALBUTTON => 1,
98 MSG => $message,
99 BUTTON => $buttonlabel,
100 CONFIRMKEY => $self->p->stamp,
101 FORCEUPGRADE => $forceUpgrade,
102 URL => $url,
103 (
104 0 ▶ $self->conf->{"skip${action}Confirmation"}
Branch: 1 branch
BranchTrueFalseTotal
$self->conf->{"skip${action}Confirmation"} ? : 0 0 0
105 ? ( CUSTOM_SCRIPT =>
106 qq'<script type="text/javascript" src="$self->{p}->{staticPrefix}/common/js/autoRenew.min.js?v=$cacheTag"></script>'
107 )
108 : ()
109 )
110 }
111 );
112 }
113  
114 sub confirm {
115 0 ▶ my ( $self, $req, $sfOnly ) = @_;
Subroutine confirm: not called CC=12 SCAR=50.5
Pod undocumented
116 0 my $upg;
117  
118 0 my $old_id = $req->userData->{_session_id};
119  
120 0 ▶ if ( $req->param('kerberos') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->param('kerberos')) { } 0 0 0
121 0 $upg = 1;
122 }
123 else {
124 0 ▶ if ( my $t = $req->param('upgrading') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $t = $req->param("upgrading")) 0 0 0
125 0 ▶ if ( $self->ott->getToken($t) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ott->getToken($t)) { } 0 0 0
126 0 $upg = 1;
127 }
128 else {
129 0 return $self->p->doPE($req, PE_TOKENEXPIRED);
130 }
131 }
132 }
133  
134 0 $req->steps( ['controlUrl'] );
135 0 my $res = $self->p->process($req);
136 0 ▶ return $self->p->doPE($req, $res) if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
137  
138 0 ▶ if ( $upg or $req->param('confirm') and $req->param('confirm') == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($upg or $req->param('confirm') and $req->param('confirm') == 1) { } 0 0 0
Condition0%0/6
$upg or $req->param("confirm") and $req->param("confirm") == 1
l!l&&r!l&&!r
000
$req->param("confirm") and $req->param("confirm") == 1
!ll&&!rl&&r
000
MC/DC0%0/3
$upg or $req->param("confirm") and $req->param("confirm") == 1
$upg $req->param("confirm") $req->param("confirm") == 1
Truth table0%0/4
A or B and C
A= $upgB= $req->param("confirm")C= $req->param("confirm") == 1
ABCresult
1XX1
0111
00X0
0100
139 0 $req->data->{noerror} = 1;
140  
141 0 ▶ if ($sfOnly) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sfOnly) { } 0 0 0
142 0 $req->data->{doingSfUpgrade} = 1;
143  
144 # Short circuit the first part of login, only do a 2FA step
145 return $self->p->do(
146 $req,
147 [
148 'importHandlerData', 'secondFactor',
149 0 @{ $self->p->afterData }, $self->p->validSession,
150 0 @{ $self->p->endAuth },
151 ]
152 );
153 }
154 else {
155 0 $self->p->setHiddenFormValue(
156 $req,
157 upgrading => $self->ott->createToken,
158 '', 0
159 ); # Insert token
160 # Do a regular login
161 0 my $res = $self->p->login($req);
162  
163 0 ▶ if ( $old_id and $req->id and $old_id ne $req->id ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old_id and $req->id and $old_id ne $req->id) 0 0 0
Condition0%0/6
$old_id and $req->id and $old_id ne $req->id
!ll&&!rl&&r
000
$old_id and $req->id
!ll&&!rl&&r
000
MC/DC0%0/3
$old_id and $req->id and $old_id ne $req->id
$old_id $req->id $old_id ne $req->id
Truth table0%0/4
A and B and C
A= $old_idB= $req->idC= $old_id ne $req->id
ABCresult
0XX0
10X0
1100
1111
164 0 $self->p->processHook( $req, 'updateSessionId', $old_id,
165 $req->id );
166 }
167 0 return $res;
168 }
169 }
170 else {
171  
172 # Go to portal
173 0 $self->logger->debug("Upgrade session did not trigger -> Go to Portal");
174 0 $req->mustRedirect(1);
175 0 return $self->p->doPE($req, PE_OK);
176 }
177 }
178  
179 # Takes care of callbacks for external methods (SAML, OIDC...)
180 sub handleAuthRequests {
181 0 ▶ my ( $self, $req ) = @_;
Subroutine handleAuthRequests: not called CC=3 SCAR=24.8
Pod undocumented
182 0 ▶ if ( $self->p->_authentication->can('isCallback')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->p->_authentication->can("isCallback") and $self->p->_authentication->isCallback($req)) 0 0 0
Condition0%0/3
$self->p->_authentication->can("isCallback") and $self->p->_authentication->isCallback($req)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->p->_authentication->can("isCallback") and $self->p->_authentication->isCallback($req)
$self->p->_authentication->can("isCallback") $self->p->_authentication->isCallback($req)
Truth table0%0/3
A and B
A= $self->p->_authentication->can("isCallback")B= $self->p->_authentication->isCallback($req)
ABresult
0X0
100
111
183 and $self->p->_authentication->isCallback($req) )
184 {
185 0 $req->id(undef);
186 0 $req->parameters->{'confirm'} = 1;
187 0 $req->response( $self->confirm($req) );
188 0 return PE_SENDRESPONSE;
189 }
190 0 return PE_OK;
191 }
192  
193 93 1;
« blib/lib/Lemonldap/NG/Portal/2F/Register/WebAuthn.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Plugins/BruteForceProtection.pm »