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

filter: Statementstmt 77.5% 62 / 80 Branchbran 55.5% 10 / 18 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 66.6% 8 / 12 Podpod 33.3% 3 / 9 totaltotal 70.5% 91 / 129 CC 14 SCAR 17.9
CC
14
Cov
74%
delCookie
20.0
setInfo
6.0
init
5.0
CRAP 6.0
« blib/lib/Lemonldap/NG/Portal/Plugins/CDA.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Plugins/AutoSignin.pm »
1 package Lemonldap::NG::Portal::Main::Request;
2  
3 # Developpers, be careful: new() is never called so default values will not be
4 # taken in account (see Portal::Run::handler()): set default values in init()
5  
6 442 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 442 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 442 ▶use Lemonldap::NG::Portal::Main::Constants ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 442 our $VERSION = '2.19.0';
11  
12 442 extends 'Lemonldap::NG::Common::PSGI::Request';
13  
14 # List of methods to call
15 442 has steps => ( is => 'rw' );
16  
17 # Authentication result
18 442 has authResult => ( is => 'rw' );
19  
20 # Session data when created
21 442 has id => ( is => 'rw' );
22 442 has sessionInfo => ( is => 'rw' );
23 442 has user => ( is => 'rw' );
24  
25 # Persistent data (stored in cookie during auth, erased when auth is ready)
26 442 has pdata => ( is => 'rw' );
27  
28 # Response cookies (list of strings built by cookie())
29 442 has respCookies => ( is => 'rw' );
30  
31 # Embedded response
32 442 has response => ( is => 'rw' );
33  
34 # Template to display (if not defined, login or menu)
35 442 has template => ( is => 'rw' );
36  
37 # Custom template parameters
38 442 has customParameters => ( is => 'rw' );
39  
40 # Boolean to indicate that response must be a redirection
41 442 has mustRedirect => ( is => 'rw' );
42  
43 # Boolean to indicate that login form must not be displayed (used to reset
44 # authentication)
45 442 has noLoginDisplay => ( is => 'rw' );
46  
47 # Portal URL, can be dynamic
48  
49 442 has portal => ( is => 'rw' );
50  
51 # Store URL for redirections
52 442 has urldc => ( is => 'rw' );
53 442 has postUrl => ( is => 'rw' );
54 442 has postFields => ( is => 'rw' );
55 442 has portalHiddenFormValues => ( is => 'rw' );
56  
57 # Flag that permit to a auth module to return PE_OK without setting $user
58 442 has continue => ( is => 'rw' );
59  
60 # "check logins "flag"
61 442 has checkLogins => ( is => 'rw' );
62  
63 # Boolean to indicate that url isn't Base64 encoded
64 442 has urlNotBase64 => ( is => 'rw' );
65 442 has maybeNotBase64 => ( is => 'rw' );
66  
67 # Menu error
68 442 has menuError => ( is => 'rw' );
69  
70 # Frame flag (used by Run to not send Content-Security-Policy header)
71 442 has frame => ( is => 'rw' );
72  
73 # Refresh flag to avoid double cookies sessions to be renewed
74 442 has refresh => ( is => 'rw' );
75  
76 # Scalar to display lock time
77 442 has lockTime => ( is => 'rw' );
78  
79 # Security
80 #
81 # Captcha HTML code to display in forms
82 442 has captchaHtml => ( is => 'rw' );
83  
84 # DEPRECATED: 2.0 captcha compatibility
85 442 has captcha => ( is => 'rw' );
86  
87 # Token
88 442 has token => ( is => 'rw' );
89  
90 # Whether or not to include a HTML render of the error message
91 # in error responses
92 442 has wantErrorRender => ( is => 'rw' );
93  
94 # Error type
95  
96 sub error_role {
97 389 ▶ my $req = shift;
Subroutine error_role: called CC=2 SCAR=6.9
Pod undocumented
98 389 ▶ return $req->error_type(@_) eq 'negative' ? 'alert' : 'status';
Branch: 1 branch
BranchTrueFalseTotal
$req->error_type(@_) eq 'negative' ? : 263 126 389
99 }
100  
101 sub error_type {
102 778 ▶ my $req = shift;
Subroutine error_type: called CC=4 SCAR=13.9
Pod undocumented
103 778 ▶ my $code = shift || $req->error;
Condition66%2/3
shift() || $req->error
l!l&&r!l&&!r
074236
MC/DC50%1/2
shift() || $req->error
shift() $req->error
Truth table66%2/3
A || B
A= shift()B= $req->error
ABresult
1X1
011
000
104 778 $req->error($code);
105  
106 # Positive errors
107 return "positive"
108 if (
109 scalar(
110 778 ▶ grep { /^$code$/ } (
Branch: 1 branch
BranchTrueFalseTotal
if scalar grep({/^$code$/;} -2, -1, 0, 35, 46, 47, 69, 71, 72, 78, 99) 162 616 778
111 PE_REDIRECT, PE_DONE,
112 PE_OK, PE_PASSWORD_OK,
113 PE_MAILOK, PE_LOGOUT_OK,
114 PE_MAILFIRSTACCESS, PE_PASSWORDFIRSTACCESS,
115 PE_MAILCONFIRMOK, PE_REGISTERFIRSTACCESS,
116 PE_RESETCERTIFICATE_FIRSTACCESS,
117 )
118 )
119 );
120  
121 # Warning errors
122 return "warning"
123 if (
124 scalar(
125 616 ▶ grep { /^$code$/ } (
Branch: 1 branch
BranchTrueFalseTotal
if scalar grep({/^$code$/;} -3, 1, 2, 9, 32, 33, 36, 37, 42, 43, 66, 67, 77, 79, 25, 98, 110) 90 526 616
126 PE_INFO,
127 PE_SESSIONEXPIRED,
128 PE_FORMEMPTY,
129 PE_FIRSTACCESS,
130 PE_PP_GRACE,
131 PE_PP_EXP_WARNING,
132 PE_NOTIFICATION,
133 PE_BADURL,
134 PE_CONFIRM,
135 PE_MAILFORMEMPTY,
136 PE_MAILCONFIRMATION_ALREADY_SENT,
137 PE_PASSWORDFORMEMPTY,
138 PE_CAPTCHAEMPTY,
139 PE_REGISTERFORMEMPTY,
140 PE_PP_CHANGE_AFTER_RESET,
141 PE_RESETCERTIFICATE_FORMEMPTY,
142 PE_RETRY_2FA,
143 )
144 )
145 );
146  
147 # Negative errors (default)
148 526 return "negative";
149  
150 #TODO
151 }
152  
153 sub init {
154 3105 ▶ my ( $self, $conf ) = @_;
Subroutine init: called CC=5 SCAR=16.1
Pod undocumented
155 3105 $self->{$_} = {} foreach (qw(data customParameters sessionInfo pdata));
156 3105 $self->{$_} = [] foreach (qw(respCookies));
157 3105 ▶ if ( $conf->{whatToTrace}
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"whatToTrace"} and my $tmp = $self->userData->{$conf->{"whatToTrace"}}) 113 2992 3105
Condition100%3/3
$conf->{"whatToTrace"} and my $tmp = $self->userData->{$conf->{"whatToTrace"}}
!ll&&!rl&&r
12991113
MC/DC100%2/2
$conf->{"whatToTrace"} and my $tmp = $self->userData->{$conf->{"whatToTrace"}}
$conf->{"whatToTrace"} my $tmp = $self->userData->{$conf->{"whatToTrace"}}
Truth table100%3/3
A and B
A= $conf->{"whatToTrace"}B= my $tmp = $self->userData->{$conf->{"whatToTrace"}}
ABresult
0X0
100
111
158 and my $tmp = $self->userData->{ $conf->{whatToTrace} } )
159 {
160 113 $self->user($tmp);
161 }
162 }
163  
164 sub errorString {
165 0 ▶ print STDERR "TODO Request::errorString()\n";
Subroutine errorString: not called CC=1 SCAR=6.9
Pod undocumented
166 }
167  
168 sub loginInfo {
169 0 ▶ print STDERR "TODO Request::loginInfo()\n";
Subroutine loginInfo: not called CC=1 SCAR=6.9
Pod undocumented
170 }
171  
172 sub setInfo {
173 0 ▶ my ( $self, $info ) = @_;
Subroutine setInfo: not called CC=2 SCAR=17.9
Pod undocumented
174 0 ▶ $self->data->{_info} = $info if ( defined $info );
Branch: 1 branch
BranchTrueFalseTotal
if defined $info 0 0 0
175 0 return $self->data->{_info};
176 }
177  
178 sub info {
179 1722 ▶ my ( $self, $info ) = @_;
Subroutine info: called CC=2 SCAR=6.9
Pod documented
180 1722 ▶ $self->data->{_info} .= $info if ( defined $info );
Branch: 1 branch
BranchTrueFalseTotal
if defined $info 22 1700 1722
181 1722 return $self->data->{_info};
182 }
183  
184 sub addCookie {
185 287 ▶ my ( $self, $cookie ) = @_;
Subroutine addCookie: called CC=1 SCAR=0.0
Pod documented
186 287 push @{ $self->respHeaders }, 'Set-Cookie' => $cookie;
187 }
188  
189 sub delCookie {
190 0 ▶ my ( $self, $cookieName ) = @_;
Subroutine delCookie: not called CC=4 SCAR=30.0
Pod documented
191 0 my $i = 0;
192 0 @{ $self->respHeaders } = map {
193  
194 # Look for a Set-Cookie header
195 0 ▶ if ( $_ =~ /^Set-Cookie$/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_ =~ /^Set-Cookie$/i) { } 0 0 0
elsif ($i) { } 0 0 0
196 0 $i = 1;
197 0 return ();
198 }
199 elsif ($i) {
200  
201 # Keep other cookies
202 0 ▶ unless (/^$cookieName\s*=/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/^$cookieName\s*=/i) 0 0 0
203 0 $i = 0;
204 0 return ( 'Set-Cookie' => $_ );
205 }
206  
207 #Value is hidden here
208 0 return ();
209 }
210 0 return $_;
211 0 } @{ $self->respHeaders };
212 }
213  
214 # TODO: oldpassword
215 442 1;
216 __END__
217  
218 =head1 NAME
219  
220 =encoding utf8
221  
222 Lemonldap::NG::Portal::Main::Request - HTTP request object used in LLNG
223 portal methods.
224  
225 =head1 SYNOPSIS
226  
227 # Somewhere in a plugin...
228 sub run {
229 my ( $self, $req ) = @_;
230 # $req is a Lemonldap::NG::Portal::Main::Request object
231 ...
232 }
233  
234 =head1 DESCRIPTION
235  
236 Lemonldap::NG::Portal::Main::Request extends
237 L<Lemonldap::NG::Common::PSGI::Request> to add all parameters needed to manage
238 portal jobs.
239  
240 =head1 METHODS
241  
242 =head2 Accessors
243  
244 =head3 steps()
245  
246 Stack of methods to call for this requests. It can be modified to change
247 authentication process
248  
249 =head3 data()
250  
251 Free hash ref where plugins can store their data (during one request). Using it
252 is a LLNG best practice
253  
254 =head3 pdata
255  
256 Free hash ref where plugins can store some persistent data: data are kept
257 during auth process and cleaned after successful authentication, except if
258 C<$req-E<gt>pdata-E<gt>{keepPdata}> is set to an array of values. In this
259 case, module that has set these values must remove them after its job ends.
260  
261 =head3 User information
262  
263 =head4 id()
264  
265 Session id (main cookie value).
266  
267 =head4 sessionInfo()
268  
269 Hash ref that will be stored in session DB.
270  
271 =head4 user()
272  
273 Username given by authentication module, used by userDB module.
274  
275 =head3 mustRedirect()
276  
277 Boolean to indicate that response must be a redirection (used for example when
278 request is a POST).
279  
280 =head3 urlNotBase64
281  
282 Boolean to indicate that url isn't Base64 encoded.
283  
284 =head2 Other methods
285  
286 =head3 info()
287  
288 Store info to display in response.
289  
290 =head3 menuError()
291  
292 =head3 notification()
293  
294 see notification plugin.
295  
296 =head3 errorType()
297  
298 Returns positive/warning/negative depending on value stored in error property.
299  
300 =head2 Cookie methods
301  
302 =over
303  
304 =item addCookie(string $cookie): add cookie in $req response headers. String
305 is a complete cookie string, ex: "lemonldap=xxx"
306  
307 =item delCookie(string $cookieName): remove cookie from $req response headers.
308 It doesn't remove navigator cookie but remove a "Set-Cookie" header if value
309 match "L<lt>cookieNameL<gt>=..."
310  
311 =back
312  
313 =head1 SEE ALSO
314  
315 L<http://lemonldap-ng.org/>, L<Lemonldap::NG::Common::PSGI::Request>
316  
317 =head1 AUTHORS
318  
319 =over
320  
321 =item LemonLDAP::NG team L<http://lemonldap-ng.org/team>
322  
323 =back
324  
325 =head1 BUG REPORT
326  
327 Use OW2 system to report bug or ask for features:
328 L<https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues>
329  
330 =head1 DOWNLOAD
331  
332 Lemonldap::NG is available at
333 L<https://lemonldap-ng.org/download>
334  
335 =head1 COPYRIGHT AND LICENSE
336  
337 See COPYING file for details.
338  
339 This library is free software; you can redistribute it and/or modify
340 it under the terms of the GNU General Public License as published by
341 the Free Software Foundation; either version 2, or (at your option)
342 any later version.
343  
344 This program is distributed in the hope that it will be useful,
345 but WITHOUT ANY WARRANTY; without even the implied warranty of
346 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
347 GNU General Public License for more details.
348  
349 You should have received a copy of the GNU General Public License
350 along with this program. If not, see L<http://www.gnu.org/licenses/>.
351  
352 =cut
« blib/lib/Lemonldap/NG/Portal/Plugins/CDA.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Plugins/AutoSignin.pm »