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

filter: Statementstmt 68.2% 43 / 63 Branchbran 33.3% 4 / 12 Conditioncond 31.2% 5 / 16 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 80.0% 12 / 15 Podpod 0.0% 0 / 5 totaltotal 54.6% 65 / 119 CC 14 SCAR 20.6
CC
14
Cov
57%
storeRememberedAuthChoice
30.0
__ANON__
6.0
removeRememberedAuthChoice
6.0
CRAP 7.8
« blib/lib/Lemonldap/NG/Portal/Register/LDAP.pm ↑ Summary scripts/downloadSamlMetadata »
1 # Plugin to remember which authentication method has been chosen,
2 # and laun it automatically
3  
4 package Lemonldap::NG::Portal::Plugins::RememberAuthChoice;
5  
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 use Lemonldap::NG::Portal::Main::Constants qw(
9 PE_OK
10 PE_SENDRESPONSE
11 1 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 our $VERSION = '2.20.0';
14  
15 1 extends 'Lemonldap::NG::Portal::Main::Plugin';
16  
17 # INTERFACE
18  
19 1 ▶use constant endAuth => 'storeRememberedAuthChoice';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use constant beforeAuth => 'checkRememberedAuthChoice';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use constant beforeLogout => 'removeRememberedAuthChoice';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use constant hook => { getAuthChoice => "autoChoice", };
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 2 ▶has rule => ( is => 'rw', default => sub { 0 } );
Subroutine __ANON__: called CC=1 SCAR=0.0
25  
26 has rememberCookieName => (
27 is => 'ro',
28 lazy => 1,
29 default => sub {
30 1 ▶ $_[0]->conf->{rememberCookieName} // 'llngrememberauthchoice';
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
$_[0]->conf->{"rememberCookieName"} // "llngrememberauthchoice"
l!l
10
MC/DC0%0/1
$_[0]->conf->{"rememberCookieName"} // "llngrememberauthchoice"
$_[0]->conf->{"rememberCookieName"}
Truth table50%1/2
A
A= $_[0]->conf->{"rememberCookieName"}
Aresult
11
00
31 }
32 1 );
33  
34 # Default timeout: 1 year
35 has rememberCookieTimeout => (
36 is => 'ro',
37 lazy => 1,
38 default => sub {
39 0 ▶ $_[0]->conf->{rememberCookieTimeout} // 31536000;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$_[0]->conf->{"rememberCookieTimeout"} // 31536000
l!l
00
MC/DC0%0/1
$_[0]->conf->{"rememberCookieTimeout"} // 31536000
$_[0]->conf->{"rememberCookieTimeout"}
Truth table0%0/2
A
A= $_[0]->conf->{"rememberCookieTimeout"}
Aresult
11
00
40 }
41 1 );
42  
43 sub init {
44 2 ▶ my ($self) = @_;
Subroutine init: called CC=2 SCAR=7.0
Pod undocumented
45  
46 # Parse activation rule
47 $self->rule(
48 $self->p->buildRule(
49 $self->conf->{rememberAuthChoiceRule},
50 2 'rememberAuthChoiceRule'
51 )
52 );
53 2 ▶ return 0 unless $self->rule;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->rule 0 2 2
54  
55 2 return 1;
56 }
57  
58 sub storeRememberedAuthChoice {
59 0 ▶ my ( $self, $req ) = @_;
Subroutine storeRememberedAuthChoice: not called CC=5 SCAR=34.0
Pod undocumented
60  
61 # Get directly authentication choice from sessionInfo
62 0 my $lmAuth = $req->sessionInfo->{_choice};
63  
64 # Get rememberauthchoice tick from corresponding hash
65 # * req->pdata for Issuer auth modules (SAML, OIDC,...)
66 # * req->data for direct auth modules (LDAP)
67 my $rememberauthchoice =
68 $req->pdata->{rememberauthchoice}
69 || $req->data->{rememberauthchoice}
70 0 ▶ || "";
Condition0%0/5
$req->pdata->{'rememberauthchoice'} || $req->data->{'rememberauthchoice'} || ''
l!l
00
$req->pdata->{"rememberauthchoice"} or $req->data->{"rememberauthchoice"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$req->pdata->{'rememberauthchoice'} || $req->data->{'rememberauthchoice'} || ''
$req->pdata->{"rememberauthchoice"} $req->data->{"rememberauthchoice"}
Truth table0%0/3
A or B
A= $req->pdata->{"rememberauthchoice"}B= $req->data->{"rememberauthchoice"}
ABresult
1X1
011
000
71  
72 0 ▶ if ($lmAuth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lmAuth) 0 0 0
73  
74 # Store cookie to remember the authentication choice
75 0 ▶ if ( $rememberauthchoice eq "true" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rememberauthchoice eq 'true') { } 0 0 0
76 0 $self->logger->warn( "RememberAuthChoice: set cookie "
77 . $self->rememberCookieName
78 . " with authentication choice lmAuth="
79 . $lmAuth );
80 $req->addCookie(
81 $self->p->cookie(
82 name => $self->rememberCookieName,
83 value => $lmAuth,
84 max_age => $self->rememberCookieTimeout,
85 secure => $self->conf->{securedCookie},
86 0 HttpOnly => 0, # required for cookie to be read by js
87 )
88 );
89 }
90  
91 # Remove cookie to forget previous authentication choice
92 else {
93  
94 0 $self->logger->warn( "RememberAuthChoice: Remove cookie "
95 . $self->rememberCookieName );
96  
97 $req->addCookie(
98 $self->p->cookie(
99 name => $self->rememberCookieName,
100 value => 0,
101 expires => 'Wed, 21 Oct 2015 00:00:00 GMT',
102 secure => $self->conf->{securedCookie},
103 )
104 0 );
105  
106 # Avoid regressions with #3228
107 $req->addCookie(
108 $self->p->genDomainCookie(
109 $req,
110 name => $self->rememberCookieName,
111 value => 0,
112 expires => 'Wed, 21 Oct 2015 00:00:00 GMT',
113 secure => $self->conf->{securedCookie},
114 )
115 0 );
116 }
117 }
118  
119 0 return PE_OK;
120 }
121  
122 sub checkRememberedAuthChoice {
123 3 ▶ my ( $self, $req ) = @_;
Subroutine checkRememberedAuthChoice: called CC=4 SCAR=15.9
Pod undocumented
124  
125 # Check if form has been sent with a rememberauthchoice tick
126 3 ▶ my $lmAuth = $req->param('lmAuth') || "";
Condition50%1/2
$req->param('lmAuth') || ''
l!l
03
MC/DC0%0/1
$req->param('lmAuth') || ''
$req->param('lmAuth')
Truth table50%1/2
A
A= $req->param('lmAuth')
Aresult
11
00
127 3 ▶ my $rememberauthchoice = $req->param('rememberauthchoice') || "";
Condition50%1/2
$req->param('rememberauthchoice') || ''
l!l
03
MC/DC0%0/1
$req->param('rememberauthchoice') || ''
$req->param('rememberauthchoice')
Truth table50%1/2
A
A= $req->param('rememberauthchoice')
Aresult
11
00
128  
129 # If so, store rememberauthchoice tick for the endAuth endpoint
130 3 ▶ if ($lmAuth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lmAuth) 0 3 3
131  
132 # For authentication method occurring in the same request
133 0 $req->data->{rememberauthchoice} = $rememberauthchoice;
134  
135 # For authentication method occurring in a different request
136 0 $req->pdata->{rememberauthchoice} = $rememberauthchoice;
137 }
138  
139 3 return PE_OK;
140 }
141  
142 sub removeRememberedAuthChoice {
143 0 ▶ my ( $self, $req ) = @_;
Subroutine removeRememberedAuthChoice: not called CC=2 SCAR=17.9
Pod undocumented
144  
145 0 ▶ if ( $self->conf->{rememberAuthChoiceForgetAtLogout} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"rememberAuthChoiceForgetAtLogout"}) 0 0 0
146  
147 0 $self->logger->debug( "RememberAuthChoice: Remove cookie "
148 . $self->rememberCookieName
149 . " at logout" );
150  
151 $req->addCookie(
152 $self->p->cookie(
153 name => $self->rememberCookieName,
154 value => 0,
155 expires => 'Wed, 21 Oct 2015 00:00:00 GMT',
156 secure => $self->conf->{securedCookie},
157 )
158 0 );
159  
160 # Avoid regressions with #3228
161 $req->addCookie(
162 $self->p->genDomainCookie(
163 $req,
164 name => $self->rememberCookieName,
165 value => 0,
166 expires => 'Wed, 21 Oct 2015 00:00:00 GMT',
167 secure => $self->conf->{securedCookie},
168 )
169 0 );
170  
171 }
172 0 return PE_OK;
173 }
174  
175 sub autoChoice {
176 3 ▶ my ( $self, $req, $context ) = @_;
Subroutine autoChoice: called CC=3 SCAR=11.0
Pod undocumented
177  
178 3 ▶ if ( my $choice = $req->cookies->{ $self->rememberCookieName }
Branch: 1 branch
BranchTrueFalseTotal
if (my $choice = $req->cookies->{$self->rememberCookieName} and $self->conf->{"rememberTimer"} == 0) 2 1 3
Condition66%2/3
my $choice = $req->cookies->{$self->rememberCookieName} and $self->conf->{"rememberTimer"} == 0
!ll&&!rl&&r
102
MC/DC50%1/2
my $choice = $req->cookies->{$self->rememberCookieName} and $self->conf->{"rememberTimer"} == 0
my $choice = $req->cookies->{$self->rememberCookieName} $self->conf->{"rememberTimer"} == 0
Truth table66%2/3
A and B
A= my $choice = $req->cookies->{$self->rememberCookieName}B= $self->conf->{"rememberTimer"} == 0
ABresult
0X0
100
111
179 and $self->conf->{rememberTimer} == 0 )
180 {
181 2 $context->{choice} = $choice;
182  
183 # Continue remembering the choice
184 2 $req->pdata->{rememberauthchoice} = "true";
185 }
186 3 return PE_OK;
187 }
188  
189 1 1;
« blib/lib/Lemonldap/NG/Portal/Register/LDAP.pm ↑ Summary scripts/downloadSamlMetadata »