Revert "Figure out the DBM implementation dynamically"

This reverts commit e4834da2c1.
This commit is contained in:
Joona Hoikkala 2018-08-22 11:32:24 +03:00
parent e4834da2c1
commit ba9de53768
No known key found for this signature in database
GPG key ID: D5AA86BBF9B29A5C
2 changed files with 7 additions and 19 deletions

View file

@ -2523,18 +2523,6 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
os.makedirs(path)
os.chmod(path, 0o755)
def _ocsp_db_path(self):
"""Helper function to determine OCSP database path. This is required
as the underlaying DBM implementation behaves a bit differently
regarding the db file paths"""
cache_path = os.path.join(self.config.config_dir, "ocsp", "ocsp_cache")
if hasattr(dbm, 'library') and getattr(dbm, 'library') == "Berkeley DB":
return cache_path
return cache_path+".db"
def _ocsp_refresh_if_needed(self, pf_obj):
"""Refreshes OCSP response for a certiifcate if it's due
@ -2566,7 +2554,9 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
apache_util.certid_sha1_hex(cert_path))
if handler.ocsp_request_to_file(ocsp_workfile):
# Guaranteed good response
db = dbm.open(self._ocsp_db_path(), "c")
cache_path = os.path.join(self.config.config_dir, "ocsp", "ocsp_cache")
# dbm.open automatically adds the file extension, it will be
db = dbm.open(cache_path, "c")
cert_sha = apache_util.certid_sha1(cert_path)
db[cert_sha] = self._ocsp_response_dbm(ocsp_workfile)
db.close()

View file

@ -72,7 +72,7 @@ class OCSPPrefetchTest(util.ApacheTest):
self.call_mocked(self.config.enable_ocsp_prefetch,
self.lineage,
["ocspvhost.com"])
odbm = dbm.open(self.config._ocsp_db_path(), 'c')
odbm = dbm.open(os.path.join(self.config_dir, "ocsp", "ocsp_cache"), 'c')
self.assertEquals(len(odbm.keys()), 1)
# The actual response data is prepended by Apache timestamp
self.assertTrue(odbm[odbm.keys()[0]].endswith(b'MOCKRESPONSE'))
@ -103,17 +103,15 @@ class OCSPPrefetchTest(util.ApacheTest):
@mock.patch("certbot_apache.configurator.ApacheConfigurator.config_test")
def test_ocsp_prefetch_backup_db(self, _mock_test):
db_path = self.config._ocsp_db_path()
db_path = os.path.join(self.config_dir, "ocsp", "ocsp_cache.db")
def ocsp_del_db():
"""Side effect of _reload() that deletes the DBM file, like Apache
does when restarting"""
if not db_path.endswith(".db"):
db_path = db_path+".db"
os.remove(db_path)
self.assertFalse(os.path.isfile(db_path))
self.config._ensure_ocsp_dirs()
odbm = dbm.open(db_path, 'c')
odbm = dbm.open(db_path[:-3], 'c')
odbm["mock_key"] = b'mock_value'
odbm.close()
@ -123,7 +121,7 @@ class OCSPPrefetchTest(util.ApacheTest):
with mock.patch(rel_path, side_effect=ocsp_del_db) as mock_reload:
self.config.restart()
odbm = dbm.open(db_path, 'c')
odbm = dbm.open(db_path[:-3], 'c')
self.assertEquals(odbm["mock_key"], b'mock_value')
odbm.close()