mirror of
https://github.com/certbot/certbot.git
synced 2026-05-28 04:34:11 -04:00
Fix 10260 (#10283)
Builds off of https://github.com/certbot/certbot/pull/7066 to stringify these validation errors Fixes #10260 --------- Co-authored-by: George Daramouskas <gdaramouskas@therp.nl> Co-authored-by: Brad Warren <bmw@users.noreply.github.com>
This commit is contained in:
parent
dcdfdacf75
commit
0fc755fe08
2 changed files with 41 additions and 0 deletions
|
|
@ -51,5 +51,36 @@ class PollErrorTest(unittest.TestCase):
|
|||
'sentinel.AR2})' % repr(set()) == repr(self.invalid)
|
||||
|
||||
|
||||
class ValidationErrorTest(unittest.TestCase):
|
||||
"""Tests for acme.errors.ValidationError"""
|
||||
|
||||
def setUp(self):
|
||||
from acme.errors import ValidationError
|
||||
from acme.challenges import DNS01
|
||||
from acme.messages import Error
|
||||
from acme.messages import Authorization
|
||||
from acme.messages import AuthorizationResource
|
||||
from acme.messages import IDENTIFIER_FQDN
|
||||
from acme.messages import ChallengeBody
|
||||
from acme.messages import Identifier
|
||||
self.challenge_error = Error(typ='custom', detail='bar')
|
||||
failed_authzr = AuthorizationResource(
|
||||
body=Authorization(
|
||||
identifier=Identifier(typ=IDENTIFIER_FQDN, value="example.com"),
|
||||
challenges=[ChallengeBody(
|
||||
chall=DNS01(),
|
||||
error=self.challenge_error,
|
||||
)]
|
||||
)
|
||||
)
|
||||
self.error = ValidationError([failed_authzr])
|
||||
|
||||
def test_repr(self):
|
||||
err_message = str(self.error)
|
||||
assert 'Authorization for example.com failed' in err_message
|
||||
assert 'Challenge dns-01 failed' in err_message
|
||||
assert str(self.challenge_error) in err_message
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(pytest.main(sys.argv[1:] + [__file__])) # pragma: no cover
|
||||
|
|
|
|||
|
|
@ -107,6 +107,16 @@ class ValidationError(Error):
|
|||
self.failed_authzrs = failed_authzrs
|
||||
super().__init__()
|
||||
|
||||
def __str__(self) -> str:
|
||||
msg = []
|
||||
for authzr in self.failed_authzrs:
|
||||
msg.append(f'Authorization for {authzr.body.identifier.value} ' \
|
||||
'failed due to one or more failed challenges:')
|
||||
for challenge in authzr.body.challenges:
|
||||
msg.append(f' Challenge {challenge.chall.typ} failed ' \
|
||||
f'with error {str(challenge.error)}')
|
||||
return '\n'.join(msg)
|
||||
|
||||
|
||||
class TimeoutError(Error): # pylint: disable=redefined-builtin
|
||||
"""Error for when polling an authorization or an order times out."""
|
||||
|
|
|
|||
Loading…
Reference in a new issue