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

filter: Statementstmt 38.0% 19 / 50 Branchbran 13.6% 3 / 22 Conditioncond 13.3% 2 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 3 totaltotal 28.3% 30 / 106 CC 18 SCAR 33.9
CC
18
Cov
28%
checkIP
45.8
checkHeader
26.3
checkCertificate
25.7
CRAP 29.6
« blib/lib/Lemonldap/NG/Portal/Lib/Radius.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/2F/Register/Generic.pm »
1 ##@file
2 # Slave common functions
3  
4 ##@class
5 # Slave common functions
6 package Lemonldap::NG::Portal::Lib::Slave;
7  
8 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Net::CIDR;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 6 our $VERSION = '2.23.0';
13  
14 # RUNNING METHODS
15  
16 ## @method Lemonldap::NG::Portal::_Slave checkIP()
17 # @return true if remote IP is accredited in LL::NG conf
18 3 ▶sub checkIP {
Subroutine checkIP: called CC=8 SCAR=38.2
Pod undocumented
19 3 my ( $self, $req ) = @_;
20 3 my ( @networks, @IPs );
21 3 my $remoteIP = $req->address;
22  
23 return 1
24 3 ▶ unless $self->conf->{slaveMasterIP};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->conf->{"slaveMasterIP"} 3 0 3
25  
26 @IPs = grep {
27 0 ▶ if ( m#/# && Net::CIDR::cidrvalidate($_) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (m[/] and Net::CIDR::cidrvalidate($_)) { } 0 0 0
elsif (Net::CIDR::cidrvalidate($_)) { } 0 0 0
Condition0%0/3
m[/] and Net::CIDR::cidrvalidate($_)
!ll&&!rl&&r
000
MC/DC0%0/2
m[/] and Net::CIDR::cidrvalidate($_)
m[/] Net::CIDR::cidrvalidate($_)
Truth table0%0/3
A and B
A= m[/]B= Net::CIDR::cidrvalidate($_)
ABresult
0X0
100
111
28 0 push @networks, $_;
29 0 $self->logger->debug("Found netblock: $_");
30 0 0;
31 }
32 elsif ( Net::CIDR::cidrvalidate($_) ) {
33 0 $self->logger->debug("Found IP address: $_");
34 0 1;
35 }
36 else {
37 0 $self->logger->warn("Found a non valid IP: $_");
38 0 0;
39 }
40 0 } split /[,\s]/, $self->conf->{slaveMasterIP};
41  
42 0 foreach (@IPs) {
43 0 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
if $remoteIP eq $_ 0 0 0
44 if $remoteIP eq $_;
45 }
46 0 ▶ return 1 if Net::CIDR::cidrlookup( $remoteIP, @networks );
Branch: 1 branch
BranchTrueFalseTotal
if Net::CIDR::cidrlookup($remoteIP, @networks) 0 0 0
47  
48 0 $self->userLogger->warn('Client IP not accredited for Slave module');
49 0 return 0;
50 }
51  
52 ## @method Lemonldap::NG::Portal::_Slave checkHeader()
53 # @return true if header content matches LL::NG conf
54 3 ▶sub checkHeader {
Subroutine checkHeader: called CC=6 SCAR=32.7
Pod undocumented
55 3 my ( $self, $req ) = @_;
56 return 1
57 unless ( $self->conf->{slaveHeaderName}
58 3 ▶ && $self->conf->{slaveHeaderContent} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->conf->{"slaveHeaderName"} and $self->conf->{"slaveHeaderContent"} 3 0 3
Condition33%1/3
$self->conf->{"slaveHeaderName"} and $self->conf->{"slaveHeaderContent"}
!ll&&!rl&&r
300
MC/DC0%0/2
$self->conf->{"slaveHeaderName"} and $self->conf->{"slaveHeaderContent"}
$self->conf->{"slaveHeaderName"} $self->conf->{"slaveHeaderContent"}
Truth table33%1/3
A and B
A= $self->conf->{"slaveHeaderName"}B= $self->conf->{"slaveHeaderContent"}
ABresult
0X0
100
111
59  
60 0 my $slave_header = 'HTTP_' . uc( $self->conf->{slaveHeaderName} );
61 0 $slave_header =~ s/\-/_/g;
62 0 my $headerContent = $req->env->{$slave_header};
63 0 ▶ if ( $headerContent && length $headerContent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($headerContent and length $headerContent) { } 0 0 0
Condition0%0/3
$headerContent and length $headerContent
!ll&&!rl&&r
000
MC/DC0%0/2
$headerContent and length $headerContent
$headerContent length $headerContent
Truth table0%0/3
A and B
A= $headerContentB= length $headerContent
ABresult
0X0
100
111
64 0 $self->logger->debug(
65 "Required Slave header: $self->{conf}->{slaveHeaderName}"
66 . "\nReceived Slave header content: $headerContent" );
67 return 1
68 0 ▶ if ( $self->conf->{slaveHeaderContent} =~ /\b$headerContent\b/ );
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"slaveHeaderContent"} =~ /\b$headerContent\b/ 0 0 0
69 }
70 else {
71 0 $self->logger->notice("No Slave header content received");
72 }
73  
74 0 $self->userLogger->warn('Matching header not found for Slave module');
75 0 return 0;
76 }
77  
78 ## @method Lemonldap::NG::Portal::_Slave checkCertificate()
79 # @return true if value matches LL::NG conf
80 3 ▶sub checkCertificate {
Subroutine checkCertificate: called CC=6 SCAR=32.5
Pod undocumented
81 3 my ( $self, $req ) = @_;
82 return 1
83 unless ( $self->conf->{slaveCertificateField}
84 3 ▶ && $self->conf->{slaveCertificateRegexp} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->conf->{"slaveCertificateField"} and $self->conf->{"slaveCertificateRegexp"} 3 0 3
Condition33%1/3
$self->conf->{"slaveCertificateField"} and $self->conf->{"slaveCertificateRegexp"}
!ll&&!rl&&r
300
MC/DC0%0/2
$self->conf->{"slaveCertificateField"} and $self->conf->{"slaveCertificateRegexp"}
$self->conf->{"slaveCertificateField"} $self->conf->{"slaveCertificateRegexp"}
Truth table33%1/3
A and B
A= $self->conf->{"slaveCertificateField"}B= $self->conf->{"slaveCertificateRegexp"}
ABresult
0X0
100
111
85  
86 0 my $regexp = $self->conf->{slaveCertificateRegexp};
87 0 my $value = $req->env->{ $self->conf->{slaveCertificateField} };
88 0 ▶ if ( $value && length $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value and length $value) { } 0 0 0
Condition0%0/3
$value and length $value
!ll&&!rl&&r
000
MC/DC0%0/2
$value and length $value
$value length $value
Truth table0%0/3
A and B
A= $valueB= length $value
ABresult
0X0
100
111
89 0 $self->logger->debug(
90 "Required Slave field: $self->{conf}->{slaveCertificateField}"
91 . "\nReceived Slave value: $value" );
92 0 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ qr/$regexp/ 0 0 0
93 if ( $value =~ qr/$regexp/ );
94 }
95 else {
96 0 $self->logger->notice(
97 "No subject found in certificate, check your configuration");
98 }
99  
100 0 $self->userLogger->warn(
101 'Client certificate not accredited for Slave module');
102 0 return 0;
103 }
104  
105 6 1;
« blib/lib/Lemonldap/NG/Portal/Lib/Radius.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/2F/Register/Generic.pm »