lib/Rex/Rancher/Checksum.pm

filter: Statementstmt 100% 19 / 19 Branchbran 100% 10 / 10 Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 3 / 3 totaltotal 95.3% 41 / 43 CC 9 SCAR 12.0
CC
9
Cov
97%
expected_sha256
4.0
verify_sha256
4.0
sha256_of
3.0
CRAP 3.3
« lib/Rex/Rancher/Agent.pm ↑ Summary lib/Rex/Rancher/Uninstall.pm »
1 # ABSTRACT: SHA-256 checks of downloaded release artifacts
2  
3 package Rex::Rancher::Checksum;
4 63 our $VERSION = '0.004';
5 63 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 63 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 17 ▶sub expected_sha256 {
Subroutine expected_sha256: called CC=4 SCAR=13.9
Pod documented
10 17 my ( $self, $sums_text, $asset ) = @_;
11 17 ▶ for my $line (split /\n/, $sums_text // '') {
Condition100%2/2
$sums_text // ""
l!l
161
MC/DC100%1/1
$sums_text // ""
$sums_text
Truth table100%2/2
A
A= $sums_text
Aresult
11
00
12 25 ▶ return lc $1 if $line =~ /\A\s*([0-9a-fA-F]{64})\s+\*?\Q$asset\E\s*\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\A\s*([0-9a-fA-F]{64})\s+\*?\Q$asset\E\s*\z/u 11 14 25
13 }
14 6 return;
15 }
16  
17  
18 10 ▶sub sha256_of {
Subroutine sha256_of: called CC=3 SCAR=11.1
Pod documented
19 10 my ( $self, $out ) = @_;
20 10 ▶ return lc $1 if ($out // '') =~ /\A\s*([0-9a-fA-F]{64})\b/;
Branch: 1 branch
BranchTrueFalseTotal
if ($out // "") =~ /\A\s*([0-9a-fA-F]{64})\b/u 9 1 10
Condition50%1/2
$out // ""
l!l
100
MC/DC0%0/1
$out // ""
$out
Truth table50%1/2
A
A= $out
Aresult
11
00
21 1 return;
22 }
23  
24  
25 16 ▶sub verify_sha256 {
Subroutine verify_sha256: called CC=4 SCAR=13.9
Pod documented
26 16 my ( $self, $expected, $actual, $asset ) = @_;
27 16 ▶ die "No checksum for $asset in the release's sha256sum file\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expected 5 11 16
28 unless defined $expected;
29 11 ▶ die "Could not compute sha256 of downloaded $asset\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $actual 1 10 11
30 unless defined $actual;
31 10 ▶ die "Checksum mismatch for $asset: expected $expected, got $actual\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $expected eq $actual 5 5 10
32 unless $expected eq $actual;
33 5 return 1;
34 }
35  
36 63 1;
37  
38 __END__
« lib/Rex/Rancher/Agent.pm ↑ Summary lib/Rex/Rancher/Uninstall.pm »