mirror of
https://github.com/certbot/certbot.git
synced 2026-01-23 07:20:55 +03:00
Fix pylint and add test
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import collections
|
||||
|
||||
from acme import challenges
|
||||
from acme import errors
|
||||
from acme import fields
|
||||
from acme import jose
|
||||
from acme import util
|
||||
@@ -373,17 +374,17 @@ class Authorization(ResourceBody):
|
||||
|
||||
@challenges.decoder
|
||||
def challenges(value): # pylint: disable=missing-docstring,no-self-argument
|
||||
# The from_json method raises errors.UnrecognizedTypeError when a
|
||||
# The from_json method raises errors.UnrecognizedTypeError when a
|
||||
# challenge of unknown type is encountered. We want to ignore this
|
||||
# case. This forces us to do an explicit iteration, since list
|
||||
# comprehensions can't handle exceptions.
|
||||
challenges = []
|
||||
challs = []
|
||||
for chall in value:
|
||||
try:
|
||||
challenges.append(ChallengeBody.from_json(chall))
|
||||
except errors.UnknownTypeError:
|
||||
challs.append(ChallengeBody.from_json(chall))
|
||||
except jose.UnrecognizedTypeError:
|
||||
continue
|
||||
return tuple(challenges)
|
||||
return tuple(challs)
|
||||
|
||||
@property
|
||||
def resolved_combinations(self):
|
||||
|
||||
@@ -274,6 +274,9 @@ class AuthorizationTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
from acme.messages import ChallengeBody
|
||||
from acme.messages import STATUS_VALID
|
||||
|
||||
unknown_chall = mock.MagicMock()
|
||||
unknown_chall.to_json.side_effect = side_effect=jose.UnrecognizedTypeError
|
||||
self.challbs = (
|
||||
ChallengeBody(
|
||||
uri='http://challb1', status=STATUS_VALID,
|
||||
@@ -300,6 +303,19 @@ class AuthorizationTest(unittest.TestCase):
|
||||
'combinations': combinations,
|
||||
}
|
||||
|
||||
# For unknown challenge types
|
||||
self.jmsg_unknown_chall = {
|
||||
'resource': 'challenge',
|
||||
'uri': 'random_uri',
|
||||
'type': 'unknown',
|
||||
'tls': True,
|
||||
}
|
||||
|
||||
self.jobj_from_unknown = {
|
||||
'identifier': identifier.to_json(),
|
||||
'challenges': [self.jmsg_unknown_chall],
|
||||
}
|
||||
|
||||
def test_from_json(self):
|
||||
from acme.messages import Authorization
|
||||
Authorization.from_json(self.jobj_from)
|
||||
@@ -314,6 +330,11 @@ class AuthorizationTest(unittest.TestCase):
|
||||
(self.challbs[1], self.challbs[2]),
|
||||
))
|
||||
|
||||
def test_unknown_chall_type(self):
|
||||
"""Just make sure an error isn't thrown."""
|
||||
from acme.messages import Authorization
|
||||
Authorization.from_json(self.jobj_from_unknown)
|
||||
|
||||
|
||||
class AuthorizationResourceTest(unittest.TestCase):
|
||||
"""Tests for acme.messages.AuthorizationResource."""
|
||||
|
||||
Reference in New Issue
Block a user