Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into new-dl
Browse files Browse the repository at this point in the history
  • Loading branch information
pde committed May 11, 2016
2 parents ba7688b + 255e205 commit 54220a1
Show file tree
Hide file tree
Showing 16 changed files with 320 additions and 185 deletions.
8 changes: 5 additions & 3 deletions acme/acme/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,11 @@ def from_json(cls, value):
def test_check_response_not_ok_jobj_no_error(self):
self.response.ok = False
self.response.json.return_value = {}
# pylint: disable=protected-access
self.assertRaises(
errors.ClientError, self.net._check_response, self.response)
with mock.patch('acme.client.messages.Error.from_json') as from_json:
from_json.side_effect = jose.DeserializationError
# pylint: disable=protected-access
self.assertRaises(
errors.ClientError, self.net._check_response, self.response)

def test_check_response_not_ok_jobj_error(self):
self.response.ok = False
Expand Down
15 changes: 3 additions & 12 deletions acme/acme/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class Error(jose.JSONObjectWithFields, errors.Error):
)
)

typ = jose.Field('type')
typ = jose.Field('type', omitempty=True, default='about:blank')
title = jose.Field('title', omitempty=True)
detail = jose.Field('detail')
detail = jose.Field('detail', omitempty=True)

@property
def description(self):
Expand Down Expand Up @@ -143,12 +143,6 @@ def register(cls, resource_body_cls):

def __init__(self, jobj):
canon_jobj = util.map_keys(jobj, self._canon_key)
if not set(canon_jobj).issubset(
set(self._REGISTERED_TYPES).union(['meta'])):
# TODO: acme-spec is not clear about this: 'It is a JSON
# dictionary, whose keys are the "resource" values listed
# in {{https-requests}}'
raise ValueError('Wrong directory fields')
# TODO: check that everything is an absolute URL; acme-spec is
# not clear on that
self._jobj = canon_jobj
Expand All @@ -171,10 +165,7 @@ def to_partial_json(self):
@classmethod
def from_json(cls, jobj):
jobj['meta'] = cls.Meta.from_json(jobj.pop('meta', {}))
try:
return cls(jobj)
except ValueError as error:
raise jose.DeserializationError(str(error))
return cls(jobj)


class Resource(jose.JSONObjectWithFields):
Expand Down
17 changes: 12 additions & 5 deletions acme/acme/messages_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ def setUp(self):
self.error_custom = Error(typ='custom', detail='bar')
self.jobj_cusom = {'type': 'custom', 'detail': 'bar'}

def test_default_typ(self):
from acme.messages import Error
self.assertEqual(Error().typ, 'about:blank')

def test_from_json_empty(self):
from acme.messages import Error
self.assertEqual(Error(), Error.from_json('{}'))

def test_from_json_hashable(self):
from acme.messages import Error
hash(Error.from_json(self.error.to_json()))
Expand Down Expand Up @@ -97,9 +105,9 @@ def setUp(self):
),
})

def test_init_wrong_key_value_error(self):
def test_init_wrong_key_value_success(self): # pylint: disable=no-self-use
from acme.messages import Directory
self.assertRaises(ValueError, Directory, {'foo': 'bar'})
Directory({'foo': 'bar'})

def test_getitem(self):
self.assertEqual('reg', self.dir['new-reg'])
Expand Down Expand Up @@ -127,10 +135,9 @@ def test_to_json(self):
},
})

def test_from_json_deserialization_error_on_wrong_key(self):
def test_from_json_deserialization_unknown_key_success(self): # pylint: disable=no-self-use
from acme.messages import Directory
self.assertRaises(
jose.DeserializationError, Directory.from_json, {'foo': 'bar'})
Directory.from_json({'foo': 'bar'})


class RegistrationTest(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion certbot-nginx/certbot_nginx/nginxparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RawNginxParser(object):
right_bracket = Literal("}").suppress()
semicolon = Literal(";").suppress()
space = White().suppress()
key = Word(alphanums + "_/")
key = Word(alphanums + "_/+-.")
# Matches anything that is not a special character AND any chars in single
# or double quotes
value = Regex(r"((\".*\")?(\'.*\')?[^\{\};,]?)+")
Expand Down
3 changes: 3 additions & 0 deletions certbot/plugins/webroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ def cleanup(self, achalls): # pylint: disable=missing-docstring
elif exc.errno == errno.EACCES:
logger.debug("Challenges cleaned up but no permissions for %s",
root_path)
elif exc.errno == errno.ENOENT:
logger.debug("Challenges cleaned up, %s does not exists",
root_path)
else:
raise

Expand Down
15 changes: 14 additions & 1 deletion certbot/plugins/webroot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,26 @@ def test_cleanup_oserror(self, mock_rmdir):
self.auth.perform([self.achall])

os_error = OSError()
os_error.errno = errno.ENOENT
os_error.errno = errno.EPERM
mock_rmdir.side_effect = os_error

self.assertRaises(OSError, self.auth.cleanup, [self.achall])
self.assertFalse(os.path.exists(self.validation_path))
self.assertTrue(os.path.exists(self.root_challenge_path))

@mock.patch('os.rmdir')
def test_cleanup_file_not_exists(self, mock_rmdir):
self.auth.prepare()
self.auth.perform([self.achall])

os_error = OSError()
os_error.errno = errno.ENOENT
mock_rmdir.side_effect = os_error

self.auth.cleanup([self.achall])
self.assertFalse(os.path.exists(self.validation_path))
self.assertTrue(os.path.exists(self.root_challenge_path))


class WebrootActionTest(unittest.TestCase):
"""Tests for webroot argparse actions."""
Expand Down
Loading

0 comments on commit 54220a1

Please sign in to comment.