blib/lib/Lemonldap/NG/Common/Session/Purge.pm

filter: Statementstmt 64.2% 318 / 495 Branchbran 29.2% 45 / 154 Conditioncond 28.4% 31 / 109 MC/DCmcdc 14.7% 9 / 61 Subroutinesub 89.0% 49 / 55 Podpod 0.0% 0 / 4 totaltotal 51.4% 452 / 878 CC 136 SCAR 45.5
CC
136
Cov
52%
_cleanup_errors
486.1
__ANON__
90.0
_purge_for_backend
78.8
CRAP 94.2
« blib/lib/Lemonldap/NG/Common/OpenIDConnect/Metadata.pm ↑ Summary blib/lib/Lemonldap/NG/Common/Notifications/LDAP.pm »
1 package Lemonldap::NG::Common::Session::Purge;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Lemonldap::NG::Common::Conf;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Lemonldap::NG::Common::Conf::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Lemonldap::NG::Common::Apache::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Lemonldap::NG::Common::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Lemonldap::NG::Common::Safelib;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Lemonldap::NG::Common::PSGI::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Time::HiRes;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use POSIX qw(strftime);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use constant defaultLogger => 'Lemonldap::NG::Common::Logger::Std';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 has logLevel => ( is => 'rw' );
18 2 has force => ( is => 'rw' );
19 2 has audit => ( is => 'rw' );
20 2 has json => ( is => 'rw' );
21 has conf => (
22 is => 'ro',
23 default => sub {
24 0 ▶ my $ca = Lemonldap::NG::Common::Conf->new()
Subroutine __ANON__: not called CC=9 SCAR=45.0
Branch: 1 branch
BranchTrueFalseTotal
my $ca = "Lemonldap::NG::Common::Conf"->new or die $Lemonldap::NG::Common::Conf::msg 0 0 0
25 or die $Lemonldap::NG::Common::Conf::msg;
26 0 ▶ my $conf =
Branch: 1 branch
BranchTrueFalseTotal
my $conf = $ca->getConf or die "Unable to get configuration ($!)" or die "Unable to get configuration ($!)" 0 0 0
Condition0%0/2
my $conf = $ca->getConf or die "Unable to get configuration ($!)"
l!l
00
MC/DC0%0/1
my $conf = $ca->getConf or die "Unable to get configuration ($!)"
my $conf = $ca->getConf
Truth table0%0/2
A
A= my $conf = $ca->getConf
Aresult
11
00
27 $ca->getConf
28 or die "Unable to get configuration ($!)"
29 or die "Unable to get configuration ($!)";
30 0 ▶ my $localconf = $ca->getLocalConf(PORTALSECTION)
Branch: 1 branch
BranchTrueFalseTotal
my $localconf = $ca->getLocalConf("portal") or die "Unable to get local configuration ($!)" 0 0 0
31 or die "Unable to get local configuration ($!)";
32 0 ▶ if ($localconf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($localconf) 0 0 0
33 0 $conf->{$_} = $localconf->{$_} foreach ( keys %$localconf );
34 }
35 0 ▶ $conf->{logLevel} = $_[0]->logLevel || $conf->{logLevel} || 'info';
Condition0%0/5
$_[0]->logLevel || $conf->{'logLevel'} || 'info'
l!l
00
$_[0]->logLevel or $conf->{"logLevel"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0]->logLevel || $conf->{'logLevel'} || 'info'
$_[0]->logLevel $conf->{"logLevel"}
Truth table0%0/3
A or B
A= $_[0]->logLevelB= $conf->{"logLevel"}
ABresult
1X1
011
000
36 0 return $conf;
37 },
38 2 lazy => 1,
39 );
40  
41 has logger => (
42 is => 'ro',
43 default => sub {
44 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=7 SCAR=40.3
45 0 my $conf = $self->conf;
46 my $logger =
47 0 ▶ $self->conf->{logger} || $ENV{LLNG_DEFAULTLOGGER} || defaultLogger;
Condition0%0/5
$self->conf->{'logger'} || $ENV{'LLNG_DEFAULTLOGGER'} || 'Lemonldap::NG::Common::Logger::Std'
l!l
00
$self->conf->{"logger"} or $ENV{"LLNG_DEFAULTLOGGER"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->conf->{'logger'} || $ENV{'LLNG_DEFAULTLOGGER'} || 'Lemonldap::NG::Common::Logger::Std'
$self->conf->{"logger"} $ENV{"LLNG_DEFAULTLOGGER"}
Truth table0%0/3
A or B
A= $self->conf->{"logger"}B= $ENV{"LLNG_DEFAULTLOGGER"}
ABresult
1X1
011
000
48 0 $logger =~ s/^::/Lemonldap::NG::Common::Logger::/;
49 0 ▶ $logger = defaultLogger
Branch: 1 branch
BranchTrueFalseTotal
if $logger eq "Lemonldap::NG::Common::Logger::Apache2" 0 0 0
50 if $logger eq 'Lemonldap::NG::Common::Logger::Apache2';
51 0 eval "require $logger";
52 0 ▶ die $@ if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
53 0 my $err;
54  
55 0 ▶ unless ( $conf->{logLevel} =~ /^(?:debug|info|notice|warn|error)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($conf->{"logLevel"} =~ /^(?:debug|info|notice|warn|error)$/) 0 0 0
56 0 $err = "Bad logLevel value $conf->{logLevel}, use 'info'";
57 0 $conf->{logLevel} = 'info';
58 }
59 0 $logger = $logger->new($conf);
60 0 ▶ $logger->error($err) if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
61 0 return $logger;
62 },
63 2 lazy => 1,
64 );
65  
66 has userLogger => (
67 is => 'ro',
68 default => sub {
69 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=7 SCAR=40.3
70 0 my $conf = $self->conf;
71 my $logger =
72 0 ▶ $self->conf->{userLogger} || $ENV{LLNG_USERLOGGER} || defaultLogger;
Condition0%0/5
$self->conf->{'userLogger'} || $ENV{'LLNG_USERLOGGER'} || 'Lemonldap::NG::Common::Logger::Std'
l!l
00
$self->conf->{"userLogger"} or $ENV{"LLNG_USERLOGGER"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->conf->{'userLogger'} || $ENV{'LLNG_USERLOGGER'} || 'Lemonldap::NG::Common::Logger::Std'
$self->conf->{"userLogger"} $ENV{"LLNG_USERLOGGER"}
Truth table0%0/3
A or B
A= $self->conf->{"userLogger"}B= $ENV{"LLNG_USERLOGGER"}
ABresult
1X1
011
000
73 0 $logger =~ s/^::/Lemonldap::NG::Common::Logger::/;
74 0 ▶ $logger = defaultLogger
Branch: 1 branch
BranchTrueFalseTotal
if $logger eq "Lemonldap::NG::Common::Logger::Apache2" 0 0 0
75 if $logger eq 'Lemonldap::NG::Common::Logger::Apache2';
76 0 eval "require $logger";
77 0 ▶ die $@ if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
78 0 my $err;
79  
80 0 ▶ unless ( $conf->{logLevel} =~ /^(?:debug|info|notice|warn|error)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($conf->{"logLevel"} =~ /^(?:debug|info|notice|warn|error)$/) 0 0 0
81 0 $err = "Bad logLevel value $conf->{logLevel}, use 'info'";
82 0 $conf->{logLevel} = 'info';
83 }
84 0 $logger = $logger->new($conf);
85 0 ▶ $logger->error($err) if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
86 0 return $logger;
87 },
88 2 lazy => 1,
89 );
90  
91 has _auditLogger => (
92 is => 'ro',
93 default => sub {
94 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=4 SCAR=30.0
95 0 my $conf = $self->conf;
96 my $logger =
97 $self->conf->{auditLogger}
98 || $ENV{LLNG_AUDITLOGGER}
99 0 ▶ || "Lemonldap::NG::Common::AuditLogger::UserLoggerCompat";
Condition0%0/5
$self->conf->{'auditLogger'} || $ENV{'LLNG_AUDITLOGGER'} || 'Lemonldap::NG::Common::AuditLogger::UserLoggerCompat'
l!l
00
$self->conf->{"auditLogger"} or $ENV{"LLNG_AUDITLOGGER"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->conf->{'auditLogger'} || $ENV{'LLNG_AUDITLOGGER'} || 'Lemonldap::NG::Common::AuditLogger::UserLoggerCompat'
$self->conf->{"auditLogger"} $ENV{"LLNG_AUDITLOGGER"}
Truth table0%0/3
A or B
A= $self->conf->{"auditLogger"}B= $ENV{"LLNG_AUDITLOGGER"}
ABresult
1X1
011
000
100  
101 0 eval "require $logger";
102 0 ▶ die $@ if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
103  
104 0 $logger = $logger->new($self);
105 0 return $logger;
106 },
107 2 lazy => 1,
108 );
109  
110 has persistent_backend_options => (
111 is => 'ro',
112 default => sub {
113 9 ▶ my $conf = $_[0]->conf;
Subroutine __ANON__: called CC=4 SCAR=13.9
114 9 my $logger = $_[0]->logger;
115  
116 9 my $type;
117 my $options;
118  
119 # sessions
120 9 ▶ if ( $conf->{persistentStorage} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{'persistentStorage'}) { } 9 0 9
121 9 $type = 'persistent';
122 }
123 else {
124 0 $type = 'global';
125 }
126  
127 # load module
128 9 my $module = $conf->{"${type}Storage"};
129 1 ▶ eval "use $module";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
130 9 ▶ die $@ if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 9 9
131  
132 9 ▶ $options = { %{ $conf->{"${type}StorageOptions"} // {} } };
Condition50%1/2
$$conf{"${type}StorageOptions"} // {}
l!l
90
MC/DC0%0/1
$$conf{"${type}StorageOptions"} // {}
$$conf{"${type}StorageOptions"}
Truth table50%1/2
A
A= $$conf{"${type}StorageOptions"}
Aresult
11
00
133 9 $options->{backend} = $module;
134  
135 9 $logger->debug("persistent session backend $module will be used");
136 9 return $options;
137 },
138 2 lazy => 1,
139 );
140  
141 has backends => (
142 is => 'ro',
143 default => sub {
144 6 ▶ my $conf = $_[0]->conf;
Subroutine __ANON__: called CC=23 SCAR=41.6
145 6 my $logger = $_[0]->logger;
146 6 my %backends;
147 my $module;
148  
149 # Sessions
150 6 ▶ if ( $conf->{globalStorage} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"globalStorage"}) 6 0 6
151  
152 # Load module
153 6 $module = $conf->{globalStorage};
154 6 ▶ eval "use $module";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
155 6 ▶ die $@ if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 6 6
156 6 $conf->{globalStorageOptions}->{backend} = $module;
157  
158 # Add module in managed backends
159 6 $backends{SSO} = $conf->{globalStorageOptions};
160  
161 6 $logger->debug("Session backend $module will be used");
162 }
163  
164 # SAML
165 6 ▶ if ( $conf->{samlStorage}
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"samlStorage"} or keys %{$conf->{"samlStorageOptions"} ||= {};}) 6 0 6
Condition33%1/3
$conf->{"samlStorage"} or keys %{$conf->{"samlStorageOptions"} ||= {};}
l!l&&r!l&&!r
600
MC/DC0%0/2
$conf->{"samlStorage"} or keys %{$conf->{"samlStorageOptions"} ||= {};}
$conf->{"samlStorage"} keys %{$conf->{"samlStorageOptions"} ||= {};}
Truth table33%1/3
A or B
A= $conf->{"samlStorage"}B= keys %{$conf->{"samlStorageOptions"} ||= {};}
ABresult
1X1
011
000
166 0 ▶ or keys %{ $conf->{samlStorageOptions} ||= {} } )
Condition0%0/2
$conf->{"samlStorageOptions"} ||= {}
l!l
00
MC/DC0%0/1
$conf->{"samlStorageOptions"} ||= {}
$conf->{"samlStorageOptions"}
Truth table0%0/2
A
A= $conf->{"samlStorageOptions"}
Aresult
11
00
167 {
168  
169 # Load module
170 6 ▶ $module = $conf->{samlStorage} || $conf->{globalStorage};
Condition33%1/3
$conf->{'samlStorage'} || $conf->{'globalStorage'}
l!l&&r!l&&!r
600
MC/DC0%0/2
$conf->{'samlStorage'} || $conf->{'globalStorage'}
$conf->{'samlStorage'} $conf->{'globalStorage'}
Truth table33%1/3
A || B
A= $conf->{'samlStorage'}B= $conf->{'globalStorage'}
ABresult
1X1
011
000
171 6 ▶ eval "use $module";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
172 6 ▶ die $@ if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 6 6
173 6 $conf->{samlStorageOptions}->{backend} = $module;
174  
175 # Add module in managed backends
176 6 $backends{SAML} = $conf->{samlStorageOptions};
177  
178 6 $logger->debug("SAML backend $module will be used");
179 }
180  
181 # CAS
182 6 ▶ if ( $conf->{casStorage}
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"casStorage"} or keys %{$conf->{"casStorageOptions"} ||= {};}) 0 6 6
Condition33%1/3
$conf->{"casStorage"} or keys %{$conf->{"casStorageOptions"} ||= {};}
l!l&&r!l&&!r
006
MC/DC0%0/2
$conf->{"casStorage"} or keys %{$conf->{"casStorageOptions"} ||= {};}
$conf->{"casStorage"} keys %{$conf->{"casStorageOptions"} ||= {};}
Truth table33%1/3
A or B
A= $conf->{"casStorage"}B= keys %{$conf->{"casStorageOptions"} ||= {};}
ABresult
1X1
011
000
183 6 ▶ or keys %{ $conf->{casStorageOptions} ||= {} } )
Condition50%1/2
$conf->{"casStorageOptions"} ||= {}
l!l
06
MC/DC0%0/1
$conf->{"casStorageOptions"} ||= {}
$conf->{"casStorageOptions"}
Truth table50%1/2
A
A= $conf->{"casStorageOptions"}
Aresult
11
00
184 {
185  
186 # Load module
187 0 ▶ $module = $conf->{casStorage} || $conf->{globalStorage};
Condition0%0/3
$conf->{'casStorage'} || $conf->{'globalStorage'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$conf->{'casStorage'} || $conf->{'globalStorage'}
$conf->{'casStorage'} $conf->{'globalStorage'}
Truth table0%0/3
A || B
A= $conf->{'casStorage'}B= $conf->{'globalStorage'}
ABresult
1X1
011
000
188 0 eval "use $module";
189 0 ▶ die $@ if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
190 0 $conf->{casStorageOptions}->{backend} = $module;
191  
192 # Add module in managed backends
193 0 $backends{CAS} = $conf->{casStorageOptions};
194  
195 0 $logger->debug("CAS backend $module will be used");
196 }
197  
198 # Captcha
199 6 ▶ if ( $conf->{captchaStorage}
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"captchaStorage"} or keys %{$conf->{"captchaStorageOptions"} ||= {};}) 0 6 6
Condition33%1/3
$conf->{"captchaStorage"} or keys %{$conf->{"captchaStorageOptions"} ||= {};}
l!l&&r!l&&!r
006
MC/DC0%0/2
$conf->{"captchaStorage"} or keys %{$conf->{"captchaStorageOptions"} ||= {};}
$conf->{"captchaStorage"} keys %{$conf->{"captchaStorageOptions"} ||= {};}
Truth table33%1/3
A or B
A= $conf->{"captchaStorage"}B= keys %{$conf->{"captchaStorageOptions"} ||= {};}
ABresult
1X1
011
000
200 6 ▶ or keys %{ $conf->{captchaStorageOptions} ||= {} } )
Condition50%1/2
$conf->{"captchaStorageOptions"} ||= {}
l!l
06
MC/DC0%0/1
$conf->{"captchaStorageOptions"} ||= {}
$conf->{"captchaStorageOptions"}
Truth table50%1/2
A
A= $conf->{"captchaStorageOptions"}
Aresult
11
00
201 {
202  
203 # Load module
204 0 ▶ $module = $conf->{captchaStorage} || $conf->{globalStorage};
Condition0%0/3
$conf->{'captchaStorage'} || $conf->{'globalStorage'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$conf->{'captchaStorage'} || $conf->{'globalStorage'}
$conf->{'captchaStorage'} $conf->{'globalStorage'}
Truth table0%0/3
A || B
A= $conf->{'captchaStorage'}B= $conf->{'globalStorage'}
ABresult
1X1
011
000
205 0 eval "use $module";
206 0 ▶ die $@ if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
207 0 $conf->{captchaStorageOptions}->{backend} = $module;
208  
209 # Add module in managed backends
210 0 $backends{Captcha} = $conf->{captchaStorageOptions};
211  
212 0 $logger->debug("Captcha backend $module will be used");
213 }
214  
215 # OpenIDConnect
216 6 ▶ if ( $conf->{oidcStorage}
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"oidcStorage"} or keys %{$conf->{"oidcStorageOptions"} ||= {};}) 0 6 6
Condition33%1/3
$conf->{"oidcStorage"} or keys %{$conf->{"oidcStorageOptions"} ||= {};}
l!l&&r!l&&!r
006
MC/DC0%0/2
$conf->{"oidcStorage"} or keys %{$conf->{"oidcStorageOptions"} ||= {};}
$conf->{"oidcStorage"} keys %{$conf->{"oidcStorageOptions"} ||= {};}
Truth table33%1/3
A or B
A= $conf->{"oidcStorage"}B= keys %{$conf->{"oidcStorageOptions"} ||= {};}
ABresult
1X1
011
000
217 6 ▶ or keys %{ $conf->{oidcStorageOptions} ||= {} } )
Condition50%1/2
$conf->{"oidcStorageOptions"} ||= {}
l!l
06
MC/DC0%0/1
$conf->{"oidcStorageOptions"} ||= {}
$conf->{"oidcStorageOptions"}
Truth table50%1/2
A
A= $conf->{"oidcStorageOptions"}
Aresult
11
00
218 {
219  
220 # Load module
221 0 ▶ $module = $conf->{oidcStorage} || $conf->{globalStorage};
Condition0%0/3
$conf->{'oidcStorage'} || $conf->{'globalStorage'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$conf->{'oidcStorage'} || $conf->{'globalStorage'}
$conf->{'oidcStorage'} $conf->{'globalStorage'}
Truth table0%0/3
A || B
A= $conf->{'oidcStorage'}B= $conf->{'globalStorage'}
ABresult
1X1
011
000
222 0 eval "use $module";
223 0 ▶ die $@ if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
224 0 $conf->{oidcStorageOptions}->{backend} = $module;
225  
226 # Add module in managed backends
227 0 $backends{OIDC} = $conf->{oidcStorageOptions};
228  
229 0 $logger->debug("OIDC backend $module will be used");
230 }
231 6 return \%backends;
232 },
233 2 lazy => 1,
234 );
235  
236 2 has force => ( is => 'ro' );
237  
238 my %PSESSION_FILTERS = (
239 age => {
240 filter => sub {
241 8 ▶ my ( $self, $entry, $value ) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.1
242 return ( defined( $entry->{_utime} )
243 8 ▶ and $entry->{_utime} < ( time - $value ) );
Condition66%2/3
defined $entry->{'_utime'} && $entry->{'_utime'} < &CORE::GLOBAL::time() - $value
!ll&&!rl&&r
035
MC/DC50%1/2
defined $entry->{'_utime'} && $entry->{'_utime'} < &CORE::GLOBAL::time() - $value
defined $entry->{'_utime'} $entry->{'_utime'} < &CORE::GLOBAL::time() - $value
Truth table66%2/3
A && B
A= defined $entry->{'_utime'}B= $entry->{'_utime'} < &CORE::GLOBAL::time() - $value
ABresult
0X0
100
111
244 }
245 },
246 update => {
247 filter => sub {
248 2 ▶ my ( $self, $entry, $value ) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.0
249 2 my $min_updateTime =
250 strftime( "%Y%m%d%H%M%S", localtime( time - $value ) );
251 my $filter_result = ( defined( $entry->{_updateTime} )
252 2 ▶ and $entry->{_updateTime} < $min_updateTime );
Condition66%2/3
defined $entry->{'_updateTime'} && $entry->{'_updateTime'} < $min_updateTime
!ll&&!rl&&r
011
MC/DC50%1/2
defined $entry->{'_updateTime'} && $entry->{'_updateTime'} < $min_updateTime
defined $entry->{'_updateTime'} $entry->{'_updateTime'} < $min_updateTime
Truth table66%2/3
A && B
A= defined $entry->{'_updateTime'}B= $entry->{'_updateTime'} < $min_updateTime
ABresult
0X0
100
111
253 }
254 },
255 login => {
256 filter => sub {
257 12 ▶ my ( $self, $entry, $value ) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
258 my $lastLogin =
259 12 $entry->{_loginHistory}->{successLogin}->[0]->{_utime};
260  
261 12 ▶ my $filter_result = (
Condition100%6/6
!defined($lastLogin) || defined $value && $lastLogin < &CORE::GLOBAL::time() - $value
l!l&&r!l&&!r
525
defined $value and $lastLogin < &CORE::GLOBAL::time() - $value
!ll&&!rl&&r
232
MC/DC100%3/3
!defined($lastLogin) || defined $value && $lastLogin < &CORE::GLOBAL::time() - $value
!defined($lastLogin) defined $value $lastLogin < &CORE::GLOBAL::time() - $value
Truth table100%4/4
not(A) || B and C
A= !defined($lastLogin)B= defined $valueC= $lastLogin < &CORE::GLOBAL::time() - $value
ABCresult
1XX1
0111
00X0
0100
262 not defined($lastLogin)
263 or ( defined($value) and ( $lastLogin < ( time - $value ) ) )
264 );
265 }
266 },
267 sfdevice => {
268 filter => sub {
269 3 ▶ my ( $self, $entry, $value ) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
270 3 return !Lemonldap::NG::Common::Safelib::has2f_internal($entry);
271 }
272 },
273 2 );
274  
275 sub purge {
276 6 ▶ my ($self) = @_;
Subroutine purge: called CC=8 SCAR=20.8
Pod undocumented
277  
278 6 my $internal_stats;
279  
280 # Compute the list of backends here to avoid having big timing
281 # inconsistencies
282 6 my $backends = $self->backends;
283  
284 # Trigger lazy init
285 6 my $conf = $self->conf;
286  
287 6 $self->logger->info("Session purge started");
288 6 $internal_stats->{start_time}->{total} = Time::HiRes::time();
289  
290 6 ▶ while ( my ( $type, $options ) = each %$backends ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$backends) 12 6 18
291 12 $self->_purge_for_backend( $type, $options, $internal_stats );
292 }
293  
294 6 $internal_stats->{end_time}->{total} = Time::HiRes::time();
295  
296 6 my $total_purged = 0;
297 6 $total_purged += $_ for values %{ $internal_stats->{nb_purged} };
298 6 $internal_stats->{nb_purged}->{total} = $total_purged;
299  
300 6 my $total_error = 0;
301 6 $total_error += $_ for values %{ $internal_stats->{nb_error} };
302 6 $internal_stats->{nb_error}->{total} = $total_error;
303  
304 6 my $return_stats;
305 6 for my $type ( "total", sort keys %{ $self->backends } ) {
306 18 $return_stats->{$type}->{errors} = $internal_stats->{nb_error}->{$type};
307 $return_stats->{$type}->{purged} =
308 18 $internal_stats->{nb_purged}->{$type};
309 $return_stats->{$type}->{duration_u} = int(
310 1000000 * (
311 $internal_stats->{end_time}->{$type} -
312 18 $internal_stats->{start_time}->{$type}
313 )
314 );
315 }
316  
317 6 my $log = "Session purge completed: ";
318 6 ▶ if ( $self->json ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->json) { } 0 6 6
319 0 $log .= to_json($return_stats);
320 }
321 else {
322 6 my @logentries;
323 6 for my $type ( "total", sort keys %{ $self->backends } ) {
324 18 my $logentry .= "$type (";
325 18 $logentry .= $return_stats->{$type}->{purged} . " purged, ";
326 18 $logentry .= $return_stats->{$type}->{errors} . " errors in ";
327 18 $logentry .= $return_stats->{$type}->{duration_u} . " us";
328 18 $logentry .= ")";
329 18 push @logentries, $logentry;
330 }
331 6 $log .= join( ', ', @logentries );
332 }
333  
334 6 $self->logger->notice($log);
335 6 ▶ $self->logger->warn(
Branch: 1 branch
BranchTrueFalseTotal
if $total_error 0 6 6
336 "$total_error sessions remaining, try to purge them with force (option -f)"
337 ) if $total_error;
338  
339 return {
340 6 success => !($total_error),
341 purged => $total_purged,
342 errors => $total_error,
343 stats => $return_stats,
344 };
345 }
346  
347 sub _purge_for_backend {
348 12 ▶ my ( $self, $type, $options, $internal_stats ) = @_;
Subroutine _purge_for_backend: called CC=18 SCAR=43.7
349 12 my $conf = $self->conf;
350 12 $self->logger->debug("Cleaning $type sessions");
351  
352 12 $internal_stats->{nb_error}->{$type} = 0;
353 12 $internal_stats->{nb_purged}->{$type} = 0;
354 12 $internal_stats->{start_time}->{$type} = Time::HiRes::time();
355  
356 12 ▶ if ( $options->{backend} eq "Apache::Session::Memcached" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"backend"} eq "Apache::Session::Memcached") 0 12 12
357 0 $internal_stats->{end_time}->{$type} = Time::HiRes::time();
358 0 return;
359 }
360  
361 12 my @t;
362  
363 # Memorize some OIDC parameters
364 12 my ( $rpActivity, $rtMinTimeout );
365 12 ▶ foreach my $rp ( keys %{ $conf->{oidcRPMetaDataOptions} || {} } ) {
Branch: 1 branch
BranchTrueFalseTotal
$conf->{"oidcRPMetaDataOptions"} or {} 12 0 12
366 my $v = $conf->{oidcRPMetaDataOptions}->{$rp}
367 0 ->{oidcRPMetaDataOptionsRtActivity};
368 0 ▶ next unless $v;
Branch: 1 branch
BranchTrueFalseTotal
unless $v 0 0 0
369  
370 # Store the mapping ClientID -> RT timeout
371 $rpActivity->{ $conf->{oidcRPMetaDataOptions}->{$rp}
372 0 ->{oidcRPMetaDataOptionsClientID} } = $v;
373 0 ▶ $rtMinTimeout = $v if !$rpActivity or $v < $rpActivity;
Branch: 1 branch
BranchTrueFalseTotal
if not $rpActivity or $v < $rpActivity 0 0 0
Condition0%0/3
not $rpActivity or $v < $rpActivity
l!l&&r!l&&!r
000
MC/DC0%0/2
not $rpActivity or $v < $rpActivity
not $rpActivity $v < $rpActivity
Truth table0%0/3
not(A) or B
A= not $rpActivityB= $v < $rpActivity
ABresult
1X1
011
000
374 }
375  
376 my $checkRtExpiration = sub {
377 0 ▶ my ( $id, $session ) = @_;
Subroutine __ANON__: not called CC=6 SCAR=37.4
378 0 ▶ return unless $session->{_session_kind} eq 'OIDCI';
Branch: 1 branch
BranchTrueFalseTotal
unless $session->{"_session_kind"} eq "OIDCI" 0 0 0
379 0 ▶ return unless $session->{_type} eq 'refresh_token';
Branch: 1 branch
BranchTrueFalseTotal
unless $session->{"_type"} eq "refresh_token" 0 0 0
380 0 ▶ my $v = $session->{_oidcRtUpdate} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $v = $session->{"_oidcRtUpdate"} or return 0 0 0
381 0 ▶ my $timeout = $rpActivity->{ $session->{client_id} } or return;
Branch: 1 branch
BranchTrueFalseTotal
my $timeout = $$rpActivity{$session->{"client_id"}} or return 0 0 0
382 0 ▶ push @t, $id if $v + $timeout < time;
Branch: 1 branch
BranchTrueFalseTotal
if $v + $timeout < &CORE::GLOBAL::time() 0 0 0
383 12 };
384  
385 # Real purge
386 12 ▶ if ( $options->{backend}->can('deleteIfLowerThan') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{'backend'}->can('deleteIfLowerThan')) { } 0 12 12
387 0 $self->logger->debug("Found deleteIfLowerThan() in backend, using it");
388 my ( $success, $rows ) = $options->{backend}->deleteIfLowerThan(
389 $options,
390 {
391 not => { '_session_kind' => 'Persistent' },
392 or => {
393 _utime => time - $conf->{timeout},
394 (
395 $conf->{timeoutActivity}
396 ? ( _lastSeen => time - $conf->{timeoutActivity} )
397 0 ▶ : ()
Branch: 1 branch
BranchTrueFalseTotal
$conf->{'timeoutActivity'} ? : 0 0 0
398 )
399 }
400 }
401 );
402  
403 0 ▶ if ($success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($success) 0 0 0
404 0 ▶ if ($rows) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rows) 0 0 0
405 0 $internal_stats->{nb_purged}->{$type} += $rows;
406 }
407 0 ▶ if ($rtMinTimeout) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rtMinTimeout) 0 0 0
408 my $rtSessions = $options->{backend}
409 0 ->searchLt( $options, '_oidcRtUpdate', time - $rtMinTimeout );
410 0 ▶ if ($rtSessions) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rtSessions) 0 0 0
411 0 foreach my $id ( keys %$rtSessions ) {
412 0 $checkRtExpiration->( $id, $rtSessions->{$id} );
413 }
414 }
415 }
416 0 $internal_stats->{end_time}->{$type} = Time::HiRes::time();
417 0 ▶ return unless @t;
Branch: 1 branch
BranchTrueFalseTotal
unless @t 0 0 0
418 }
419 }
420  
421 else {
422 # Get all expired sessions
423 Lemonldap::NG::Common::Apache::Session->get_key_from_all_sessions(
424 $options,
425 sub {
426 18 ▶ my $entry = shift;
Subroutine __ANON__: called CC=9 SCAR=22.7
427 18 my $id = shift;
428 18 my $time = time;
429  
430 18 $self->logger->debug("Check session $id");
431  
432 # Empty session need to be removed
433 18 ▶ unless ($entry) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($entry) 0 18 18
434 0 push @t, $id;
435 0 $self->logger->debug(
436 "Session $id is empty (corrupted?), delete forced");
437 }
438  
439 # Do net check sessions without _utime
440 18 ▶ return undef unless $entry->{_utime};
Branch: 1 branch
BranchTrueFalseTotal
unless $entry->{"_utime"} 0 18 18
441  
442 # Do not expire persistent sessions
443 18 ▶ return undef if ( $entry->{_session_kind} eq "Persistent" );
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"_session_kind"} eq "Persistent" 2 16 18
444  
445 # Session expired
446 16 ▶ if ( $time - $entry->{_utime} > $conf->{timeout} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($time - $entry->{'_utime'} > $conf->{'timeout'}) { } 8 8 16
elsif ($conf->{'timeoutActivity'} and $entry->{'_lastSeen'} and $time - $entry->{'_lastSeen'} > $conf->{'timeoutActivity'}) { } 2 6 8
elsif ($rtMinTimeout) { } 0 6 6
447 8 push @t, $id;
448 8 $self->logger->debug("Session $id expired");
449 }
450  
451 # User has no activity, so considere the session has expired
452 ▶ elsif ( $conf->{timeoutActivity}
Condition83%5/6
$conf->{"timeoutActivity"} and $entry->{"_lastSeen"} and $time - $entry->{"_lastSeen"} > $conf->{"timeoutActivity"}
!ll&&!rl&&r
512
$conf->{"timeoutActivity"} and $entry->{"_lastSeen"}
!ll&&!rl&&r
503
MC/DC66%2/3
$conf->{"timeoutActivity"} and $entry->{"_lastSeen"} and $time - $entry->{"_lastSeen"} > $conf->{"timeoutActivity"}
$conf->{"timeoutActivity"} $entry->{"_lastSeen"} $time - $entry->{"_lastSeen"} > $conf->{"timeoutActivity"}
Truth table75%3/4
A and B and C
A= $conf->{"timeoutActivity"}B= $entry->{"_lastSeen"}C= $time - $entry->{"_lastSeen"} > $conf->{"timeoutActivity"}
ABCresult
0XX0
10X0
1100
1111
453 and $entry->{_lastSeen}
454 and $time - $entry->{_lastSeen} > $conf->{timeoutActivity} )
455 {
456 2 push @t, $id;
457 2 $self->logger->debug("Session $id inactive");
458 }
459 elsif ($rtMinTimeout) {
460 0 $checkRtExpiration->( $id, $entry );
461 }
462 16 undef;
463 }
464 12 );
465 }
466  
467 # Delete sessions
468 12 my @errors;
469 12 for my $id (@t) {
470  
471 my $session = Lemonldap::NG::Common::Session->new(
472 storageModule => $options->{backend},
473 storageModuleOptions => $options,
474 cacheModule => $conf->{localSessionStorage},
475 cacheModuleOptions => $conf->{localSessionStorageOptions},
476 10 id => $id,
477 );
478  
479 10 ▶ unless ( $session->data ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($session->data) 0 10 10
480 0 $self->logger->debug("Error while opening session $id");
481 0 print STDERR "Error on session $id\n";
482 0 $internal_stats->{nb_error}->{$type}++;
483 0 push @errors, $id;
484 0 next;
485 }
486  
487 10 ▶ unless ( $session->remove ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($session->remove) 0 10 10
488 0 $self->logger->debug("Error while deleting session $id");
489 0 print STDERR "Error on session $id\n";
490 0 $internal_stats->{nb_error}->{$type}++;
491 0 push @errors, $id;
492 0 next;
493 }
494 10 $self->logger->debug("Session $id has been purged");
495 10 $internal_stats->{nb_purged}->{$type}++;
496 }
497  
498 12 $self->_cleanup_lock_files( $type, $options, $internal_stats );
499 12 $self->_cleanup_errors( $type, $options, $internal_stats, \@errors );
500  
501 12 $internal_stats->{end_time}->{$type} = Time::HiRes::time();
502 }
503  
504 sub _cleanup_lock_files {
505 12 ▶ my ( $self, $type, $options, $internal_stats ) = @_;
Subroutine _cleanup_lock_files: called CC=3 SCAR=11.3
506 12 my $conf = $self->conf;
507  
508 # Remove lock files for File backend
509 12 ▶ if ( $options->{backend} =~ /^Apache::Session::(?:Browseable::)?File$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"backend"} =~ /^Apache::Session::(?:Browseable::)?File$/i) 12 0 12
510 12 require Apache::Session::Lock::File;
511 12 my $l = Apache::Session::Lock::File->new;
512 12 ▶ my $lock_directory = $options->{LockDirectory} || $options->{Directory};
Condition33%1/3
$options->{'LockDirectory'} || $options->{'Directory'}
l!l&&r!l&&!r
1200
MC/DC0%0/2
$options->{'LockDirectory'} || $options->{'Directory'}
$options->{'LockDirectory'} $options->{'Directory'}
Truth table33%1/3
A || B
A= $options->{'LockDirectory'}B= $options->{'Directory'}
ABresult
1X1
011
000
513 12 $l->clean( $lock_directory, $conf->{timeout} );
514 }
515 12 return;
516 }
517  
518 sub _cleanup_errors {
519 12 ▶ my ( $self, $type, $options, $internal_stats, $errors_ref ) = @_;
Subroutine _cleanup_errors: called CC=26 SCAR=61.9
520 12 my @errors = @$errors_ref;
521 12 my $conf = $self->conf;
522  
523 # Force deletion of corrupted sessions for File backend
524 12 ▶ if ( $options->{backend} =~ /^Apache::Session::(?:Browseable::)?File$/i
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"backend"} =~ /^Apache::Session::(?:Browseable::)?File$/i and $self->force) 0 12 12
Condition33%1/3
$options->{"backend"} =~ /^Apache::Session::(?:Browseable::)?File$/i and $self->force
!ll&&!rl&&r
0120
MC/DC0%0/2
$options->{"backend"} =~ /^Apache::Session::(?:Browseable::)?File$/i and $self->force
$options->{"backend"} =~ /^Apache::Session::(?:Browseable::)?File$/i $self->force
Truth table33%1/3
A and B
A= $options->{"backend"} =~ /^Apache::Session::(?:Browseable::)?File$/iB= $self->force
ABresult
0X0
100
111
525 and $self->force )
526 {
527 0 foreach (@errors) {
528 0 my $id = $_;
529 0 eval { unlink $options->{Directory} . "/$id"; };
530 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
531 0 $self->logger->error("Unable to remove session $id");
532 }
533 else {
534 0 $self->logger->warn("Session $id removed with force");
535 0 $internal_stats->{nb_error}->{$type}--;
536 }
537 }
538 }
539  
540 # Force deletion of corrupted sessions for DBI backend
541 12 ▶ if ( $options->{backend} =~
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"backend"} =~ /^Apache::Session::(?:Browseable::)?(MySQL|Postgres|DBI|Oracle|Informix|MySQLJSON|PgHstore|PgJSON|SQLLite|Sybase)$/i and $self->force) 0 12 12
Condition33%1/3
$options->{"backend"} =~ /^Apache::Session::(?:Browseable::)?(MySQL|Postgres|DBI|Oracle|Informix|MySQLJSON|PgHstore|PgJSON|SQLLite|Sybase)$/i and $self->force
!ll&&!rl&&r
1200
MC/DC0%0/2
$options->{"backend"} =~ /^Apache::Session::(?:Browseable::)?(MySQL|Postgres|DBI|Oracle|Informix|MySQLJSON|PgHstore|PgJSON|SQLLite|Sybase)$/i and $self->force
$options->{"backend"} =~ /^Apache::Session::(?:Browseable::)?(MySQL|Postgres|DBI|Oracle|Informix|MySQLJSON|PgHstore|PgJSON|SQLLite|Sybase)$/i $self->force
Truth table33%1/3
A and B
A= $options->{"backend"} =~ /^Apache::Session::(?:Browseable::)?(MySQL|Postgres|DBI|Oracle|Informix|MySQLJSON|PgHstore|PgJSON|SQLLite|Sybase)$/iB= $self->force
ABresult
0X0
100
111
542 /^Apache::Session::(?:Browseable::)?(MySQL|Postgres|DBI|Oracle|Informix|MySQLJSON|PgHstore|PgJSON|SQLLite|Sybase)$/i
543 and $self->force )
544 {
545 my $dbi = DBI->connect_cached( $options->{DataSource},
546 0 $options->{UserName}, $options->{Password} );
547 0 ▶ my $table = $options->{TableName} || "sessions";
Condition0%0/2
$options->{'TableName'} || 'sessions'
l!l
00
MC/DC0%0/1
$options->{'TableName'} || 'sessions'
$options->{'TableName'}
Truth table0%0/2
A
A= $options->{'TableName'}
Aresult
11
00
548 0 my $req = $dbi->prepare("DELETE from $table WHERE id=?");
549 0 foreach (@errors) {
550 0 my $id = $_;
551 0 my $res = $req->execute($id);
552 0 ▶ unless ( $res == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res == 1) { } 0 0 0
553 0 $self->logger->error("Fail to delete session $id with force");
554 }
555 else {
556 0 $self->logger->warn("Session $id removed with force");
557 0 $internal_stats->{nb_error}->{$type}--;
558 }
559 }
560 }
561  
562 # Force deletion of corrupted sessions for LDAP backend
563 12 ▶ if ( $options->{backend} =~ /^Apache::Session::(?:Browseable::)?LDAP$/i
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"backend"} =~ /^Apache::Session::(?:Browseable::)?LDAP$/i and $self->force) 0 12 12
Condition33%1/3
$options->{"backend"} =~ /^Apache::Session::(?:Browseable::)?LDAP$/i and $self->force
!ll&&!rl&&r
1200
MC/DC0%0/2
$options->{"backend"} =~ /^Apache::Session::(?:Browseable::)?LDAP$/i and $self->force
$options->{"backend"} =~ /^Apache::Session::(?:Browseable::)?LDAP$/i $self->force
Truth table33%1/3
A and B
A= $options->{"backend"} =~ /^Apache::Session::(?:Browseable::)?LDAP$/iB= $self->force
ABresult
0X0
100
111
564 and $self->force )
565 {
566 0 my $useTls = 0;
567 0 my $tlsParam;
568 0 my @servers = ();
569 0 foreach my $server ( split /[\s,]+/, $options->{ldapServer} ) {
570 0 ▶ if ( $server =~ m{^ldap\+tls://([^/]+)/?\??(.*)$} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($server =~ m[^ldap\+tls://([^/]+)/?\??(.*)$]) { } 0 0 0
571 0 $useTls = 1;
572 0 $server = $1;
573 0 ▶ $tlsParam = $2 || "";
Condition0%0/2
$2 || ''
l!l
00
MC/DC0%0/1
$2 || ''
$2
Truth table0%0/2
A
A= $2
Aresult
11
00
574 }
575 else {
576 0 $useTls = 0;
577 }
578 0 push @servers, $server;
579 }
580 0 my $ldap =
581 Net::LDAP->new( \@servers, keepalive => 1, onerror => undef, );
582 0 ▶ unless ($ldap) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ldap) 0 0 0
583 0 print STDERR "Unable to connect to LDAP server\n";
584 0 $internal_stats->{nb_error}->{$type}++;
585 0 return;
586 }
587  
588 # Start TLS if needed
589 0 ▶ if ($useTls) {
Branch: 1 branch
BranchTrueFalseTotal
if ($useTls) 0 0 0
590 0 my %h = split( /[&=]/, $tlsParam );
591 0 ▶ $h{verify} ||= $options->{ldapVerify} || "require";
Condition0%0/5
$h{"verify"} ||= $options->{"ldapVerify"} || "require"
l!l&&r!l&&!r
000
$options->{'ldapVerify'} || 'require'
l!l
00
MC/DC0%0/2
$h{"verify"} ||= $options->{"ldapVerify"} || "require"
$h{"verify"} $options->{'ldapVerify'}
Truth table0%0/3
A ||= B
A= $h{"verify"}B= $options->{'ldapVerify'}
ABresult
1X1
011
000
592 $h{cafile} ||= $options->{ldapCAFile}
593 0 ▶ if ( $options->{ldapCAFile} );
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"ldapCAFile"} 0 0 0
Condition0%0/3
$h{"cafile"} ||= $options->{"ldapCAFile"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$h{"cafile"} ||= $options->{"ldapCAFile"}
$h{"cafile"} $options->{"ldapCAFile"}
Truth table0%0/3
A ||= B
A= $h{"cafile"}B= $options->{"ldapCAFile"}
ABresult
1X1
011
000
594 $h{capath} ||= $options->{ldapCAPath}
595 0 ▶ if ( $options->{ldapCAPath} );
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"ldapCAPath"} 0 0 0
Condition0%0/3
$h{"capath"} ||= $options->{"ldapCAPath"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$h{"capath"} ||= $options->{"ldapCAPath"}
$h{"capath"} $options->{"ldapCAPath"}
Truth table0%0/3
A ||= B
A= $h{"capath"}B= $options->{"ldapCAPath"}
ABresult
1X1
011
000
596 0 my $start_tls = $ldap->start_tls(%h);
597 0 ▶ if ( $start_tls->code ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start_tls->code) 0 0 0
598 0 print STDERR "STARTTLS error: "
599 . $start_tls->code . ': '
600 . $start_tls->error;
601 0 $internal_stats->{nb_error}->{$type}++;
602 0 return;
603 }
604 }
605  
606 my $bind = $ldap->bind( $options->{ldapBindDN},
607 0 password => $options->{ldapBindPassword} );
608 0 my $attrId = $options->{ldapAttributeId} | "cn";
609 0 foreach (@errors) {
610 0 my $id = $_;
611 my $sessionDn =
612 0 $attrId . "=" . $id . "," . $options->{ldapConfBase};
613 0 my $delete = $ldap->delete($sessionDn);
614 0 ▶ if ( $delete->is_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delete->is_error) { } 0 0 0
615 0 $self->logger->error("Fail to delete session $id with force");
616 }
617 else {
618 0 $self->logger->warn("Session $id removed with force");
619 0 $internal_stats->{nb_error}->{$type}--;
620 }
621 }
622 }
623 12 return;
624 }
625  
626 sub persistentPurge {
627 9 ▶ my ( $self, $filters ) = @_;
Subroutine persistentPurge: called CC=6 SCAR=17.9
Pod undocumented
628  
629 9 my $internal_stats;
630  
631 9 $self->logger->info("Persistent session purge started");
632  
633 9 $internal_stats->{start_time}->{total} = Time::HiRes::time();
634  
635 9 $self->_purge_persistent( $filters, $internal_stats );
636  
637 9 $internal_stats->{end_time}->{total} = Time::HiRes::time();
638  
639 9 my $total_purged = 0;
640 9 $total_purged += $_ for values %{ $internal_stats->{nb_purged} };
641 9 $internal_stats->{nb_purged}->{total} = $total_purged;
642  
643 9 my $total_error = 0;
644 9 $total_error += $_ for values %{ $internal_stats->{nb_error} };
645 9 $internal_stats->{nb_error}->{total} = $total_error;
646  
647 9 my $return_stats;
648 9 for my $type ( "total", 'Persistent' ) {
649 18 $return_stats->{$type}->{errors} = $internal_stats->{nb_error}->{$type};
650 $return_stats->{$type}->{purged} =
651 18 $internal_stats->{nb_purged}->{$type};
652 $return_stats->{$type}->{duration_u} = int(
653 1000000 * (
654 $internal_stats->{end_time}->{$type} -
655 18 $internal_stats->{start_time}->{$type}
656 )
657 );
658 }
659  
660 9 my $log = "Persistent session purge completed: ";
661 9 ▶ if ( $self->json ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->json) { } 0 9 9
662 0 $log .= to_json($return_stats);
663 }
664 else {
665 9 my @logentries;
666 9 for my $type ( "total", "Persistent" ) {
667 18 my $logentry .= "$type (";
668 18 $logentry .= $return_stats->{$type}->{purged} . " purged, ";
669 18 $logentry .= $return_stats->{$type}->{errors} . " errors in ";
670 18 $logentry .= $return_stats->{$type}->{duration_u} . " us";
671 18 $logentry .= ")";
672 18 push @logentries, $logentry;
673 }
674 9 $log .= join( ', ', @logentries );
675 }
676  
677 9 $self->logger->notice($log);
678  
679 return {
680 9 success => 1,
681  
682 purged => $total_purged,
683 errors => $total_error,
684 stats => $return_stats,
685 };
686 }
687  
688 sub _purge_persistent {
689 9 ▶ my ( $self, $filters, $internal_stats ) = @_;
Subroutine _purge_persistent: called CC=5 SCAR=17.2
690 9 my $type = "Persistent";
691 9 my $conf = $self->conf;
692 9 my $options = $self->persistent_backend_options;
693  
694 9 my @t;
695  
696 9 $internal_stats->{nb_error}->{$type} = 0;
697 9 $internal_stats->{nb_purged}->{$type} = 0;
698 9 $internal_stats->{start_time}->{$type} = Time::HiRes::time();
699  
700 # Get all expired sessions
701 Lemonldap::NG::Common::Apache::Session->get_key_from_all_sessions(
702 $options,
703 sub {
704 22 ▶ my $entry = shift;
Subroutine __ANON__: called CC=8 SCAR=21.6
705 22 my $id = shift;
706 22 my $time = time;
707  
708 22 $self->logger->debug("Check session $id");
709  
710 22 ▶ unless ($entry) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($entry) 0 22 22
711 0 $self->logger->debug("Session $id is empty");
712 0 return;
713 }
714  
715 # Ignore non-persistent sessions
716 22 ▶ return unless ( $entry->{_session_kind} eq "Persistent" );
Branch: 1 branch
BranchTrueFalseTotal
unless $entry->{"_session_kind"} eq "Persistent" 0 22 22
717  
718 # safety check: do not remove if there are no filters
719 22 ▶ my $remove = keys %$filters ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
keys %$filters ? : 21 1 22
720  
721 22 ▶ while ( my ( $filter_type, $value ) = each %$filters ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$filters) 25 22 47
722 25 ▶ if ( my $filter_configuration =
Branch: 1 branch
BranchTrueFalseTotal
if (my $filter_configuration = $PSESSION_FILTERS{$filter_type}) { } 25 0 25
723 $PSESSION_FILTERS{$filter_type} )
724 {
725 my $filter_result =
726 $filter_configuration->{filter}
727 25 ->( $self, $entry, $value );
728 25 $self->logger->debug(
729 "$filter_type filter result: " . int($filter_result) );
730 25 ▶ $remove &&= $filter_result;
Condition100%3/3
$remove &&= $filter_result
!ll&&!rl&&r
2914
MC/DC100%2/2
$remove &&= $filter_result
$remove $filter_result
Truth table100%3/3
A &&= B
A= $removeB= $filter_result
ABresult
0X0
100
111
731 }
732 else {
733 0 $self->logger->debug("Unknown filter $filter_type");
734 0 $remove = 0;
735 }
736 }
737  
738 22 ▶ push @t, $id if $remove;
Branch: 1 branch
BranchTrueFalseTotal
if $remove 12 10 22
739  
740 }
741 9 );
742  
743 # Delete sessions
744 9 my @errors;
745 9 for my $id (@t) {
746  
747 my $session = Lemonldap::NG::Common::Session->new(
748 storageModule => $options->{backend},
749 storageModuleOptions => $options,
750 cacheModule => $conf->{localSessionStorage},
751 cacheModuleOptions => $conf->{localSessionStorageOptions},
752 12 id => $id,
753 );
754  
755 12 ▶ unless ( $session->data ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($session->data) 0 12 12
756 0 $self->logger->debug("Error while opening session $id");
757 0 print STDERR "Error on session $id\n";
758 0 $internal_stats->{nb_error}->{$type}++;
759 0 push @errors, $id;
760 0 next;
761 }
762  
763 12 ▶ unless ( $session->remove ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($session->remove) 0 12 12
764 0 $self->logger->debug("Error while deleting session $id");
765 0 print STDERR "Error on session $id\n";
766 0 $internal_stats->{nb_error}->{$type}++;
767 0 push @errors, $id;
768 0 next;
769 }
770 12 $self->logger->debug("Session $id has been purged");
771 12 ▶ $self->_auditPurgePsession( $session->data ) if $self->audit;
Branch: 1 branch
BranchTrueFalseTotal
if $self->audit 1 11 12
772 12 $internal_stats->{nb_purged}->{$type}++;
773 }
774 9 $internal_stats->{end_time}->{$type} = Time::HiRes::time();
775 }
776  
777 sub localPurge {
778 0 ▶ my ($self) = @_;
Subroutine localPurge: not called CC=4 SCAR=30.0
Pod undocumented
779 0 $self->logger->debug( __PACKAGE__ . "::localPurge() called" );
780 0 my $conf = $self->conf;
781 0 ▶ if ( $conf->{localSessionStorage} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"localSessionStorage"}) 0 0 0
782 0 eval "require $conf->{localSessionStorage}";
783 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
784 0 ▶ $conf->{localSessionStorageOptions}->{default_expires_in} ||= 600;
Condition0%0/2
$conf->{"localSessionStorageOptions"}{"default_expires_in"} ||= 600
l!l
00
MC/DC0%0/1
$conf->{"localSessionStorageOptions"}{"default_expires_in"} ||= 600
$conf->{"localSessionStorageOptions"}{"default_expires_in"}
Truth table0%0/2
A
A= $conf->{"localSessionStorageOptions"}{"default_expires_in"}
Aresult
11
00
785 my $s = $conf->{localSessionStorage}
786 0 ->new( $conf->{localSessionStorageOptions} );
787 0 $s->purge();
788 }
789 }
790  
791 sub auditLog {
792 1 ▶ my ( $self, $req, %info ) = @_;
Subroutine auditLog: called CC=1 SCAR=0.0
Pod undocumented
793 1 $self->_auditLogger->log( $req, %info );
794 }
795  
796 sub _auditPurgePsession {
797 1 ▶ my ( $self, $session ) = @_;
Subroutine _auditPurgePsession: called CC=1 SCAR=0.0
798 1 my $dummy_req = Lemonldap::NG::Common::PSGI::Request->new(
799 { PATH_INFO => "", REQUEST_URI => "" } );
800 1 my $uid = $session->{_session_uid};
801 1 $self->auditLog(
802 $dummy_req,
803 message => ("Persistent session for $uid was removed"),
804 code => "PSESSION_REMOVED",
805 user => $uid,
806 );
807 }
808  
809 2 1;
« blib/lib/Lemonldap/NG/Common/OpenIDConnect/Metadata.pm ↑ Summary blib/lib/Lemonldap/NG/Common/Notifications/LDAP.pm »