ACME/Challenge/Pending/http_01/Handler.pm

filter: Statementstmt 91.3% 53 / 58 Branchbran 50.0% 3 / 6 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 83.3% 10 / 12 Podpod 0.0% 0 / 3 totaltotal 76.4% 68 / 89 CC 7 SCAR 8.2
CC
7
Cov
83%
_mkdir_if_not_exists
4.1
_unlink_if_exists
3.1
DESTROY
2.1
CRAP 2.3
« ACME/X/HTTP/Protocol.pm ↑ Summary ACME/Error.pm »
1 package Net::ACME::Challenge::Pending::http_01::Handler;
2  
3 =encoding utf-8
4  
5 =head1 NAME
6  
7 Net::ACME::Challenge::Pending::http_01::Handler - http-01 challenge handler
8  
9 =head1 DESCRIPTION
10  
11 This module handles the creation and removal of a domain control file for
12 http-01 challenges. Creation happens on instantiation; removal happens
13 when the object is destroyed.
14  
15 See C<Net::ACME::Challenge::Pending::http_01>’s documentation for more
16 information, including a usage example.
17  
18 To handle challenges that have been unhandled (successfully or not),
19 see C<Net::ACME::Challenge>.
20  
21 =cut
22  
23 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 10 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 10 ▶use Errno ();
Subroutine BEGIN: called CC=1 SCAR=0.0
29 10 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 10 ▶use Net::ACME::Constants ();
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 #docroot, token, key_authz
34 3 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
35 3 my ( $class, %opts ) = @_;
36  
37 3 my $docroot_relative_path = "$Net::ACME::Constants::HTTP_01_CHALLENGE_DCV_DIR_IN_DOCROOT/$opts{'token'}";
38  
39 3 my $file_path = "$opts{'docroot'}/$docroot_relative_path";
40  
41 3 _mkdir_if_not_exists("$opts{'docroot'}/$Net::ACME::Constants::HTTP_01_CHALLENGE_DCV_DIR_IN_DOCROOT");
42  
43 3 local ( $!, $^E );
44  
45 3 open my $wfh, '>', $file_path;
46 3 chmod 0644, $file_path;
47 3 syswrite $wfh, $opts{'key_authz'};
48 3 close $wfh;
49  
50 my $self = {
51 _euid => $>,
52 _path => $file_path,
53 _docroot_relative_path => $docroot_relative_path,
54 3 _content => $opts{'key_authz'},
55 };
56  
57 3 return bless $self, $class;
58 }
59  
60 0 ▶sub expected_content {
Subroutine expected_content: not called CC=1 SCAR=6.9
Pod undocumented
61 0 my ($self) = @_;
62  
63 0 return $self->{'_content'};
64 }
65  
66 0 ▶sub verification_path {
Subroutine verification_path: not called CC=1 SCAR=6.9
Pod undocumented
67 0 my ($self) = @_;
68  
69 0 return "/$self->{'_docroot_relative_path'}";
70 }
71  
72 3 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.4
73 3 my ($self) = @_;
74  
75 3 ▶ if ( $> != $self->{'_euid'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($> != $self->{"_euid"}) 0 3 3
76 0 die "XXX attempt to delete “$self->{'_path'}” with EUID $>; created with EUID $self->{'_euid'}!";
77 }
78  
79 3 _unlink_if_exists( $self->{'_path'} );
80  
81 3 return;
82 }
83  
84 3 ▶sub _mkdir_if_not_exists {
Subroutine _mkdir_if_not_exists: called CC=4 SCAR=14.1
85 3 my ($path) = @_;
86  
87 #cf. eval_bug.readme
88 3 my $eval_err = $@;
89  
90 3 local ( $!, $^E );
91  
92 3 my @ppath = File::Spec->splitdir($path);
93 3 pop @ppath;
94 3 my $ppath_str = File::Spec->catdir(@ppath);
95  
96 3 for my $p ($ppath_str, $path) {
97 6 eval { mkdir $p };
98 6 ▶ die if $@ && $@->errno() != Errno::EEXIST();
Branch: 1 branch
BranchTrueFalseTotal
if $@ and $@->errno != 17 0 6 6
Condition33%1/3
$@ and $@->errno != 17
!ll&&!rl&&r
600
MC/DC0%0/2
$@ and $@->errno != 17
$@ $@->errno != 17
Truth table33%1/3
A and B
A= $@B= $@->errno != 17
ABresult
0X0
100
111
99 }
100  
101 3 $@ = $eval_err;
102  
103 3 return;
104 }
105  
106 3 ▶sub _unlink_if_exists {
Subroutine _unlink_if_exists: called CC=3 SCAR=11.4
107 3 my ($path) = @_;
108  
109 3 local $@;
110 3 local ( $!, $^E );
111 3 eval { unlink $path };
112 3 ▶ die if $@ && $@->errno() != Errno::ENOENT();
Branch: 1 branch
BranchTrueFalseTotal
if $@ and $@->errno != 2 0 3 3
Condition33%1/3
$@ and $@->errno != 2
!ll&&!rl&&r
300
MC/DC0%0/2
$@ and $@->errno != 2
$@ $@->errno != 2
Truth table33%1/3
A and B
A= $@B= $@->errno != 2
ABresult
0X0
100
111
113  
114 3 return;
115 }
116  
117 10 1;
« ACME/X/HTTP/Protocol.pm ↑ Summary ACME/Error.pm »