| 1 | package Mogura::Scanner::Client; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use Mojo::Base -base; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Mojo::UserAgent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Mojo::Asset::File; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Digest::SHA; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Fcntl qw(O_RDONLY O_NOFOLLOW); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use IO::Socket::SSL 2.009; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | has 'config'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | has ua => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | Mojo::UserAgent->new->insecure(0) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | ->max_redirects(0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | ->connect_timeout(10) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | ->inactivity_timeout(30) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | ->max_response_size(262144); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | sub initialize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
initialize: called CC=8 SCAR=24.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | sysopen my $fh, $self->config->token_file, O_RDONLY | O_NOFOLLOW or die "Open token file: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | my @st = stat $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | die 'Token file must be private and owned by the scanner user' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
-f $fh and $st[4] == $> and not $st[2] & 63 and $st[7] <= 65
-f $fh and $st[4] == $> and not $st[2] & 63
-f $fh and $st[4] == $>
MC/DC0%0/4
-f $fh and $st[4] == $> and not $st[2] & 63 and $st[7] <= 65
-f $fh
$st[4] == $>
not $st[2] & 63
$st[7] <= 65
Truth table20%1/5
A and B and not(C) and D
A= -f $fhB= $st[4] == $>C= not $st[2] & 63D= $st[7] <= 65
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | unless -f $fh && $st[4] == $> && !($st[2] & 0077) && $st[7] <= 65; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | my $token = <$fh> // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
readline $fh // ""
MC/DC0%0/1
readline $fh // ""
readline $fh
Truth table50%1/2
A
A= readline $fh
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | chomp $token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | die 'Invalid token file' unless $token =~ /\A[a-f0-9]{64}\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | $self->{token} = $token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 99 | ▶ | sub request { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request: called CC=22 SCAR=38.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 99 | my ($self, $method, $route, $data, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | my $tx = $self->ua->build_tx( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | $method => $self->config->server . '/api' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | . $route => {Authorization => 'Bearer ' . $self->{token}}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 99 | ▶ | (defined $data ? (json => $data) : ()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 99 | ▶ | if (defined $file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | ▶ | open my $fh, '<:raw', $file or die "Open artifact: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | $tx->req->headers->header( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 'X-Content-SHA256' => Digest::SHA->new(256)->addfile($fh)->hexdigest); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | $tx->req->headers->content_type('application/octet-stream'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | $tx->req->content->asset(Mojo::Asset::File->new(path => "$file")); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 99 | ▶ | my $res = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | $self->ua->request_timeout(defined($file) ? $self->config->upload_timeout : 15) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ->start($tx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | ->result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 97 | ▶ | return {expired => 1} if $res->code == 410 && $route =~ m{/claim\z}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$res->code == 410 and $route =~ m[/claim\z]u
MC/DC0%0/2
$res->code == 410 and $route =~ m[/claim\z]u
$res->code == 410
$route =~ m[/claim\z]u
Truth table33%1/3
A and B
A= $res->code == 410B= $route =~ m[/claim\z]u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 97 | ▶ | die "Server $method $route: HTTP " . $res->code . "\n" unless $res->is_success; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 97 | my $reply = $res->json; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 97 | ▶ | die "Invalid server acknowledgement for $route" unless ref($reply) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 97 | ▶ | if ($route =~ m{\A/jobs/([^/]+)/([^/]+)/(.+)\z}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 8 | my ($id, $run, $action) = ($1, $2, $3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | die 'Wrong execution acknowledgement' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 8 | ▶ | unless ($reply->{id} // '') eq $id && ($reply->{run} // '') eq $run; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition42%3/7
($reply->{"id"} // "") eq $id and ($reply->{"run"} // "") eq $run
$reply->{"id"} // ""
$reply->{"run"} // ""
MC/DC0%0/2
($reply->{"id"} // "") eq $id and ($reply->{"run"} // "") eq $run
$reply->{"id"}
$reply->{"run"}
Truth table33%1/3
A and B
A= $reply->{"id"}B= $reply->{"run"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 8 | ▶ | if (defined $file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | die 'Wrong artifact receipt' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | unless $action eq 'files/' . ($reply->{kind} // '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | && ($reply->{sha256} // '') eq $tx->req->headers->header('X-Content-SHA256'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/7
$action eq 'files/' . ($reply->{"kind"} // "") and ($reply->{"sha256"} // "") eq $tx->req->headers->header("X-Content-SHA256")
$reply->{"kind"} // ""
$reply->{"sha256"} // ""
MC/DC0%0/2
$action eq 'files/' . ($reply->{"kind"} // "") and ($reply->{"sha256"} // "") eq $tx->req->headers->header("X-Content-SHA256")
$action eq 'files/' . ($reply->{"kind"} // "")
$reply->{"sha256"}
MC/DC0%0/1
$reply->{"kind"} // ""
$reply->{"kind"}
Truth table0%0/3
A and B
A= $action eq 'files/' . ($reply->{"kind"} // "")B= $reply->{"sha256"}
Truth table0%0/2
A
A= $reply->{"kind"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | elsif ($action ne 'claim') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | ▶ | die 'Wrong state acknowledgement' unless ($reply->{action} // '') eq $action; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$reply->{"action"} // ""
MC/DC0%0/1
$reply->{"action"} // ""
$reply->{"action"}
Truth table50%1/2
A
A= $reply->{"action"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 97 | return $reply; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||