blib/lib/Lemonldap/NG/Portal/Lib/Choice.pm

filter: Statementstmt 79.6% 145 / 182 Branchbran 60.9% 50 / 82 Conditioncond 39.5% 19 / 48 MC/DCmcdc 14.8% 4 / 27 Subroutinesub 93.7% 15 / 16 Podpod 0.0% 0 / 3 totaltotal 65.0% 233 / 358 CC 62 SCAR 34.6
CC
62
Cov
69%
_buildAuthLoop
60.9
_getChoiceFromReq
37.5
init
16.5
CRAP 31.7
« blib/lib/Lemonldap/NG/Portal/Plugins/AdaptativeAuthenticationLevel.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Lib/RESTProxy.pm »
1 package Lemonldap::NG::Portal::Lib::Choice;
2  
3 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 ▶use Safe;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 27 use Lemonldap::NG::Portal::Main::Constants qw(
7 PE_OK
8 URIRE
9 27 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 25 extends 'Lemonldap::NG::Portal::Lib::Wrapper';
12 25 with 'Lemonldap::NG::Portal::Lib::OverConf';
13  
14 25 our $VERSION = '2.22.0';
15  
16 66 ▶has modules => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
17 66 ▶has rules => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
18 25 has type => ( is => 'rw' );
19 66 ▶has catch => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
20 25 has sessionKey => ( is => 'ro', default => '_choice' );
21  
22 25 my $_choiceRules;
23 25 my $_disabledModules = {};
24  
25 # INITIALIZATION
26  
27 # init() must be called by module::init() with a number:
28 # - 0 for auth
29 # - 1 for userDB
30 # - 2 for passwordDB
31 sub init {
32 66 ▶ my ( $self, $type ) = @_;
Subroutine init: called CC=13 SCAR=28.0
Pod undocumented
33 66 $self->type($type);
34  
35 66 ▶ unless ( $self->conf->{authChoiceModules}
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->conf->{"authChoiceModules"} and %{$self->conf->{"authChoiceModules"};}) 0 66 66
Condition33%1/3
$self->conf->{"authChoiceModules"} and %{$self->conf->{"authChoiceModules"};}
!ll&&!rl&&r
0066
MC/DC0%0/2
$self->conf->{"authChoiceModules"} and %{$self->conf->{"authChoiceModules"};}
$self->conf->{"authChoiceModules"} %{$self->conf->{"authChoiceModules"};}
Truth table33%1/3
A and B
A= $self->conf->{"authChoiceModules"}B= %{$self->conf->{"authChoiceModules"};}
ABresult
0X0
100
111
36 66 and %{ $self->conf->{authChoiceModules} } )
37 {
38 0 $self->error("'authChoiceModules' is empty");
39 0 return 0;
40 }
41  
42 66 foreach my $name ( keys %{ $self->conf->{authChoiceModules} } ) {
43 my @mods =
44 128 split( /;\s*/, $self->conf->{authChoiceModules}->{$name} );
45 128 my $module = '::'
46 . [ 'Auth', 'UserDB', 'Password' ]->[$type] . '::'
47 . $mods[$type];
48 128 my $over;
49 128 ▶ if ( $mods[5] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mods[5]) 36 92 128
50 36 eval { $over = JSON::from_json( $mods[5] ) };
51 36 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 36 36
52 0 $self->logger->error("Bad over value ($@), skipped");
53 }
54 }
55 128 ▶ if ( $module = $self->loadModule( $module, $over ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module = $self->loadModule($module, $over)) { } 128 0 128
56 128 $self->modules->{$name} = $module;
57 128 $self->logger->debug(
58 [qw(Authentication User Password)]->[$type]
59 . " module $name selected" );
60 }
61 else {
62 0 $_disabledModules->{$name}->{$type} = 1;
63 0 $self->logger->error( "Choice: unable to load $name ("
64 . [ 'Auth', 'UserDB', 'Password' ]->[$type]
65 . "), disabling it: "
66 . $self->error );
67 0 $self->error('');
68 }
69  
70 # Test if auth module wants to catch some path
71 128 ▶ unless ($type) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type) 63 65 128
72 63 ▶ if ( $module->can('catch') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module->can("catch")) 0 63 63
73 0 $self->catch->{$name} = $module->catch;
74 }
75 }
76  
77 # Display conditions
78 128 my $cond = $mods[4];
79 128 ▶ if ( defined $cond and $cond ne "" ) { # 0 is a valid rule!
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cond and $cond ne '') { } 4 124 128
Condition100%3/3
defined $cond and $cond ne ""
!ll&&!rl&&r
88364
MC/DC100%2/2
defined $cond and $cond ne ""
defined $cond $cond ne ""
Truth table100%3/3
A and B
A= defined $condB= $cond ne ""
ABresult
0X0
100
111
80 4 my $rule =
81 $self->p->buildRule( $cond, "Choice condition for $name" );
82 4 ▶ return 0 unless $rule;
Branch: 1 branch
BranchTrueFalseTotal
unless $rule 0 4 4
83 4 $_choiceRules->{$name} = $rule;
84 }
85 else {
86 124 $self->logger->debug("No rule for $name");
87 124 ▶ $_choiceRules->{$name} = sub { 1 };
Subroutine __ANON__: called CC=1 SCAR=0.0
88 }
89 }
90 66 ▶ unless ( keys %{ $self->modules } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %{$self->modules;}) 0 66 66
91 0 $self->error('Choice: no available module found, aborting');
92 0 return 0;
93 }
94 66 return 1;
95 }
96  
97 # RUNNING METHODS
98  
99 sub checkChoice {
100 29 ▶ my ( $self, $req ) = @_;
Subroutine checkChoice: called CC=5 SCAR=16.4
Pod undocumented
101 29 my ( $name, $how ) = $self->_getChoiceFromReq($req);
102  
103 29 ▶ return 0 unless ($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $name 3 26 29
104 26 $self->logger->debug("Choice $name selected from $how");
105  
106 26 ▶ unless ( defined $self->modules->{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->modules->{$name}) 0 26 26
107 0 $self->logger->error("Unknown choice '$name'");
108 0 return 0;
109 }
110  
111 26 ▶ unless ( $req->data->{findUserChoice} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->data->{"findUserChoice"}) 26 0 26
112  
113 # Store choice if module loops
114 26 $req->pdata->{_choice} = $name;
115 26 $req->data->{_authChoice} = $name;
116 26 $req->sessionInfo->{_choice} = $name;
117 26 $self->p->_authentication->authnLevel("${name}AuthnLevel");
118 }
119  
120 26 ▶ return $name if ( $req->data->{ "enabledMods" . $self->type } );
Branch: 1 branch
BranchTrueFalseTotal
if $req->data->{'enabledMods' . $self->type} 4 22 26
121 $req->data->{ "enabledMods" . $self->type } =
122 22 [ $self->modules->{$name} ];
123 22 return $name;
124 }
125  
126 sub _getChoiceFromReq {
127 29 ▶ my ( $self, $req ) = @_;
Subroutine _getChoiceFromReq: called CC=19 SCAR=36.2
128  
129 # Check Choice from pdata
130 29 ▶ if ( defined $req->pdata->{_choice} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $req->pdata->{'_choice'}) { } 9 20 29
elsif (defined $req->data->{'_authChoice'} or defined $req->data->{'_choice'}) { } 0 20 20
131 9 return ( $req->pdata->{_choice}, "pdata" );
132 }
133 ▶ elsif (( defined $req->data->{_authChoice} )
Condition33%1/3
defined $req->data->{"_authChoice"} or defined $req->data->{"_choice"}
l!l&&r!l&&!r
0020
MC/DC0%0/2
defined $req->data->{"_authChoice"} or defined $req->data->{"_choice"}
defined $req->data->{"_authChoice"} defined $req->data->{"_choice"}
Truth table33%1/3
A or B
A= defined $req->data->{"_authChoice"}B= defined $req->data->{"_choice"}
ABresult
1X1
011
000
134 or ( defined $req->data->{_choice} ) )
135 {
136 0 ▶ my $name = $req->data->{_authChoice} || $req->data->{_choice};
Condition0%0/3
$req->data->{'_authChoice'} || $req->data->{'_choice'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$req->data->{'_authChoice'} || $req->data->{'_choice'}
$req->data->{'_authChoice'} $req->data->{'_choice'}
Truth table0%0/3
A || B
A= $req->data->{'_authChoice'}B= $req->data->{'_choice'}
ABresult
1X1
011
000
137 0 return ( $name, "req->data" );
138 }
139  
140 # Check with catch method
141 20 foreach ( keys %{ $self->catch } ) {
142 0 ▶ if ( $req->path_info =~ $self->catch->{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->path_info =~ /$self->catch->{$_}/) 0 0 0
143 0 return ( $_, "caught path " . $req->path_info );
144 }
145 }
146  
147 # Set by OAuth Resource Owner grant // RESTServer pwdCheck
148 20 ▶ if ( $req->data->{_pwdCheck} and $self->{conf}->{authChoiceAuthBasic} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->data->{"_pwdCheck"} and $self->{"conf"}{"authChoiceAuthBasic"}) 0 20 20
Condition33%1/3
$req->data->{"_pwdCheck"} and $self->{"conf"}{"authChoiceAuthBasic"}
!ll&&!rl&&r
2000
MC/DC0%0/2
$req->data->{"_pwdCheck"} and $self->{"conf"}{"authChoiceAuthBasic"}
$req->data->{"_pwdCheck"} $self->{"conf"}{"authChoiceAuthBasic"}
Truth table33%1/3
A and B
A= $req->data->{"_pwdCheck"}B= $self->{"conf"}{"authChoiceAuthBasic"}
ABresult
0X0
100
111
149 0 return ( $self->{conf}->{authChoiceAuthBasic}, "basic auth context" );
150 }
151  
152 20 ▶ if ( $req->data->{findUserChoice} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->data->{"findUserChoice"}) 0 20 20
153 0 return ( $req->data->{findUserChoice}, "findUser" );
154 }
155  
156 20 ▶ if ( $req->parameters->get( $self->conf->{authChoiceParam} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->parameters->get($self->conf->{"authChoiceParam"})) 6 14 20
157 6 return ( $req->parameters->get( $self->conf->{authChoiceParam} ),
158 "param" );
159 }
160  
161 # Use the choice from current session unless we are doing an upgrade
162 # in which case the user should be offered to choose again
163 14 ▶ unless ( $req->data->{discardChoiceForCurrentSession} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->data->{"discardChoiceForCurrentSession"}) 14 0 14
164 14 ▶ if ( $req->userData->{_choice} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->userData->{"_choice"}) 0 14 14
165 0 return ( $req->userData->{_choice}, "userData" );
166 }
167 14 ▶ if ( $req->sessionInfo->{_choice} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->sessionInfo->{"_choice"}) 0 14 14
168 0 return ( $req->sessionInfo->{_choice}, "sessionInfo" );
169 }
170 }
171  
172 14 ▶ if ( $self->conf->{authChoiceSelectOnly} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"authChoiceSelectOnly"}) 9 5 14
173 9 my @allowed_choices = grep { $self->_evaluateRule( $req, $_ ) }
174 9 keys %{ $self->conf->{authChoiceModules} };
175 9 ▶ if ( @allowed_choices == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@allowed_choices == 1) 9 0 9
176 9 return ( $allowed_choices[0], "only available" );
177 }
178 }
179  
180 # Try hook
181 5 my $context = {};
182 5 my $h = $self->p->processHook( $req, 'getAuthChoice', $context );
183 5 ▶ return 0 if ( $h != PE_OK );
Branch: 1 branch
BranchTrueFalseTotal
if $h != 0 0 5 5
184 5 ▶ if ( $h == PE_OK and $context->{choice} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h == 0 and $context->{"choice"}) 2 3 5
Condition66%2/3
$h == 0 and $context->{"choice"}
!ll&&!rl&&r
032
MC/DC50%1/2
$h == 0 and $context->{"choice"}
$h == 0 $context->{"choice"}
Truth table66%2/3
A and B
A= $h == 0B= $context->{"choice"}
ABresult
0X0
100
111
185 2 return ( $context->{choice}, "hook" );
186 }
187  
188 3 return 0;
189 }
190  
191 sub name {
192 6 ▶ my ( $self, $req, $type ) = @_;
Subroutine name: called CC=3 SCAR=11.7
Pod undocumented
193 6 ▶ unless ($req) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($req) 0 6 6
194 0 return 'Choice';
195 }
196  
197 6 my $module = $req->data->{ "enabledMods" . $self->type }->[0];
198 6 ▶ if ( my $sub = eval { $module->can('name') } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = eval { do { $module->can('name') } }) { } 0 6 6
199 0 return $sub->($module, $req, $type );
200 }
201 else {
202 6 my $n = ref($module);
203 6 $n =~ s/^Lemonldap::NG::Portal::(?:(?:UserDB|Auth)::)?//;
204 6 return $n;
205 }
206 }
207  
208 package Lemonldap::NG::Portal::Main;
209  
210 # Build authentication loop displayed in template
211 # Return authLoop array reference
212 sub _buildAuthLoop {
213 14 ▶ my ( $self, $req ) = @_;
Subroutine _buildAuthLoop: called CC=24 SCAR=41.1
214 14 my @authLoop;
215  
216 # Test authentication choices
217 14 ▶ unless ( ref $self->conf->{authChoiceModules} eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self->conf->{"authChoiceModules"} eq "HASH") 0 14 14
218 0 $self->logger->warn("No authentication choices defined");
219 0 return [];
220 }
221  
222 14 foreach ( sort keys %{ $self->conf->{authChoiceModules} } ) {
223  
224 20 my $name = $_;
225  
226 # Name can have a digit as first character
227 # for sorting purpose
228 # Remove it in displayed name
229 20 $name =~ s/^(\d*)?(\s*)?//;
230  
231 # Replace also _ by space for a nice display
232 20 $name =~ s/\_/ /g;
233  
234 # Find modules associated to authChoice
235 my ( $auth, $userDB, $passwordDB, $url, $condition ) =
236 20 split( /;\s*/, $self->conf->{authChoiceModules}->{$_} );
237  
238 20 ▶ unless ( $self->_evaluateRule( $req, $_ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_evaluateRule($req, $_)) { } 20 0 20
239 0 $self->logger->debug(
240 "Condition returns false, authentication choice $_"
241 . " will not be displayed" );
242 }
243 else {
244 20 ▶ if ( $auth
Branch: 1 branch
BranchTrueFalseTotal
if ($auth and not $_disabledModules->{$_}{'0'} and $userDB and not $_disabledModules->{$_}{'1'} and $passwordDB and not $_disabledModules->{$_}{'2'}) { } 20 0 20
Condition33%5/15
$auth and not $_disabledModules->{$_}{0} and $userDB and not $_disabledModules->{$_}{1} and $passwordDB and not $_disabledModules->{$_}{2}
!ll&&!rl&&r
0020
$auth and not $_disabledModules->{$_}{0} and $userDB and not $_disabledModules->{$_}{1} and $passwordDB
!ll&&!rl&&r
0020
$auth and not $_disabledModules->{$_}{0} and $userDB and not $_disabledModules->{$_}{1}
!ll&&!rl&&r
0020
$auth and not $_disabledModules->{$_}{0} and $userDB
!ll&&!rl&&r
0020
$auth and not $_disabledModules->{$_}{0}
!ll&&!rl&&r
0020
MC/DC0%0/6
$auth and not $_disabledModules->{$_}{0} and $userDB and not $_disabledModules->{$_}{1} and $passwordDB and not $_disabledModules->{$_}{2}
$auth not $_disabledModules->{$_}{0} $userDB not $_disabledModules->{$_}{1} $passwordDB not $_disabledModules->{$_}{2}
Truth table14%1/7
A and not(B) and C and not(D) and E and not(F)
A= $authB= not $_disabledModules->{$_}{0}C= $userDBD= not $_disabledModules->{$_}{1}E= $passwordDBF= not $_disabledModules->{$_}{2}
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
245 and not $_disabledModules->{$_}->{0}
246 and $userDB
247 and not $_disabledModules->{$_}->{1}
248 and $passwordDB
249 and not $_disabledModules->{$_}->{2} )
250 {
251 20 $self->logger->debug("Displaying authentication choice $_");
252  
253 # Default URL
254 20 ▶ $req->data->{cspFormAction} ||= {};
Condition100%2/2
$req->data->{"cspFormAction"} ||= {}
l!l
614
MC/DC100%1/1
$req->data->{"cspFormAction"} ||= {}
$req->data->{"cspFormAction"}
Truth table100%2/2
A
A= $req->data->{"cspFormAction"}
Aresult
11
00
255 20 ▶ if ( defined $url and $url =~ URIRE ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $url and $url =~ m[(((?^:https?))://((?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)|(?:[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)))(?::((?:[0-9]*)))?(/(((?:(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:/(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))(?:[?]((?:(?:[;/?:\@&=+\$,a-zA-Z0-9\-_.!~*'()]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)))?))?)]) { } 0 20 20
Condition66%2/3
defined $url and $url =~ m[(((?^:https?))://((?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)|(?:[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)))(?::((?:[0-9]*)))?(/(((?:(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:/(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))(?:[?]((?:(?:[;/?:\@&=+\$,a-zA-Z0-9\-_.!~*'()]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)))?))?)]
!ll&&!rl&&r
1370
MC/DC0%0/2
defined $url and $url =~ m[(((?^:https?))://((?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)|(?:[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)))(?::((?:[0-9]*)))?(/(((?:(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:/(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))(?:[?]((?:(?:[;/?:\@&=+\$,a-zA-Z0-9\-_.!~*'()]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)))?))?)]
defined $url $url =~ m[(((?^:https?))://((?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)|(?:[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)))(?::((?:[0-9]*)))?(/(((?:(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:/(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))(?:[?]((?:(?:[;/?:\@&=+\$,a-zA-Z0-9\-_.!~*'()]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)))?))?)]
Truth table66%2/3
A and B
A= defined $urlB= $url =~ m[(((?^:https?))://((?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)|(?:[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)))(?::((?:[0-9]*)))?(/(((?:(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:/(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))(?:[?]((?:(?:[;/?:\@&=+\$,a-zA-Z0-9\-_.!~*'()]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)))?))?)]
ABresult
0X0
100
111
256 0 my $csp_uri = $self->cspGetHost($url);
257 0 $req->data->{cspFormAction}->{$csp_uri} = 1;
258 }
259 else {
260 20 $url .= '#';
261 }
262 20 $self->logger->debug("Use URL $url");
263  
264 20 eval {
265 20 my $mod = $self->_authentication->modules->{$_};
266 20 ▶ $mod->initDisplay($req) if $mod->can('initDisplay');
Branch: 1 branch
BranchTrueFalseTotal
if $mod->can("initDisplay") 20 0 20
267 };
268 20 ▶ $self->logger->info(
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 20 20
269 "Unable to initialize choice $_ display: $@")
270 if $@;
271  
272 20 my $name_without_space = $name =~ s/^\s*//r;
273  
274 # Options to store in the loop
275 20 my $optionsLoop = {
276 name => $name,
277 key => $_,
278 module => $auth,
279 url => $url,
280 "name_$name_without_space" => 1,
281 "module_$auth" => 1,
282 "key_$_" => 1,
283 };
284  
285 # Get displayType for this module
286 25 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
287 20 ▶ my $displayType = eval {
Condition50%1/2
eval { || 'logo'
l!l
200
MC/DC0%0/1
eval { do { $self->_authentication->modules->{$_}->can('getDisplayType')->($self, $req) } } || 'logo'
eval { do { $self->_authentication->modules->{$_}->can('getDisplayType')->($self, $req) } }
Truth table50%1/2
A
A= eval { do { $self->_authentication->modules->{$_}->can('getDisplayType')->($self, $req) } }
Aresult
11
00
288 20 $self->_authentication->modules->{$_}
289 ->can('getDisplayType')->( $self, $req );
290 } || 'logo';
291  
292 20 $self->logger->debug(
293 "Display type $displayType for module $auth");
294 20 $optionsLoop->{$displayType} = 1;
295 20 my $logo = $_;
296  
297 20 my $foundLogo = 0;
298  
299 # If displayType is logo, check if key.png is available
300 20 ▶ if ( -e $self->conf->{templateDir}
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->conf->{'templateDir'} . '/../htdocs/static/common/modules/' . $logo . '.png') { } 0 20 20
301 . "/../htdocs/static/common/modules/"
302 . $logo
303 . ".png" )
304 {
305 0 $optionsLoop->{logoFile} = $logo . ".png";
306 0 $foundLogo = 1;
307 }
308 else {
309 20 $optionsLoop->{logoFile} = $auth . ".png";
310 }
311  
312 # Compatibility, with Custom, try the module name if
313 # key was not found
314 20 ▶ if ( $auth eq 'Custom' and not $foundLogo ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($auth eq "Custom" and not $foundLogo) 0 20 20
Condition33%1/3
$auth eq "Custom" and not $foundLogo
!ll&&!rl&&r
2000
MC/DC0%0/2
$auth eq "Custom" and not $foundLogo
$auth eq "Custom" not $foundLogo
Truth table33%1/3
A and not(B)
A= $auth eq "Custom"B= not $foundLogo
ABresult
0X0
100
111
315 $logo =
316 0 ▶ ( ( $self->{conf}->{customAuth} || "" ) =~ /::(\w+)$/ )
Condition0%0/2
$self->{'conf'}{'customAuth'} || ''
l!l
00
MC/DC0%0/1
$self->{'conf'}{'customAuth'} || ''
$self->{'conf'}{'customAuth'}
Truth table0%0/2
A
A= $self->{'conf'}{'customAuth'}
Aresult
11
00
317 [0];
318 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($logo and -e $self->conf->{"templateDir"} . '/../htdocs/static/common/modules/' . $logo . '.png') 0 0 0
Condition0%0/3
$logo and -e $self->conf->{"templateDir"} . '/../htdocs/static/common/modules/' . $logo . '.png'
!ll&&!rl&&r
000
MC/DC0%0/2
$logo and -e $self->conf->{"templateDir"} . '/../htdocs/static/common/modules/' . $logo . '.png'
$logo -e $self->conf->{"templateDir"} . '/../htdocs/static/common/modules/' . $logo . '.png'
Truth table0%0/3
A and B
A= $logoB= -e $self->conf->{"templateDir"} . '/../htdocs/static/common/modules/' . $logo . '.png'
ABresult
0X0
100
111
319 $logo
320 and ( -e $self->conf->{templateDir}
321 . "/../htdocs/static/common/modules/"
322 . $logo
323 . ".png" )
324 )
325 {
326 0 $optionsLoop->{logoFile} = $logo . ".png";
327 }
328 }
329  
330 # If a choice has already been selected,
331 # activate the corresponding form
332 20 ▶ if ( $req->data->{_authChoice} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->data->{'_authChoice'}) { } 8 12 20
333 $optionsLoop->{ACTIVE_FORM} =
334 8 ( $req->data->{_authChoice} eq $_ );
335  
336 }
337  
338 # if not, activate the first form in the list
339 else {
340 12 ▶ $optionsLoop->{ACTIVE_FORM} = @authLoop ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
@authLoop ? : 5 7 12
341 }
342  
343 # Register item in loop
344 20 push @authLoop, $optionsLoop;
345  
346 20 $self->logger->debug(
347 "Authentication choice $name_without_space will be displayed");
348 }
349 else {
350 0 $self->logger->debug(
351 "Authentication choice $_ is invalid and will not be displayed"
352 );
353 0 $req->error("Authentication choice $_ is invalid");
354 0 next;
355 }
356 }
357  
358 }
359  
360 14 return \@authLoop;
361  
362 }
363  
364 sub _evaluateRule {
365 29 ▶ my ( $self, $req, $choice ) = @_;
Subroutine _evaluateRule: called CC=3 SCAR=13.0
366  
367 29 my $extraData = {};
368 $extraData->{targetAuthnLevel} = $req->pdata->{targetAuthnLevel}
369 29 ▶ if defined $req->pdata->{targetAuthnLevel};
Branch: 1 branch
BranchTrueFalseTotal
if defined $req->pdata->{"targetAuthnLevel"} 0 29 29
370 29 ▶ unless ( $_choiceRules->{$choice} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_choiceRules->{$choice}) 0 29 29
371 0 $self->logger->error("$choice has no rule");
372 0 ▶ $_choiceRules->{$choice} = sub { 1 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
373 }
374 29 return $_choiceRules->{$_}->( $req, $extraData );
375 }
376  
377 25 1;
378  
« blib/lib/Lemonldap/NG/Portal/Plugins/AdaptativeAuthenticationLevel.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Lib/RESTProxy.pm »