2015-06-11 11:00:18 -04:00
|
|
|
"""Tests for acme.messages."""
|
2021-03-10 14:51:27 -05:00
|
|
|
from typing import Dict
|
2015-03-27 05:47:03 -04:00
|
|
|
import unittest
|
2021-02-05 18:51:18 -05:00
|
|
|
from unittest import mock
|
2015-03-27 05:47:03 -04:00
|
|
|
|
2017-12-11 14:25:09 -05:00
|
|
|
import josepy as jose
|
2015-03-27 05:47:03 -04:00
|
|
|
|
2015-05-10 07:26:21 -04:00
|
|
|
from acme import challenges
|
2019-11-26 18:25:41 -05:00
|
|
|
import test_util
|
2015-03-27 05:47:03 -04:00
|
|
|
|
2015-12-23 13:48:52 -05:00
|
|
|
CERT = test_util.load_comparable_cert('cert.der')
|
|
|
|
|
CSR = test_util.load_comparable_csr('csr.der')
|
2015-07-10 08:26:51 -04:00
|
|
|
KEY = test_util.load_rsa_private_key('rsa512_key.pem')
|
2015-04-28 15:58:58 -04:00
|
|
|
|
|
|
|
|
|
2015-03-27 05:47:03 -04:00
|
|
|
class ErrorTest(unittest.TestCase):
|
2015-06-11 11:00:18 -04:00
|
|
|
"""Tests for acme.messages.Error."""
|
2015-03-27 05:47:03 -04:00
|
|
|
|
|
|
|
|
def setUp(self):
|
2016-10-12 17:46:02 -04:00
|
|
|
from acme.messages import Error, ERROR_PREFIX
|
Lint certbot code on Python 3, and update Pylint to the latest version (#7551)
Part of #7550
This PR makes appropriate corrections to run pylint on Python 3.
Why not keeping the dependencies unchanged and just run pylint on Python 3?
Because the old version of pylint breaks horribly on Python 3 because of unsupported version of astroid.
Why updating pylint + astroid to the latest version ?
Because this version only fixes some internal errors occuring during the lint of Certbot code, and is also ready to run gracefully on Python 3.8.
Why upgrading mypy ?
Because the old version does not support the new version of astroid required to run pylint correctly.
Why not upgrading mypy to its latest version ?
Because this latest version includes a new typshed version, that adds a lot of new type definitions, and brings dozens of new errors on the Certbot codebase. I would like to fix that in a future PR.
That said so, the work has been to find the correct set of new dependency versions, then configure pylint for sane configuration errors in our situation, disable irrelevant lintings errors, then fixing (or ignoring for good reason) the remaining mypy errors.
I also made PyLint and MyPy checks run correctly on Windows.
* Start configuration
* Reconfigure travis
* Suspend a check specific to python 3. Start fixing code.
* Repair call_args
* Fix return + elif lints
* Reconfigure development to run mainly on python3
* Remove incompatible Python 3.4 jobs
* Suspend pylint in some assertions
* Remove pylint in dev
* Take first mypy that supports typed-ast>=1.4.0 to limit the migration path
* Various return + else lint errors
* Find a set of deps that is working with current mypy version
* Update local oldest requirements
* Remove all current pylint errors
* Rebuild letsencrypt-auto
* Update mypy to fix pylint with new astroid version, and fix mypy issues
* Explain type: ignore
* Reconfigure tox, fix none path
* Simplify pinning
* Remove useless directive
* Remove debugging code
* Remove continue
* Update requirements
* Disable unsubscriptable-object check
* Disable one check, enabling two more
* Plug certbot dev version for oldest requirements
* Remove useless disable directives
* Remove useless no-member disable
* Remove no-else-* checks. Use elif in symetric branches.
* Add back assertion
* Add new line
* Remove unused pylint disable
* Remove other pylint disable
2019-12-10 17:12:50 -05:00
|
|
|
self.error = Error.with_code('malformed', detail='foo', title='title')
|
2015-11-07 15:01:29 -05:00
|
|
|
self.jobj = {
|
|
|
|
|
'detail': 'foo',
|
|
|
|
|
'title': 'some title',
|
2016-10-12 17:46:02 -04:00
|
|
|
'type': ERROR_PREFIX + 'malformed',
|
2015-11-07 15:01:29 -05:00
|
|
|
}
|
|
|
|
|
self.error_custom = Error(typ='custom', detail='bar')
|
2017-07-10 22:05:52 -04:00
|
|
|
self.empty_error = Error()
|
2015-03-27 05:47:03 -04:00
|
|
|
|
2016-04-09 04:15:24 -04:00
|
|
|
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('{}'))
|
|
|
|
|
|
2015-11-07 15:01:29 -05:00
|
|
|
def test_from_json_hashable(self):
|
2015-06-11 11:00:18 -04:00
|
|
|
from acme.messages import Error
|
2015-11-07 15:01:29 -05:00
|
|
|
hash(Error.from_json(self.error.to_json()))
|
2015-03-27 05:47:03 -04:00
|
|
|
|
|
|
|
|
def test_description(self):
|
Lint certbot code on Python 3, and update Pylint to the latest version (#7551)
Part of #7550
This PR makes appropriate corrections to run pylint on Python 3.
Why not keeping the dependencies unchanged and just run pylint on Python 3?
Because the old version of pylint breaks horribly on Python 3 because of unsupported version of astroid.
Why updating pylint + astroid to the latest version ?
Because this version only fixes some internal errors occuring during the lint of Certbot code, and is also ready to run gracefully on Python 3.8.
Why upgrading mypy ?
Because the old version does not support the new version of astroid required to run pylint correctly.
Why not upgrading mypy to its latest version ?
Because this latest version includes a new typshed version, that adds a lot of new type definitions, and brings dozens of new errors on the Certbot codebase. I would like to fix that in a future PR.
That said so, the work has been to find the correct set of new dependency versions, then configure pylint for sane configuration errors in our situation, disable irrelevant lintings errors, then fixing (or ignoring for good reason) the remaining mypy errors.
I also made PyLint and MyPy checks run correctly on Windows.
* Start configuration
* Reconfigure travis
* Suspend a check specific to python 3. Start fixing code.
* Repair call_args
* Fix return + elif lints
* Reconfigure development to run mainly on python3
* Remove incompatible Python 3.4 jobs
* Suspend pylint in some assertions
* Remove pylint in dev
* Take first mypy that supports typed-ast>=1.4.0 to limit the migration path
* Various return + else lint errors
* Find a set of deps that is working with current mypy version
* Update local oldest requirements
* Remove all current pylint errors
* Rebuild letsencrypt-auto
* Update mypy to fix pylint with new astroid version, and fix mypy issues
* Explain type: ignore
* Reconfigure tox, fix none path
* Simplify pinning
* Remove useless directive
* Remove debugging code
* Remove continue
* Update requirements
* Disable unsubscriptable-object check
* Disable one check, enabling two more
* Plug certbot dev version for oldest requirements
* Remove useless disable directives
* Remove useless no-member disable
* Remove no-else-* checks. Use elif in symetric branches.
* Add back assertion
* Add new line
* Remove unused pylint disable
* Remove other pylint disable
2019-12-10 17:12:50 -05:00
|
|
|
self.assertEqual('The request message was malformed', self.error.description)
|
2015-11-07 15:01:29 -05:00
|
|
|
self.assertTrue(self.error_custom.description is None)
|
2015-04-18 01:48:32 -04:00
|
|
|
|
2016-10-12 17:46:02 -04:00
|
|
|
def test_code(self):
|
|
|
|
|
from acme.messages import Error
|
|
|
|
|
self.assertEqual('malformed', self.error.code)
|
|
|
|
|
self.assertEqual(None, self.error_custom.code)
|
|
|
|
|
self.assertEqual(None, Error().code)
|
|
|
|
|
|
|
|
|
|
def test_is_acme_error(self):
|
Lint certbot code on Python 3, and update Pylint to the latest version (#7551)
Part of #7550
This PR makes appropriate corrections to run pylint on Python 3.
Why not keeping the dependencies unchanged and just run pylint on Python 3?
Because the old version of pylint breaks horribly on Python 3 because of unsupported version of astroid.
Why updating pylint + astroid to the latest version ?
Because this version only fixes some internal errors occuring during the lint of Certbot code, and is also ready to run gracefully on Python 3.8.
Why upgrading mypy ?
Because the old version does not support the new version of astroid required to run pylint correctly.
Why not upgrading mypy to its latest version ?
Because this latest version includes a new typshed version, that adds a lot of new type definitions, and brings dozens of new errors on the Certbot codebase. I would like to fix that in a future PR.
That said so, the work has been to find the correct set of new dependency versions, then configure pylint for sane configuration errors in our situation, disable irrelevant lintings errors, then fixing (or ignoring for good reason) the remaining mypy errors.
I also made PyLint and MyPy checks run correctly on Windows.
* Start configuration
* Reconfigure travis
* Suspend a check specific to python 3. Start fixing code.
* Repair call_args
* Fix return + elif lints
* Reconfigure development to run mainly on python3
* Remove incompatible Python 3.4 jobs
* Suspend pylint in some assertions
* Remove pylint in dev
* Take first mypy that supports typed-ast>=1.4.0 to limit the migration path
* Various return + else lint errors
* Find a set of deps that is working with current mypy version
* Update local oldest requirements
* Remove all current pylint errors
* Rebuild letsencrypt-auto
* Update mypy to fix pylint with new astroid version, and fix mypy issues
* Explain type: ignore
* Reconfigure tox, fix none path
* Simplify pinning
* Remove useless directive
* Remove debugging code
* Remove continue
* Update requirements
* Disable unsubscriptable-object check
* Disable one check, enabling two more
* Plug certbot dev version for oldest requirements
* Remove useless disable directives
* Remove useless no-member disable
* Remove no-else-* checks. Use elif in symetric branches.
* Add back assertion
* Add new line
* Remove unused pylint disable
* Remove other pylint disable
2019-12-10 17:12:50 -05:00
|
|
|
from acme.messages import is_acme_error, Error
|
2016-10-12 17:46:02 -04:00
|
|
|
self.assertTrue(is_acme_error(self.error))
|
|
|
|
|
self.assertFalse(is_acme_error(self.error_custom))
|
Lint certbot code on Python 3, and update Pylint to the latest version (#7551)
Part of #7550
This PR makes appropriate corrections to run pylint on Python 3.
Why not keeping the dependencies unchanged and just run pylint on Python 3?
Because the old version of pylint breaks horribly on Python 3 because of unsupported version of astroid.
Why updating pylint + astroid to the latest version ?
Because this version only fixes some internal errors occuring during the lint of Certbot code, and is also ready to run gracefully on Python 3.8.
Why upgrading mypy ?
Because the old version does not support the new version of astroid required to run pylint correctly.
Why not upgrading mypy to its latest version ?
Because this latest version includes a new typshed version, that adds a lot of new type definitions, and brings dozens of new errors on the Certbot codebase. I would like to fix that in a future PR.
That said so, the work has been to find the correct set of new dependency versions, then configure pylint for sane configuration errors in our situation, disable irrelevant lintings errors, then fixing (or ignoring for good reason) the remaining mypy errors.
I also made PyLint and MyPy checks run correctly on Windows.
* Start configuration
* Reconfigure travis
* Suspend a check specific to python 3. Start fixing code.
* Repair call_args
* Fix return + elif lints
* Reconfigure development to run mainly on python3
* Remove incompatible Python 3.4 jobs
* Suspend pylint in some assertions
* Remove pylint in dev
* Take first mypy that supports typed-ast>=1.4.0 to limit the migration path
* Various return + else lint errors
* Find a set of deps that is working with current mypy version
* Update local oldest requirements
* Remove all current pylint errors
* Rebuild letsencrypt-auto
* Update mypy to fix pylint with new astroid version, and fix mypy issues
* Explain type: ignore
* Reconfigure tox, fix none path
* Simplify pinning
* Remove useless directive
* Remove debugging code
* Remove continue
* Update requirements
* Disable unsubscriptable-object check
* Disable one check, enabling two more
* Plug certbot dev version for oldest requirements
* Remove useless disable directives
* Remove useless no-member disable
* Remove no-else-* checks. Use elif in symetric branches.
* Add back assertion
* Add new line
* Remove unused pylint disable
* Remove other pylint disable
2019-12-10 17:12:50 -05:00
|
|
|
self.assertFalse(is_acme_error(Error()))
|
2017-07-10 22:05:52 -04:00
|
|
|
self.assertFalse(is_acme_error(self.empty_error))
|
|
|
|
|
self.assertFalse(is_acme_error("must pet all the {dogs|rabbits}"))
|
|
|
|
|
|
|
|
|
|
def test_unicode_error(self):
|
Lint certbot code on Python 3, and update Pylint to the latest version (#7551)
Part of #7550
This PR makes appropriate corrections to run pylint on Python 3.
Why not keeping the dependencies unchanged and just run pylint on Python 3?
Because the old version of pylint breaks horribly on Python 3 because of unsupported version of astroid.
Why updating pylint + astroid to the latest version ?
Because this version only fixes some internal errors occuring during the lint of Certbot code, and is also ready to run gracefully on Python 3.8.
Why upgrading mypy ?
Because the old version does not support the new version of astroid required to run pylint correctly.
Why not upgrading mypy to its latest version ?
Because this latest version includes a new typshed version, that adds a lot of new type definitions, and brings dozens of new errors on the Certbot codebase. I would like to fix that in a future PR.
That said so, the work has been to find the correct set of new dependency versions, then configure pylint for sane configuration errors in our situation, disable irrelevant lintings errors, then fixing (or ignoring for good reason) the remaining mypy errors.
I also made PyLint and MyPy checks run correctly on Windows.
* Start configuration
* Reconfigure travis
* Suspend a check specific to python 3. Start fixing code.
* Repair call_args
* Fix return + elif lints
* Reconfigure development to run mainly on python3
* Remove incompatible Python 3.4 jobs
* Suspend pylint in some assertions
* Remove pylint in dev
* Take first mypy that supports typed-ast>=1.4.0 to limit the migration path
* Various return + else lint errors
* Find a set of deps that is working with current mypy version
* Update local oldest requirements
* Remove all current pylint errors
* Rebuild letsencrypt-auto
* Update mypy to fix pylint with new astroid version, and fix mypy issues
* Explain type: ignore
* Reconfigure tox, fix none path
* Simplify pinning
* Remove useless directive
* Remove debugging code
* Remove continue
* Update requirements
* Disable unsubscriptable-object check
* Disable one check, enabling two more
* Plug certbot dev version for oldest requirements
* Remove useless disable directives
* Remove useless no-member disable
* Remove no-else-* checks. Use elif in symetric branches.
* Add back assertion
* Add new line
* Remove unused pylint disable
* Remove other pylint disable
2019-12-10 17:12:50 -05:00
|
|
|
from acme.messages import Error, is_acme_error
|
|
|
|
|
arabic_error = Error.with_code(
|
|
|
|
|
'malformed', detail=u'\u0639\u062f\u0627\u0644\u0629', title='title')
|
2017-07-10 22:05:52 -04:00
|
|
|
self.assertTrue(is_acme_error(arabic_error))
|
2016-10-12 17:46:02 -04:00
|
|
|
|
|
|
|
|
def test_with_code(self):
|
|
|
|
|
from acme.messages import Error, is_acme_error
|
|
|
|
|
self.assertTrue(is_acme_error(Error.with_code('badCSR')))
|
|
|
|
|
self.assertRaises(ValueError, Error.with_code, 'not an ACME error code')
|
|
|
|
|
|
2017-12-01 13:59:55 -05:00
|
|
|
def test_str(self):
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
str(self.error),
|
|
|
|
|
u"{0.typ} :: {0.description} :: {0.detail} :: {0.title}"
|
|
|
|
|
.format(self.error))
|
|
|
|
|
|
2015-03-27 05:47:03 -04:00
|
|
|
|
|
|
|
|
class ConstantTest(unittest.TestCase):
|
2015-06-11 11:00:18 -04:00
|
|
|
"""Tests for acme.messages._Constant."""
|
2015-03-27 05:47:03 -04:00
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-06-11 11:00:18 -04:00
|
|
|
from acme.messages import _Constant
|
2015-09-06 05:19:26 -04:00
|
|
|
|
2015-03-27 05:47:03 -04:00
|
|
|
class MockConstant(_Constant): # pylint: disable=missing-docstring
|
2021-03-10 14:51:27 -05:00
|
|
|
POSSIBLE_NAMES: Dict = {}
|
2015-03-27 05:47:03 -04:00
|
|
|
|
|
|
|
|
self.MockConstant = MockConstant # pylint: disable=invalid-name
|
|
|
|
|
self.const_a = MockConstant('a')
|
|
|
|
|
self.const_b = MockConstant('b')
|
|
|
|
|
|
2015-04-18 04:11:28 -04:00
|
|
|
def test_to_partial_json(self):
|
|
|
|
|
self.assertEqual('a', self.const_a.to_partial_json())
|
|
|
|
|
self.assertEqual('b', self.const_b.to_partial_json())
|
2015-03-27 05:47:03 -04:00
|
|
|
|
|
|
|
|
def test_from_json(self):
|
|
|
|
|
self.assertEqual(self.const_a, self.MockConstant.from_json('a'))
|
|
|
|
|
self.assertRaises(
|
|
|
|
|
jose.DeserializationError, self.MockConstant.from_json, 'c')
|
|
|
|
|
|
2015-04-18 01:48:32 -04:00
|
|
|
def test_from_json_hashable(self):
|
|
|
|
|
hash(self.MockConstant.from_json('a'))
|
|
|
|
|
|
2015-03-27 05:47:03 -04:00
|
|
|
def test_repr(self):
|
|
|
|
|
self.assertEqual('MockConstant(a)', repr(self.const_a))
|
|
|
|
|
self.assertEqual('MockConstant(b)', repr(self.const_b))
|
|
|
|
|
|
2015-04-27 15:42:50 -04:00
|
|
|
def test_equality(self):
|
2015-04-27 17:59:44 -04:00
|
|
|
const_a_prime = self.MockConstant('a')
|
2020-11-12 17:33:02 -05:00
|
|
|
self.assertNotEqual(self.const_a, self.const_b)
|
|
|
|
|
self.assertEqual(self.const_a, const_a_prime)
|
2015-04-27 15:42:50 -04:00
|
|
|
|
2020-11-12 17:33:02 -05:00
|
|
|
self.assertNotEqual(self.const_a, self.const_b)
|
|
|
|
|
self.assertEqual(self.const_a, const_a_prime)
|
2015-03-27 05:47:03 -04:00
|
|
|
|
2015-06-02 15:08:17 -04:00
|
|
|
|
2015-09-08 16:37:09 -04:00
|
|
|
class DirectoryTest(unittest.TestCase):
|
|
|
|
|
"""Tests for acme.messages.Directory."""
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
from acme.messages import Directory
|
|
|
|
|
self.dir = Directory({
|
|
|
|
|
'new-reg': 'reg',
|
|
|
|
|
mock.MagicMock(resource_type='new-cert'): 'cert',
|
2016-04-06 02:14:31 -04:00
|
|
|
'meta': Directory.Meta(
|
|
|
|
|
terms_of_service='https://example.com/acme/terms',
|
|
|
|
|
website='https://www.example.com/',
|
|
|
|
|
caa_identities=['example.com'],
|
|
|
|
|
),
|
2015-09-08 16:37:09 -04:00
|
|
|
})
|
|
|
|
|
|
2016-05-11 12:49:23 -04:00
|
|
|
def test_init_wrong_key_value_success(self): # pylint: disable=no-self-use
|
2015-09-08 16:37:09 -04:00
|
|
|
from acme.messages import Directory
|
2016-05-11 12:49:23 -04:00
|
|
|
Directory({'foo': 'bar'})
|
2015-09-08 16:37:09 -04:00
|
|
|
|
|
|
|
|
def test_getitem(self):
|
|
|
|
|
self.assertEqual('reg', self.dir['new-reg'])
|
|
|
|
|
from acme.messages import NewRegistration
|
|
|
|
|
self.assertEqual('reg', self.dir[NewRegistration])
|
|
|
|
|
self.assertEqual('reg', self.dir[NewRegistration()])
|
|
|
|
|
|
|
|
|
|
def test_getitem_fails_with_key_error(self):
|
|
|
|
|
self.assertRaises(KeyError, self.dir.__getitem__, 'foo')
|
|
|
|
|
|
|
|
|
|
def test_getattr(self):
|
|
|
|
|
self.assertEqual('reg', self.dir.new_reg)
|
|
|
|
|
|
|
|
|
|
def test_getattr_fails_with_attribute_error(self):
|
|
|
|
|
self.assertRaises(AttributeError, self.dir.__getattr__, 'foo')
|
|
|
|
|
|
2016-04-06 02:14:31 -04:00
|
|
|
def test_to_json(self):
|
|
|
|
|
self.assertEqual(self.dir.to_json(), {
|
|
|
|
|
'new-reg': 'reg',
|
|
|
|
|
'new-cert': 'cert',
|
|
|
|
|
'meta': {
|
|
|
|
|
'terms-of-service': 'https://example.com/acme/terms',
|
|
|
|
|
'website': 'https://www.example.com/',
|
2018-02-14 22:19:23 -05:00
|
|
|
'caaIdentities': ['example.com'],
|
2016-04-06 02:14:31 -04:00
|
|
|
},
|
|
|
|
|
})
|
2015-09-08 16:37:09 -04:00
|
|
|
|
2016-05-11 12:49:23 -04:00
|
|
|
def test_from_json_deserialization_unknown_key_success(self): # pylint: disable=no-self-use
|
2015-09-08 16:37:09 -04:00
|
|
|
from acme.messages import Directory
|
2016-05-11 12:49:23 -04:00
|
|
|
Directory.from_json({'foo': 'bar'})
|
2015-09-08 16:37:09 -04:00
|
|
|
|
2018-02-15 22:04:17 -05:00
|
|
|
def test_iter_meta(self):
|
|
|
|
|
result = False
|
|
|
|
|
for k in self.dir.meta:
|
|
|
|
|
if k == 'terms_of_service':
|
|
|
|
|
result = self.dir.meta[k] == 'https://example.com/acme/terms'
|
|
|
|
|
self.assertTrue(result)
|
|
|
|
|
|
2015-09-08 16:37:09 -04:00
|
|
|
|
2018-12-03 18:27:35 -05:00
|
|
|
class ExternalAccountBindingTest(unittest.TestCase):
|
|
|
|
|
def setUp(self):
|
|
|
|
|
from acme.messages import Directory
|
|
|
|
|
self.key = jose.jwk.JWKRSA(key=KEY.public_key())
|
|
|
|
|
self.kid = "kid-for-testing"
|
|
|
|
|
self.hmac_key = "hmac-key-for-testing"
|
|
|
|
|
self.dir = Directory({
|
|
|
|
|
'newAccount': 'http://url/acme/new-account',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
def test_from_data(self):
|
|
|
|
|
from acme.messages import ExternalAccountBinding
|
|
|
|
|
eab = ExternalAccountBinding.from_data(self.key, self.kid, self.hmac_key, self.dir)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(len(eab), 3)
|
|
|
|
|
self.assertEqual(sorted(eab.keys()), sorted(['protected', 'payload', 'signature']))
|
|
|
|
|
|
|
|
|
|
|
2015-04-17 18:09:19 -04:00
|
|
|
class RegistrationTest(unittest.TestCase):
|
2015-06-11 11:00:18 -04:00
|
|
|
"""Tests for acme.messages.Registration."""
|
2015-04-17 18:09:19 -04:00
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-07-05 09:11:33 -04:00
|
|
|
key = jose.jwk.JWKRSA(key=KEY.public_key())
|
2015-06-02 15:08:17 -04:00
|
|
|
contact = (
|
|
|
|
|
'mailto:admin@foo.com',
|
|
|
|
|
'tel:1234',
|
|
|
|
|
)
|
2015-04-18 02:01:21 -04:00
|
|
|
agreement = 'https://letsencrypt.org/terms'
|
2015-04-17 18:09:19 -04:00
|
|
|
|
2015-06-11 11:00:18 -04:00
|
|
|
from acme.messages import Registration
|
2015-07-25 07:53:37 -04:00
|
|
|
self.reg = Registration(key=key, contact=contact, agreement=agreement)
|
2017-04-07 12:52:12 -04:00
|
|
|
self.reg_none = Registration()
|
2015-04-18 02:01:21 -04:00
|
|
|
|
2015-04-18 02:19:54 -04:00
|
|
|
self.jobj_to = {
|
2015-04-18 02:01:21 -04:00
|
|
|
'contact': contact,
|
|
|
|
|
'agreement': agreement,
|
2015-04-18 02:19:54 -04:00
|
|
|
'key': key,
|
2015-04-17 18:09:19 -04:00
|
|
|
}
|
2015-04-18 02:19:54 -04:00
|
|
|
self.jobj_from = self.jobj_to.copy()
|
2015-04-18 04:11:28 -04:00
|
|
|
self.jobj_from['key'] = key.to_json()
|
2015-04-17 18:09:19 -04:00
|
|
|
|
2015-06-02 15:08:17 -04:00
|
|
|
def test_from_data(self):
|
|
|
|
|
from acme.messages import Registration
|
|
|
|
|
reg = Registration.from_data(phone='1234', email='admin@foo.com')
|
|
|
|
|
self.assertEqual(reg.contact, (
|
|
|
|
|
'tel:1234',
|
|
|
|
|
'mailto:admin@foo.com',
|
|
|
|
|
))
|
|
|
|
|
|
2018-12-03 18:27:35 -05:00
|
|
|
def test_new_registration_from_data_with_eab(self):
|
|
|
|
|
from acme.messages import NewRegistration, ExternalAccountBinding, Directory
|
|
|
|
|
key = jose.jwk.JWKRSA(key=KEY.public_key())
|
|
|
|
|
kid = "kid-for-testing"
|
|
|
|
|
hmac_key = "hmac-key-for-testing"
|
|
|
|
|
directory = Directory({
|
|
|
|
|
'newAccount': 'http://url/acme/new-account',
|
|
|
|
|
})
|
|
|
|
|
eab = ExternalAccountBinding.from_data(key, kid, hmac_key, directory)
|
|
|
|
|
reg = NewRegistration.from_data(email='admin@foo.com', external_account_binding=eab)
|
|
|
|
|
self.assertEqual(reg.contact, (
|
|
|
|
|
'mailto:admin@foo.com',
|
|
|
|
|
))
|
|
|
|
|
self.assertEqual(sorted(reg.external_account_binding.keys()),
|
|
|
|
|
sorted(['protected', 'payload', 'signature']))
|
|
|
|
|
|
2015-06-02 15:08:17 -04:00
|
|
|
def test_phones(self):
|
|
|
|
|
self.assertEqual(('1234',), self.reg.phones)
|
|
|
|
|
|
|
|
|
|
def test_emails(self):
|
|
|
|
|
self.assertEqual(('admin@foo.com',), self.reg.emails)
|
|
|
|
|
|
2015-04-18 04:11:28 -04:00
|
|
|
def test_to_partial_json(self):
|
|
|
|
|
self.assertEqual(self.jobj_to, self.reg.to_partial_json())
|
2015-04-17 18:09:19 -04:00
|
|
|
|
|
|
|
|
def test_from_json(self):
|
2015-06-11 11:00:18 -04:00
|
|
|
from acme.messages import Registration
|
2015-04-18 02:19:54 -04:00
|
|
|
self.assertEqual(self.reg, Registration.from_json(self.jobj_from))
|
2015-04-18 02:01:21 -04:00
|
|
|
|
|
|
|
|
def test_from_json_hashable(self):
|
2015-06-11 11:00:18 -04:00
|
|
|
from acme.messages import Registration
|
2015-04-18 02:19:54 -04:00
|
|
|
hash(Registration.from_json(self.jobj_from))
|
2015-04-17 18:09:19 -04:00
|
|
|
|
2020-08-26 18:22:51 -04:00
|
|
|
def test_default_not_transmitted(self):
|
|
|
|
|
from acme.messages import NewRegistration
|
|
|
|
|
empty_new_reg = NewRegistration()
|
|
|
|
|
new_reg_with_contact = NewRegistration(contact=())
|
|
|
|
|
|
|
|
|
|
self.assertEqual(empty_new_reg.contact, ())
|
|
|
|
|
self.assertEqual(new_reg_with_contact.contact, ())
|
|
|
|
|
|
|
|
|
|
self.assertTrue('contact' not in empty_new_reg.to_partial_json())
|
|
|
|
|
self.assertTrue('contact' not in empty_new_reg.fields_to_partial_json())
|
|
|
|
|
self.assertTrue('contact' in new_reg_with_contact.to_partial_json())
|
|
|
|
|
self.assertTrue('contact' in new_reg_with_contact.fields_to_partial_json())
|
|
|
|
|
|
2015-04-17 18:09:19 -04:00
|
|
|
|
2015-06-30 12:17:33 -04:00
|
|
|
class UpdateRegistrationTest(unittest.TestCase):
|
|
|
|
|
"""Tests for acme.messages.UpdateRegistration."""
|
|
|
|
|
|
|
|
|
|
def test_empty(self):
|
|
|
|
|
from acme.messages import UpdateRegistration
|
|
|
|
|
jstring = '{"resource": "reg"}'
|
|
|
|
|
self.assertEqual(jstring, UpdateRegistration().json_dumps())
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
UpdateRegistration(), UpdateRegistration.json_loads(jstring))
|
|
|
|
|
|
|
|
|
|
|
2015-06-02 15:08:17 -04:00
|
|
|
class RegistrationResourceTest(unittest.TestCase):
|
|
|
|
|
"""Tests for acme.messages.RegistrationResource."""
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
from acme.messages import RegistrationResource
|
|
|
|
|
self.regr = RegistrationResource(
|
|
|
|
|
body=mock.sentinel.body, uri=mock.sentinel.uri,
|
|
|
|
|
terms_of_service=mock.sentinel.terms_of_service)
|
|
|
|
|
|
|
|
|
|
def test_to_partial_json(self):
|
|
|
|
|
self.assertEqual(self.regr.to_json(), {
|
|
|
|
|
'body': mock.sentinel.body,
|
|
|
|
|
'uri': mock.sentinel.uri,
|
|
|
|
|
'terms_of_service': mock.sentinel.terms_of_service,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
2015-03-27 05:47:03 -04:00
|
|
|
class ChallengeResourceTest(unittest.TestCase):
|
2015-06-11 11:00:18 -04:00
|
|
|
"""Tests for acme.messages.ChallengeResource."""
|
2015-03-27 05:47:03 -04:00
|
|
|
|
|
|
|
|
def test_uri(self):
|
2015-06-11 11:00:18 -04:00
|
|
|
from acme.messages import ChallengeResource
|
2015-03-27 05:47:03 -04:00
|
|
|
self.assertEqual('http://challb', ChallengeResource(body=mock.MagicMock(
|
2015-03-27 06:33:07 -04:00
|
|
|
uri='http://challb'), authzr_uri='http://authz').uri)
|
2015-03-27 05:47:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChallengeBodyTest(unittest.TestCase):
|
2015-06-11 11:00:18 -04:00
|
|
|
"""Tests for acme.messages.ChallengeBody."""
|
2015-03-27 05:47:03 -04:00
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-08-22 11:41:37 -04:00
|
|
|
self.chall = challenges.DNS(token=jose.b64decode(
|
|
|
|
|
'evaGxfADs6pSRb2LAv9IZf17Dt3juxGJ-PCt92wr-oA'))
|
2015-03-27 05:47:03 -04:00
|
|
|
|
2015-06-11 11:00:18 -04:00
|
|
|
from acme.messages import ChallengeBody
|
2015-06-23 11:01:23 -04:00
|
|
|
from acme.messages import Error
|
|
|
|
|
from acme.messages import STATUS_INVALID
|
|
|
|
|
self.status = STATUS_INVALID
|
Lint certbot code on Python 3, and update Pylint to the latest version (#7551)
Part of #7550
This PR makes appropriate corrections to run pylint on Python 3.
Why not keeping the dependencies unchanged and just run pylint on Python 3?
Because the old version of pylint breaks horribly on Python 3 because of unsupported version of astroid.
Why updating pylint + astroid to the latest version ?
Because this version only fixes some internal errors occuring during the lint of Certbot code, and is also ready to run gracefully on Python 3.8.
Why upgrading mypy ?
Because the old version does not support the new version of astroid required to run pylint correctly.
Why not upgrading mypy to its latest version ?
Because this latest version includes a new typshed version, that adds a lot of new type definitions, and brings dozens of new errors on the Certbot codebase. I would like to fix that in a future PR.
That said so, the work has been to find the correct set of new dependency versions, then configure pylint for sane configuration errors in our situation, disable irrelevant lintings errors, then fixing (or ignoring for good reason) the remaining mypy errors.
I also made PyLint and MyPy checks run correctly on Windows.
* Start configuration
* Reconfigure travis
* Suspend a check specific to python 3. Start fixing code.
* Repair call_args
* Fix return + elif lints
* Reconfigure development to run mainly on python3
* Remove incompatible Python 3.4 jobs
* Suspend pylint in some assertions
* Remove pylint in dev
* Take first mypy that supports typed-ast>=1.4.0 to limit the migration path
* Various return + else lint errors
* Find a set of deps that is working with current mypy version
* Update local oldest requirements
* Remove all current pylint errors
* Rebuild letsencrypt-auto
* Update mypy to fix pylint with new astroid version, and fix mypy issues
* Explain type: ignore
* Reconfigure tox, fix none path
* Simplify pinning
* Remove useless directive
* Remove debugging code
* Remove continue
* Update requirements
* Disable unsubscriptable-object check
* Disable one check, enabling two more
* Plug certbot dev version for oldest requirements
* Remove useless disable directives
* Remove useless no-member disable
* Remove no-else-* checks. Use elif in symetric branches.
* Add back assertion
* Add new line
* Remove unused pylint disable
* Remove other pylint disable
2019-12-10 17:12:50 -05:00
|
|
|
error = Error.with_code('serverInternal', detail='Unable to communicate with DNS server')
|
2015-03-27 05:47:03 -04:00
|
|
|
self.challb = ChallengeBody(
|
2015-06-23 11:01:23 -04:00
|
|
|
uri='http://challb', chall=self.chall, status=self.status,
|
|
|
|
|
error=error)
|
2015-03-27 05:47:03 -04:00
|
|
|
|
|
|
|
|
self.jobj_to = {
|
|
|
|
|
'uri': 'http://challb',
|
|
|
|
|
'status': self.status,
|
|
|
|
|
'type': 'dns',
|
2015-08-22 11:41:37 -04:00
|
|
|
'token': 'evaGxfADs6pSRb2LAv9IZf17Dt3juxGJ-PCt92wr-oA',
|
2015-06-23 11:01:23 -04:00
|
|
|
'error': error,
|
2015-03-27 05:47:03 -04:00
|
|
|
}
|
|
|
|
|
self.jobj_from = self.jobj_to.copy()
|
2015-06-23 11:01:23 -04:00
|
|
|
self.jobj_from['status'] = 'invalid'
|
|
|
|
|
self.jobj_from['error'] = {
|
2016-10-12 17:46:02 -04:00
|
|
|
'type': 'urn:ietf:params:acme:error:serverInternal',
|
2015-06-23 11:01:23 -04:00
|
|
|
'detail': 'Unable to communicate with DNS server',
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 23:50:26 -05:00
|
|
|
def test_encode(self):
|
|
|
|
|
self.assertEqual(self.challb.encode('uri'), self.challb.uri)
|
|
|
|
|
|
2015-04-18 04:11:28 -04:00
|
|
|
def test_to_partial_json(self):
|
|
|
|
|
self.assertEqual(self.jobj_to, self.challb.to_partial_json())
|
2015-03-27 05:47:03 -04:00
|
|
|
|
2015-04-18 01:48:32 -04:00
|
|
|
def test_from_json(self):
|
2015-06-11 11:00:18 -04:00
|
|
|
from acme.messages import ChallengeBody
|
2015-03-27 05:47:03 -04:00
|
|
|
self.assertEqual(self.challb, ChallengeBody.from_json(self.jobj_from))
|
|
|
|
|
|
2015-04-18 01:48:32 -04:00
|
|
|
def test_from_json_hashable(self):
|
2015-06-11 11:00:18 -04:00
|
|
|
from acme.messages import ChallengeBody
|
2015-04-18 01:48:32 -04:00
|
|
|
hash(ChallengeBody.from_json(self.jobj_from))
|
|
|
|
|
|
2015-05-05 15:09:35 -04:00
|
|
|
def test_proxy(self):
|
2015-08-22 11:41:37 -04:00
|
|
|
self.assertEqual(jose.b64decode(
|
|
|
|
|
'evaGxfADs6pSRb2LAv9IZf17Dt3juxGJ-PCt92wr-oA'), self.challb.token)
|
2015-05-05 15:09:35 -04:00
|
|
|
|
2015-03-27 05:47:03 -04:00
|
|
|
|
|
|
|
|
class AuthorizationTest(unittest.TestCase):
|
2015-06-11 11:00:18 -04:00
|
|
|
"""Tests for acme.messages.Authorization."""
|
2015-03-27 05:47:03 -04:00
|
|
|
|
|
|
|
|
def setUp(self):
|
2015-06-11 11:00:18 -04:00
|
|
|
from acme.messages import ChallengeBody
|
|
|
|
|
from acme.messages import STATUS_VALID
|
2015-09-28 18:24:51 -04:00
|
|
|
|
2015-03-27 05:47:03 -04:00
|
|
|
self.challbs = (
|
|
|
|
|
ChallengeBody(
|
|
|
|
|
uri='http://challb1', status=STATUS_VALID,
|
2015-10-28 16:41:15 -04:00
|
|
|
chall=challenges.HTTP01(token=b'IlirfxKKXAsHtmzK29Pj8A')),
|
2015-03-27 05:47:03 -04:00
|
|
|
ChallengeBody(uri='http://challb2', status=STATUS_VALID,
|
2015-07-31 18:45:48 -04:00
|
|
|
chall=challenges.DNS(
|
|
|
|
|
token=b'DGyRejmCefe7v4NfDGDKfA')),
|
2015-03-27 05:47:03 -04:00
|
|
|
)
|
2016-03-07 21:42:44 -05:00
|
|
|
combinations = ((0,), (1,))
|
2015-03-27 05:47:03 -04:00
|
|
|
|
2015-06-11 11:00:18 -04:00
|
|
|
from acme.messages import Authorization
|
|
|
|
|
from acme.messages import Identifier
|
|
|
|
|
from acme.messages import IDENTIFIER_FQDN
|
2015-03-27 05:47:03 -04:00
|
|
|
identifier = Identifier(typ=IDENTIFIER_FQDN, value='example.com')
|
|
|
|
|
self.authz = Authorization(
|
|
|
|
|
identifier=identifier, combinations=combinations,
|
|
|
|
|
challenges=self.challbs)
|
|
|
|
|
|
|
|
|
|
self.jobj_from = {
|
2015-04-18 04:11:28 -04:00
|
|
|
'identifier': identifier.to_json(),
|
|
|
|
|
'challenges': [challb.to_json() for challb in self.challbs],
|
2015-03-27 05:47:03 -04:00
|
|
|
'combinations': combinations,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def test_from_json(self):
|
2015-06-11 11:00:18 -04:00
|
|
|
from acme.messages import Authorization
|
2015-03-27 05:47:03 -04:00
|
|
|
Authorization.from_json(self.jobj_from)
|
|
|
|
|
|
2015-04-18 01:48:32 -04:00
|
|
|
def test_from_json_hashable(self):
|
2015-06-11 11:00:18 -04:00
|
|
|
from acme.messages import Authorization
|
2015-04-18 01:48:32 -04:00
|
|
|
hash(Authorization.from_json(self.jobj_from))
|
|
|
|
|
|
2015-03-27 05:47:03 -04:00
|
|
|
def test_resolved_combinations(self):
|
|
|
|
|
self.assertEqual(self.authz.resolved_combinations, (
|
2016-03-07 21:42:44 -05:00
|
|
|
(self.challbs[0],),
|
|
|
|
|
(self.challbs[1],),
|
2015-03-27 05:47:03 -04:00
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
2015-06-02 15:08:17 -04:00
|
|
|
class AuthorizationResourceTest(unittest.TestCase):
|
|
|
|
|
"""Tests for acme.messages.AuthorizationResource."""
|
|
|
|
|
|
|
|
|
|
def test_json_de_serializable(self):
|
|
|
|
|
from acme.messages import AuthorizationResource
|
|
|
|
|
authzr = AuthorizationResource(
|
|
|
|
|
uri=mock.sentinel.uri,
|
2017-03-15 00:44:57 -04:00
|
|
|
body=mock.sentinel.body)
|
2015-06-02 15:08:17 -04:00
|
|
|
self.assertTrue(isinstance(authzr, jose.JSONDeSerializable))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CertificateRequestTest(unittest.TestCase):
|
|
|
|
|
"""Tests for acme.messages.CertificateRequest."""
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
from acme.messages import CertificateRequest
|
2015-06-30 12:17:33 -04:00
|
|
|
self.req = CertificateRequest(csr=CSR)
|
2015-06-02 15:08:17 -04:00
|
|
|
|
|
|
|
|
def test_json_de_serializable(self):
|
|
|
|
|
self.assertTrue(isinstance(self.req, jose.JSONDeSerializable))
|
|
|
|
|
from acme.messages import CertificateRequest
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
self.req, CertificateRequest.from_json(self.req.to_json()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CertificateResourceTest(unittest.TestCase):
|
|
|
|
|
"""Tests for acme.messages.CertificateResourceTest."""
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
from acme.messages import CertificateResource
|
|
|
|
|
self.certr = CertificateResource(
|
|
|
|
|
body=CERT, uri=mock.sentinel.uri, authzrs=(),
|
|
|
|
|
cert_chain_uri=mock.sentinel.cert_chain_uri)
|
|
|
|
|
|
|
|
|
|
def test_json_de_serializable(self):
|
|
|
|
|
self.assertTrue(isinstance(self.certr, jose.JSONDeSerializable))
|
|
|
|
|
from acme.messages import CertificateResource
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
self.certr, CertificateResource.from_json(self.certr.to_json()))
|
|
|
|
|
|
|
|
|
|
|
2015-03-27 05:47:03 -04:00
|
|
|
class RevocationTest(unittest.TestCase):
|
2015-06-11 11:00:18 -04:00
|
|
|
"""Tests for acme.messages.RevocationTest."""
|
2015-03-27 05:47:03 -04:00
|
|
|
|
2015-06-17 12:13:26 -04:00
|
|
|
def setUp(self):
|
|
|
|
|
from acme.messages import Revocation
|
|
|
|
|
self.rev = Revocation(certificate=CERT)
|
2015-03-27 05:47:03 -04:00
|
|
|
|
2015-04-18 01:48:32 -04:00
|
|
|
def test_from_json_hashable(self):
|
2015-06-11 11:00:18 -04:00
|
|
|
from acme.messages import Revocation
|
2015-06-17 12:13:26 -04:00
|
|
|
hash(Revocation.from_json(self.rev.to_json()))
|
2015-04-18 01:48:32 -04:00
|
|
|
|
2015-03-27 05:47:03 -04:00
|
|
|
|
2018-02-14 22:19:23 -05:00
|
|
|
class OrderResourceTest(unittest.TestCase):
|
|
|
|
|
"""Tests for acme.messages.OrderResource."""
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
from acme.messages import OrderResource
|
|
|
|
|
self.regr = OrderResource(
|
|
|
|
|
body=mock.sentinel.body, uri=mock.sentinel.uri)
|
|
|
|
|
|
|
|
|
|
def test_to_partial_json(self):
|
|
|
|
|
self.assertEqual(self.regr.to_json(), {
|
|
|
|
|
'body': mock.sentinel.body,
|
|
|
|
|
'uri': mock.sentinel.uri,
|
|
|
|
|
'authorizations': None,
|
|
|
|
|
})
|
|
|
|
|
|
2020-03-13 12:56:35 -04:00
|
|
|
|
2018-10-18 13:37:56 -04:00
|
|
|
class NewOrderTest(unittest.TestCase):
|
|
|
|
|
"""Tests for acme.messages.NewOrder."""
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
from acme.messages import NewOrder
|
|
|
|
|
self.reg = NewOrder(
|
|
|
|
|
identifiers=mock.sentinel.identifiers)
|
|
|
|
|
|
|
|
|
|
def test_to_partial_json(self):
|
|
|
|
|
self.assertEqual(self.reg.to_json(), {
|
|
|
|
|
'identifiers': mock.sentinel.identifiers,
|
|
|
|
|
})
|
|
|
|
|
|
2018-02-14 22:19:23 -05:00
|
|
|
|
2020-03-13 12:56:35 -04:00
|
|
|
class JWSPayloadRFC8555Compliant(unittest.TestCase):
|
|
|
|
|
"""Test for RFC8555 compliance of JWS generated from resources/challenges"""
|
|
|
|
|
def test_message_payload(self):
|
|
|
|
|
from acme.messages import NewAuthorization
|
|
|
|
|
|
|
|
|
|
new_order = NewAuthorization()
|
|
|
|
|
new_order.le_acme_version = 2
|
|
|
|
|
|
|
|
|
|
jobj = new_order.json_dumps(indent=2).encode()
|
|
|
|
|
# RFC8555 states that JWS bodies must not have a resource field.
|
|
|
|
|
self.assertEqual(jobj, b'{}')
|
|
|
|
|
|
|
|
|
|
|
2015-03-27 05:47:03 -04:00
|
|
|
if __name__ == '__main__':
|
2015-05-10 13:34:25 -04:00
|
|
|
unittest.main() # pragma: no cover
|