blib/lib/Alien/Build/Plugin/Fetch/HostAllowList.pm

filter: Statementstmt 97.0% 33 / 34 Branchbran 50.0% 5 / 10 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 87.5% 7 / 8 Podpod 100% 1 / 1 totaltotal 82.7% 48 / 58 CC 7 SCAR 12.9
CC
7
Cov
85%
__ANON__
6.2
__ANON__
3.7
init
1.0
CRAP 3.6
↑ Summary
1 package Alien::Build::Plugin::Fetch::HostAllowList;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Alien::Build::Plugin 2.64;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # ABSTRACT: Require that Alien::Build based aliens only fetch from an allow list of hosts
10 1 our $VERSION = '0.02'; # VERSION
11  
12  
13 0 ▶has '+allow_hosts' => sub { [
Subroutine __ANON__: not called CC=2 SCAR=13.0
14 defined $ENV{ALIEN_BUILD_HOST_ALLOW}
15 ? split /,/, $ENV{ALIEN_BUILD_HOST_ALLOW}
16 : ()
17 0 ▶] };
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'ALIEN_BUILD_HOST_ALLOW'} ? : 0 0 0
18  
19 sub init
20 1 ▶{
Subroutine init: called CC=1 SCAR=0.0
Pod documented
21 1 my($self, $meta) = @_;
22  
23 1 my %allowed = map { $_ => 1 } @{ $self->allow_hosts };
24  
25 3 ▶ $meta->around_hook( fetch => sub {
Subroutine __ANON__: called CC=6 SCAR=18.3
26 3 my $orig = shift;
27 3 my $build = shift;
28 3 ▶ my $url = $_[0] || $build->meta_prop->{start_url};
Condition66%2/3
$_[0] || $build->meta_prop->{'start_url'}
l!l&&r!l&&!r
210
MC/DC0%0/2
$_[0] || $build->meta_prop->{'start_url'}
$_[0] $build->meta_prop->{'start_url'}
Truth table66%2/3
A || B
A= $_[0]B= $build->meta_prop->{'start_url'}
ABresult
1X1
011
000
29  
30 # If URL doesn't have a : then it doesn't have a scheme or
31 # protocol and we assume that it is a file or directory.
32 3 ▶ if($url =~ /:/)
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ /:/) 3 0 3
33 {
34 3 my $url = URI->new($url);
35 3 ▶ if($url->scheme ne 'file')
Branch: 1 branch
BranchTrueFalseTotal
if ($url->scheme ne "file") 3 0 3
36 {
37 3 my $host = eval { $url->host };
38 3 ▶ die "unable to determine host from $url: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
39 3 ▶ die "The host $host is not in the allow list" unless $allowed{$host};
Branch: 1 branch
BranchTrueFalseTotal
unless $allowed{$host} 1 2 3
40 }
41 }
42  
43 2 $orig->($build, @_);
44 1 });
45 }
46  
47  
48 1 1;
49  
50 __END__
↑ Summary