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

filter: Statementstmt 70.3% 45 / 64 Branchbran 46.1% 12 / 26 Conditioncond 30.7% 4 / 13 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 4 totaltotal 55.7% 68 / 122 CC 19 SCAR 34.2
CC
19
Cov
59%
getUser
50.4
setSessionInfo
5.8
findUser
2.0
CRAP 30.4
« blib/lib/Lemonldap/NG/Portal/UserDB/WebID.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Lib/Radius.pm »
1 package Lemonldap::NG::Portal::UserDB::OpenIDConnect;
2  
3 45 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 45 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 45 ▶use Lemonldap::NG::Common::JWT 'getJWTPayload';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 45 ▶use Lemonldap::NG::Portal::Main::Constants qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
7 PE_OIDC_AUTH_ERROR
8 PE_BADCREDENTIALS
9 PE_ERROR
10 PE_OK
11 45 );
12  
13 45 our $VERSION = '2.23.0';
14  
15 45 extends qw(
16 Lemonldap::NG::Portal::Main::UserDB
17 Lemonldap::NG::Portal::Lib::OpenIDConnect
18 );
19  
20 # INITIALIZATION
21  
22 48 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
23 48 my ($self) = @_;
24 48 return $self->loadOPs;
25 }
26  
27 # RUNNING METHODS
28  
29 1 ▶sub getUser {
Subroutine getUser: called CC=15 SCAR=39.2
Pod undocumented
30 1 my ( $self, $req ) = @_;
31  
32 1 my ( $op, $access_token ) = $self->getUserInfoParams($req);
33  
34 # This is likely to happen when running getUser without extractFormInfo
35 # see #1980
36 1 ▶ unless ($op) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($op) 0 1 1
37 0 $self->logger->warn("No OP found in current session");
38 0 return PE_ERROR;
39 }
40  
41 1 ▶ unless ($access_token) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($access_token) 0 1 1
42 0 $self->logger->warn("Could not get Access Token for User Info request");
43 0 return PE_ERROR;
44 }
45  
46 1 my $userinfo_content;
47 my $source = $self->opOptions->{$op}->{oidcOPMetaDataOptionsUserinfoSource}
48 1 ▶ || 'userinfo';
Condition50%1/2
$self->opOptions->{$op}{'oidcOPMetaDataOptionsUserinfoSource'} || 'userinfo'
l!l
01
MC/DC0%0/1
$self->opOptions->{$op}{'oidcOPMetaDataOptionsUserinfoSource'} || 'userinfo'
$self->opOptions->{$op}{'oidcOPMetaDataOptionsUserinfoSource'}
Truth table50%1/2
A
A= $self->opOptions->{$op}{'oidcOPMetaDataOptionsUserinfoSource'}
Aresult
11
00
49 1 ▶ if ( $source eq 'id_token' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($source eq 'id_token') { } 0 1 1
elsif ($source eq 'access_token') { } 0 1 1
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 };
Condition0%0/2
$userinfo_content || {}
l!l
00
MC/DC0%0/1
$userinfo_content || {}
$userinfo_content
Truth table0%0/2
A
A= $userinfo_content
Aresult
11
00
59 }
60 else {
61 0 $self->logger->error(
62 "Unable to read ID token content: $access_token");
63 }
64 }
65 1 ▶ unless ($userinfo_content) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($userinfo_content) 1 0 1
66 1 ▶ unless ( $source eq 'userinfo' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($source eq "userinfo") 0 1 1
67 0 $self->logger->error(
68 "Failed to get user info from $source, trying userinfo endpoint"
69 );
70 }
71 1 $userinfo_content = $self->getUserInfo( $op, $access_token );
72 }
73  
74 1 ▶ unless ($userinfo_content) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($userinfo_content) 0 1 1
75 0 $self->logger->warn("No User Info content");
76 0 return PE_OK;
77 }
78  
79 # call oidcGotUserInfo hook
80 1 my $h =
81 $self->p->processHook( $req, 'oidcGotUserInfo', $op, $userinfo_content, );
82 1 ▶ return PE_OIDC_AUTH_ERROR if ( $h != PE_OK );
Branch: 1 branch
BranchTrueFalseTotal
if $h != 0 0 1 1
83  
84 1 $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 1 ▶ $req->data->{id_token_sub} || $req->userData->{_oidc_sub};
Condition33%1/3
$req->data->{'id_token_sub'} || $req->userData->{'_oidc_sub'}
l!l&&r!l&&!r
100
MC/DC0%0/2
$req->data->{'id_token_sub'} || $req->userData->{'_oidc_sub'}
$req->data->{'id_token_sub'} $req->userData->{'_oidc_sub'}
Truth table33%1/3
A || B
A= $req->data->{'id_token_sub'}B= $req->userData->{'_oidc_sub'}
ABresult
1X1
011
000
89 1 my $received_sub = $req->data->{OpenIDConnect_user_info}->{'sub'};
90 1 ▶ unless ( $received_sub eq $id_token_sub ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($received_sub eq $id_token_sub) 0 1 1
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 1 return PE_OK;
98 }
99  
100 0 ▶sub findUser {
Subroutine findUser: not called CC=1 SCAR=6.9
Pod undocumented
101  
102 # Nothing to do here
103 0 return PE_OK;
104 }
105  
106 # Get all required attributes
107 1 ▶sub setSessionInfo {
Subroutine setSessionInfo: called CC=5 SCAR=17.6
Pod undocumented
108 1 my ( $self, $req ) = @_;
109 1 my $op = $req->data->{_oidcOPCurrent};
110  
111 my %vars =
112 1 ( %{ $self->conf->{exportedVars} }, %{ $self->opAttributes->{$op} } );
113  
114 1 ▶ while ( my ( $k, $v ) = each %vars ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %vars) 4 1 5
115 4 my $value = $req->data->{OpenIDConnect_user_info}->{$v};
116  
117 # Flatten arrays if all their values are scalars
118 4 ▶ if ( ref($value)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value and ref $value eq 'ARRAY' and not grep({ref $_;} @$value)) { } 0 4 4
Condition33%2/6
ref $value and ref $value eq "ARRAY" and not grep({ref $_;} @$value)
!ll&&!rl&&r
400
ref $value and ref $value eq "ARRAY"
!ll&&!rl&&r
400
MC/DC0%0/3
ref $value and ref $value eq "ARRAY" and not grep({ref $_;} @$value)
ref $value ref $value eq "ARRAY" not grep({ref $_;} @$value)
Truth table25%1/4
A and B and not(C)
A= ref $valueB= ref $value eq "ARRAY"C= not grep({ref $_;} @$value)
ABCresult
0XX0
10X0
1100
1111
119 and ref($value) eq "ARRAY"
120 0 and not grep { ref($_) } @$value )
121 {
122 $req->{sessionInfo}->{$k} =
123 0 join( $self->conf->{multiValuesSeparator}, @$value );
124 }
125  
126 # Else, store the value as-is
127 else {
128 4 $req->{sessionInfo}->{$k} = $value;
129 }
130 }
131  
132 1 return PE_OK;
133 }
134  
135 45 1;
« blib/lib/Lemonldap/NG/Portal/UserDB/WebID.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Lib/Radius.pm »