Client/Role/ClaimsValidator.pm

filter: Statementstmt 100% 45 / 45 Branchbran 90.6% 29 / 32 Conditioncond 60.0% 3 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 15 / 15 Podpod n/a totaltotal 92.0% 92 / 100 CC 19 SCAR 12.1
CC
19
Cov
94%
_validate_audience
5.1
_validate_authorized_party
5.0
_validate_age
4.2
CRAP 3.3
« Client/Role/AttributesManager.pm ↑ Summary Client/AccessTokenBuilder.pm »
1 package OIDC::Client::Role::ClaimsValidator;
2 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶no warnings 'experimental::signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use List::Util qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use OIDC::Client::Error::TokenValidation;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =encoding utf8
12  
13 =head1 NAME
14  
15 OIDC::Client::Role::ClaimsValidator - Claims Validator
16  
17 =head1 DESCRIPTION
18  
19 This Moose role covers private methods for validating token claims.
20  
21 =cut
22  
23  
24 5 requires qw(audience
25 provider_metadata
26 jwt_decoding_options);
27  
28  
29 30 ▶sub _validate_issuer ($self, $issuer) {
Subroutine _validate_issuer: called CC=4 SCAR=13.9
30  
31 30 ▶ defined $issuer
Branch: 1 branch
BranchTrueFalseTotal
defined $issuer or "OIDC::Client::Error::TokenValidation"->throw("OIDC: 'iss' claim is missing") 29 1 30
32 or OIDC::Client::Error::TokenValidation->throw("OIDC: 'iss' claim is missing");
33  
34 my $expected_issuer = $self->provider_metadata->{issuer}
35 29 ▶ or croak("OIDC: issuer not found in provider metadata");
Branch: 1 branch
BranchTrueFalseTotal
my $expected_issuer = $self->provider_metadata->{"issuer"} or croak("OIDC: issuer not found in provider metadata") 29 0 29
36  
37 29 ▶ $issuer eq $expected_issuer
Branch: 1 branch
BranchTrueFalseTotal
$issuer eq $expected_issuer or "OIDC::Client::Error::TokenValidation"->throw("OIDC: unexpected issuer, expected '${expected_issuer}' but got '${issuer}'") 27 2 29
38 or OIDC::Client::Error::TokenValidation->throw(
39 "OIDC: unexpected issuer, expected '$expected_issuer' but got '$issuer'"
40 );
41 }
42  
43  
44 27 ▶sub _validate_audience ($self, $audience, $expected_audience) {
Subroutine _validate_audience: called CC=5 SCAR=16.2
45  
46 27 ▶ defined $audience
Branch: 1 branch
BranchTrueFalseTotal
defined $audience or "OIDC::Client::Error::TokenValidation"->throw("OIDC: 'aud' claim is missing") 26 1 27
47 or OIDC::Client::Error::TokenValidation->throw("OIDC: 'aud' claim is missing");
48  
49 26 ▶ $expected_audience ||= $self->audience;
Condition66%2/3
$expected_audience ||= $self->audience
l!l&&r!l&&!r
4220
MC/DC0%0/2
$expected_audience ||= $self->audience
$expected_audience $self->audience
Truth table66%2/3
A ||= B
A= $expected_audienceB= $self->audience
ABresult
1X1
011
000
50  
51 26 ▶ my @audiences = ref $audience eq 'ARRAY' ? @$audience : ($audience);
Branch: 1 branch
BranchTrueFalseTotal
ref $audience eq 'ARRAY' ? : 0 26 26
52  
53 26 ▶ any { $_ eq $expected_audience } @audiences
Subroutine __ANON__: called CC=1 SCAR=0.0
54 or OIDC::Client::Error::TokenValidation->throw(
55 26 ▶ "OIDC: unexpected audience, expected '$expected_audience' but got " . join(', ', map { "'$_'" } @audiences)
Branch: 1 branch
BranchTrueFalseTotal
&any(sub { $_ eq $expected_audience; } , @audiences) or "OIDC::Client::Error::TokenValidation"->throw("OIDC: unexpected audience, expected '${expected_audience}' but got " . join(", ", map({"'${_}'";} @audiences))) 23 3 26
56 );
57 }
58  
59  
60 5 ▶sub _validate_authorized_party ($self, $azp, $expected_authorized_party) {
Subroutine _validate_authorized_party: called CC=5 SCAR=16.1
61  
62 5 ▶ if (defined $expected_authorized_party) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $expected_authorized_party) { } 3 2 5
elsif (defined $azp) { } 1 1 2
63 3 ▶ defined $azp
Branch: 1 branch
BranchTrueFalseTotal
defined $azp or "OIDC::Client::Error::TokenValidation"->throw("OIDC: 'azp' claim is missing") 2 1 3
64 or OIDC::Client::Error::TokenValidation->throw("OIDC: 'azp' claim is missing");
65 2 ▶ $azp eq $expected_authorized_party
Branch: 1 branch
BranchTrueFalseTotal
$azp eq $expected_authorized_party or "OIDC::Client::Error::TokenValidation"->throw("OIDC: unexpected authorized party, expected '${expected_authorized_party}' but got '${azp}'") 1 1 2
66 or OIDC::Client::Error::TokenValidation->throw(
67 "OIDC: unexpected authorized party, expected '$expected_authorized_party' but got '$azp'"
68 );
69 }
70 elsif (defined $azp) {
71 1 OIDC::Client::Error::TokenValidation->throw("OIDC: unexpected 'azp' claim");
72 }
73 }
74  
75  
76 3 ▶sub _validate_subject ($self, $subject, $expected_subject) {
Subroutine _validate_subject: called CC=3 SCAR=11.0
77  
78 3 ▶ defined $subject
Branch: 1 branch
BranchTrueFalseTotal
defined $subject or "OIDC::Client::Error::TokenValidation"->throw("OIDC: 'sub' claim is missing") 2 1 3
79 or OIDC::Client::Error::TokenValidation->throw("OIDC: 'sub' claim is missing");
80  
81 2 ▶ $subject eq $expected_subject
Branch: 1 branch
BranchTrueFalseTotal
$subject eq $expected_subject or "OIDC::Client::Error::TokenValidation"->throw("OIDC: unexpected subject, expected '${expected_subject}' but got '${subject}'") 1 1 2
82 or OIDC::Client::Error::TokenValidation->throw(
83 "OIDC: unexpected subject, expected '$expected_subject' but got '$subject'"
84 );
85 }
86  
87 4 ▶sub _validate_nonce ($self, $nonce, $expected_nonce) {
Subroutine _validate_nonce: called CC=3 SCAR=11.0
88  
89 4 ▶ defined $nonce
Branch: 1 branch
BranchTrueFalseTotal
defined $nonce or "OIDC::Client::Error::TokenValidation"->throw("OIDC: 'nonce' claim is missing") 3 1 4
90 or OIDC::Client::Error::TokenValidation->throw("OIDC: 'nonce' claim is missing");
91  
92 3 ▶ $nonce eq $expected_nonce
Branch: 1 branch
BranchTrueFalseTotal
$nonce eq $expected_nonce or "OIDC::Client::Error::TokenValidation"->throw("OIDC: unexpected nonce, expected '${expected_nonce}' but got '${nonce}'") 2 1 3
93 or OIDC::Client::Error::TokenValidation->throw(
94 "OIDC: unexpected nonce, expected '$expected_nonce' but got '$nonce'"
95 );
96 }
97  
98  
99 3 ▶sub _validate_age ($self, $issued_at, $max_token_age) {
Subroutine _validate_age: called CC=4 SCAR=14.5
100  
101 3 ▶ defined $issued_at
Branch: 1 branch
BranchTrueFalseTotal
defined $issued_at or "OIDC::Client::Error::TokenValidation"->throw("OIDC: 'iat' claim is missing") 3 0 3
102 or OIDC::Client::Error::TokenValidation->throw("OIDC: 'iat' claim is missing");
103  
104 3 ▶ $issued_at >= time - ($self->jwt_decoding_options->{leeway} // 0) - $max_token_age
Branch: 1 branch
BranchTrueFalseTotal
$issued_at >= time - ($self->jwt_decoding_options->{"leeway"} // 0) - $max_token_age or "OIDC::Client::Error::TokenValidation"->throw("OIDC: the token is too old") 2 1 3
Condition50%1/2
$self->jwt_decoding_options->{"leeway"} // 0
l!l
30
MC/DC0%0/1
$self->jwt_decoding_options->{"leeway"} // 0
$self->jwt_decoding_options->{"leeway"}
Truth table50%1/2
A
A= $self->jwt_decoding_options->{"leeway"}
Aresult
11
00
105 or OIDC::Client::Error::TokenValidation->throw(
106 "OIDC: the token is too old"
107 );
108 }
109  
110  
111 5 1;
« Client/Role/AttributesManager.pm ↑ Summary Client/AccessTokenBuilder.pm »