diff --git a/certbot-apache/certbot_apache/tests/ocsp_prefetch_test.py b/certbot-apache/tests/ocsp_prefetch_test.py similarity index 95% rename from certbot-apache/certbot_apache/tests/ocsp_prefetch_test.py rename to certbot-apache/tests/ocsp_prefetch_test.py index 7858861d0..fd17d32ef 100644 --- a/certbot-apache/certbot_apache/tests/ocsp_prefetch_test.py +++ b/certbot-apache/tests/ocsp_prefetch_test.py @@ -13,23 +13,23 @@ from acme.magic_typing import Dict, List, Set, Union # pylint: disable=unused-i from certbot import errors from certbot.compat import os +import util -from certbot_apache.tests import util class MockDBM(object): # pylint: disable=missing-docstring """Main mock DBM class for Py3 dbm module""" - def __init__(self): - self.ndbm = Mockdbm_impl() + def __init__(self, library='Berkeley DB'): + self.ndbm = Mockdbm_impl(library) class Mockdbm_impl(object): """Mock dbm implementation that satisfies both bsddb and dbm interfaces""" # pylint: disable=missing-docstring - def __init__(self): - self.library = 'Berkeley DB' + def __init__(self, library='Berkeley DB'): + self.library = library self.name = 'ndbm' def open(self, path, mode): @@ -269,11 +269,17 @@ class OCSPPrefetchTest(util.ApacheTest): def test_ocsp_prefetch_preflight_check_noerror(self): self.call_mocked_py2(self.config._ensure_ocsp_prefetch_compatibility) self.call_mocked_py3(self.config._ensure_ocsp_prefetch_compatibility) - mockdbm_path = "certbot_apache.tests.ocsp_prefetch_test.Mockdbm_impl" - with mock.patch(mockdbm_path) as mock_dbm: - mock_dbm.library = 'Not Berkeley DB' + + real_import = six.moves.builtins.__import__ + + def mock_import(*args, **kwargs): + if args[0] == "bsddb": + raise ImportError + return real_import(*args, **kwargs) + with mock.patch('six.moves.builtins.__import__', side_effect=mock_import): + sys.modules['dbm'] = MockDBM(library='Not Berkeley DB') self.assertRaises(errors.NotSupportedError, - self.call_mocked_py3, + self._call_mocked, self.config._ensure_ocsp_prefetch_compatibility) def test_ocsp_prefetch_open_dbm_no_file(self): diff --git a/certbot/certbot/crypto_util.py b/certbot/certbot/crypto_util.py index 66b78b981..fe46242c4 100644 --- a/certbot/certbot/crypto_util.py +++ b/certbot/certbot/crypto_util.py @@ -251,7 +251,8 @@ def verify_renewable_cert_sig(renewable_cert): try: with open(renewable_cert.chain_path, 'rb') as chain_file: # type: IO[bytes] chain = x509.load_pem_x509_certificate(chain_file.read(), default_backend()) - cert = load_cert(renewable_cert.cert) + with open(renewable_cert.cert_path, 'rb') as cert_file: # type: IO[bytes] + cert = x509.load_pem_x509_certificate(cert_file.read(), default_backend()) pk = chain.public_key() with warnings.catch_warnings(): verify_signed_payload(pk, cert.signature, cert.tbs_certificate_bytes,