blib/lib/Google/Auth/IDTokens/KeySources.pm

filter: Statementstmt 78.1% 150 / 192 Branchbran 54.2% 38 / 70 Conditioncond 55.2% 21 / 38 MC/DCmcdc 26.0% 6 / 23 Subroutinesub 80.0% 32 / 40 Podpod n/a totaltotal 68.0% 247 / 363 CC 53 SCAR 18.0
CC
53
Cov
70%
new
20.0
refresh_keys
12.0
refresh_keys
11.9
CRAP 6.1
« blib/lib/Google/Auth/ClientId.pm ↑ Summary blib/lib/Google/Auth.pm »
1 # frozen_string_literal: true
2 # Copyright 2020 Google LLC and contributors
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15  
16 package Google::Auth::IDTokens::KeySources;
17  
18 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 5 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 5 ▶use Google::Auth;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 5 ▶use MIME::Base64 qw(decode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 5 1;
28  
29 ##
30 # A public key used for verifying ID tokens.
31 #
32 # This includes the public key data, ID, and the algorithm used for
33 # signature verification. RSA and Elliptical Curve (EC) keys are
34 # supported.
35 #
36  
37 package Google::Auth::IDTokens::KeyInfo;
38  
39 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 5 my $coder = JSON::MaybeXS->new->ascii->pretty->allow_nonref;
42  
43 ##
44 # Create a public key info structure.
45 #
46 # @param id [String] The key ID.
47 # @param key [Crypt::PK::RSA,Crypt::PK::ECC] The key itself.
48 # @param algorithm [String] The algorithm (normally `RS256` or `ES256`)
49 #
50 16 ▶sub new {
Subroutine new: called CC=7 SCAR=19.5
51 16 my ($class, $params) = @_;
52 16 ▶ $params //= {};
Condition100%2/2
$params //= {}
l!l
511
MC/DC100%1/1
$params //= {}
$params
Truth table100%2/2
A
A= $params
Aresult
11
00
53 16 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 16 16
54 my $self = bless {
55 id => $params->{id} // undef,
56 key => $params->{key} // undef,
57 algorithm => $params->{algorithm} // undef,
58 key_type => $params->{key_type} // undef,
59 16 ▶ }, $class;
Condition100%8/8
$params->{"id"} // undef
l!l
511
$params->{"key"} // undef
l!l
511
$params->{"algorithm"} // undef
l!l
511
$params->{"key_type"} // undef
l!l
214
MC/DC100%1/1
$params->{"id"} // undef
$params->{"id"}
MC/DC100%1/1
$params->{"key"} // undef
$params->{"key"}
MC/DC100%1/1
$params->{"algorithm"} // undef
$params->{"algorithm"}
MC/DC100%1/1
$params->{"key_type"} // undef
$params->{"key_type"}
Truth table100%2/2
A
A= $params->{"id"}
Aresult
11
00
Truth table100%2/2
A
A= $params->{"key"}
Aresult
11
00
Truth table100%2/2
A
A= $params->{"algorithm"}
Aresult
11
00
Truth table100%2/2
A
A= $params->{"key_type"}
Aresult
11
00
60 16 return $self;
61 }
62  
63 ##
64 # The key ID.
65 # @return [String]
66 #
67 32 ▶sub id { return $_[0]->{id} }
Subroutine id: called CC=1 SCAR=0.0
68  
69 ##
70 # The key itself.
71 # @return [OpenSSL::PKey::RSA,OpenSSL::PKey::EC]
72 #
73 14 ▶sub key { return $_[0]->{key} }
Subroutine key: called CC=1 SCAR=0.0
74  
75 ##
76 # The signature algorithm. (normally `RS256` or `ES256`)
77 # @return [String]
78 #
79 42 ▶sub algorithm { return $_[0]->{algorithm} }
Subroutine algorithm: called CC=1 SCAR=0.0
80  
81 ##
82 # The public key family (`RSA` or `EC`).
83 # @return [String]
84 #
85 40 ▶sub key_type { return $_[0]->{key_type} }
Subroutine key_type: called CC=1 SCAR=0.0
86  
87 ##
88 # Create a KeyInfo from a single JWK, which may be given as either a
89 # hash or an unparsed JSON string.
90 #
91 # @param jwk [Hash,String] The JWK specification.
92 # @return [KeyInfo]
93 # @raise [KeySourceError] If the key could not be extracted from the
94 # JWK.
95 #
96 11 ▶sub from_jwk {
Subroutine from_jwk: called CC=5 SCAR=16.3
97 11 my ($self, $jwk) = @_;
98 11 $jwk = $self->ensure_json_parsed($jwk);
99  
100 11 ▶ my $instance = ref $self ? $self : $self->new();
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 11 11
101  
102 11 ▶ if (!defined $jwk->{kty}) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $jwk->{'kty'}) { } 0 11 11
elsif ($jwk->{'kty'} eq 'RSA') { } 4 7 11
elsif ($jwk->{'kty'} eq 'EC') { } 6 1 7
103 0 die 'Key type not found';
104 } elsif ($jwk->{kty} eq 'RSA') {
105 4 $instance->{key} = $instance->extract_rsa_key($jwk);
106 } elsif ($jwk->{kty} eq 'EC') {
107 6 $instance->{key} = $instance->extract_ec_key($jwk);
108 } else {
109 1 die 'Cannot use key type ' . $jwk->{kty};
110 }
111 10 $instance->{id} = $jwk->{kid};
112 10 $instance->{algorithm} = $jwk->{alg};
113 10 $instance->{key_type} = $jwk->{kty};
114  
115 10 return $instance;
116 }
117 ##
118 # Create an array of KeyInfo from a JWK Set, which may be given as
119 # either a hash or an unparsed JSON string.
120 #
121 # @param jwk [Hash,String] The JWK Set specification.
122 # @return [Array<KeyInfo>]
123 # @raise [KeySourceError] If a key could not be extracted from the
124 # JWK Set.
125 #
126 6 ▶sub from_jwk_set {
Subroutine from_jwk_set: called CC=4 SCAR=14.0
127 6 my ($self, $jwk_set) = @_;
128 6 ▶ confess 'jwk_set is a required argument' unless $jwk_set;
Branch: 1 branch
BranchTrueFalseTotal
unless $jwk_set 0 6 6
129 6 $jwk_set = $self->ensure_json_parsed($jwk_set);
130 confess "No keys found in jwk set"
131 unless (exists $jwk_set->{keys}
132 6 ▶ && ref $jwk_set->{keys} eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless exists $jwk_set->{"keys"} and ref $jwk_set->{"keys"} eq "ARRAY" 1 5 6
Condition66%2/3
exists $jwk_set->{"keys"} and ref $jwk_set->{"keys"} eq "ARRAY"
!ll&&!rl&&r
105
MC/DC50%1/2
exists $jwk_set->{"keys"} and ref $jwk_set->{"keys"} eq "ARRAY"
exists $jwk_set->{"keys"} ref $jwk_set->{"keys"} eq "ARRAY"
Truth table66%2/3
A and B
A= exists $jwk_set->{"keys"}B= ref $jwk_set->{"keys"} eq "ARRAY"
ABresult
0X0
100
111
133 5 my $jwks = [map { $self->from_jwk($_) } @{$jwk_set->{keys}}];
134  
135 4 return $jwks;
136 }
137  
138 17 ▶sub ensure_json_parsed {
Subroutine ensure_json_parsed: called CC=4 SCAR=20.4
139 17 my ($self, $input) = @_;
140 17 ▶ confess 'input is a required argument' unless $input;
Branch: 1 branch
BranchTrueFalseTotal
unless $input 0 17 17
141 17 ▶ return $input if ref $input;
Branch: 1 branch
BranchTrueFalseTotal
if ref $input 17 0 17
142 0 my $decoded = eval { $coder->decode($input) };
143  
144 0 ▶ confess("Unable to parse JSON: $@$/" . "input: $input") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
145 0 return $decoded;
146 }
147  
148 0 ▶sub symbolize_keys {
Subroutine symbolize_keys: not called CC=2 SCAR=17.9
149 0 my ($self, $hash) = @_;
150 0 my $result = {};
151 0 ▶ while (my ($key, $val) = each %$hash) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$hash) 0 0 0
152 0 $result->{$key} = $val;
153 }
154 0 return $result;
155 }
156  
157 20 ▶sub _decode_base64url {
Subroutine _decode_base64url: called CC=2 SCAR=6.9
158 20 my ($s) = @_;
159 20 $s =~ tr{-_}{+/};
160 20 my $padding = length($s) % 4;
161 20 ▶ if ($padding) {
Branch: 1 branch
BranchTrueFalseTotal
if ($padding) 16 4 20
162 16 $s .= '=' x (4 - $padding);
163 }
164 20 return MIME::Base64::decode_base64($s);
165 }
166  
167 4 ▶sub extract_rsa_key {
Subroutine extract_rsa_key: called CC=2 SCAR=7.0
168 4 my ($self, $jwk) = @_;
169 4 my $n = _decode_base64url($jwk->{n});
170 4 my $e = _decode_base64url($jwk->{e});
171 4 my $pubkey = Google::Auth::load_rsa_pubkey($n, $e);
172 4 ▶ die 'Failed to load RSA public key' unless defined $pubkey;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pubkey 0 4 4
173 4 return $pubkey;
174 }
175  
176 # @private
177 5 my $CURVE_NAME_MAP = {
178 'P-256' => 'prime256v1',
179 'P-384' => 'secp384r1',
180 'P-521' => 'secp521r1',
181 'secp256k1' => 'secp256k1'
182 };
183  
184 6 ▶sub extract_ec_key {
Subroutine extract_ec_key: called CC=3 SCAR=11.1
185 6 my ($self, $jwk) = @_;
186 6 my $curve = $jwk->{crv};
187 die 'Unsupported EC curve ' . $curve
188 6 ▶ unless exists $CURVE_NAME_MAP->{$curve};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $CURVE_NAME_MAP->{$curve} 0 6 6
189  
190 6 my $x = _decode_base64url($jwk->{x});
191 6 my $y = _decode_base64url($jwk->{y});
192  
193 6 my $openssl_curve = $CURVE_NAME_MAP->{$curve};
194 6 my $pubkey = Google::Auth::load_ec_pubkey($openssl_curve, $x, $y);
195 6 ▶ die 'Failed to load EC public key' unless defined $pubkey;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pubkey 0 6 6
196 6 return $pubkey;
197 }
198  
199 5 1;
200  
201 package Google::Auth::IDTokens::StaticKeySource;
202 ##
203 # A key source that contains a static set of keys.
204 #
205 ##
206 # Create a static key source with the given keys.
207 #
208 # @param keys [Array<KeyInfo>] The keys
209 #
210 2 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
211 2 my ($class, $params) = @_;
212 2 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 2 2
213 2 my $self = bless {current_keys => [@{$params->{keys}}]}, $class;
214 2 return $self;
215 }
216  
217 ##
218 # Return the current keys. Does not perform any refresh.
219 #
220 # @return [Array<KeyInfo>]
221 #
222 3 ▶sub current_keys { return $_[0]->{current_keys} }
Subroutine current_keys: called CC=1 SCAR=0.0
223 5 *refresh_keys = \&current_keys;
224  
225 ##
226 # Create a static key source containing a single key parsed from a
227 # single JWK, which may be given as either a hash or an unparsed
228 # JSON string.
229 #
230 # @param jwk [Hash,String] The JWK specification.
231 # @return [StaticKeySource]
232 #
233 0 ▶sub from_jwk {
Subroutine from_jwk: not called CC=1 SCAR=6.9
234 0 my ($self, $jwk) = @_;
235 0 return Google::Auth::IDTokens::KeyInfo->new()->from_jwk($jwk);
236 }
237  
238 ##
239 # Create a static key source containing multiple keys parsed from a
240 # JWK Set, which may be given as either a hash or an unparsed JSON
241 # string.
242 #
243 # @param jwk_set [Hash,String] The JWK Set specification.
244 # @return [StaticKeySource]
245 #
246 0 ▶sub from_jwk_set {
Subroutine from_jwk_set: not called CC=1 SCAR=6.9
247 0 my ($self, $jwk_set) = @_;
248 0 return Google::Auth::IDTokens::KeyInfo->new()->from_jwk_set($jwk_set);
249 }
250  
251 5 1;
252  
253 package Google::Auth::IDTokens::HttpKeySource;
254 ##
255 # A base key source that downloads keys from a URI. Subclasses should
256 # override {HttpKeySource#interpret_json} to parse the response.
257 #
258 ##
259 # The default interval between retries in seconds (3600s = 1hr).
260 #
261 # @return [Integer]
262 #
263 5 our $DEFAULT_RETRY_INTERVAL = 3600;
264  
265 ##
266 # Create an HTTP key source.
267 #
268 # @param uri [String,URI] The URI from which to download keys.
269 # @param retry_interval [Integer,nil] Override the retry interval in
270 # seconds. This is the minimum time between retries of failed key
271 # downloads.
272 #
273 16 ▶sub new {
Subroutine new: called CC=7 SCAR=23.0
274 16 my ($class, $params) = @_;
275 16 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 16 16
276 die "uri is a required parameter$/" . Data::Dumper::Dumper($params)
277 16 ▶ unless (exists $params->{uri} && $params->{uri});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params->{"uri"} and $params->{"uri"} 0 16 16
Condition33%1/3
exists $params->{"uri"} and $params->{"uri"}
!ll&&!rl&&r
0016
MC/DC0%0/2
exists $params->{"uri"} and $params->{"uri"}
exists $params->{"uri"} $params->{"uri"}
Truth table33%1/3
A and B
A= exists $params->{"uri"}B= $params->{"uri"}
ABresult
0X0
100
111
278  
279 my $self = bless {
280 retry_interval => $params->{retry_interval} || $DEFAULT_RETRY_INTERVAL,
281 allow_refresh_at => time(),
282 current_keys => [],
283 16 ▶ uri => URI->new($params->{uri}),
Condition66%2/3
$params->{'retry_interval'} || $Google::Auth::IDTokens::HttpKeySource::DEFAULT_RETRY_INTERVAL
l!l&&r!l&&!r
4120
MC/DC0%0/2
$params->{'retry_interval'} || $Google::Auth::IDTokens::HttpKeySource::DEFAULT_RETRY_INTERVAL
$params->{'retry_interval'} $Google::Auth::IDTokens::HttpKeySource::DEFAULT_RETRY_INTERVAL
Truth table66%2/3
A || B
A= $params->{'retry_interval'}B= $Google::Auth::IDTokens::HttpKeySource::DEFAULT_RETRY_INTERVAL
ABresult
1X1
011
000
284 }, $class;
285  
286 16 ▶ if (exists $ENV{TESTING} && $ENV{TESTING}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{'TESTING'} and $ENV{'TESTING'}) { } 16 0 16
Condition33%1/3
exists $ENV{"TESTING"} and $ENV{"TESTING"}
!ll&&!rl&&r
0016
MC/DC0%0/2
exists $ENV{"TESTING"} and $ENV{"TESTING"}
exists $ENV{"TESTING"} $ENV{"TESTING"}
Truth table33%1/3
A and B
A= exists $ENV{"TESTING"}B= $ENV{"TESTING"}
ABresult
0X0
100
111
287 16 $self->{ua} = $KeySourcesTest::useragent;
288 } else {
289 0 $self->{ua} = HTTP::Tiny->new(timeout => 10, verify_SSL => 1);
290 }
291  
292 16 return $self;
293 }
294  
295 ##
296 # The URI from which to download keys.
297 # @return [Array<KeyInfo>]
298 #
299 0 ▶sub uri { return $_[0]->{uri} }
Subroutine uri: not called CC=1 SCAR=6.9
300  
301 ##
302 # Return the current keys, without attempting to re-download.
303 #
304 # @return [Array<KeyInfo>]
305 #
306 12 ▶sub current_keys { return $_[0]->{current_keys} }
Subroutine current_keys: called CC=1 SCAR=0.0
307  
308 ##
309 # Attempt to re-download keys (if the retry interval has expired) and
310 # return the new keys.
311 #
312 # @return [Array<KeyInfo>]
313 # @raise [KeySourceError] if key retrieval failed.
314 #
315 18 ▶sub refresh_keys {
Subroutine refresh_keys: called CC=10 SCAR=24.8
316 18 my ($self) = @_;
317 $self->{allow_refresh_at} = time()
318 18 ▶ unless (exists $self->{allow_refresh_at});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"allow_refresh_at"} 0 18 18
319  
320 18 ▶ if (time() < $self->{allow_refresh_at}) {
Branch: 1 branch
BranchTrueFalseTotal
if (time < $self->{"allow_refresh_at"}) 2 16 18
321 2 ▶ print STDERR 'cache hit', $/ if $ENV{TESTING} && $ENV{VERBOSE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"TESTING"} and $ENV{"VERBOSE"} 0 2 2
Condition33%1/3
$ENV{"TESTING"} and $ENV{"VERBOSE"}
!ll&&!rl&&r
020
MC/DC0%0/2
$ENV{"TESTING"} and $ENV{"VERBOSE"}
$ENV{"TESTING"} $ENV{"VERBOSE"}
Truth table33%1/3
A and B
A= $ENV{"TESTING"}B= $ENV{"VERBOSE"}
ABresult
0X0
100
111
322 2 return $self->{current_keys};
323 }
324 16 ▶ print STDERR 'cache miss', $/ if $ENV{TESTING} && $ENV{VERBOSE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"TESTING"} and $ENV{"VERBOSE"} 0 16 16
Condition33%1/3
$ENV{"TESTING"} and $ENV{"VERBOSE"}
!ll&&!rl&&r
0160
MC/DC0%0/2
$ENV{"TESTING"} and $ENV{"VERBOSE"}
$ENV{"TESTING"} $ENV{"VERBOSE"}
Truth table33%1/3
A and B
A= $ENV{"TESTING"}B= $ENV{"VERBOSE"}
ABresult
0X0
100
111
325  
326 16 my $response = $self->{ua}->get($self->{uri});
327  
328 16 my ($success, $status, $reason, $content);
329 16 ▶ if (ref($response) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $response eq 'HASH') { } 0 16 16
330 0 $success = $response->{success};
331 0 $status = $response->{status};
332 0 $reason = $response->{reason};
333 0 $content = $response->{content};
334 } else {
335 16 $success = $response->is_success;
336 16 $status = $response->code;
337 16 $reason = $response->message;
338 16 $content = $response->decoded_content;
339 }
340  
341 16 ▶ die(
Branch: 1 branch
BranchTrueFalseTotal
unless $success 3 13 16
342 "KeySourceError: Unable to retrieve data from $self->{uri}: $status $reason"
343 ) unless $success;
344  
345 13 $self->{last_response} = $response;
346 13 my $data = eval { $coder->decode($content) };
347 13 ▶ die("KeySourceError: Unable to parse JSON: $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 4 9 13
348  
349 9 $self->{current_keys} = [$self->interpret_json($data)];
350  
351 6 $self->{allow_refresh_at} = time() + $self->{retry_interval};
352  
353 6 return $self->{current_keys};
354 }
355  
356 1 ▶sub interpret_json {
Subroutine interpret_json: called CC=1 SCAR=0.0
357 1 my ($self, $data) = @_;
358 1 return ();
359 }
360  
361 5 1;
362  
363 package Google::Auth::IDTokens::X509CertHttpKeySource;
364 5 ▶use base 'Google::Auth::IDTokens::HttpKeySource';
Subroutine BEGIN: called CC=1 SCAR=0.0
365 ##
366 # A key source that downloads X509 certificates.
367 # Used by the legacy OAuth V1 public certs endpoint.
368 #
369  
370 ##
371 # Create a key source that downloads X509 certificates.
372 #
373 # @param uri [String,URI] The URI from which to download keys.
374 # @param algorithm [String] The algorithm to use for signature
375 # verification. Defaults to "`RS256`".
376 # @param retry_interval [Integer,nil] Override the retry interval in
377 # seconds. This is the minimum time between retries of failed key
378 # downloads.
379 #
380 4 ▶sub new {
Subroutine new: called CC=6 SCAR=19.9
381 4 my ($class, $params) = @_;
382 4 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 4 4
383  
384 die "missing required parameters"
385 4 ▶ unless exists $params->{uri} && $params->{uri};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params->{"uri"} and $params->{"uri"} 0 4 4
Condition33%1/3
exists $params->{"uri"} and $params->{"uri"}
!ll&&!rl&&r
004
MC/DC0%0/2
exists $params->{"uri"} and $params->{"uri"}
exists $params->{"uri"} $params->{"uri"}
Truth table33%1/3
A and B
A= exists $params->{"uri"}B= $params->{"uri"}
ABresult
0X0
100
111
386  
387 4 ▶ $params->{retry_interval} //= 30;
Condition50%1/2
$params->{"retry_interval"} //= 30
l!l
04
MC/DC0%0/1
$params->{"retry_interval"} //= 30
$params->{"retry_interval"}
Truth table50%1/2
A
A= $params->{"retry_interval"}
Aresult
11
00
388  
389 4 my $self = $class->SUPER::new($params);
390 4 ▶ $self->{algorithm} = $params->{algorithm} || 'RS256';
Condition50%1/2
$params->{'algorithm'} || 'RS256'
l!l
04
MC/DC0%0/1
$params->{'algorithm'} || 'RS256'
$params->{'algorithm'}
Truth table50%1/2
A
A= $params->{'algorithm'}
Aresult
11
00
391 4 return $self;
392 }
393  
394 2 ▶sub interpret_json {
Subroutine interpret_json: called CC=2 SCAR=6.9
395 2 my ($self, $data) = @_;
396 return map {
397 2 my $pubkey = Google::Auth::load_pubkey_from_x509_cert($data->{$_});
398 3 ▶ die "Failed to load X509 certificate for key $_" unless defined $pubkey;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pubkey 1 2 3
399 Google::Auth::IDTokens::KeyInfo->new({
400 id => $_,
401 key => $pubkey,
402 algorithm => $self->{algorithm},
403 2 key_type => 'RSA'
404 });
405 } sort keys %$data;
406 }
407  
408 package Google::Auth::IDTokens::JwkHttpKeySource;
409 5 ▶use base 'Google::Auth::IDTokens::HttpKeySource';
Subroutine BEGIN: called CC=1 SCAR=0.0
410 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
411 ##
412 # A key source that downloads a JWK set.
413 #
414 ##
415 # Create a key source that downloads a JWT Set.
416 #
417 # @param uri [String,URI] The URI from which to download keys.
418 # @param retry_interval [Integer,nil] Override the retry interval in
419 # seconds. This is the minimum time between retries of failed key
420 # downloads.
421 #
422 9 ▶sub new {
Subroutine new: called CC=3 SCAR=11.4
423 9 my ($self, $params) = @_;
424 9 ▶ my $class = ref $self ? ref $self : $self;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 9 9
425  
426 die "uri is a required parameter$/" . Data::Dumper::Dumper($params)
427 9 ▶ unless exists($params->{uri});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params->{"uri"} 0 9 9
428 9 $class->SUPER::new($params);
429 }
430  
431 6 ▶sub interpret_json {
Subroutine interpret_json: called CC=2 SCAR=7.0
432 6 my ($self, $data) = @_;
433 6 ▶ confess 'data is a required argument' unless $data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data 0 6 6
434 6 my $jwks = Google::Auth::IDTokens::KeyInfo->from_jwk_set($data);
435 4 return @$jwks;
436 }
437  
438 ##
439 # The URI from which to download keys.
440 # @return [Array<KeyInfo>]
441 #
442 0 ▶sub uri { return $_[0]->SUPER::uri }
Subroutine uri: not called CC=1 SCAR=6.9
443  
444 package Google::Auth::IDTokens::AggregateKeySource;
445 ##
446 # A key source that aggregates other key sources. This means it will
447 # aggregate the keys provided by its constituent sources. Additionally,
448 # when asked to refresh, it will refresh all its constituent sources.
449 #
450 ##
451 # Create a key source that aggregates other key sources.
452 #
453 # @param sources [Array<key source>] The key sources to aggregate.
454 #
455 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
456 0 my ($class, $params) = @_;
457 die "sources is a required parameter$/" . Data::Dumper::Dumper($params)
458 0 ▶ unless exists $params->{sources} && $params->{sources};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params->{"sources"} and $params->{"sources"} 0 0 0
Condition0%0/3
exists $params->{"sources"} and $params->{"sources"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $params->{"sources"} and $params->{"sources"}
exists $params->{"sources"} $params->{"sources"}
Truth table0%0/3
A and B
A= exists $params->{"sources"}B= $params->{"sources"}
ABresult
0X0
100
111
459  
460 0 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
461 0 my $self = bless {sources => [@{$params->{sources}}]}, $class;
462 0 return $self;
463 }
464  
465 ##
466 # Return the current keys, without attempting to refresh.
467 #
468 # @return [Array<KeyInfo>]
469 #
470 0 ▶sub current_keys {
Subroutine current_keys: not called CC=2 SCAR=17.9
471 0 my ($self) = @_;
472 0 my @current_keys_set;
473 0 foreach my $source (@{$self->{sources}}) {
474 0 push(@current_keys_set, $source->current_keys);
475 }
476 0 return @current_keys_set;
477 }
478  
479 ##
480 # Attempt to refresh keys and return the new keys.
481 #
482 # @return [Array<KeyInfo>]
483 # @raise [KeySourceError] if key retrieval failed.
484 #
485 0 ▶sub refresh_keys {
Subroutine refresh_keys: not called CC=3 SCAR=24.8
486 0 my ($self) = @_;
487 0 my @current_keys_set;
488 0 foreach my $source (@{$self->{sources}}) {
489 0 eval { $source->refresh_keys(); };
490 0 ▶ die "KeySourceError: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
491 0 push(@current_keys_set, $source->current_keys);
492 }
493 0 return @current_keys_set;
494 }
« blib/lib/Google/Auth/ClientId.pm ↑ Summary blib/lib/Google/Auth.pm »