From fa992faf52be93309506ae728eb64340fd388706 Mon Sep 17 00:00:00 2001 From: James Kasten Date: Mon, 28 Sep 2015 15:24:51 -0700 Subject: [PATCH] Fix pylint and add test --- acme/acme/messages.py | 11 ++++++----- acme/acme/messages_test.py | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/acme/acme/messages.py b/acme/acme/messages.py index 002c08767..594b3d5c7 100644 --- a/acme/acme/messages.py +++ b/acme/acme/messages.py @@ -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): diff --git a/acme/acme/messages_test.py b/acme/acme/messages_test.py index 25f07018c..ac722909c 100644 --- a/acme/acme/messages_test.py +++ b/acme/acme/messages_test.py @@ -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."""