ACME/Error.pm

filter: Statementstmt 100% 30 / 30 Branchbran 100% 6 / 6 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 3 totaltotal 87.2% 48 / 55 CC 6 SCAR 8.1
CC
6
Cov
95%
to_string
4.0
type
2.1
description
2.0
CRAP 2.2
« ACME/Challenge/Pending/http_01/Handler.pm ↑ Summary ACME/RetryAfter.pm »
1 package Net::ACME::Error;
2  
3 =encoding utf-8
4  
5 =head1 NAME
6  
7 Net::ACME::Error - error parsing logic for ACME
8  
9 =head1 SYNOPSIS
10  
11 use Net::ACME::Error;
12  
13 my $err = Net::ACME::Error->new( { type => '..', .. } );
14  
15 =head1 DESCRIPTION
16  
17 This simple module interfaces with ACME “error” objects,
18 which are described in section 5.5 of the protocol spec.
19 (cf. L<https://ietf-wg-acme.github.io/acme/#rfc.section.5.5>)
20  
21 =head1 NOTES
22  
23 ACME’s errors are basically just HTTP API problem detail documents,
24 which are described in more detail at L<https://tools.ietf.org/html/draft-ietf-appsawg-http-problem-03>.
25  
26 =cut
27  
28 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 8 ▶use parent qw( Net::ACME::AccessorBase );
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 #require.pm fails weirdly here.
34 8 our ( %TYPE_DESCRIPTION );
35  
36 8 ▶use constant _ACCESSORS => qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
37 detail
38 instance
39 status
40 title
41 type
42 8 );
43  
44 8 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 #cf. https://ietf-wg-acme.github.io/acme/#errors
47 8 %TYPE_DESCRIPTION = (
48 badCSR => 'The CSR is unacceptable (e.g., due to a short key)',
49 badNonce => 'The client sent an unacceptable anti-replay nonce',
50 connection => 'The server could not connect to the client for validation',
51 dnssec => 'The server could not validate a DNSSEC signed domain',
52 caa => 'CAA records forbid the CA from issuing',
53 malformed => 'The request message was malformed',
54 serverInternal => 'The server experienced an internal error',
55 tls => 'The server experienced a TLS error during validation',
56 unauthorized => 'The client lacks sufficient authorization',
57 unknownHost => 'The server could not resolve a domain name',
58 rateLimited => 'The request exceeds a rate limit',
59 invalidContact => 'The provided contact URI for a registration was invalid',
60 rejectedIdentifier => 'The server will not issue for the identifier',
61 unsupportedIdentifier => 'Identifier is not supported, but may be in the future',
62 agreementRequired => 'The client must agree to terms before proceeding',
63 );
64 }
65  
66 17 ▶sub type {
Subroutine type: called CC=2 SCAR=7.2
Pod undocumented
67 17 my ($self) = @_;
68  
69 17 ▶ return $self->SUPER::type() || 'about:blank';
Condition50%1/2
$self->SUPER::type || 'about:blank'
l!l
170
MC/DC0%0/1
$self->SUPER::type || 'about:blank'
$self->SUPER::type
Truth table50%1/2
A
A= $self->SUPER::type
Aresult
11
00
70 }
71  
72 8 ▶sub description {
Subroutine description: called CC=2 SCAR=6.9
Pod undocumented
73 8 my ($self) = @_;
74  
75 8 my $type = $self->type();
76  
77 #The spec describes errors in the “urn:ietf:params:acme:error:”
78 #namespace; however, Boulder/LE gives them in “urn:acme:error:”.
79 #
80 #This is because Boulder implements an older version of the spec:
81 #https://github.com/letsencrypt/boulder/issues/1769
82 8 ▶ if ( !( $type =~ s<\Aurn:ietf:params:acme:error:><> ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type =~ s/\Aurn:ietf:params:acme:error://) 4 4 8
83 4 $type =~ s<\Aurn:acme:error:><>;
84 }
85  
86 8 return $TYPE_DESCRIPTION{$type};
87 }
88  
89 #This might warrant expansion?
90 3 ▶sub to_string {
Subroutine to_string: called CC=4 SCAR=13.9
Pod undocumented
91 3 my ($self) = @_;
92  
93 3 my $type = $self->type();
94 3 ▶ if ( my $desc = $self->description() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $desc = $self->description) 2 1 3
95 2 $type = sprintf "%s (%s)", $desc, $type;
96 }
97  
98 3 my $detail = $self->detail();
99 3 ▶ if ( defined $detail && length $detail ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $detail and length $detail) 2 1 3
Condition66%2/3
defined $detail and length $detail
!ll&&!rl&&r
102
MC/DC50%1/2
defined $detail and length $detail
defined $detail length $detail
Truth table66%2/3
A and B
A= defined $detailB= length $detail
ABresult
0X0
100
111
100 2 return sprintf "%s (%s)", $self->detail(), $type;
101 }
102  
103 1 return $type;
104 }
105  
106 8 1;
« ACME/Challenge/Pending/http_01/Handler.pm ↑ Summary ACME/RetryAfter.pm »