blib/lib/Lemonldap/NG/Portal/UserDB/OpenIDConnect.pm

filter: Statementstmt 26.9% 17 / 63 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 62.5% 5 / 8 Podpod 0.0% 0 / 4 totaltotal 18.9% 22 / 116 CC 18 SCAR 49.9
CC
18
Cov
17%
getUser
240.0
setSessionInfo
20.0
findUser
2.0
CRAP 147.5
« blib/lib/Lemonldap/NG/Portal/Lib/Notifications/XML.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Auth/CAS.pm »
1 package Lemonldap::NG::Portal::UserDB::OpenIDConnect;
2  
3 39 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 39 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 39 ▶use Lemonldap::NG::Common::JWT 'getJWTPayload';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 39 use Lemonldap::NG::Portal::Main::Constants qw(
7 PE_OIDC_AUTH_ERROR
8 PE_BADCREDENTIALS
9 PE_ERROR
10 PE_OK
11 39 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 39 our $VERSION = '2.21.0';
14  
15 39 extends qw(
16 Lemonldap::NG::Portal::Main::UserDB
17 Lemonldap::NG::Portal::Lib::OpenIDConnect
18 );
19  
20 # INITIALIZATION
21  
22 sub init {
23 39 ▶ my ($self) = @_;
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
24 39 return $self->loadOPs;
25 }
26  
27 # RUNNING METHODS
28  
29 sub getUser {
30 0 ▶ my ( $self, $req ) = @_;
Subroutine getUser: not called CC=15 SCAR=54.8
Pod undocumented
31  
32 0 my ( $op, $access_token ) = $self->getUserInfoParams($req);
33  
34 # This is likely to happen when running getUser without extractFormInfo
35 # see #1980
36 0 ▶ unless ($op) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($op) 0 0 0
37 0 $self->logger->warn("No OP found in current session");
38 0 return PE_ERROR;
39 }
40  
41 0 ▶ unless ($access_token) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($access_token) 0 0 0
42 0 $self->logger->warn("Could not get Access Token for User Info request");
43 0 return PE_ERROR;
44 }
45  
46 0 my $userinfo_content;
47 my $source = $self->opOptions->{$op}->{oidcOPMetaDataOptionsUserinfoSource}
48 0 ▶ || 'userinfo';
Condition0%0/2
$self->opOptions->{$op}{'oidcOPMetaDataOptionsUserinfoSource'} || 'userinfo'
l!l
00
MC/DC0%0/1
$self->opOptions->{$op}{'oidcOPMetaDataOptionsUserinfoSource'} || 'userinfo'
$self->opOptions->{$op}{'oidcOPMetaDataOptionsUserinfoSource'}
Truth table0%0/2
A
A= $self->opOptions->{$op}{'oidcOPMetaDataOptionsUserinfoSource'}
Aresult
11
00
49 0 ▶ if ( $source eq 'id_token' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($source eq 'id_token') { } 0 0 0
elsif ($source eq 'access_token') { } 0 0 0
50 0 $userinfo_content = getJWTPayload( $req->data->{id_token} );
51 $self->logger->error(
52 "Unable to read ID token content: " . $req->data->{id_token} )
53 0 ▶ unless ($userinfo_content);
Branch: 1 branch
BranchTrueFalseTotal
unless $userinfo_content 0 0 0
54 }
55 elsif ( $source eq 'access_token' ) {
56 0 my $tmp = getJWTPayload($access_token);
57 0 ▶ if ($tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp) { } 0 0 0
58 0 ▶ $userinfo_content = { %{ $userinfo_content || {} }, %$tmp };
Branch: 1 branch
BranchTrueFalseTotal
$userinfo_content or {} 0 0 0
59 }
60 else {
61 0 $self->logger->error(
62 "Unable to read ID token content: $access_token");
63 }
64 }
65 0 ▶ unless ($userinfo_content) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($userinfo_content) 0 0 0
66 0 ▶ unless ( $source eq 'userinfo' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($source eq "userinfo") 0 0 0
67 0 $self->logger->error(
68 "Failed to get user info from $source, trying userinfo endpoint"
69 );
70 }
71 0 $userinfo_content = $self->getUserInfo( $op, $access_token );
72 }
73  
74 0 ▶ unless ($userinfo_content) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($userinfo_content) 0 0 0
75 0 $self->logger->warn("No User Info content");
76 0 return PE_OK;
77 }
78  
79 # call oidcGotUserInfo hook
80 0 my $h =
81 $self->p->processHook( $req, 'oidcGotUserInfo', $op, $userinfo_content, );
82 0 ▶ return PE_OIDC_AUTH_ERROR if ( $h != PE_OK );
Branch: 1 branch
BranchTrueFalseTotal
if $h != 0 0 0 0
83  
84 0 $req->data->{OpenIDConnect_user_info} = $userinfo_content;
85  
86 # Check that received sub is the same than current user
87 my $id_token_sub =
88 0 ▶ $req->data->{id_token_sub} || $req->userData->{_oidc_sub};
Condition0%0/3
$req->data->{'id_token_sub'} || $req->userData->{'_oidc_sub'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$req->data->{'id_token_sub'} || $req->userData->{'_oidc_sub'}
$req->data->{'id_token_sub'} $req->userData->{'_oidc_sub'}
Truth table0%0/3
A || B
A= $req->data->{'id_token_sub'}B= $req->userData->{'_oidc_sub'}
ABresult
1X1
011
000
89 0 my $received_sub = $req->data->{OpenIDConnect_user_info}->{'sub'};
90 0 ▶ unless ( $received_sub eq $id_token_sub ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($received_sub eq $id_token_sub) 0 0 0
91 0 $self->logger->error(
92 "Received sub $received_sub does not match current user $id_token_sub"
93 );
94 0 return PE_BADCREDENTIALS;
95 }
96  
97 0 return PE_OK;
98 }
99  
100 sub findUser {
101  
102 # Nothing to do here
103 0 ▶ return PE_OK;
Subroutine findUser: not called CC=1 SCAR=6.9
Pod undocumented
104 }
105  
106 # Get all required attributes
107 sub setSessionInfo {
108 0 ▶ my ( $self, $req ) = @_;
Subroutine setSessionInfo: not called CC=4 SCAR=30.0
Pod undocumented
109 0 my $op = $req->data->{_oidcOPCurrent};
110  
111 my %vars =
112 0 ( %{ $self->conf->{exportedVars} }, %{ $self->opAttributes->{$op} } );
113  
114 0 ▶ while ( my ( $k, $v ) = each %vars ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %vars) 0 0 0
115 0 my $value = $req->data->{OpenIDConnect_user_info}->{$v};
116 0 ▶ if ( ref($value) and ref($value) eq "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value and ref $value eq 'ARRAY') { } 0 0 0
Condition0%0/3
ref $value and ref $value eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $value and ref $value eq "ARRAY"
ref $value ref $value eq "ARRAY"
Truth table0%0/3
A and B
A= ref $valueB= ref $value eq "ARRAY"
ABresult
0X0
100
111
117 $req->{sessionInfo}->{$k} =
118 0 join( $self->conf->{multiValuesSeparator}, @$value );
119 }
120 else {
121 0 $req->{sessionInfo}->{$k} = $value;
122 }
123 }
124  
125 0 return PE_OK;
126 }
127  
128 39 1;
« blib/lib/Lemonldap/NG/Portal/Lib/Notifications/XML.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Auth/CAS.pm »