ACME2/Challenge/http_01.pm

filter: Statementstmt 85.7% 24 / 28 Branchbran 33.3% 2 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 3 / 3 totaltotal 79.5% 35 / 44 SCAR 14.4
CC
4
Cov
76%
get_content
6.0
create_handler
3.1
BEGIN
1.0
CRAP 4.2
« ACME2/LetsEncrypt.pm ↑ Summary ACME2/Order.pm »
1 package Net::ACME2::Challenge::http_01;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use parent qw( Net::ACME2::Challenge );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use constant _PATH_DIRECTORY => '/.well-known/acme-challenge';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =encoding utf-8
11  
12 =head1 NAME
13  
14 Net::ACME2::Challenge::http_01
15  
16 =head1 SYNOPSIS
17  
18 #e.g., “/.well-known/acme-challenge/12341243sdafdewrsvfd”
19 my $path = $challenge->path();
20  
21 {
22 my $handler = $challenge->create_handler( ... );
23  
24 $acme->accept_challenge($challenge);
25  
26 sleep 1 while !$acme->poll_authorization();
27 }
28  
29 =head1 DESCRIPTION
30  
31 This module is instantiated by L<Net::ACME2::Authorization> and is a
32 subclass of L<Net::ACME2::Challenge>.
33  
34 =head1 METHODS
35  
36 =head2 I<OBJ>->create_handler( KEY_AUTHZ, DOCROOT )
37  
38 Creates a file in the given DOCROOT that will, if served up normally,
39 satisfy ACME’s requirements for this challenge. The return value is
40 an object that, when DESTROYed, will remove that file.
41  
42 (KEY_AUTHZ is the return of the L<Net::ACME2> instance’s
43 C<make_key_authorization()> method.)
44  
45 This can simplify the authorization process
46 if you’re on the same server as all of the authorization object’s
47 identifiers’ HTTP document roots.
48  
49 =cut
50  
51 sub create_handler {
52 2 ▶ my ($self, $key_authorization, $docroot) = @_;
Subroutine create_handler: called CC=3 SCAR=11.2
Pod documented
53  
54 2 ▶ die 'need key authz!' if !$key_authorization;
Branch: 1 branch
BranchTrueFalseTotal
unless $key_authorization 0 2 2
55 2 ▶ die 'need docroot!' if !length $docroot;
Branch: 1 branch
BranchTrueFalseTotal
unless length $docroot 0 2 2
56  
57 2 my $class = (ref $self) . '::Handler';
58  
59 2 require Module::Load;
60 2 Module::Load::load($class);
61  
62 2 return $class->new(
63 key_authorization => $key_authorization,
64 challenge => $self,
65 document_root => $docroot,
66 );
67 }
68  
69 #----------------------------------------------------------------------
70  
71 =head2 I<OBJ>->get_path()
72  
73 Returns the path component of the URL that should serve up the
74 relevant content. This is useful if, for whatever reason,
75 you’re not using C<create_handler()> to satisfy this challenge.
76  
77 Example:
78  
79 /.well-known/acme-challenge/LoqXcYV8q5ONbJQxbmR7SCTNo3tiAXDfowyjxAjEuX0
80  
81 =cut
82  
83 sub get_path {
84 4 ▶ my ($self) = @_;
Subroutine get_path: called CC=1 SCAR=0.0
Pod documented
85  
86 4 my $token = $self->token();
87  
88 4 return $self->_PATH_DIRECTORY() . "/$token";
89 }
90  
91 # legacy - a courtesy to early adopters
92 4 *path = \*get_path;
93  
94 #----------------------------------------------------------------------
95  
96 =head2 I<OBJ>->get_content( $ACME )
97  
98 Accepts a L<Net::ACME2> instance and returns the content that the
99 URL should serve.
100  
101 Example:
102  
103 q1hcOY6mDLNh7jummITkoQ1PHBpaxwNwyERZEqbADqI._jDy0skz-fuLE9OyLfS2UBa9z9QtS_MZGWq3x2nMx34
104  
105 =cut
106  
107 sub get_content {
108 0 ▶ my ($self, $acme) = @_;
Subroutine get_content: not called CC=2 SCAR=17.9
Pod documented
109  
110 # Errors for the programmer.
111 0 ▶ if (!$acme) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($acme) 0 0 0
112 0 die 'Need “Net::ACME2” instance to compute HTTP content!'
113 }
114  
115 0 return $acme->make_key_authorization($self);
116 }
117  
118 4 1;
« ACME2/LetsEncrypt.pm ↑ Summary ACME2/Order.pm »