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

filter: Statementstmt 80.7% 147 / 182 Branchbran 63.4% 52 / 82 Conditioncond 39.5% 19 / 48 MC/DCmcdc 14.8% 4 / 27 Subroutinesub 93.7% 15 / 16 Podpod 0.0% 0 / 3 totaltotal 66.2% 237 / 358 CC 62 SCAR 34.3
CC
62
Cov
70%
_buildAuthLoop
60.9
_getChoiceFromReq
33.5
init
16.5
CRAP 30.8
« blib/lib/Lemonldap/NG/Portal/UserDB/WebID.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Lib/Radius.pm »
1 package Lemonldap::NG::Portal::Lib::Choice;
2  
3 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 29 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 29 ▶use Safe;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 29 use Lemonldap::NG::Portal::Main::Constants qw(
7 PE_OK
8 URIRE
9 29 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 27 extends 'Lemonldap::NG::Portal::Lib::Wrapper';
12 27 with 'Lemonldap::NG::Portal::Lib::OverConf';
13  
14 27 our $VERSION = '2.23.0';
15  
16 122 ▶has modules => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
17 122 ▶has rules => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
18 27 has type => ( is => 'rw' );
19 122 ▶has catch => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
20 27 has sessionKey => ( is => 'ro', default => '_choice' );
21  
22 27 my $_choiceRules;
23 27 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 122 ▶ my ( $self, $type ) = @_;
Subroutine init: called CC=13 SCAR=28.0
Pod undocumented
33 122 $self->type($type);
34  
35 122 ▶ unless ( $self->conf->{authChoiceModules}
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->conf->{"authChoiceModules"} and %{$self->conf->{"authChoiceModules"};}) 0 122 122
Condition33%1/3
$self->conf->{"authChoiceModules"} and %{$self->conf->{"authChoiceModules"};}
!ll&&!rl&&r
00122
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 122 and %{ $self->conf->{authChoiceModules} } )
37 {
38 0 $self->error("'authChoiceModules' is empty");
39 0 return 0;
40 }
41  
42 122 foreach my $name ( keys %{ $self->conf->{authChoiceModules} } ) {
43 my @mods =
44 258 split( /;\s*/, $self->conf->{authChoiceModules}->{$name} );
45 258 my $module = '::'
46 . [ 'Auth', 'UserDB', 'Password' ]->[$type] . '::'
47 . $mods[$type];
48 258 my $over;
49 258 ▶ if ( $mods[5] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mods[5]) 40 218 258
50 40 eval { $over = JSON::from_json( $mods[5] ) };
51 40 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 40 40
52 0 $self->logger->error("Bad over value ($@), skipped");
53 }
54 }
55 258 ▶ if ( $module = $self->loadModule( $module, $over ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module = $self->loadModule($module, $over)) { } 258 0 258
56 258 $self->modules->{$name} = $module;
57 258 $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 258 ▶ unless ($type) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type) 126 132 258
72 126 ▶ if ( $module->can('catch') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module->can("catch")) 0 126 126
73 0 $self->catch->{$name} = $module->catch;
74 }
75 }
76  
77 # Display conditions
78 258 my $cond = $mods[4];
79 258 ▶ if ( defined $cond and $cond ne "" ) { # 0 is a valid rule!
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cond and $cond ne '') { } 4 254 258
Condition100%3/3
defined $cond and $cond ne ""
!ll&&!rl&&r
214404
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 254 $self->logger->debug("No rule for $name");
87 254 ▶ $_choiceRules->{$name} = sub { 1 };
Subroutine __ANON__: called CC=1 SCAR=0.0
88 }
89 }
90 122 ▶ unless ( keys %{ $self->modules } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %{$self->modules;}) 0 122 122
91 0 $self->error('Choice: no available module found, aborting');
92 0 return 0;
93 }
94 122 return 1;
95 }
96  
97 # RUNNING METHODS
98  
99 sub checkChoice {
100 96 ▶ my ( $self, $req ) = @_;
Subroutine checkChoice: called CC=5 SCAR=16.4
Pod undocumented
101 96 my ( $name, $how ) = $self->_getChoiceFromReq($req);
102  
103 96 ▶ return 0 unless ($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $name 11 85 96
104 85 $self->logger->debug("Choice $name selected from $how");
105  
106 85 ▶ unless ( defined $self->modules->{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->modules->{$name}) 0 85 85
107 0 $self->logger->error("Unknown choice '$name'");
108 0 return 0;
109 }
110  
111 85 ▶ unless ( $req->data->{findUserChoice} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->data->{"findUserChoice"}) 85 0 85
112  
113 # Store choice if module loops
114 85 $req->pdata->{_choice} = $name;
115 85 $req->data->{_authChoice} = $name;
116 85 $req->sessionInfo->{_choice} = $name;
117 85 $self->p->_authentication->authnLevel("${name}AuthnLevel");
118 }
119  
120 85 ▶ return $name if ( $req->data->{ "enabledMods" . $self->type } );
Branch: 1 branch
BranchTrueFalseTotal
if $req->data->{'enabledMods' . $self->type} 23 62 85
121 $req->data->{ "enabledMods" . $self->type } =
122 62 [ $self->modules->{$name} ];
123 62 return $name;
124 }
125  
126 sub _getChoiceFromReq {
127 96 ▶ my ( $self, $req ) = @_;
Subroutine _getChoiceFromReq: called CC=19 SCAR=35.1
128  
129 # Check Choice from pdata
130 96 ▶ if ( defined $req->pdata->{_choice} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $req->pdata->{'_choice'}) { } 44 52 96
elsif (defined $req->data->{'_authChoice'} or defined $req->data->{'_choice'}) { } 0 52 52
131 44 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
0052
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 52 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 52 ▶ if ( $req->data->{_pwdCheck} and $self->{conf}->{authChoiceAuthBasic} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->data->{"_pwdCheck"} and $self->{"conf"}{"authChoiceAuthBasic"}) 0 52 52
Condition33%1/3
$req->data->{"_pwdCheck"} and $self->{"conf"}{"authChoiceAuthBasic"}
!ll&&!rl&&r
5200
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 52 ▶ if ( $req->data->{findUserChoice} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->data->{"findUserChoice"}) 0 52 52
153 0 return ( $req->data->{findUserChoice}, "findUser" );
154 }
155  
156 52 ▶ if ( $req->parameters->get( $self->conf->{authChoiceParam} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->parameters->get($self->conf->{"authChoiceParam"})) 22 30 52
157 22 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 30 ▶ unless ( $req->data->{discardChoiceForCurrentSession} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->data->{"discardChoiceForCurrentSession"}) 30 0 30
164 30 ▶ if ( $req->userData->{_choice} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->userData->{"_choice"}) 8 22 30
165 8 return ( $req->userData->{_choice}, "userData" );
166 }
167 22 ▶ if ( $req->sessionInfo->{_choice} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->sessionInfo->{"_choice"}) 0 22 22
168 0 return ( $req->sessionInfo->{_choice}, "sessionInfo" );
169 }
170 }
171  
172 22 ▶ if ( $self->conf->{authChoiceSelectOnly} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"authChoiceSelectOnly"}) 9 13 22
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 13 my $context = {};
182 13 my $h = $self->p->processHook( $req, 'getAuthChoice', $context );
183 13 ▶ return 0 if ( $h != PE_OK );
Branch: 1 branch
BranchTrueFalseTotal
if $h != 0 0 13 13
184 13 ▶ if ( $h == PE_OK and $context->{choice} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h == 0 and $context->{"choice"}) 2 11 13
Condition66%2/3
$h == 0 and $context->{"choice"}
!ll&&!rl&&r
0112
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 11 return 0;
189 }
190  
191 sub name {
192 22 ▶ my ( $self, $req, $type ) = @_;
Subroutine name: called CC=3 SCAR=11.1
Pod undocumented
193 22 ▶ unless ($req) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($req) 0 22 22
194 0 return 'Choice';
195 }
196  
197 22 my $module = $req->data->{ "enabledMods" . $self->type }->[0];
198 22 ▶ if ( my $sub = eval { $module->can('name') } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = eval { do { $module->can('name') } }) { } 10 12 22
199 10 return $sub->( $module, $req, $type );
200 }
201 else {
202 12 my $n = ref($module);
203 12 $n =~ s/^Lemonldap::NG::Portal::(?:(?:UserDB|Auth)::)?//;
204 12 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 17 ▶ my ( $self, $req ) = @_;
Subroutine _buildAuthLoop: called CC=24 SCAR=41.1
214 17 my @authLoop;
215  
216 # Test authentication choices
217 17 ▶ unless ( ref $self->conf->{authChoiceModules} eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self->conf->{"authChoiceModules"} eq "HASH") 0 17 17
218 0 $self->logger->warn("No authentication choices defined");
219 0 return [];
220 }
221  
222 17 foreach ( sort keys %{ $self->conf->{authChoiceModules} } ) {
223  
224 28 my $name = $_;
225  
226 # Name can have a digit as first character
227 # for sorting purpose
228 # Remove it in displayed name
229 28 $name =~ s/^(\d*)?(\s*)?//;
230  
231 # Replace also _ by space for a nice display
232 28 $name =~ s/\_/ /g;
233  
234 # Find modules associated to authChoice
235 my ( $auth, $userDB, $passwordDB, $url, $condition ) =
236 28 split( /;\s*/, $self->conf->{authChoiceModules}->{$_} );
237  
238 28 ▶ unless ( $self->_evaluateRule( $req, $_ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_evaluateRule($req, $_)) { } 28 0 28
239 0 $self->logger->debug(
240 "Condition returns false, authentication choice $_"
241 . " will not be displayed" );
242 }
243 else {
244 28 ▶ if ( $auth
Branch: 1 branch
BranchTrueFalseTotal
if ($auth and not $_disabledModules->{$_}{'0'} and $userDB and not $_disabledModules->{$_}{'1'} and $passwordDB and not $_disabledModules->{$_}{'2'}) { } 28 0 28
Condition33%5/15
$auth and not $_disabledModules->{$_}{0} and $userDB and not $_disabledModules->{$_}{1} and $passwordDB and not $_disabledModules->{$_}{2}
!ll&&!rl&&r
0028
$auth and not $_disabledModules->{$_}{0} and $userDB and not $_disabledModules->{$_}{1} and $passwordDB
!ll&&!rl&&r
0028
$auth and not $_disabledModules->{$_}{0} and $userDB and not $_disabledModules->{$_}{1}
!ll&&!rl&&r
0028
$auth and not $_disabledModules->{$_}{0} and $userDB
!ll&&!rl&&r
0028
$auth and not $_disabledModules->{$_}{0}
!ll&&!rl&&r
0028
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 28 $self->logger->debug("Displaying authentication choice $_");
252  
253 # Default URL
254 28 ▶ $req->data->{cspFormAction} ||= {};
Condition100%2/2
$req->data->{"cspFormAction"} ||= {}
l!l
1117
MC/DC100%1/1
$req->data->{"cspFormAction"} ||= {}
$req->data->{"cspFormAction"}
Truth table100%2/2
A
A= $req->data->{"cspFormAction"}
Aresult
11
00
255 28 ▶ 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 28 28
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
1990
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 28 $url .= '#';
261 }
262 28 $self->logger->debug("Use URL $url");
263  
264 28 eval {
265 28 my $mod = $self->_authentication->modules->{$_};
266 28 ▶ $mod->initDisplay($req) if $mod->can('initDisplay');
Branch: 1 branch
BranchTrueFalseTotal
if $mod->can("initDisplay") 28 0 28
267 };
268 28 ▶ $self->logger->info(
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 28 28
269 "Unable to initialize choice $_ display: $@")
270 if $@;
271  
272 28 my $name_without_space = $name =~ s/^\s*//r;
273  
274 # Options to store in the loop
275 28 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 27 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
287 28 ▶ my $displayType = eval {
Condition50%1/2
eval { || 'logo'
l!l
280
MC/DC0%0/1
eval { do { $self->_authentication->modules->{$_}->getDisplayType($req) } } || 'logo'
eval { do { $self->_authentication->modules->{$_}->getDisplayType($req) } }
Truth table50%1/2
A
A= eval { do { $self->_authentication->modules->{$_}->getDisplayType($req) } }
Aresult
11
00
288 28 $self->_authentication->modules->{$_}->getDisplayType($req);
289 } || 'logo';
290  
291 28 $self->logger->debug(
292 "Display type $displayType for module $auth");
293 28 $optionsLoop->{$displayType} = 1;
294 28 my $logo = $_;
295  
296 28 my $foundLogo = 0;
297  
298 # If displayType is logo, check if key.png is available
299 28 ▶ if ( -e $self->conf->{templateDir}
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->conf->{'templateDir'} . '/../htdocs/static/common/modules/' . $logo . '.png') { } 0 28 28
300 . "/../htdocs/static/common/modules/"
301 . $logo
302 . ".png" )
303 {
304 0 $optionsLoop->{logoFile} = $logo . ".png";
305 0 $foundLogo = 1;
306 }
307 else {
308 28 $optionsLoop->{logoFile} = $auth . ".png";
309 }
310  
311 # Compatibility, with Custom, try the module name if
312 # key was not found
313 28 ▶ if ( $auth eq 'Custom' and not $foundLogo ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($auth eq "Custom" and not $foundLogo) 0 28 28
Condition33%1/3
$auth eq "Custom" and not $foundLogo
!ll&&!rl&&r
2800
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
314 $logo =
315 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
316 [0];
317 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
318 $logo
319 and ( -e $self->conf->{templateDir}
320 . "/../htdocs/static/common/modules/"
321 . $logo
322 . ".png" )
323 )
324 {
325 0 $optionsLoop->{logoFile} = $logo . ".png";
326 }
327 }
328  
329 # If a choice has already been selected,
330 # activate the corresponding form
331 28 ▶ if ( $req->data->{_authChoice} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->data->{'_authChoice'}) { } 14 14 28
332 $optionsLoop->{ACTIVE_FORM} =
333 14 ( $req->data->{_authChoice} eq $_ );
334  
335 }
336  
337 # if not, activate the first form in the list
338 else {
339 14 ▶ $optionsLoop->{ACTIVE_FORM} = @authLoop ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
@authLoop ? : 6 8 14
340 }
341  
342 # Register item in loop
343 28 push @authLoop, $optionsLoop;
344  
345 28 $self->logger->debug(
346 "Authentication choice $name_without_space will be displayed"
347 );
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 17 return \@authLoop;
361  
362 }
363  
364 sub _evaluateRule {
365 37 ▶ my ( $self, $req, $choice ) = @_;
Subroutine _evaluateRule: called CC=3 SCAR=13.0
366  
367 37 my $extraData = {};
368 $extraData->{targetAuthnLevel} = $req->pdata->{targetAuthnLevel}
369 37 ▶ if defined $req->pdata->{targetAuthnLevel};
Branch: 1 branch
BranchTrueFalseTotal
if defined $req->pdata->{"targetAuthnLevel"} 0 37 37
370 37 ▶ unless ( $_choiceRules->{$choice} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_choiceRules->{$choice}) 0 37 37
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 37 return $_choiceRules->{$_}->( $req, $extraData );
375 }
376  
377 27 1;
378  
« blib/lib/Lemonldap/NG/Portal/UserDB/WebID.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Lib/Radius.pm »