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

filter: Statementstmt 53.8% 28 / 52 Branchbran 25.0% 4 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 3 totaltotal 46.4% 39 / 84 CC 11 SCAR 22.8
CC
11
Cov
46%
checkRemoteId
20.0
init
11.3
goToPortal
6.0
CRAP 9.8
« blib/lib/Lemonldap/NG/Portal/2F/Password.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Main/UserDB.pm »
1 package Lemonldap::NG::Portal::Lib::Remote;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Lemonldap::NG::Common::Session;
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_REDIRECT
12 3 );
13  
14 3 our $VERSION = '2.19.0';
15  
16 3 has cookieName => ( is => 'rw' );
17  
18 # INITIALIZATION
19  
20 2 ▶sub init {
Subroutine init: called CC=7 SCAR=24.2
Pod undocumented
21 2 my $self = shift;
22 2 my @missing = ();
23 2 foreach (qw(remotePortal remoteGlobalStorage)) {
24 4 ▶ push @missing, $_ unless ( defined( $self->conf->{$_} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->conf->{$_} 0 4 4
25 }
26 2 ▶ if (@missing) {
Branch: 1 branch
BranchTrueFalseTotal
if (@missing) 0 2 2
27 0 $self->error( "Missing required parameters" . join( ', ', @missing ) );
28 0 return 0;
29 }
30  
31 2 ▶ unless ( $self->conf->{remotePortal} =~ URIRE ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->conf->{"remotePortal"} =~ 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 2 2
32 0 $self->error("Bad remotePortal URL");
33 0 return 0;
34 }
35  
36 2 eval "require " . $self->conf->{remoteGlobalStorage};
37 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
38 0 $self->error($@);
39 0 return 0;
40 }
41 $self->cookieName( $self->conf->{remoteCookieName}
42 2 ▶ || $self->conf->{cookieName} );
Condition33%1/3
$self->conf->{'remoteCookieName'} || $self->conf->{'cookieName'}
l!l&&r!l&&!r
020
MC/DC0%0/2
$self->conf->{'remoteCookieName'} || $self->conf->{'cookieName'}
$self->conf->{'remoteCookieName'} $self->conf->{'cookieName'}
Truth table33%1/3
A || B
A= $self->conf->{'remoteCookieName'}B= $self->conf->{'cookieName'}
ABresult
1X1
011
000
43  
44 2 return 1;
45 }
46  
47 # RUNNING METHODS
48  
49 ## @apmethod int checkRemoteId()
50 # check if a CDA mechanism has been instantiated and if session is available.
51 # Redirect user to remote portal else by calling goToPortal().
52 # @return Lemonldap::NG::Portal constant
53 0 ▶sub checkRemoteId {
Subroutine checkRemoteId: not called CC=4 SCAR=30.0
Pod undocumented
54 0 my ( $self, $req ) = @_;
55 0 my %h;
56  
57 0 ▶ if ( my $rId = $req->param( $self->cookieName ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rId = $req->param($self->cookieName)) 0 0 0
58 0 $req->mustRedirect(1);
59  
60 # Trying to recover session from global session storage
61 my $remoteSession = Lemonldap::NG::Common::Session->new( {
62 storageModule => $self->conf->{remoteGlobalStorage},
63 storageModuleOptions =>
64 $self->conf->{remoteGlobalStorageOptions},
65 cacheModule => $self->conf->{localSessionStorage},
66 cacheModuleOptions => $self->conf->{localSessionStorageOptions},
67 0 id => $rId,
68 kind => "SSO",
69 }
70 );
71 0 ▶ if ( $remoteSession->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remoteSession->error) 0 0 0
72 0 $self->logger->error("Remote session error");
73 0 $self->logger->error( $remoteSession->error );
74 0 return PE_ERROR;
75 }
76  
77 0 %{ $req->data->{rSessionInfo} } = %{ $remoteSession->data() };
78 delete( $req->data->{rSessionInfo}->{'_password'} )
79 0 ▶ unless $self->conf->{storePassword};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->conf->{"storePassword"} 0 0 0
80 0 return PE_OK;
81 }
82  
83 0 return $self->goToPortal($req);
84 }
85  
86 ## @method protected void goToPortal()
87 # Redirect user to remote portal.
88 0 ▶sub goToPortal {
Subroutine goToPortal: not called CC=2 SCAR=17.9
Pod undocumented
89 0 my ( $self, $req ) = @_;
90 $req->urldc(
91 0 ▶ $self->conf->{remotePortal} . '?url='
Branch: 1 branch
BranchTrueFalseTotal
$req->query_string ? : 0 0 0
92 . encode_base64(
93 $req->portal
94 . ( $req->query_string ? '?' . $req->query_string : '' ),
95 ''
96 )
97 );
98  
99 0 return PE_REDIRECT;
100 }
101  
102 3 1;
103  
« blib/lib/Lemonldap/NG/Portal/2F/Password.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Main/UserDB.pm »