From ba9de5376895dffe88a76e1f291a4bcd58dc3e0c Mon Sep 17 00:00:00 2001 From: Joona Hoikkala Date: Wed, 22 Aug 2018 11:32:24 +0300 Subject: [PATCH] Revert "Figure out the DBM implementation dynamically" This reverts commit e4834da2c1b60ffe38597b0092a367394c16e308. --- certbot-apache/certbot_apache/configurator.py | 16 +++------------- .../certbot_apache/tests/ocsp_prefetch_test.py | 10 ++++------ 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/certbot-apache/certbot_apache/configurator.py b/certbot-apache/certbot_apache/configurator.py index 9f0167490..665254429 100644 --- a/certbot-apache/certbot_apache/configurator.py +++ b/certbot-apache/certbot_apache/configurator.py @@ -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() diff --git a/certbot-apache/certbot_apache/tests/ocsp_prefetch_test.py b/certbot-apache/certbot_apache/tests/ocsp_prefetch_test.py index e1735a90c..09899d53f 100644 --- a/certbot-apache/certbot_apache/tests/ocsp_prefetch_test.py +++ b/certbot-apache/certbot_apache/tests/ocsp_prefetch_test.py @@ -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()