blib/lib/Test/Signature.pm

filter: Statementstmt 77.7% 28 / 36 Branchbran 37.5% 3 / 8 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 80.0% 8 / 10 Podpod 50.0% 2 / 4 totaltotal 64.1% 43 / 67 CC 8 SCAR 19.4
CC
8
Cov
66%
signature_ok
13.9
signature_force_ok
6.0
action_ok
2.0
CRAP 7.0
↑ Summary
1 package Test::Signature;
2  
3 1 ▶use 5.005;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Test::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 $VERSION = '1.11';
11 1 @ISA = qw( Exporter );
12 1 @EXPORT = qw( signature_ok );
13 1 @EXPORT_OK = qw( signature_force_ok );
14 }
15  
16 1 my $test = Test::Builder->new();
17  
18 =head1 NAME
19  
20 Test::Signature - Automated SIGNATURE testing
21  
22 =head1 SYNOPSIS
23  
24 # This is actually the t/0-signature.t file from this distribution.
25 use Test::More tests => 1;
26 use Test::Signature;
27  
28 signature_ok();
29  
30 =head1 ABSTRACT
31  
32 C<Test::Signature> verifies that the C<Module::Signature> generated
33 signature of a module is correct.
34  
35 =head1 DESCRIPTION
36  
37 C<Module::Signature> allows you to verify that a distribution has
38 not been tampered with. C<Test::Signature> lets that be tested
39 as part of the distribution's test suite.
40  
41 By default, if C<Module::Signature> is not installed then it will just
42 say so and not fail the test. That can be overridden though.
43  
44 B<IMPORTANT>: This is not a substitute for the users verifying
45 the distribution themselves. By the time this module is run, the
46 users will have already run your F<Makefile.PL> or F<Build.PL> scripts
47 which could have been compromised.
48  
49 This module is more for ensuring you've updated your signature
50 appropriately before distributing, and for preventing accidental
51 errors during transmission or packaging.
52  
53 =cut
54  
55 =head1 FUNCTIONS
56  
57 C<signature_ok> is exported by default. C<signature_force_ok> must be
58 explicitly exported.
59  
60 =head2 signature_ok()
61  
62 This will test that the C<Module::Signature> generated signature
63 is valid for the distribution. It can be given two optional parameters.
64 The first is a name for the test. The default is C<Valid signature>.
65 The second is whether a lack of C<Module::Signature> should be regarded
66 as a failure. The default is C<0> meaning 'no'.
67  
68 # Test with defaults
69 signature_ok()
70 # Test with custom name
71 signature_ok( "Is the signature valid?" );
72 # Test with custom name and force C<Module::Signature> to exist
73 signature_ok( "Is the signature valid?", 1 );
74 # Test without custom name, but forcing
75 signature_ok( undef, 1 );
76  
77 =cut
78  
79 1 ▶sub action_skip { $test->skip( $_[0] ) }
Subroutine action_skip: called CC=1 SCAR=0.0
Pod undocumented
80 0 ▶sub action_ok { $test->ok( 0, $_[0] ) }
Subroutine action_ok: not called CC=1 SCAR=6.9
Pod undocumented
81  
82 1 ▶sub signature_ok {
Subroutine signature_ok: called CC=7 SCAR=26.3
Pod documented
83 1 ▶ my $name = shift || 'Valid signature';
Condition50%1/2
shift() || 'Valid signature'
l!l
01
MC/DC0%0/1
shift() || 'Valid signature'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
84 1 ▶ my $force = shift || 0;
Condition50%1/2
shift() || 0
l!l
01
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
85 1 ▶ my $action = $force ? \&action_ok : \&action_skip;
Branch: 1 branch
BranchTrueFalseTotal
$force ? : 0 1 1
86 SKIP: {
87 1 ▶ if ( !-s 'SIGNATURE' ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not -s 'SIGNATURE') { } 0 1 1
elsif (not eval { do { require Module::Signature; 1 } }) { } 1 0 1
elsif (not eval { do { require Socket; Socket::inet_aton('pgp.mit.edu') } }) { } 0 0 0
88 0 $action->("No SIGNATURE file found.");
89 }
90 0 elsif ( !eval { require Module::Signature; 1 } ) {
91 1 $action->(
92 "Next time around, consider installing Module::Signature, "
93 . "so you can verify the integrity of this distribution." );
94 }
95 0 elsif ( !eval { require Socket; Socket::inet_aton('pgp.mit.edu') } ) {
96 0 $action->("Cannot connect to the keyserver.");
97 }
98 else {
99 0 $test->ok( Module::Signature::verify(skip => 1) ==
100 Module::Signature::SIGNATURE_OK() => $name );
101 }
102 }
103 }
104  
105 =head2 signature_force_ok()
106  
107 This is equivalent to calling C<< signature_ok( $name, 1 ) >>
108 but is more readable.
109  
110 # These are equivalent:
111 signature_force_ok( "Is our signature valid?" );
112 signature_ok( "Is our signature valid?", 1);
113  
114 # These are equivalent:
115 signature_force_ok();
116 signature_ok( undef, 1 );
117  
118 =cut
119  
120 0 ▶sub signature_force_ok {
Subroutine signature_force_ok: not called CC=2 SCAR=17.9
Pod documented
121 0 ▶ signature_ok( $_[0] || undef, 1 );
Condition0%0/2
$_[0] || undef
l!l
00
MC/DC0%0/1
$_[0] || undef
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
122 }
123  
124 1 1;
125 __END__
↑ Summary