blib/lib/Skilletor/Probe.pm

filter: Statementstmt 100% 50 / 50 Branchbran 91.6% 11 / 12 Conditioncond 79.3% 23 / 29 MC/DCmcdc 57.1% 8 / 14 Subroutinesub 100% 13 / 13 Podpod 100% 1 / 1 totaltotal 89.0% 106 / 119 CC 17 SCAR 14.9
CC
17
Cov
92%
_head_ok
8.1
_ls_remote
6.0
make_probe
3.0
CRAP 4.4
« /usr/local/lib/perl5/site_perl/5.44.0/Moo/sification.pm ↑ Summary /usr/local/lib/perl5/5.44.0/x86_64-linux/mro.pm »
1 package Skilletor::Probe;
2 # ABSTRACT: The probe of `skilletor add` for a generic host – git ls-remote, then a HEAD on the tarball
3  
4 108 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 108 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 108 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 108 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 108 ▶use Skilletor::FSUtil qw( encode_text );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 108 ▶use Skilletor::GitEnv qw( git_env );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 108 ▶use Skilletor::Process qw( run_command );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 108 ▶use Skilletor::URL qw( parse_url );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 108 our $VERSION = '0.008000';
15  
16 108 our @EXPORT_OK = qw( make_probe );
17  
18 108 ▶use constant TIMEOUT_MS => 5_000;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # The headers Node's fetch sends with a HEAD (as Skilletor::Source::Url's requests carry them),
21 # so a host answers the probe as it answers the reference's.
22 108 my %FETCH_HEADERS = (
23 accept => '*/*',
24 'accept-language' => '*',
25 'sec-fetch-mode' => 'cors',
26 'accept-encoding' => 'gzip, deflate',
27 );
28  
29 15 ▶sub make_probe {
Subroutine make_probe: called CC=3 SCAR=11.0
Pod documented
30 15 my ( %args ) = @_;
31 15 ▶ my $timeout_ms = $args{timeout_ms} // TIMEOUT_MS;
Condition100%2/2
$args{"timeout_ms"} // 5000
l!l
312
MC/DC100%1/1
$args{"timeout_ms"} // 5000
$args{"timeout_ms"}
Truth table100%2/2
A
A= $args{"timeout_ms"}
Aresult
11
00
32 my $http = $args{http}
33 15 ▶ // HTTP::Tiny->new( agent => 'node', timeout => $timeout_ms / 1000, verify_SSL => 1, max_redirect => 20 );
Condition33%1/3
$args{"http"} // "HTTP::Tiny"->new("agent", "node", "timeout", $timeout_ms / 1000, "verify_SSL", 1, "max_redirect", 20)
l!l&&r!l&&!r
0150
MC/DC0%0/2
$args{"http"} // "HTTP::Tiny"->new("agent", "node", "timeout", $timeout_ms / 1000, "verify_SSL", 1, "max_redirect", 20)
$args{"http"} "HTTP::Tiny"->new("agent", "node", "timeout", $timeout_ms / 1000, "verify_SSL", 1, "max_redirect", 20)
Truth table33%1/3
A // B
A= $args{"http"}B= "HTTP::Tiny"->new("agent", "node", "timeout", $timeout_ms / 1000, "verify_SSL", 1, "max_redirect", 20)
ABresult
1X1
011
000
34 80 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
35 80 my ( $base ) = @_;
36 80 ▶ return { git => 1 } if _ls_remote( $base, $timeout_ms );
Branch: 1 branch
BranchTrueFalseTotal
if _ls_remote($base, $timeout_ms) 12 57 69
37 57 ▶ return { tarball => 1 } if _head_ok( $http, $base.'.tar.gz' );
Branch: 1 branch
BranchTrueFalseTotal
if _head_ok($http, $base . '.tar.gz') 20 37 57
38 37 return {};
39 15 };
40 }
41  
42 # Does git list the address's refs within the timeout? The address goes after `--`, never an
43 # option (k85); git runs in git's environment, never steered by an exported GIT_DIR (k91).
44 80 ▶sub _ls_remote {
Subroutine _ls_remote: called CC=6 SCAR=18.0
45 80 my ( $url, $timeout_ms ) = @_;
46 80 my $r = eval {
47 80 run_command( cmd => [ 'git', 'ls-remote', '--', encode_text($url) ], env => git_env(), timeout_ms => $timeout_ms );
48 };
49 69 ▶ return $r && !$r->{timed_out} && !$r->{spawn_error} && defined $r->{code} && $r->{code} == 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$r && !$r->{'timed_out'} && !$r->{'spawn_error'} && defined $r->{'code'} && $r->{'code'} == 0 ? : 12 57 69
Condition83%10/12
$r and not $r->{"timed_out"} and not $r->{"spawn_error"} and defined $r->{"code"} and $r->{"code"} == 0
!ll&&!rl&&r
65112
$r and not $r->{"timed_out"} and not $r->{"spawn_error"} and defined $r->{"code"}
!ll&&!rl&&r
6063
$r and not $r->{"timed_out"} and not $r->{"spawn_error"}
!ll&&!rl&&r
3363
$r and not $r->{"timed_out"}
!ll&&!rl&&r
0366
MC/DC60%3/5
$r and not $r->{"timed_out"} and not $r->{"spawn_error"} and defined $r->{"code"} and $r->{"code"} == 0
$r not $r->{"timed_out"} not $r->{"spawn_error"} defined $r->{"code"} $r->{"code"} == 0
Truth table66%4/6
A and not(B) and not(C) and D and E
A= $rB= not $r->{"timed_out"}C= not $r->{"spawn_error"}D= defined $r->{"code"}E= $r->{"code"} == 0
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
50 }
51  
52 # Does a HEAD on the URL answer 2xx, redirects followed? What fetch refuses to send – no URL to
53 # `new URL`, another scheme than http(s), credentials in the URL – is no answer; the URL goes
54 # out as fetch sends it (the host IDNA-encoded, the path percent-encoded, no fragment).
55 57 ▶sub _head_ok {
Subroutine _head_ok: called CC=8 SCAR=20.9
56 57 my ( $http, $url ) = @_;
57 57 my $u = parse_url($url);
58 57 ▶ return 0 unless $u && $u->{protocol} =~ /\Ahttps?:\z/ && $u->{username} eq '' && $u->{password} eq '';
Branch: 1 branch
BranchTrueFalseTotal
unless $u and $u->{"protocol"} =~ /\Ahttps?:\z/ and $u->{"username"} eq "" and $u->{"password"} eq "" 21 36 57
Condition88%8/9
$u and $u->{"protocol"} =~ /\Ahttps?:\z/ and $u->{"username"} eq "" and $u->{"password"} eq ""
!ll&&!rl&&r
21036
$u and $u->{"protocol"} =~ /\Ahttps?:\z/ and $u->{"username"} eq ""
!ll&&!rl&&r
16536
$u and $u->{"protocol"} =~ /\Ahttps?:\z/
!ll&&!rl&&r
41241
MC/DC75%3/4
$u and $u->{"protocol"} =~ /\Ahttps?:\z/ and $u->{"username"} eq "" and $u->{"password"} eq ""
$u $u->{"protocol"} =~ /\Ahttps?:\z/ $u->{"username"} eq "" $u->{"password"} eq ""
Truth table80%4/5
A and B and C and D
A= $uB= $u->{"protocol"} =~ /\Ahttps?:\z/C= $u->{"username"} eq ""D= $u->{"password"} eq ""
ABCDresult
0XXX0
10XX0
110X0
11100
11111
59 36 ▶ my $href = $u->{protocol}.'//'.$u->{hostname}.( length $u->{port} ? ':'.$u->{port} : '' ).$u->{pathname}.$u->{search};
Branch: 1 branch
BranchTrueFalseTotal
length $u->{'port'} ? : 36 0 36
60 36 my $res = eval { $http->request( 'HEAD', encode_text($href), { headers => {%FETCH_HEADERS} } ) };
61 36 ▶ return $res && $res->{success} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$res && $res->{'success'} ? : 20 16 36
Condition66%2/3
$res and $res->{"success"}
!ll&&!rl&&r
01620
MC/DC50%1/2
$res and $res->{"success"}
$res $res->{"success"}
Truth table66%2/3
A and B
A= $resB= $res->{"success"}
ABresult
0X0
100
111
62 }
63  
64 108 1;
65  
66 __END__
« /usr/local/lib/perl5/site_perl/5.44.0/Moo/sification.pm ↑ Summary /usr/local/lib/perl5/5.44.0/x86_64-linux/mro.pm »