mirror of
https://github.com/certbot/certbot.git
synced 2026-08-01 19:02:52 +02:00
Add Directory.meta (fixes #2768)
This commit is contained in:
+10
-2
@@ -123,6 +123,12 @@ class Directory(jose.JSONDeSerializable):
|
|||||||
|
|
||||||
_REGISTERED_TYPES = {}
|
_REGISTERED_TYPES = {}
|
||||||
|
|
||||||
|
class Meta(jose.JSONObjectWithFields):
|
||||||
|
"""Directory Meta."""
|
||||||
|
terms_of_service = jose.Field('terms-of-service', omitempty=True)
|
||||||
|
website = jose.Field('website', omitempty=True)
|
||||||
|
caa_identities = jose.Field('caa-identities', omitempty=True)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _canon_key(cls, key):
|
def _canon_key(cls, key):
|
||||||
return getattr(key, 'resource_type', key)
|
return getattr(key, 'resource_type', key)
|
||||||
@@ -137,10 +143,11 @@ class Directory(jose.JSONDeSerializable):
|
|||||||
|
|
||||||
def __init__(self, jobj):
|
def __init__(self, jobj):
|
||||||
canon_jobj = util.map_keys(jobj, self._canon_key)
|
canon_jobj = util.map_keys(jobj, self._canon_key)
|
||||||
if not set(canon_jobj).issubset(self._REGISTERED_TYPES):
|
if not set(canon_jobj).issubset(
|
||||||
|
set(self._REGISTERED_TYPES).union(['meta'])):
|
||||||
# TODO: acme-spec is not clear about this: 'It is a JSON
|
# TODO: acme-spec is not clear about this: 'It is a JSON
|
||||||
# dictionary, whose keys are the "resource" values listed
|
# dictionary, whose keys are the "resource" values listed
|
||||||
# in {{https-requests}}'z
|
# in {{https-requests}}'
|
||||||
raise ValueError('Wrong directory fields')
|
raise ValueError('Wrong directory fields')
|
||||||
# TODO: check that everything is an absolute URL; acme-spec is
|
# TODO: check that everything is an absolute URL; acme-spec is
|
||||||
# not clear on that
|
# not clear on that
|
||||||
@@ -163,6 +170,7 @@ class Directory(jose.JSONDeSerializable):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, jobj):
|
def from_json(cls, jobj):
|
||||||
|
jobj['meta'] = cls.Meta.from_json(jobj.pop('meta', {}))
|
||||||
try:
|
try:
|
||||||
return cls(jobj)
|
return cls(jobj)
|
||||||
except ValueError as error:
|
except ValueError as error:
|
||||||
|
|||||||
@@ -90,6 +90,11 @@ class DirectoryTest(unittest.TestCase):
|
|||||||
self.dir = Directory({
|
self.dir = Directory({
|
||||||
'new-reg': 'reg',
|
'new-reg': 'reg',
|
||||||
mock.MagicMock(resource_type='new-cert'): 'cert',
|
mock.MagicMock(resource_type='new-cert'): 'cert',
|
||||||
|
'meta': Directory.Meta(
|
||||||
|
terms_of_service='https://example.com/acme/terms',
|
||||||
|
website='https://www.example.com/',
|
||||||
|
caa_identities=['example.com'],
|
||||||
|
),
|
||||||
})
|
})
|
||||||
|
|
||||||
def test_init_wrong_key_value_error(self):
|
def test_init_wrong_key_value_error(self):
|
||||||
@@ -111,9 +116,16 @@ class DirectoryTest(unittest.TestCase):
|
|||||||
def test_getattr_fails_with_attribute_error(self):
|
def test_getattr_fails_with_attribute_error(self):
|
||||||
self.assertRaises(AttributeError, self.dir.__getattr__, 'foo')
|
self.assertRaises(AttributeError, self.dir.__getattr__, 'foo')
|
||||||
|
|
||||||
def test_to_partial_json(self):
|
def test_to_json(self):
|
||||||
self.assertEqual(
|
self.assertEqual(self.dir.to_json(), {
|
||||||
self.dir.to_partial_json(), {'new-reg': 'reg', 'new-cert': 'cert'})
|
'new-reg': 'reg',
|
||||||
|
'new-cert': 'cert',
|
||||||
|
'meta': {
|
||||||
|
'terms-of-service': 'https://example.com/acme/terms',
|
||||||
|
'website': 'https://www.example.com/',
|
||||||
|
'caa-identities': ['example.com'],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
def test_from_json_deserialization_error_on_wrong_key(self):
|
def test_from_json_deserialization_error_on_wrong_key(self):
|
||||||
from acme.messages import Directory
|
from acme.messages import Directory
|
||||||
|
|||||||
Reference in New Issue
Block a user