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

filter: Statementstmt 27.2% 21 / 77 Branchbran 7.1% 2 / 28 Conditioncond 9.0% 2 / 22 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 46.1% 6 / 13 Podpod 0.0% 0 / 9 totaltotal 19.2% 31 / 161 CC 23 SCAR 43.5
CC
23
Cov
20%
confirm
156.0
ask
90.0
handleAuthRequests
4.1
CRAP 77.5
« blib/lib/Lemonldap/NG/Portal/2F/Register/WebAuthn.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Plugins/OIDC/NativeSso.pm »
1 package Lemonldap::NG::Portal::Plugins::Upgrade;
2  
3 105 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 105 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 105 ▶use Lemonldap::NG::Portal::Main::Constants qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
6 PE_OK
7 PE_CONFIRM
8 PE_TOKENEXPIRED
9 PE_SENDRESPONSE
10 105 );
11  
12 105 our $VERSION = '2.23.0';
13  
14 105 extends 'Lemonldap::NG::Portal::Main::Plugin';
15  
16 331 ▶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 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 my $ott =
25 0 $_[0]->{p}->loadModule('Lemonldap::NG::Portal::Lib::OneTimeToken');
26 0 $ott->timeout( $_[0]->{conf}->{formTimeout} );
27 0 return $ott;
28 }
29 105 );
30  
31 331 ▶sub init {
Subroutine init: called CC=2 SCAR=7.9
Pod undocumented
32 331 my ($self) = @_;
33 331 ▶ if ( $self->conf->{forceGlobalStorageUpgradeOTT} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"forceGlobalStorageUpgradeOTT"}) 0 331 331
34 0 $self->logger->debug(
35 "-> Upgrade tokens will be stored into global storage");
36 0 $self->ott->cache(undef);
37 }
38 331 $self->addAuthRoute( upgradesession => 'askUpgrade', ['GET'] )
39 ->addAuthRoute( upgradesession => 'confirmUpgrade', ['POST'] )
40 ->addAuthRoute( renewsession => 'askRenew', ['GET'] )
41 ->addAuthRoute( renewsession => 'confirmRenew', ['POST'] );
42  
43 331 return 1;
44 }
45  
46 0 ▶sub askUpgrade {
Subroutine askUpgrade: not called CC=1 SCAR=6.9
Pod undocumented
47 0 my ( $self, $req ) = @_;
48 0 $self->ask( $req, '/upgradesession', 'askToUpgrade', 'upgradeSession' );
49 }
50  
51 0 ▶sub askRenew {
Subroutine askRenew: not called CC=1 SCAR=6.9
Pod undocumented
52 0 my ( $self, $req ) = @_;
53 0 $self->ask( $req, '/renewsession', 'askToRenew', 'renewSession' );
54 }
55  
56 0 ▶sub confirmUpgrade {
Subroutine confirmUpgrade: not called CC=1 SCAR=6.9
Pod undocumented
57 0 my ( $self, $req ) = @_;
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 0 ▶sub confirmRenew {
Subroutine confirmRenew: not called CC=1 SCAR=6.9
Pod undocumented
66 0 my ( $self, $req ) = @_;
67 0 return $self->confirm($req);
68 }
69  
70 # RUNNING METHOD
71  
72 0 ▶sub ask {
Subroutine ask: not called CC=9 SCAR=45.0
Pod undocumented
73 0 my ( $self, $req, $form_action, $message, $buttonlabel ) = @_;
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 = ''
Branch: 1 branch
BranchTrueFalseTotal
if $self->p->checkXSSAttack("forceUpgrade", $forceUpgrade) 0 0 0
89 if $self->p->checkXSSAttack( 'forceUpgrade', $forceUpgrade );
90  
91 0 my $cacheTag = $self->p->cacheTag;
92  
93 # Display form
94 return $self->p->sendHtml(
95 $req,
96 'upgradesession',
97 params => {
98 FORMACTION => $form_action,
99 PORTALBUTTON => 1,
100 MSG => $message,
101 BUTTON => $buttonlabel,
102 CONFIRMKEY => $self->p->stamp,
103 FORCEUPGRADE => $forceUpgrade,
104 URL => $url,
105 (
106 0 ▶ $self->conf->{"skip${action}Confirmation"}
Branch: 1 branch
BranchTrueFalseTotal
$self->conf->{"skip${action}Confirmation"} ? : 0 0 0
107 ? ( CUSTOM_SCRIPT =>
108 qq'<script type="text/javascript" src="$self->{p}->{staticPrefix}/common/js/autoRenew.min.js?v=$cacheTag"></script>'
109 )
110 : ()
111 )
112 }
113 );
114 }
115  
116 0 ▶sub confirm {
Subroutine confirm: not called CC=12 SCAR=50.5
Pod undocumented
117 0 my ( $self, $req, $sfOnly ) = @_;
118 0 my $upg;
119  
120 0 my $old_id = $req->userData->{_session_id};
121  
122 0 ▶ if ( $req->param('kerberos') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->param('kerberos')) { } 0 0 0
123 0 $upg = 1;
124 }
125 else {
126 0 ▶ if ( my $t = $req->param('upgrading') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $t = $req->param("upgrading")) 0 0 0
127 0 ▶ if ( $self->ott->getToken($t) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ott->getToken($t)) { } 0 0 0
128 0 $upg = 1;
129 }
130 else {
131 0 return $self->p->doPE( $req, PE_TOKENEXPIRED );
132 }
133 }
134 }
135  
136 0 $req->steps( ['controlUrl'] );
137 0 my $res = $self->p->process($req);
138 0 ▶ return $self->p->doPE( $req, $res ) if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
139  
140 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
141 0 $req->data->{noerror} = 1;
142  
143 0 ▶ if ($sfOnly) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sfOnly) { } 0 0 0
144 0 $req->data->{doingSfUpgrade} = 1;
145  
146 # Short circuit the first part of login, only do a 2FA step
147 return $self->p->do(
148 $req,
149 [
150 'importHandlerData', 'secondFactor',
151 0 @{ $self->p->afterData }, $self->p->validSession,
152 0 @{ $self->p->endAuth },
153 ]
154 );
155 }
156 else {
157 0 $self->p->setHiddenFormValue(
158 $req,
159 upgrading => $self->ott->createToken,
160 '', 0
161 ); # Insert token
162 # Do a regular login
163 0 my $res = $self->p->login($req);
164  
165 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
166 0 $self->p->processHook( $req, 'updateSessionId', $old_id,
167 $req->id );
168 }
169 0 return $res;
170 }
171 }
172 else {
173  
174 # Go to portal
175 0 $self->logger->debug("Upgrade session did not trigger -> Go to Portal");
176 0 $req->mustRedirect(1);
177 0 return $self->p->doPE( $req, PE_OK );
178 }
179 }
180  
181 # Takes care of callbacks for external methods (SAML, OIDC...)
182 79 ▶sub handleAuthRequests {
Subroutine handleAuthRequests: called CC=3 SCAR=14.2
Pod undocumented
183 79 my ( $self, $req ) = @_;
184 79 ▶ if ( $self->p->_authentication->can('isCallback')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->p->_authentication->can("isCallback") and $self->p->_authentication->isCallback($req)) 0 79 79
Condition66%2/3
$self->p->_authentication->can("isCallback") and $self->p->_authentication->isCallback($req)
!ll&&!rl&&r
7540
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 table66%2/3
A and B
A= $self->p->_authentication->can("isCallback")B= $self->p->_authentication->isCallback($req)
ABresult
0X0
100
111
185 and $self->p->_authentication->isCallback($req) )
186 {
187 0 $req->id(undef);
188 0 $req->parameters->{'confirm'} = 1;
189 0 $req->response( $self->confirm($req) );
190 0 return PE_SENDRESPONSE;
191 }
192 79 return PE_OK;
193 }
194  
195 105 1;
« blib/lib/Lemonldap/NG/Portal/2F/Register/WebAuthn.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Plugins/OIDC/NativeSso.pm »