« blib/lib/Amazon/Credentials/Provider/SSO.pm
↑ Summary
blib/lib/Amazon/Credentials/Resolver/Profile.pm »
| 1 | package Amazon::Credentials::Role::SSOCache; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use Role::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 12 | ▶ | use Amazon::Credentials::HTTP::UserAgent; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 12 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 12 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 12 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 12 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 12 | ▶ | use Time::Local qw(timegm_modern); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 12 | ▶ | use constant { ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 12 | CACHE_DIR => '.aws/sso/cache', | |||||||||||||||||||||||||||||||||||||||||
| 19 | SSO_OIDC_HOSTNAME => 'oidc.%s.amazonaws.com', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | SSO_OIDC_TOKEN_URI => 'token', | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 12 | }; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 12 | ▶ | sub _sso_cache_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sso_cache_key: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 12 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | return | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 12 | ▶ | if !defined $value || !length $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $value and length $value
MC/DC0%0/2
defined $value and length $value
defined $value
length $value
Truth table33%1/3
A and B
A= defined $valueB= length $value
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 12 | require Digest::SHA; | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 12 | return Digest::SHA::sha1_hex($value); | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 15 | ▶ | sub _get_access_token { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_access_token: called CC=16 SCAR=28.7
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 15 | my ( $self, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 15 | ▶ | my $options | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | = ref $args[0] | ||||||||||||||||||||||||||||||||||||||||||
| 43 | ? $args[0] | ||||||||||||||||||||||||||||||||||||||||||
| 44 | : {@args}; | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 15 | ▶ | my $home = $options->{home} // $ENV{HOME}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$options->{"home"} // $ENV{"HOME"}
MC/DC0%0/2
$options->{"home"} // $ENV{"HOME"}
$options->{"home"}
$ENV{"HOME"}
Truth table66%2/3
A // B
A= $options->{"home"}B= $ENV{"HOME"}
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 15 | my $cache_key = $options->{cache_key}; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 15 | my $region = $options->{region}; | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 15 | ▶ | my $user_agent = $options->{user_agent} // Amazon::Credentials::HTTP::UserAgent->new; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$options->{"user_agent"} // "Amazon::Credentials::HTTP::UserAgent"->new
MC/DC0%0/2
$options->{"user_agent"} // "Amazon::Credentials::HTTP::UserAgent"->new
$options->{"user_agent"}
"Amazon::Credentials::HTTP::UserAgent"->new
Truth table66%2/3
A // B
A= $options->{"user_agent"}B= "Amazon::Credentials::HTTP::UserAgent"->new
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 15 | my $cache_dir = sprintf | |||||||||||||||||||||||||||||||||||||||||
| 55 | '%s/%s', | ||||||||||||||||||||||||||||||||||||||||||
| 56 | $home, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | CACHE_DIR; | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 15 | ▶ | croak "no $cache_dir found" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | if !-d $cache_dir; | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 14 | my @json_files; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 14 | ▶ | if ( defined $cache_key ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 13 | @json_files = ( sprintf '%s/%s.json', $cache_dir, $cache_key ); | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | opendir my $dh, $cache_dir | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | or croak "could not open $cache_dir: $OS_ERROR"; | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | @json_files = map { sprintf '%s/%s', $cache_dir, $_ } | |||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | grep {/[.]json\z/xsm} readdir $dh; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | closedir $dh; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 14 | my @candidates; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 14 | foreach my $file (@json_files) { | |||||||||||||||||||||||||||||||||||||||||
| 80 | 15 | ▶ | open my $fh, '<', $file | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | or next; | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 15 | my $content; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 15 | local $RS = undef; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 15 | $content = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 15 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 15 | my $json = eval { return decode_json($content); }; | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | next | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 15 | ▶ | if !ref $json || !$json->{accessToken}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $json and $json->{"accessToken"}
MC/DC0%0/2
ref $json and $json->{"accessToken"}
ref $json
$json->{"accessToken"}
Truth table33%1/3
A and B
A= ref $jsonB= $json->{"accessToken"}
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 15 | my $expires_at = $self->_parse_expires_at( $json->{expiresAt} ); | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | next | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 15 | ▶ | if !defined $expires_at; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | push @candidates, | ||||||||||||||||||||||||||||||||||||||||||
| 103 | { | ||||||||||||||||||||||||||||||||||||||||||
| 104 | data => $json, | ||||||||||||||||||||||||||||||||||||||||||
| 105 | expires_at => $expires_at, | ||||||||||||||||||||||||||||||||||||||||||
| 106 | file => $file, | ||||||||||||||||||||||||||||||||||||||||||
| 107 | token => $json->{accessToken}, | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 15 | }; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | return | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 14 | ▶ | if !@candidates; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 14 | @candidates = reverse sort { $a->{expires_at} <=> $b->{expires_at} } @candidates; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 14 | my $candidate = $candidates[0]; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | return $candidate->{token} | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 14 | ▶ | if $candidate->{expires_at} > time; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | return | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 3 | ▶ | if !$region; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | return $self->_refresh_sso_access_token( | ||||||||||||||||||||||||||||||||||||||||||
| 125 | cache_file => $candidate->{file}, | ||||||||||||||||||||||||||||||||||||||||||
| 126 | data => $candidate->{data}, | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 3 | ▶ | region => $candidate->{data}{region} || $region, | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$candidate->{'data'}{'region'} || $region
MC/DC0%0/2
$candidate->{'data'}{'region'} || $region
$candidate->{'data'}{'region'}
$region
Truth table33%1/3
A || B
A= $candidate->{'data'}{'region'}B= $region
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | user_agent => $user_agent, | ||||||||||||||||||||||||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 3 | ▶ | sub _refresh_sso_access_token { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_refresh_sso_access_token: called CC=15 SCAR=29.6
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 3 | my ( $self, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 3 | ▶ | my $options | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | = ref $args[0] | ||||||||||||||||||||||||||||||||||||||||||
| 139 | ? $args[0] | ||||||||||||||||||||||||||||||||||||||||||
| 140 | : {@args}; | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 3 | my $cache_file = $options->{cache_file}; | |||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 3 | my $token = $options->{data}; | |||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 3 | my $region = $options->{region}; | |||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 3 | ▶ | my $ua = $options->{user_agent} // Amazon::Credentials::HTTP::UserAgent->new; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$options->{"user_agent"} // "Amazon::Credentials::HTTP::UserAgent"->new
MC/DC0%0/2
$options->{"user_agent"} // "Amazon::Credentials::HTTP::UserAgent"->new
$options->{"user_agent"}
"Amazon::Credentials::HTTP::UserAgent"->new
Truth table33%1/3
A // B
A= $options->{"user_agent"}B= "Amazon::Credentials::HTTP::UserAgent"->new
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | return | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 3 | ▶ | if !ref $token; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 3 | foreach my $key ( | |||||||||||||||||||||||||||||||||||||||||
| 154 | qw( | ||||||||||||||||||||||||||||||||||||||||||
| 155 | clientId | ||||||||||||||||||||||||||||||||||||||||||
| 156 | clientSecret | ||||||||||||||||||||||||||||||||||||||||||
| 157 | refreshToken | ||||||||||||||||||||||||||||||||||||||||||
| 158 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 159 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 160 | return | ||||||||||||||||||||||||||||||||||||||||||
| 161 | if !defined $token->{$key} | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 9 | ▶ | || !length $token->{$key}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $token->{$key} and length $token->{$key}
MC/DC0%0/2
defined $token->{$key} and length $token->{$key}
defined $token->{$key}
length $token->{$key}
Truth table33%1/3
A and B
A= defined $token->{$key}B= length $token->{$key}
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 3 | my $registration_expires_at = $self->_parse_expires_at( $token->{registrationExpiresAt} ); | |||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | return | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 3 | ▶ | if defined $registration_expires_at | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $registration_expires_at and $registration_expires_at <= time
MC/DC50%1/2
defined $registration_expires_at and $registration_expires_at <= time
defined $registration_expires_at
$registration_expires_at <= time
Truth table66%2/3
A and B
A= defined $registration_expires_atB= $registration_expires_at <= time
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | && $registration_expires_at <= time; | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 2 | my $host = sprintf | |||||||||||||||||||||||||||||||||||||||||
| 172 | SSO_OIDC_HOSTNAME, | ||||||||||||||||||||||||||||||||||||||||||
| 173 | $region; | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 2 | my $url = sprintf | |||||||||||||||||||||||||||||||||||||||||
| 176 | 'https://%s/%s', | ||||||||||||||||||||||||||||||||||||||||||
| 177 | $host, | ||||||||||||||||||||||||||||||||||||||||||
| 178 | SSO_OIDC_TOKEN_URI; | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | my $content = encode_json( | ||||||||||||||||||||||||||||||||||||||||||
| 181 | { clientId => $token->{clientId}, | ||||||||||||||||||||||||||||||||||||||||||
| 182 | clientSecret => $token->{clientSecret}, | ||||||||||||||||||||||||||||||||||||||||||
| 183 | grantType => 'refresh_token', | ||||||||||||||||||||||||||||||||||||||||||
| 184 | refreshToken => $token->{refreshToken}, | ||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | my $req = HTTP::Request->new( POST => $url ); | |||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 2 | $req->header( 'Content-Type', 'application/json' ); | |||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 2 | $req->content($content); | |||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 2 | my $rsp = $ua->request($req); | |||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | return | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 2 | ▶ | if !$rsp || !$rsp->is_success; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rsp and $rsp->is_success
MC/DC0%0/2
$rsp and $rsp->is_success
$rsp
$rsp->is_success
Truth table33%1/3
A and B
A= $rspB= $rsp->is_success
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 2 | my $refreshed = eval { return decode_json( $rsp->content ); }; | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | return | ||||||||||||||||||||||||||||||||||||||||||
| 202 | if !ref $refreshed | ||||||||||||||||||||||||||||||||||||||||||
| 203 | || !$refreshed->{accessToken} | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 2 | ▶ | || !$refreshed->{expiresIn}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $refreshed and $refreshed->{"accessToken"} and $refreshed->{"expiresIn"}
ref $refreshed and $refreshed->{"accessToken"}
MC/DC0%0/3
ref $refreshed and $refreshed->{"accessToken"} and $refreshed->{"expiresIn"}
ref $refreshed
$refreshed->{"accessToken"}
$refreshed->{"expiresIn"}
Truth table25%1/4
A and B and C
A= ref $refreshedB= $refreshed->{"accessToken"}C= $refreshed->{"expiresIn"}
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 2 | $token->{accessToken} = $refreshed->{accessToken}; | |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 2 | $token->{expiresAt} = $self->_iso8601_utc( time + $refreshed->{expiresIn} ); | |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 2 | ▶ | if ( $refreshed->{refreshToken} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 1 | $token->{refreshToken} = $refreshed->{refreshToken}; | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | $self->_write_sso_cache_file( $cache_file, $token ); | |||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 2 | return $token->{accessToken}; | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 2 | ▶ | sub _write_sso_cache_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_sso_cache_file: called CC=7 SCAR=21.1
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 2 | my ( $self, $cache_file, $token ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | return | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 2 | ▶ | if !$cache_file || !ref $token; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$cache_file and ref $token
MC/DC0%0/2
$cache_file and ref $token
$cache_file
ref $token
Truth table33%1/3
A and B
A= $cache_fileB= ref $token
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 2 | my $tmp_file = sprintf | |||||||||||||||||||||||||||||||||||||||||
| 228 | '%s.%d.tmp', | ||||||||||||||||||||||||||||||||||||||||||
| 229 | $cache_file, | ||||||||||||||||||||||||||||||||||||||||||
| 230 | $PROCESS_ID; | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 2 | ▶ | open my $fh, '>', $tmp_file | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | or croak "could not open $tmp_file: $OS_ERROR"; | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 2 | print {$fh} encode_json($token); | |||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 2 | ▶ | close $fh | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | or croak "could not close $tmp_file: $OS_ERROR"; | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 2 | ▶ | if ( my @stat = stat $cache_file ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 2 | chmod $stat[2] & oct('7777'), $tmp_file; | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 2 | ▶ | rename $tmp_file, $cache_file | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | or croak "could not rename $tmp_file to $cache_file: $OS_ERROR"; | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 2 | ▶ | sub _iso8601_utc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_iso8601_utc: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 2 | my ( $self, $epoch ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 2 | my @g = gmtime $epoch; | |||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 2 | return sprintf | |||||||||||||||||||||||||||||||||||||||||
| 258 | '%04d-%02d-%02dT%02d:%02d:%02dZ', | ||||||||||||||||||||||||||||||||||||||||||
| 259 | $g[5] + 1900, | ||||||||||||||||||||||||||||||||||||||||||
| 260 | $g[4] + 1, | ||||||||||||||||||||||||||||||||||||||||||
| 261 | @g[ 3, 2, 1, 0 ]; | ||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 18 | ▶ | sub _parse_expires_at { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_expires_at: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 18 | my ( $self, $expires_at ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | return | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 18 | ▶ | if !defined $expires_at; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 18 | my @time_parts = $expires_at =~ /\A | |||||||||||||||||||||||||||||||||||||||||
| 273 | (\d{4})-(\d{2})-(\d{2}) | ||||||||||||||||||||||||||||||||||||||||||
| 274 | [T[:space:]] | ||||||||||||||||||||||||||||||||||||||||||
| 275 | (\d{2}):(\d{2}):(\d{2}) | ||||||||||||||||||||||||||||||||||||||||||
| 276 | (?:[.]\d+)? | ||||||||||||||||||||||||||||||||||||||||||
| 277 | (?:Z|UTC|[+]00:?00)? | ||||||||||||||||||||||||||||||||||||||||||
| 278 | \z/xsm; | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | return | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 18 | ▶ | if !@time_parts; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 18 | $time_parts[1] -= 1; | |||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 18 | return scalar eval { timegm_modern( reverse @time_parts ); }; | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||