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

filter: Statementstmt 98.4% 63 / 64 Branchbran 82.3% 28 / 34 Conditioncond 70.5% 24 / 34 MC/DCmcdc 42.1% 8 / 19 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 3 totaltotal 80.5% 128 / 159 CC 32 SCAR 26.4
CC
32
Cov
87%
enabledPlugins
20.3
enabledServices
8.3
checkConf
7.0
CRAP 14.0
« blib/lib/Lemonldap/NG/Portal/Auth/WebAuthn.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Auth/PAM.pm »
1 # This module loads known enabled plugins. To add custom modules, just add them
2 # into "plugins" list in lemonldap-ng.ini, section "portal"
3 package Lemonldap::NG::Portal::Main::Plugins;
4  
5 429 our $VERSION = '2.22.0';
6  
7 package Lemonldap::NG::Portal::Main;
8  
9 429 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 429 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # Plugins enabled by a simple boolean value (ordered list)
13 #
14 # Developers: 2FA must be loaded before Notifications
15 # Developers: GlobalLogout must be the last loaded plugin
16 # Developers: Notifications must be loaded before PublicNotifications
17 429 our @pList = (
18 portalDisplayResetPassword => '::Plugins::MailPasswordReset',
19 portalDisplayCertificateResetByMail => '::Plugins::CertificateResetByMail',
20 cda => '::Plugins::CDA',
21 notification => '::Plugins::Notifications',
22 publicNotifications => '::Plugins::PublicNotifications',
23 rememberAuthChoiceRule => '::Plugins::RememberAuthChoice',
24 stayConnected => '::Plugins::StayConnected',
25 portalCheckLogins => '::Plugins::History',
26 bruteForceProtection => '::Plugins::BruteForceProtection',
27 grantSessionRules => '::Plugins::GrantSession',
28 upgradeSession => '::Plugins::Upgrade',
29 autoSigninRules => '::Plugins::AutoSignin',
30 checkState => '::Plugins::CheckState',
31 webCronSecret => '::Plugins::WebCron',
32 portalForceAuthn => '::Plugins::ForceAuthn',
33 checkUser => '::Plugins::CheckUser',
34 checkDevOps => '::Plugins::CheckDevOps',
35 contextSwitchingRule => '::Plugins::ContextSwitching',
36 decryptValueRule => '::Plugins::DecryptValue',
37 findUser => '::Plugins::FindUser',
38 newLocationWarning => '::Plugins::NewLocationWarning',
39 passwordPolicyActivation => '::Plugins::BasePasswordPolicy',
40 checkHIBP => '::Plugins::CheckHIBP',
41 checkEntropy => '::Plugins::CheckEntropy',
42 initializePasswordReset => '::Plugins::InitializePasswordReset',
43 oidcOfflineTokens => '::Plugins::OidcOfflineTokens',
44 adaptativeAuthenticationLevelRules =>
45 '::Plugins::AdaptativeAuthenticationLevel',
46 refreshSessions => '::Plugins::Refresh',
47 crowdsec => '::Plugins::CrowdSec',
48 crowdsecAgent => '::Plugins::CrowdSecAgent',
49 locationDetect => '::Plugins::LocationDetect',
50 globalLogoutRule => '::Plugins::GlobalLogout',
51 samlFederationFiles => '::Plugins::SamlFederation',
52 adminLogoutServerSecret => '::Plugins::AdminLogout',
53 'or::oidcRPMetaDataOptions/*/oidcRPMetaDataOptionsAllowNativeSso' =>
54 '::Plugins::OIDCNativeSso',
55 'or::oidcOPMetaDataOptions/*/oidcOPMetaDataOptionsRequirePkce' =>
56 '::Plugins::AuthOidcPkce',
57 'or::oidcRPMetaDataOptions/*/oidcRPMetaDataOptionsTokenXAuthorizedRP' =>
58 '::Plugins::OIDCInternalTokenExchange',
59 );
60  
61 ##@method list enabledPlugins
62 #
63 #@return list of enabled plugins
64 #
65 # List can be:
66 # * a plugin name
67 # * an array ref containing:
68 # - the property into which the plugin has to be linked
69 # - the plugin name
70 #
71 # If plugin name starts with '::', the prefix Lemonldap::NG::Portal will be
72 # added
73  
74 sub enabledServices {
75 490 ▶ my ($self) = @_;
Subroutine enabledServices: called CC=8 SCAR=21.1
Pod undocumented
76 490 my $conf = $self->conf;
77 490 my @res;
78  
79 # Second factor
80 490 push @res, [ secondFactor => $self->conf->{'sfEngine'} ];
81  
82 # Portal menu
83 490 push @res, [ menu => "::Main::Menu" ];
84  
85 # Trusted browser
86 490 ▶ if ( $self->conf->{trustedBrowserRule} or $self->conf->{stayConnected} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"trustedBrowserRule"} or $self->conf->{"stayConnected"}) 8 482 490
Condition100%3/3
$self->conf->{"trustedBrowserRule"} or $self->conf->{"stayConnected"}
l!l&&r!l&&!r
17482
MC/DC100%2/2
$self->conf->{"trustedBrowserRule"} or $self->conf->{"stayConnected"}
$self->conf->{"trustedBrowserRule"} $self->conf->{"stayConnected"}
Truth table100%3/3
A or B
A= $self->conf->{"trustedBrowserRule"}B= $self->conf->{"stayConnected"}
ABresult
1X1
011
000
87 my $module =
88 8 ▶ $self->conf->{'trustedBrowserEngine'} || '::Plugins::TrustedBrowser';
Condition50%1/2
$self->conf->{'trustedBrowserEngine'} || '::Plugins::TrustedBrowser'
l!l
08
MC/DC0%0/1
$self->conf->{'trustedBrowserEngine'} || '::Plugins::TrustedBrowser'
$self->conf->{'trustedBrowserEngine'}
Truth table50%1/2
A
A= $self->conf->{'trustedBrowserEngine'}
Aresult
11
00
89 8 $self->logger->debug("$module needed");
90 8 push @res, [ trustedBrowser => $module ];
91 }
92  
93 # Captcha
94 490 ▶ if ( $self->conf->{captcha_mail_enabled}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"captcha_mail_enabled"} or $self->conf->{"captcha_login_enabled"} or $self->conf->{"captcha_register_enabled"}) 2 0 2
Condition66%4/6
$self->conf->{"captcha_mail_enabled"} or $self->conf->{"captcha_login_enabled"} or $self->conf->{"captcha_register_enabled"}
l!l&&r!l&&!r
48820
$self->conf->{"captcha_mail_enabled"} or $self->conf->{"captcha_login_enabled"}
l!l&&r!l&&!r
48802
MC/DC0%0/3
$self->conf->{"captcha_mail_enabled"} or $self->conf->{"captcha_login_enabled"} or $self->conf->{"captcha_register_enabled"}
$self->conf->{"captcha_mail_enabled"} $self->conf->{"captcha_login_enabled"} $self->conf->{"captcha_register_enabled"}
Truth table50%2/4
A or B or C
A= $self->conf->{"captcha_mail_enabled"}B= $self->conf->{"captcha_login_enabled"}C= $self->conf->{"captcha_register_enabled"}
ABCresult
1XX1
01X1
0011
0000
95 || $self->conf->{captcha_login_enabled}
96 || $self->conf->{captcha_register_enabled} )
97 {
98 490 ▶ my $module = $self->conf->{'captcha'} || '::Captcha::SecurityImage';
Condition50%1/2
$self->conf->{'captcha'} || '::Captcha::SecurityImage'
l!l
0490
MC/DC0%0/1
$self->conf->{'captcha'} || '::Captcha::SecurityImage'
$self->conf->{'captcha'}
Truth table50%1/2
A
A= $self->conf->{'captcha'}
Aresult
11
00
99 490 $self->logger->debug("$module needed");
100 490 push @res, [ captcha => $module ];
101 }
102 490 return @res;
103 }
104  
105 sub enabledPlugins {
106 169 ▶ my ($self) = @_;
Subroutine enabledPlugins: called CC=19 SCAR=30.1
Pod undocumented
107 169 my $conf = $self->conf;
108 169 my @res;
109  
110 # Search for Issuer* modules enabled
111 169 foreach my $key (qw(SAML OpenID CAS OpenIDConnect Get JitsiMeetTokens)) {
112 1014 ▶ if ( $conf->{"issuerDB${key}Activation"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$conf{"issuerDB${key}Activation"}) 46 968 1014
113 46 $self->logger->debug("Issuer${key} enabled");
114 46 push @res, "::Issuer::$key";
115 }
116 }
117  
118 # Load single session
119 push @res, '::Plugins::SingleSession'
120 if ( $conf->{singleSession}
121 or $conf->{singleIP}
122 or $conf->{singleUserByIP}
123 169 ▶ or $conf->{notifyOther} );
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"singleSession"} or $conf->{"singleIP"} or $conf->{"singleUserByIP"} or $conf->{"notifyOther"} 2 156 158
Condition88%8/9
$conf->{"singleSession"} or $conf->{"singleIP"} or $conf->{"singleUserByIP"} or $conf->{"notifyOther"}
l!l&&r!l&&!r
130156
$conf->{"singleSession"} or $conf->{"singleIP"} or $conf->{"singleUserByIP"}
l!l&&r!l&&!r
112156
$conf->{"singleSession"} or $conf->{"singleIP"}
l!l&&r!l&&!r
47158
MC/DC75%3/4
$conf->{"singleSession"} or $conf->{"singleIP"} or $conf->{"singleUserByIP"} or $conf->{"notifyOther"}
$conf->{"singleSession"} $conf->{"singleIP"} $conf->{"singleUserByIP"} $conf->{"notifyOther"}
Truth table80%4/5
A or B or C or D
A= $conf->{"singleSession"}B= $conf->{"singleIP"}C= $conf->{"singleUserByIP"}D= $conf->{"notifyOther"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
124  
125 # Load static plugin list
126 169 ▶ for ( my $i = 0 ; $i < @pList ; $i += 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @Lemonldap::NG::Portal::Main::pList) 6253 169 6422
127 6253 my $pluginConf;
128 6253 ▶ if ( $pList[$i] =~ /^(.*?)::(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Lemonldap::NG::Portal::Main::pList[$i] =~ /^(.*?)::(.*)$/) { } 507 5746 6253
129 507 $pluginConf = checkConf( $conf, $2, $1 );
130 }
131 else {
132 5746 my $c = $conf->{ $pList[$i] };
133 5746 ▶ $pluginConf = ( ref($c) && ref($c) eq 'HASH' ? scalar(%$c) : $c );
Branch: 1 branch
BranchTrueFalseTotal
ref $c && ref $c eq 'HASH' ? : 169 5577 5746
Condition66%2/3
ref $c and ref $c eq "HASH"
!ll&&!rl&&r
55770169
MC/DC50%1/2
ref $c and ref $c eq "HASH"
ref $c ref $c eq "HASH"
Truth table66%2/3
A and B
A= ref $cB= ref $c eq "HASH"
ABresult
0X0
100
111
134 }
135 6253 ▶ push @res, $pList[ $i + 1 ] if $pluginConf;
Branch: 1 branch
BranchTrueFalseTotal
if $pluginConf 519 5734 6253
136 }
137  
138 # Check if SOAP is enabled
139 push @res, '::Plugins::SOAPServer'
140 if ( $conf->{soapSessionServer}
141 169 ▶ or $conf->{soapConfigServer} );
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"soapSessionServer"} or $conf->{"soapConfigServer"} 0 169 169
Condition33%1/3
$conf->{"soapSessionServer"} or $conf->{"soapConfigServer"}
l!l&&r!l&&!r
00169
MC/DC0%0/2
$conf->{"soapSessionServer"} or $conf->{"soapConfigServer"}
$conf->{"soapSessionServer"} $conf->{"soapConfigServer"}
Truth table33%1/3
A or B
A= $conf->{"soapSessionServer"}B= $conf->{"soapConfigServer"}
ABresult
1X1
011
000
142  
143 # Add REST (check is done by plugin itself)
144 169 push @res, '::Plugins::RESTServer';
145  
146 # Check if password is enabled
147 169 ▶ if ( my $p = $conf->{passwordDB} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $p = $conf->{"passwordDB"}) 169 0 169
148 169 push @res, "::Password::$p";
149 }
150  
151 # Check if register is enabled
152 push @res, '::Plugins::Register'
153 169 ▶ if ( $conf->{registerDB} and $conf->{registerDB} ne 'Null' );
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"registerDB"} and $conf->{"registerDB"} ne "Null" 0 169 169
Condition33%1/3
$conf->{"registerDB"} and $conf->{"registerDB"} ne "Null"
!ll&&!rl&&r
01690
MC/DC0%0/2
$conf->{"registerDB"} and $conf->{"registerDB"} ne "Null"
$conf->{"registerDB"} $conf->{"registerDB"} ne "Null"
Truth table33%1/3
A and B
A= $conf->{"registerDB"}B= $conf->{"registerDB"} ne "Null"
ABresult
0X0
100
111
154  
155 # Check if custom plugins are required
156 169 ▶ if ( $conf->{customPlugins} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"customPlugins"}) 9 160 169
157 9 $self->logger->debug( 'Custom plugins: ' . $conf->{customPlugins} );
158 9 push @res, grep ( /\w+/, split( /[,\s]+/, $conf->{customPlugins} ) );
159 }
160  
161 # Impersonation overwrites req->step and pops 'afterData' EP.
162 # Static and custom 'afterData' plugins will be never launched
163 # if they are loaded after Impersonation.
164 # This plugin must be the last 'afterData' loaded plugin. Fix #2655
165 push @res, '::Plugins::Impersonation'
166 169 ▶ if $conf->{impersonationRule};
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"impersonationRule"} 0 169 169
167  
168 169 return @res;
169 }
170  
171 sub checkConf {
172 1120 ▶ my ( $conf, $path, $type ) = @_;
Subroutine checkConf: called CC=7 SCAR=19.5
Pod undocumented
173 1120 ▶ if ( $path =~ s#^(.*?)/## ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ s[^(.*?)/][]) { } 1014 106 1120
174 1014 my $w = $1;
175 1014 ▶ if ( $w eq '*' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w eq '*') { } 507 507 1014
176 507 my @res;
177 507 ▶ foreach my $k ( keys %{ $conf || {} } ) {
Branch: 1 branch
BranchTrueFalseTotal
$conf or {} 387 120 507
178 106 push @res, checkConf( $conf->{$k}, $path, $type );
179 }
180 507 ▶ if ( $type eq 'or' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'or') { } 507 0 507
181 507 my $res = 0;
182 507 ▶ map { $res ||= $_ } @res;
Condition100%3/3
$res ||= $_
l!l&&r!l&&!r
23101
MC/DC100%2/2
$res ||= $_
$res $_
Truth table100%3/3
A ||= B
A= $resB= $_
ABresult
1X1
011
000
183 507 return $res;
184 }
185 0 else { die "Unkown type $type"; }
186 }
187 else {
188 507 return checkConf( $conf->{$w}, $path, $type );
189 }
190 }
191 else {
192 106 return $conf->{$path};
193 }
194 }
195  
196 429 1;
« blib/lib/Lemonldap/NG/Portal/Auth/WebAuthn.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Auth/PAM.pm »