| 1 | package Twilio::Http::ValidationClient; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.016; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use parent 'Twilio::Http::TinyClient'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Twilio::Exceptions::ConfigurationException; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Twilio::Jwt::JWT; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Twilio::Jwt::Validation::ClientValidationJwt; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 2 | our $VERSION = '2.001'; | |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 2 | my @REQUIRED = qw(account_sid api_key_sid credential_sid private_key); | |||||||||||||||||||||||||||||||
| 15 | 2 | my @SIGNED_HEADERS = qw(authorization host); | |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 9 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 18 | 9 | my ($class, $options) = @_; | |||||||||||||||||||||||||||||||
| 19 | 9 | ▶ | $options //= {}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$options //= {}
MC/DC0%0/1
$options //= {}
$options
Truth table50%1/2
A
A= $options
| |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 9 | for my $name (@REQUIRED) { | |||||||||||||||||||||||||||||||
| 22 | 30 | ▶ | next if length($options->{$name} // q{}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$options->{$name} // ""
MC/DC100%1/1
$options->{$name} // ""
$options->{$name}
Truth table100%2/2
A
A= $options->{$name}
| |||||||||||||||||||||||||||||||||
| 23 | 4 | Twilio::Exceptions::ConfigurationException->throw("$name is required for client validation"); | |||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | # A key that can't sign fails here, at start-up, rather than on the first request. | ||||||||||||||||||||||||||||||||
| 27 | 5 | Twilio::Jwt::JWT->sign('key check', $options->{private_key}, 'RS256'); | |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 4 | return $class->SUPER::new($options); | |||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | # Signed after the parent class has added Authorization, so that header is covered too. | ||||||||||||||||||||||||||||||||
| 33 | 4 | ▶ | sub prepare_request { | ||||||||||||||||||||||||||||||
|
Subroutine
prepare_request: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 34 | 4 | my ($self, @arguments) = @_; | |||||||||||||||||||||||||||||||
| 35 | 4 | my $request = $self->SUPER::prepare_request(@arguments); | |||||||||||||||||||||||||||||||
| 36 | 4 | $request->{headers}{'Twilio-Client-Validation'} = $self->validation_token($request); | |||||||||||||||||||||||||||||||
| 37 | 4 | return $request; | |||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | 5 | ▶ | sub validation_token { | ||||||||||||||||||||||||||||||
|
Subroutine
validation_token: called CC=7 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 41 | 5 | my ($self, $request) = @_; | |||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | my ($authority, $path, $query) = | ||||||||||||||||||||||||||||||||
| 44 | 5 | ▶ | ($request->{url} // q{}) =~ m{\A[^:/?#]+://([^/?#]*)([^?#]*)(?:[?]([^#]*))?}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$request->{"url"} // ""
MC/DC0%0/1
$request->{"url"} // ""
$request->{"url"}
Truth table50%1/2
A
A= $request->{"url"}
| |||||||||||||||||||||||||||||||||
| 45 | 5 | ▶ | my $host = ($authority // q{}) =~ s/\A.*@//r; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$authority // ""
MC/DC0%0/1
$authority // ""
$authority
Truth table50%1/2
A
A= $authority
| |||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | # HTTP::Tiny sends the Host of the URL, so that is the one to sign, whatever a caller set. | ||||||||||||||||||||||||||||||||
| 48 | 5 | ▶ | my %headers = %{ $request->{headers} // {} }; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$request->{"headers"} // {}
MC/DC0%0/1
$request->{"headers"} // {}
$request->{"headers"}
Truth table50%1/2
A
A= $request->{"headers"}
| |||||||||||||||||||||||||||||||||
| 49 | 5 | delete @headers{ grep { lc eq 'host' } keys %headers }; | |||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | my $jwt = Twilio::Jwt::Validation::ClientValidationJwt->new( | ||||||||||||||||||||||||||||||||
| 52 | 5 | ▶ | @{$self}{@REQUIRED}, | ||||||||||||||||||||||||||||||
|
Condition83%5/6
$path // ""
$query // ""
$request->{"content"} // ""
MC/DC0%0/1
$path // ""
$path
MC/DC100%1/1
$query // ""
$query
MC/DC100%1/1
$request->{"content"} // ""
$request->{"content"}
Truth table50%1/2
A
A= $path
Truth table100%2/2
A
A= $query
Truth table100%2/2
A
A= $request->{"content"}
| |||||||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||||||
| 54 | method => $request->{method}, | ||||||||||||||||||||||||||||||||
| 55 | path => $path // q{}, | ||||||||||||||||||||||||||||||||
| 56 | query_string => $query // q{}, | ||||||||||||||||||||||||||||||||
| 57 | all_headers => { %headers, host => $host }, | ||||||||||||||||||||||||||||||||
| 58 | signed_headers => [@SIGNED_HEADERS], | ||||||||||||||||||||||||||||||||
| 59 | 5 | body => $request->{content} // q{}, | |||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||
| 62 | 5 | return $jwt->to_jwt; | |||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 2 | 1; | |||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | __END__ | ||||||||||||||||||||||||||||||||