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

filter: Statementstmt 41.9% 44 / 105 Branchbran 16.6% 6 / 36 Conditioncond 35.2% 6 / 17 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 75.0% 9 / 12 Podpod 0.0% 0 / 5 totaltotal 34.9% 65 / 186 CC 26 SCAR 34.5
CC
26
Cov
35%
setSessionInfo
56.0
getUser
46.9
authLogout
42.0
CRAP 31.6
« blib/lib/Lemonldap/NG/Portal/Lib/CAS.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/UserDB/WebID.pm »
1 package Lemonldap::NG::Portal::Lib::RESTProxy;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Lemonldap::NG::Common::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Lemonldap::NG::Portal::Main::Constants qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
8 URIRE
9 PE_OK
10 PE_ERROR
11 PE_BADCREDENTIALS
12 3 );
13 3 ▶use Lemonldap::NG::Common::FormEncode;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 our $VERSION = '2.23.4';
16  
17 3 has ua => ( is => 'rw' );
18 3 has cookieName => ( is => 'rw' );
19 3 has sessionService => ( is => 'rw' );
20  
21 # INITIALIZATION
22  
23 6 ▶sub init {
Subroutine init: called CC=6 SCAR=20.9
Pod undocumented
24 6 my ($self) = @_;
25  
26 6 ▶ unless ( defined $self->conf->{proxyAuthService}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->conf->{"proxyAuthService"} and $self->conf->{"proxyAuthService"} =~ 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 6 6
Condition33%1/3
defined $self->conf->{"proxyAuthService"} and $self->conf->{"proxyAuthService"} =~ 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
006
MC/DC0%0/2
defined $self->conf->{"proxyAuthService"} and $self->conf->{"proxyAuthService"} =~ 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 $self->conf->{"proxyAuthService"} $self->conf->{"proxyAuthService"} =~ 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 table33%1/3
A and B
A= defined $self->conf->{"proxyAuthService"}B= $self->conf->{"proxyAuthService"} =~ 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
27 && $self->conf->{proxyAuthService} =~ URIRE )
28 {
29 0 $self->error("Bad or missing proxyAuthService parameter");
30 0 return 0;
31 }
32  
33 my $sessionService = $self->conf->{proxySessionService}
34 6 ▶ || $self->conf->{proxyAuthService} . '/session/my';
Condition50%1/2
$self->conf->{'proxySessionService'} || $self->conf->{'proxyAuthService'} . '/session/my'
l!l
06
MC/DC0%0/1
$self->conf->{'proxySessionService'} || $self->conf->{'proxyAuthService'} . '/session/my'
$self->conf->{'proxySessionService'}
Truth table50%1/2
A
A= $self->conf->{'proxySessionService'}
Aresult
11
00
35 6 $sessionService =~ s#/*$##;
36 6 ▶ unless ( $sessionService =~ URIRE ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sessionService =~ 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 6 6
37 0 $self->error("Malformed proxySessionService parameter");
38 0 return 0;
39 }
40 6 $self->sessionService($sessionService);
41 6 $self->ua( Lemonldap::NG::Common::UserAgent->new( $self->conf ) );
42 6 $self->ua->default_header( Accept => 'application/json' );
43 $self->cookieName( $self->conf->{proxyCookieName}
44 6 ▶ || $self->conf->{cookieName} );
Condition66%2/3
$self->conf->{'proxyCookieName'} || $self->conf->{'cookieName'}
l!l&&r!l&&!r
240
MC/DC0%0/2
$self->conf->{'proxyCookieName'} || $self->conf->{'cookieName'}
$self->conf->{'proxyCookieName'} $self->conf->{'cookieName'}
Truth table66%2/3
A || B
A= $self->conf->{'proxyCookieName'}B= $self->conf->{'cookieName'}
ABresult
1X1
011
000
45  
46 6 return 1;
47 }
48  
49 3 ▶no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
50 3 *authenticate = \&getUser;
51  
52 2 ▶sub getUser {
Subroutine getUser: called CC=10 SCAR=38.5
Pod undocumented
53 2 my ( $self, $req ) = @_;
54 2 ▶ return PE_OK if ( $req->data->{_proxyQueryDone} );
Branch: 1 branch
BranchTrueFalseTotal
if $req->data->{"_proxyQueryDone"} 0 2 2
55 $self->logger->debug(
56 2 'Proxy push auth to ' . $self->conf->{proxyAuthService} );
57 my $resp = $self->ua->post(
58 $self->conf->{proxyAuthService},
59 {
60 user => $req->{user},
61 password => $req->data->{password},
62 (
63 $self->conf->{proxyAuthServiceChoiceParam}
64 && $self->conf->{proxyAuthServiceChoiceValue}
65 ? ( $self->conf->{proxyAuthServiceChoiceParam} =>
66 $self->conf->{proxyAuthServiceChoiceValue} )
67 : ()
68 ),
69 (
70 $self->conf->{proxyAuthServiceImpersonation}
71 2 ▶ && $req->param('spoofId')
Branch: 2 branches
BranchTrueFalseTotal
$self->conf->{'proxyAuthServiceChoiceParam'} && $self->conf->{'proxyAuthServiceChoiceValue'} ? : 0 2 2
$self->conf->{'proxyAuthServiceImpersonation'} && $req->param('spoofId') ? : 0 2 2
Condition33%2/6
$self->conf->{"proxyAuthServiceChoiceParam"} and $self->conf->{"proxyAuthServiceChoiceValue"}
!ll&&!rl&&r
020
$self->conf->{"proxyAuthServiceImpersonation"} and $req->param("spoofId")
!ll&&!rl&&r
200
MC/DC0%0/2
$self->conf->{"proxyAuthServiceChoiceParam"} and $self->conf->{"proxyAuthServiceChoiceValue"}
$self->conf->{"proxyAuthServiceChoiceParam"} $self->conf->{"proxyAuthServiceChoiceValue"}
MC/DC0%0/2
$self->conf->{"proxyAuthServiceImpersonation"} and $req->param("spoofId")
$self->conf->{"proxyAuthServiceImpersonation"} $req->param("spoofId")
Truth table33%1/3
A and B
A= $self->conf->{"proxyAuthServiceChoiceParam"}B= $self->conf->{"proxyAuthServiceChoiceValue"}
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= $self->conf->{"proxyAuthServiceImpersonation"}B= $req->param("spoofId")
ABresult
0X0
100
111
72 ? ( spoofId => scalar $req->param('spoofId') )
73 : ()
74 )
75 }
76 );
77 2 ▶ unless ( $resp->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($resp->is_success) 2 0 2
78 2 $self->logger->error(
79 'Unable to query authentication service: ' . $resp->status_line );
80 2 return PE_ERROR;
81 }
82 0 $self->logger->debug('Proxy gets a response');
83 0 my $res = eval { JSON::from_json( $resp->content, { allow_nonref => 1 } ) };
84 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
85 0 $self->logger->error("Bad content: $@");
86 0 return PE_ERROR;
87 }
88 0 ▶ unless ( $res->{result} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->{"result"}) 0 0 0
89 0 $self->userLogger->warn("Authentication failed for $req->{user}");
90 0 $self->setSecurity($req);
91 0 return PE_BADCREDENTIALS;
92 }
93 0 my $name = $self->cookieName;
94 0 ▶ unless ( grep /\b$name=/, $resp->header('Set-Cookie') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /\b$name=/, $resp->header("Set-Cookie")) 0 0 0
95 0 $self->logger->error("No cookie named '$name'");
96 0 return PE_ERROR;
97 }
98  
99 $req->sessionInfo->{_proxyCookies} = join '; ',
100 0 map { s/;.*$//r } $resp->header('Set-Cookie');
101 $self->logger->debug( 'Store remote cookies in session ('
102 . $req->sessionInfo->{_proxyCookies}
103 0 . ')' );
104 0 $req->data->{_proxyQueryDone}++;
105  
106 0 return PE_OK;
107 }
108  
109 0 ▶sub findUser {
Subroutine findUser: not called CC=1 SCAR=6.9
Pod undocumented
110  
111 # Nothing to do here
112 0 return PE_OK;
113 }
114  
115 0 ▶sub setSessionInfo {
Subroutine setSessionInfo: not called CC=7 SCAR=40.3
Pod undocumented
116 0 my ( $self, $req ) = @_;
117 0 ▶ return PE_OK if ( $req->data->{_setSessionInfoDone} );
Branch: 1 branch
BranchTrueFalseTotal
if $req->data->{"_setSessionInfoDone"} 0 0 0
118 0 $self->logger->debug(
119 'Proxy requests sessionInfo to ' . $self->sessionService . '/global' );
120 my $q = HTTP::Request->new(
121 GET => $self->sessionService . '/global',
122 [
123 Cookie => $req->sessionInfo->{_proxyCookies},
124 0 Accept => 'application/json'
125 ]
126 );
127 0 my $resp = $self->ua->request($q);
128 0 ▶ unless ( $resp->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($resp->is_success) 0 0 0
129 0 $self->logger->error(
130 'Unable to query session service: ' . $resp->status_line );
131 0 return PE_ERROR;
132 }
133 0 $self->logger->debug('Proxy gets a response');
134 0 my $res = eval { JSON::from_json( $resp->content, { allow_nonref => 1 } ) };
135 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
136 0 $self->logger->error("Bad content: $@");
137 0 return PE_ERROR;
138 }
139 0 foreach ( keys %$res ) {
140 0 ▶ $req->{sessionInfo}->{$_} ||= $res->{$_} unless (/^_/);
Branch: 1 branch
BranchTrueFalseTotal
unless /^_/ 0 0 0
Condition0%0/3
$req->{"sessionInfo"}{$_} ||= $res->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$req->{"sessionInfo"}{$_} ||= $res->{$_}
$req->{"sessionInfo"}{$_} $res->{$_}
Truth table0%0/3
A ||= B
A= $req->{"sessionInfo"}{$_}B= $res->{$_}
ABresult
1X1
011
000
141 }
142 0 $req->data->{_setSessionInfoDone}++;
143  
144 0 return PE_OK;
145 }
146  
147 0 ▶sub authLogout {
Subroutine authLogout: not called CC=6 SCAR=37.4
Pod undocumented
148 0 my ( $self, $req ) = @_;
149 $self->logger->debug(
150 0 'Proxy ask logout to ' . $self->conf->{proxyAuthService} );
151 my $q = HTTP::Request->new(
152 GET => $self->conf->{proxyAuthService} . '?logout=1',
153 [
154 Cookie => $req->sessionInfo->{_proxyCookies},
155 0 Accept => 'application/json'
156 ]
157 );
158 0 my $resp = $self->ua->request($q);
159 0 ▶ unless ( $resp->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($resp->is_success) 0 0 0
160 0 $self->logger->error(
161 'Unable to query authentication service: ' . $resp->status_line );
162 0 return PE_OK;
163 }
164 0 $self->logger->debug('Proxy gets a response');
165 0 my $res = eval { JSON::from_json( $resp->content, { allow_nonref => 1 } ) };
166 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
167 0 $self->logger->error("Bad content: $@");
168 0 return PE_OK;
169 }
170 0 my $user = $req->{sessionInfo}->{ $self->conf->{whatToTrace} };
171 0 ▶ unless ( $res->{result} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->{"result"}) 0 0 0
172 0 ▶ $self->userLogger->warn("Internal Portal logout failed for $user")
Branch: 1 branch
BranchTrueFalseTotal
if $user 0 0 0
173 if $user;
174 0 return PE_OK;
175 }
176 $self->userLogger->notice(
177 0 ▶ "User $user has been disconnected from internal Portal")
Branch: 1 branch
BranchTrueFalseTotal
if $user 0 0 0
178 if $user;
179  
180 0 return PE_OK;
181 }
182  
183 3 1;
184  
« blib/lib/Lemonldap/NG/Portal/Lib/CAS.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/UserDB/WebID.pm »