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

filter: Statementstmt 36.8% 21 / 57 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 66.6% 6 / 9 Podpod 0.0% 0 / 1 totaltotal 27.0% 27 / 100 CC 13 SCAR 40.4
CC
13
Cov
25%
changeUrldc
110.0
_cookie_can_be_seen
20.0
_url_is_external
2.0
CRAP 56.6
« blib/lib/Lemonldap/NG/Portal/Plugins/Notifications.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Main/Init.pm »
1 package Lemonldap::NG::Portal::Plugins::CDA;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 use Lemonldap::NG::Portal::Main::Constants qw(
7 PE_APACHESESSIONERROR
8 PE_ERROR
9 PE_OK
10 URIRE
11 2 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 our $VERSION = '2.0.14';
14  
15 2 extends 'Lemonldap::NG::Common::Module';
16  
17 # INTERFACE
18  
19 2 ▶use constant endAuth => 'changeUrldc';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use constant forAuthUser => 'changeUrldc';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 # RUNNING METHOD
23  
24 sub _url_is_external {
25 0 ▶ my ( $self, $req, $urldc ) = @_;
Subroutine _url_is_external: not called CC=1 SCAR=6.9
26  
27 0 my $portal = $req->portal;
28 0 my $domain = $self->p->getCookieDomain($req);
29 0 return $self->_cookie_can_be_seen( $portal, $domain, $urldc );
30 }
31  
32 # This method determines if a cookie set by
33 # $portal for domain $domain can be received by URL $urldc
34 sub _cookie_can_be_seen {
35 0 ▶ my ( $self, $portal, $domain, $urldc ) = @_;
Subroutine _cookie_can_be_seen: not called CC=4 SCAR=30.0
36  
37 0 ▶ if ( $urldc =~ URIRE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($urldc =~ 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 0 0
38 0 my $host = $3;
39  
40 # Domain is set: cookie is sent to the domain itself, and all subdomains
41 0 ▶ if ($domain) {
Branch: 1 branch
BranchTrueFalseTotal
if ($domain) { } 0 0 0
42 0 my $domain_without_leading_dot = $domain =~ s/^\.//r;
43  
44 0 ▶ return if $host eq $domain_without_leading_dot;
Branch: 1 branch
BranchTrueFalseTotal
if $host eq $domain_without_leading_dot 0 0 0
45 0 return $host !~ m@\Q$domain\E$@i;
46  
47 }
48  
49 # Domain is not set: cookie is only sent to the portal itself
50 else {
51 0 my $portal_host = URI->new($portal)->host;
52 0 return $host ne $portal_host;
53 }
54 }
55 0 return;
56 }
57  
58 sub changeUrldc {
59 0 ▶ my ( $self, $req ) = @_;
Subroutine changeUrldc: not called CC=10 SCAR=47.0
Pod undocumented
60 0 ▶ my $urldc = $req->{urldc} || '';
Condition0%0/2
$req->{'urldc'} || ''
l!l
00
MC/DC0%0/1
$req->{'urldc'} || ''
$req->{'urldc'}
Truth table0%0/2
A
A= $req->{'urldc'}
Aresult
11
00
61 0 ▶ if ( $req->id
Branch: 1 branch
BranchTrueFalseTotal
if ($req->id and $self->_url_is_external($req, $urldc) and $self->p->isTrustedUrl($urldc)) 0 0 0
Condition0%0/6
$req->id and $self->_url_is_external($req, $urldc) and $self->p->isTrustedUrl($urldc)
!ll&&!rl&&r
000
$req->id and $self->_url_is_external($req, $urldc)
!ll&&!rl&&r
000
MC/DC0%0/3
$req->id and $self->_url_is_external($req, $urldc) and $self->p->isTrustedUrl($urldc)
$req->id $self->_url_is_external($req, $urldc) $self->p->isTrustedUrl($urldc)
Truth table0%0/4
A and B and C
A= $req->idB= $self->_url_is_external($req, $urldc)C= $self->p->isTrustedUrl($urldc)
ABCresult
0XX0
10X0
1100
1111
62 and $self->_url_is_external( $req, $urldc )
63 and $self->p->isTrustedUrl($urldc) )
64 {
65 0 my $ssl = $urldc =~ /^https/;
66 0 $self->logger->debug('CDA request');
67  
68 # Create CDA session
69 0 my $cdaInfos = { '_utime' => time };
70 0 ▶ if ( $self->{conf}->{securedCookie} < 2 or $ssl ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'conf'}{'securedCookie'} < 2 or $ssl) { } 0 0 0
Condition0%0/3
$self->{"conf"}{"securedCookie"} < 2 or $ssl
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"conf"}{"securedCookie"} < 2 or $ssl
$self->{"conf"}{"securedCookie"} < 2 $ssl
Truth table0%0/3
A or B
A= $self->{"conf"}{"securedCookie"} < 2B= $ssl
ABresult
1X1
011
000
71 0 $cdaInfos->{cookie_value} = $req->id;
72 0 $cdaInfos->{cookie_name} = $self->{conf}->{cookieName};
73 }
74 else {
75 0 ▶ if ( $req->{sessionInfo}->{_httpSession} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{'sessionInfo'}{'_httpSession'}) { } 0 0 0
76 $cdaInfos->{cookie_value} =
77 0 $req->{sessionInfo}->{_httpSession};
78 0 $cdaInfos->{cookie_name} = $self->{conf}->{cookieName} . "http";
79 }
80 else {
81 0 $self->logger->error(
82 "Session does not contain _httpSession field. "
83 . "Portal must be accessed over HTTPS when using CDA with double cookie"
84 );
85 0 return PE_ERROR;
86 }
87 }
88  
89 0 my $cdaSession =
90 $self->p->getApacheSession( undef, kind => "CDA", info => $cdaInfos );
91 0 ▶ unless ($cdaSession) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cdaSession) 0 0 0
92 0 $self->logger->error("Unable to create CDA session");
93 0 return PE_APACHESESSIONERROR;
94 }
95  
96 # We are about to redirect the user to the CDA application,
97 # dismiss any previously stored redirections (#1650)
98 0 delete $req->{pdata}->{_url};
99  
100 $req->{urldc} .=
101 ( $urldc =~ /\?/ ? '&' : '?' )
102 0 ▶ . $self->{conf}->{cookieName} . "cda="
Branch: 1 branch
BranchTrueFalseTotal
$urldc =~ /\?/ ? : 0 0 0
103 . $cdaSession->id;
104  
105 0 $self->logger->debug( "CDA redirection to " . $req->{urldc} );
106 }
107 0 return PE_OK;
108 }
109  
110 2 1;
« blib/lib/Lemonldap/NG/Portal/Plugins/Notifications.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Main/Init.pm »