blib/lib/Lemonldap/NG/Portal/Auth/_WebForm.pm

filter: Statementstmt 72.5% 58 / 80 Branchbran 52.0% 26 / 50 Conditioncond 35.7% 15 / 42 MC/DCmcdc 12.5% 3 / 24 Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 6 totaltotal 52.3% 111 / 212 CC 40 SCAR 42.3
CC
40
Cov
58%
extractFormInfo
120.9
getFormParams
12.0
init
5.8
CRAP 68.8
« blib/lib/Lemonldap/NG/Portal/Main/Process.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Lib/SMTP.pm »
1 ##@file
2 # Web form authentication backend file
3  
4 ##@class
5 # Web form authentication backend class
6 package Lemonldap::NG::Portal::Auth::_WebForm;
7  
8 311 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 311 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 311 use Lemonldap::NG::Portal::Main::Constants qw(
11 PE_OK
12 PE_NOTOKEN
13 PE_FORMEMPTY
14 PE_FIRSTACCESS
15 PE_CAPTCHAEMPTY
16 PE_CAPTCHAERROR
17 PE_TOKENEXPIRED
18 PE_MALFORMEDUSER
19 PE_PASSWORDFORMEMPTY
20 311 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 311 our $VERSION = '2.21.0';
23  
24 311 extends qw(
25 Lemonldap::NG::Portal::Main::Auth
26 Lemonldap::NG::Portal::Lib::_tokenRule
27 );
28  
29 has authnLevel => (
30 is => 'rw',
31 lazy => 1,
32 builder => sub {
33 30 ▶ my $conf = $_[0]->{conf};
Subroutine __ANON__: called CC=2 SCAR=7.2
34 30 ▶ return ( $conf->{portal} =~ /^https/ ? 2 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$conf->{'portal'} =~ /^https/ ? : 0 30 30
35 },
36 311 );
37  
38 311 has captcha => ( is => 'rw' );
39 311 has ott => ( is => 'rw' );
40  
41 # INITIALIZATION
42  
43 sub init {
44 484 ▶ my $self = shift;
Subroutine init: called CC=5 SCAR=17.5
Pod undocumented
45  
46 $self->captcha(
47 $self->p->buildRule(
48 $self->{conf}->{captcha_login_enabled},
49 484 'captchaLogin'
50 )
51 );
52  
53 484 ▶ return 0 unless $self->captcha;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->captcha 0 484 484
54 484 ▶ unless ($self->{conf}->{captcha_login_enabled}
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"conf"}{"captcha_login_enabled"} and $self->{"conf"}{"captcha_login_enabled"} eq 0) 484 0 484
Condition33%1/3
$self->{"conf"}{"captcha_login_enabled"} and $self->{"conf"}{"captcha_login_enabled"} eq 0
!ll&&!rl&&r
48400
MC/DC0%0/2
$self->{"conf"}{"captcha_login_enabled"} and $self->{"conf"}{"captcha_login_enabled"} eq 0
$self->{"conf"}{"captcha_login_enabled"} $self->{"conf"}{"captcha_login_enabled"} eq 0
Truth table33%1/3
A and B
A= $self->{"conf"}{"captcha_login_enabled"}B= $self->{"conf"}{"captcha_login_enabled"} eq 0
ABresult
0X0
100
111
55 and $self->{conf}->{captcha_login_enabled} eq '0' )
56 {
57 484 ▶ $self->ott( $self->p->loadModule('::Lib::OneTimeToken') ) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->ott($self->p->loadModule("::Lib::OneTimeToken")) or return 0 0 484 484
58 484 $self->ott->timeout( $self->conf->{formTimeout} );
59 }
60 484 return 1;
61 }
62  
63 # RUNNING METHODS
64  
65 # Read username and password from POST data
66 sub extractFormInfo {
67 71 ▶ my ( $self, $req ) = @_;
Subroutine extractFormInfo: called CC=27 SCAR=47.9
Pod undocumented
68  
69 71 ▶ if ( $req->param('user') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->param("user")) 38 33 71
70 38 ▶ unless ( $req->param('user') =~ /$self->{conf}->{userControl}/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->param("user") =~ /$self->{"conf"}{"userControl"}/) 0 38 38
71 0 $self->setSecurity($req);
72 0 return PE_MALFORMEDUSER;
73 }
74 }
75  
76 # Detect first access and empty forms
77 71 my $defUser = defined $req->param('user');
78 71 my $defPassword = defined $req->param('password');
79 71 my $defOldPassword = defined $req->param('oldpassword');
80 71 my $res = PE_OK;
81  
82 # 1. No user defined at all -> first access
83 # _pwdCheck is a workaround to make CheckUser work while using a GET
84 71 ▶ unless ( $defUser
Branch: 3 branches
BranchTrueFalseTotal
if ($defUser and uc $req->method eq 'POST' || $req->data->{'_pwdCheck'}) { } 38 33 71
if (do { $defUser and $defPassword }) { } 38 0 38
elsif ($defUser and $defOldPassword) { } 0 0 0
Condition50%3/6
$defUser and uc $req->method eq "POST" || $req->data->{"_pwdCheck"}
!ll&&!rl&&r
33038
uc $req->method eq "POST" or $req->data->{"_pwdCheck"}
l!l&&r!l&&!r
3800
MC/DC33%1/3
$defUser and uc $req->method eq "POST" || $req->data->{"_pwdCheck"}
$defUser uc $req->method eq "POST" $req->data->{"_pwdCheck"}
Truth table50%2/4
A and B or C
A= $defUserB= uc $req->method eq "POST"C= $req->data->{"_pwdCheck"}
ABCresult
0XX0
1000
11X1
1011
85 and ( uc( $req->method ) eq "POST" or $req->data->{_pwdCheck} ) )
86 {
87 33 $res = PE_FIRSTACCESS;
88 }
89  
90 # 2. If user and password defined -> login form
91 ▶ elsif ( $defUser and $defPassword ) {
Condition33%1/3
$defUser and $defPassword
!ll&&!rl&&r
0038
MC/DC0%0/2
$defUser and $defPassword
$defUser $defPassword
Truth table33%1/3
A and B
A= $defUserB= $defPassword
ABresult
0X0
100
111
92 $res = PE_FORMEMPTY
93 unless ( ( $req->{user} = $req->param('user') )
94 38 ▶ && ( $req->data->{password} = $req->param('password') ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $req->{"user"} = $req->param("user") and $req->data->{"password"} = $req->param("password") 0 38 38
Condition33%1/3
$req->{"user"} = $req->param("user") and $req->data->{"password"} = $req->param("password")
!ll&&!rl&&r
0038
MC/DC0%0/2
$req->{"user"} = $req->param("user") and $req->data->{"password"} = $req->param("password")
$req->{"user"} = $req->param("user") $req->data->{"password"} = $req->param("password")
Truth table33%1/3
A and B
A= $req->{"user"} = $req->param("user")B= $req->data->{"password"} = $req->param("password")
ABresult
0X0
100
111
95 }
96  
97 # 3. If user and oldpassword defined -> password form
98 ▶ elsif ( $defUser and $defOldPassword ) {
Condition0%0/3
$defUser and $defOldPassword
!ll&&!rl&&r
000
MC/DC0%0/2
$defUser and $defOldPassword
$defUser $defOldPassword
Truth table0%0/3
A and B
A= $defUserB= $defOldPassword
ABresult
0X0
100
111
99 $res = PE_PASSWORDFORMEMPTY
100 unless (
101 ( $req->{user} = $req->param('user') )
102 && ( $req->data->{oldpassword} = $req->param('oldpassword') )
103 && ( $req->data->{newpassword} = $req->param('newpassword') )
104 && ( $req->data->{confirmpassword} =
105 0 ▶ $req->param('confirmpassword') )
Branch: 1 branch
BranchTrueFalseTotal
unless $req->{"user"} = $req->param("user") and $req->data->{"oldpassword"} = $req->param("oldpassword") and $req->data->{"newpassword"} = $req->param("newpassword") and $req->data->{"confirmpassword"} = $req->param("confirmpassword") 0 0 0
Condition0%0/9
$req->{"user"} = $req->param("user") and $req->data->{"oldpassword"} = $req->param("oldpassword") and $req->data->{"newpassword"} = $req->param("newpassword") and $req->data->{"confirmpassword"} = $req->param("confirmpassword")
!ll&&!rl&&r
000
$req->{"user"} = $req->param("user") and $req->data->{"oldpassword"} = $req->param("oldpassword") and $req->data->{"newpassword"} = $req->param("newpassword")
!ll&&!rl&&r
000
$req->{"user"} = $req->param("user") and $req->data->{"oldpassword"} = $req->param("oldpassword")
!ll&&!rl&&r
000
MC/DC0%0/4
$req->{"user"} = $req->param("user") and $req->data->{"oldpassword"} = $req->param("oldpassword") and $req->data->{"newpassword"} = $req->param("newpassword") and $req->data->{"confirmpassword"} = $req->param("confirmpassword")
$req->{"user"} = $req->param("user") $req->data->{"oldpassword"} = $req->param("oldpassword") $req->data->{"newpassword"} = $req->param("newpassword") $req->data->{"confirmpassword"} = $req->param("confirmpassword")
Truth table0%0/5
A and B and C and D
A= $req->{"user"} = $req->param("user")B= $req->data->{"oldpassword"} = $req->param("oldpassword")C= $req->data->{"newpassword"} = $req->param("newpassword")D= $req->data->{"confirmpassword"} = $req->param("confirmpassword")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
106 );
107 }
108  
109 # If form seems empty
110 71 ▶ if ( $res != PE_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res != 0) 33 38 71
111 33 $self->setSecurity($req);
112 33 return $res;
113 }
114  
115 # Security: check for captcha or token
116 38 my $needCaptcha = $self->captcha->( $req, {} );
117 38 ▶ if ( not $req->data->{'skipToken'}
Branch: 1 branch
BranchTrueFalseTotal
if (not $req->data->{"skipToken"} and $needCaptcha || $self->ottRule->($req, scalar {})) 2 36 38
Condition83%5/6
not $req->data->{"skipToken"} and $needCaptcha || $self->ottRule->($req, scalar {})
!ll&&!rl&&r
1352
$needCaptcha or $self->ottRule->($req, scalar {})
l!l&&r!l&&!r
0235
MC/DC66%2/3
not $req->data->{"skipToken"} and $needCaptcha || $self->ottRule->($req, scalar {})
not $req->data->{"skipToken"} $needCaptcha $self->ottRule->($req, scalar {})
Truth table75%3/4
not(A) and B or C
A= not $req->data->{"skipToken"}B= $needCaptchaC= $self->ottRule->($req, scalar {})
ABCresult
0XX0
1000
11X1
1011
118 and ( $needCaptcha or $self->ottRule->( $req, {} ) ) )
119 {
120 2 my $token;
121 2 ▶ unless ( $token = $req->param('token') or $needCaptcha ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($token = $req->param("token") or $needCaptcha) 0 2 2
Condition33%1/3
$token = $req->param("token") or $needCaptcha
l!l&&r!l&&!r
200
MC/DC0%0/2
$token = $req->param("token") or $needCaptcha
$token = $req->param("token") $needCaptcha
Truth table33%1/3
A or B
A= $token = $req->param("token")B= $needCaptcha
ABresult
1X1
011
000
122 0 $self->userLogger->error('Authentication tried without token');
123 0 $self->ott->setToken($req);
124 0 return PE_NOTOKEN;
125 }
126  
127 2 ▶ if ($needCaptcha) {
Branch: 2 branches
BranchTrueFalseTotal
if ($needCaptcha) { } 0 2 2
elsif ($self->ottRule->($req, scalar {})) { } 2 0 2
128 0 my $result = $self->p->getService('captcha')->check_captcha($req);
129 0 ▶ if ($result) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result) { } 0 0 0
130 0 $self->logger->debug("Captcha code verified");
131 }
132 else {
133 0 $self->p->getService('captcha')->init_captcha($req);
134 0 $self->userLogger->warn("Captcha failed");
135 0 return PE_CAPTCHAERROR;
136 }
137 }
138 elsif ( $self->ottRule->( $req, {} ) ) {
139 2 ▶ unless ( $req->data->{tokenVerified}
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->data->{"tokenVerified"} or $self->ott->getToken($token)) 0 2 2
Condition66%2/3
$req->data->{"tokenVerified"} or $self->ott->getToken($token)
l!l&&r!l&&!r
110
MC/DC0%0/2
$req->data->{"tokenVerified"} or $self->ott->getToken($token)
$req->data->{"tokenVerified"} $self->ott->getToken($token)
Truth table66%2/3
A or B
A= $req->data->{"tokenVerified"}B= $self->ott->getToken($token)
ABresult
1X1
011
000
140 or $self->ott->getToken($token) )
141 {
142 0 $self->ott->setToken($req);
143 0 $self->userLogger->warn('Invalid authentication form token');
144 0 return PE_TOKENEXPIRED;
145 }
146 2 $req->data->{tokenVerified} = 1;
147 }
148 }
149  
150 # Other parameters
151 38 $req->data->{timezone} = $req->param('timezone');
152  
153 38 return PE_OK;
154 }
155  
156 # Set password in session data if wanted.
157 sub setAuthSessionInfo {
158 35 ▶ my ( $self, $req ) = @_;
Subroutine setAuthSessionInfo: called CC=4 SCAR=14.2
Pod undocumented
159  
160 # authenticationLevel
161 35 $req->{sessionInfo}->{authenticationLevel} = $self->authnLevel;
162  
163 # Store submitted password if set in configuration
164 # WARNING: it can be a security hole
165 35 ▶ if ( $self->conf->{storePassword} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"storePassword"}) 1 34 35
166 my $passwordToStore =
167 1 ▶ $req->data->{'newpassword'} || $req->data->{'password'};
Condition33%1/3
$req->data->{'newpassword'} || $req->data->{'password'}
l!l&&r!l&&!r
010
MC/DC0%0/2
$req->data->{'newpassword'} || $req->data->{'password'}
$req->data->{'newpassword'} $req->data->{'password'}
Truth table33%1/3
A || B
A= $req->data->{'newpassword'}B= $req->data->{'password'}
ABresult
1X1
011
000
168 $req->{sessionInfo}->{'_password'} =
169 $self->conf->{storePasswordEncrypted}
170 1 ▶ ? $self->p->HANDLER->tsv->{cipher}->encrypt($passwordToStore)
Branch: 1 branch
BranchTrueFalseTotal
$self->conf->{'storePasswordEncrypted'} ? : 0 1 1
171 : $passwordToStore;
172 }
173  
174 # Store user timezone
175 35 $req->{sessionInfo}->{'_timezone'} = $self->{'timezone'};
176  
177 35 return PE_OK;
178 }
179  
180 # @return display type
181 sub getDisplayType {
182 94 ▶ return "standardform";
Subroutine getDisplayType: called CC=1 SCAR=0.0
Pod undocumented
183 }
184  
185 sub setSecurity {
186 37 ▶ my ( $self, $req ) = @_;
Subroutine setSecurity: called CC=4 SCAR=14.6
Pod undocumented
187 37 ▶ return if $req->data->{skipToken};
Branch: 1 branch
BranchTrueFalseTotal
if $req->data->{"skipToken"} 0 37 37
188  
189 # If captcha is enable, prepare it
190 37 ▶ if ( $self->captcha->( $req, {} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->captcha->($req, scalar {})) { } 0 36 36
elsif ($self->ottRule->($req, scalar {})) { } 1 35 36
191 0 $self->p->getService('captcha')->init_captcha($req);
192 }
193  
194 # Else get token
195 elsif ( $self->ottRule->( $req, {} ) ) {
196 1 $self->ott->setToken($req);
197 }
198 }
199  
200 # DEPRECATED, use get2fTplParams
201 sub getFormParams {
202 0 ▶ my ( $self, $req ) = @_;
Subroutine getFormParams: not called CC=3 SCAR=24.8
Pod undocumented
203 0 my $checkLogins = $req->param('checkLogins');
204 0 ▶ $self->logger->debug( $self->prefix . '2f: checkLogins set' )
Branch: 1 branch
BranchTrueFalseTotal
if $checkLogins 0 0 0
205 if $checkLogins;
206  
207 0 my $stayConnected = $req->param('stayconnected');
208 0 ▶ $self->logger->debug( $self->prefix . '2f: stayConnected set' )
Branch: 1 branch
BranchTrueFalseTotal
if $stayConnected 0 0 0
209 if $stayConnected;
210  
211 0 return ( $checkLogins, $stayConnected );
212 }
213  
214 311 1;
« blib/lib/Lemonldap/NG/Portal/Main/Process.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Lib/SMTP.pm »