| 1 | package OIDC::Client::Role::ConfigurationChecker; | ||||||||||||||||||||||||||||
| 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 MooseX::Params::Validate; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use feature 'signatures'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | no warnings 'experimental::signatures'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use List::MoreUtils qw(duplicates uniq any); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =encoding utf8 | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | OIDC::Client::Role::ConfigurationChecker - Configuration checker | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | This Moose role covers private methods for checking the configuration. | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =cut | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 5 | requires qw(config | |||||||||||||||||||||||||||
| 25 | audience | ||||||||||||||||||||||||||||
| 26 | store_mode | ||||||||||||||||||||||||||||
| 27 | token_endpoint_grant_type); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 71 | ▶ | sub _check_configuration ($self) { | ||||||||||||||||||||||||||
|
Subroutine
_check_configuration: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 71 | my @config = %{$self->config}; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 71 | validated_hash( | |||||||||||||||||||||||||||
| 34 | \@config, | ||||||||||||||||||||||||||||
| 35 | provider => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 36 | store_mode => { isa => 'StoreMode', optional => 1 }, | ||||||||||||||||||||||||||||
| 37 | proxy_detect => { isa => 'Bool', optional => 1 }, | ||||||||||||||||||||||||||||
| 38 | user_agent => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 39 | use_pkce => { isa => 'Bool', optional => 1 }, | ||||||||||||||||||||||||||||
| 40 | pkce_code_challenge_method => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 41 | id => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 42 | secret => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 43 | private_jwk_file => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 44 | private_jwk => { isa => 'HashRef', optional => 1 }, | ||||||||||||||||||||||||||||
| 45 | private_key_file => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 46 | private_key => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 47 | tls_client_key_file => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 48 | tls_client_key_passphrase => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 49 | tls_client_cert_file => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 50 | tls_ca_file => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 51 | audience => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 52 | role_prefix => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 53 | well_known_url => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 54 | issuer => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 55 | jwks_url => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 56 | authorize_url => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 57 | token_url => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 58 | introspection_url => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 59 | userinfo_url => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 60 | end_session_url => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 61 | signin_redirect_path => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 62 | signin_redirect_uri => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 63 | scope => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 64 | refresh_scope => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 65 | identity_expires_in => { isa => 'Int', optional => 1 }, | ||||||||||||||||||||||||||||
| 66 | expiration_leeway => { isa => 'Int', optional => 1 }, | ||||||||||||||||||||||||||||
| 67 | max_id_token_age => { isa => 'Int', optional => 1 }, | ||||||||||||||||||||||||||||
| 68 | jwt_decoding_options => { isa => 'HashRef', optional => 1 }, | ||||||||||||||||||||||||||||
| 69 | client_secret_jwt_encoding_options => { isa => 'HashRef', optional => 1 }, | ||||||||||||||||||||||||||||
| 70 | private_key_jwt_encoding_options => { isa => 'HashRef', optional => 1 }, | ||||||||||||||||||||||||||||
| 71 | claim_mapping => { isa => 'HashRef[Str]', optional => 1 }, | ||||||||||||||||||||||||||||
| 72 | audience_alias => { isa => 'HashRef[HashRef]', optional => 1 }, | ||||||||||||||||||||||||||||
| 73 | authorize_endpoint_response_mode => { isa => 'ResponseMode', optional => 1 }, | ||||||||||||||||||||||||||||
| 74 | authorize_endpoint_extra_params => { isa => 'HashRef', optional => 1 }, | ||||||||||||||||||||||||||||
| 75 | token_validation_method => { isa => 'TokenValidationMethod', optional => 1 }, | ||||||||||||||||||||||||||||
| 76 | token_endpoint_grant_type => { isa => 'GrantType', optional => 1 }, | ||||||||||||||||||||||||||||
| 77 | client_auth_method => { isa => 'ClientAuthMethod', optional => 1 }, | ||||||||||||||||||||||||||||
| 78 | token_endpoint_auth_method => { isa => 'ClientAuthMethod', optional => 1 }, | ||||||||||||||||||||||||||||
| 79 | introspection_endpoint_auth_method => { isa => 'ClientAuthMethod', optional => 1 }, | ||||||||||||||||||||||||||||
| 80 | client_assertion_lifetime => { isa => 'Int', optional => 1 }, | ||||||||||||||||||||||||||||
| 81 | client_assertion_audience => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 82 | username => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 83 | password => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 84 | logout_redirect_path => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 85 | post_logout_redirect_uri => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 86 | logout_with_id_token => { isa => 'Bool', optional => 1 }, | ||||||||||||||||||||||||||||
| 87 | logout_extra_params => { isa => 'HashRef', optional => 1 }, | ||||||||||||||||||||||||||||
| 88 | cache_config => { isa => 'HashRef', optional => 1 }, | ||||||||||||||||||||||||||||
| 89 | mocked_identity => { isa => 'HashRef', optional => 1 }, | ||||||||||||||||||||||||||||
| 90 | mocked_access_token => { isa => 'HashRef', optional => 1 }, | ||||||||||||||||||||||||||||
| 91 | mocked_userinfo => { isa => 'HashRef', optional => 1 }, | ||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 70 | ▶ | sub _check_client_auth_configuration ($self) { | ||||||||||||||||||||||||||
|
Subroutine
_check_client_auth_configuration: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 97 | 70 | my @auth_methods = uniq($self->token_endpoint_auth_method, | |||||||||||||||||||||||||||
| 98 | $self->introspection_endpoint_auth_method); | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 70 | ▶ | if (any { $_ eq 'tls_client_auth' } @auth_methods) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 3 | ▶ | unless ($self->tls_client_cert_file && $self->tls_client_key_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->tls_client_cert_file and $self->tls_client_key_file
MC/DC50%1/2
$self->tls_client_cert_file and $self->tls_client_key_file
$self->tls_client_cert_file
$self->tls_client_key_file
Truth table66%2/3
A and B
A= $self->tls_client_cert_fileB= $self->tls_client_key_file
| |||||||||||||||||||||||||||||
| 102 | 1 | croak("OIDC: 'tls_client_cert_file' and 'tls_client_key_file' attributes " | |||||||||||||||||||||||||||
| 103 | . "are required when tls_client_auth method is used"); | ||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 69 | ▶ | if (any { $_ eq 'private_key_jwt' } @auth_methods) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 5 | $self->private_key; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | # client_secret_* methods : we can't check the presence of the secret here because a Resource Server | ||||||||||||||||||||||||||||
| 112 | # doesn't need any secret to verify an access token (without introspection). | ||||||||||||||||||||||||||||
| 113 | # An exception is thrown when attempting to access the 'secret' attribute if it is missing. | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 68 | ▶ | sub _check_audiences_configuration ($self) { | ||||||||||||||||||||||||||
|
Subroutine
_check_audiences_configuration: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 118 | 68 | ▶ | my %config_audience_alias = %{ $self->config->{audience_alias} || {} }; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->config->{'audience_alias'} || {}
MC/DC100%1/1
$self->config->{'audience_alias'} || {}
$self->config->{'audience_alias'}
Truth table100%2/2
A
A= $self->config->{'audience_alias'}
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 78 | my @possible_audiences = grep { $_ } ($self->audience, | |||||||||||||||||||||||||||
| 121 | 68 | map { $_->{audience} } values %config_audience_alias); | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 67 | ▶ | if (my @duplicates_audiences = duplicates(@possible_audiences)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 1 | croak(sprintf('OIDC: these configured audiences are duplicated: %s', join(', ', @duplicates_audiences))); | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 66 | foreach my $audience_alias (keys %config_audience_alias) { | |||||||||||||||||||||||||||
| 128 | 7 | ▶ | my @config_audience = %{$config_audience_alias{$audience_alias} || {}}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$config_audience_alias{$audience_alias} || {}
MC/DC0%0/1
$config_audience_alias{$audience_alias} || {}
$config_audience_alias{$audience_alias}
Truth table50%1/2
A
A= $config_audience_alias{$audience_alias}
| |||||||||||||||||||||||||||||
| 129 | 7 | validated_hash( | |||||||||||||||||||||||||||
| 130 | \@config_audience, | ||||||||||||||||||||||||||||
| 131 | audience => { isa => 'Str', optional => 0 }, | ||||||||||||||||||||||||||||
| 132 | scope => { isa => 'Str', optional => 1 }, | ||||||||||||||||||||||||||||
| 133 | ); | ||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 66 | ▶ | sub _check_cache_configuration ($self) { | ||||||||||||||||||||||||||
|
Subroutine
_check_cache_configuration: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||
| 139 | 66 | ▶ | if ($self->store_mode eq 'cache') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 1 | my $grant_type = $self->token_endpoint_grant_type; | |||||||||||||||||||||||||||
| 141 | 1 | ▶ | unless ($grant_type eq 'client_credentials' || $grant_type eq 'password') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$grant_type eq "client_credentials" or $grant_type eq "password"
MC/DC0%0/2
$grant_type eq "client_credentials" or $grant_type eq "password"
$grant_type eq "client_credentials"
$grant_type eq "password"
Truth table33%1/3
A or B
A= $grant_type eq "client_credentials"B= $grant_type eq "password"
| |||||||||||||||||||||||||||||
| 142 | 1 | croak("OIDC: you cannot use the 'cache' store mode with the '$grant_type' grant type, " | |||||||||||||||||||||||||||
| 143 | . "but only with the 'client_credentials' or 'password' grant types"); | ||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 5 | 1; | |||||||||||||||||||||||||||