From ad79d7c8b6471c56c05c8ccccdaaffbbd2f4deb0 Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Fri, 12 Jun 2015 17:16:04 +0000 Subject: [PATCH] Adjust client reports to use RenewerConfiguration. Fix docs. --- letsencrypt/client.py | 5 ++--- letsencrypt/configuration.py | 5 ----- letsencrypt/constants.py | 6 +++--- letsencrypt/storage.py | 1 + letsencrypt/tests/client_test.py | 15 +++++++------- letsencrypt/tests/configuration_test.py | 26 ++++++++++++++++++++++--- 6 files changed, 37 insertions(+), 21 deletions(-) diff --git a/letsencrypt/client.py b/letsencrypt/client.py index be89ea8b7..d04116de2 100644 --- a/letsencrypt/client.py +++ b/letsencrypt/client.py @@ -236,8 +236,7 @@ class Client(object): # pylint: disable=no-self-use """Informs the user about automatic renewal and deployment. - :param cert: Newly issued certificate - :type cert: :class:`letsencrypt.storage.RenewableCert` + :param .RenewableCert cert: Newly issued certificate """ if ("autorenew" not in cert.configuration @@ -256,7 +255,7 @@ class Client(object): msg += ("been enabled for your certificate. These settings can be " "configured in the directories under {0}.").format( - cert.configuration["renewal_configs_dir"]) + cert.cli_config.renewal_configs_dir) reporter = zope.component.getUtility(interfaces.IReporter) reporter.add_message(msg, reporter.LOW_PRIORITY, True) diff --git a/letsencrypt/configuration.py b/letsencrypt/configuration.py index 522d697d9..7bd5c2ca4 100644 --- a/letsencrypt/configuration.py +++ b/letsencrypt/configuration.py @@ -81,11 +81,6 @@ class NamespaceConfig(object): def rec_token_dir(self): # pylint: disable=missing-docstring return os.path.join(self.namespace.work_dir, constants.REC_TOKEN_DIR) - @property - def renewer_config_file(self): # pylint: disable=missing-docstring - return os.path.join( - self.namespace.config_dir, constants.RENEWER_CONFIG_FILENAME) - @property def temp_checkpoint_dir(self): # pylint: disable=missing-docstring return os.path.join( diff --git a/letsencrypt/constants.py b/letsencrypt/constants.py index d949c60ec..202871144 100644 --- a/letsencrypt/constants.py +++ b/letsencrypt/constants.py @@ -47,7 +47,7 @@ List of expected options parameters: """ ARCHIVE_DIR = "archive" -"""TODO relative to `IConfig.config_dir`.""" +"""Archive directory, relative to `IConfig.config_dir`.""" CONFIG_DIRS_MODE = 0o755 """Directory mode for ``.IConfig.config_dir`` et al.""" @@ -76,7 +76,7 @@ KEY_DIR = "keys" """Directory (relative to `IConfig.config_dir`) where keys are saved.""" LIVE_DIR = "live" -"""TODO relative to `IConfig.config_dir`.""" +"""Live directory, relative to `IConfig.config_dir`.""" TEMP_CHECKPOINT_DIR = "temp_checkpoint" """Temporary checkpoint directory (relative to `IConfig.work_dir`).""" @@ -86,7 +86,7 @@ REC_TOKEN_DIR = "recovery_tokens" `IConfig.work_dir`).""" RENEWAL_CONFIGS_DIR = "configs" -"""TODO relative to `IConfig.config_dir`.""" +"""Renewal configs directory, relative to `IConfig.config_dir`.""" RENEWER_CONFIG_FILENAME = "renewer.conf" """Renewer config file name (relative to `IConfig.config_dir`).""" diff --git a/letsencrypt/storage.py b/letsencrypt/storage.py index c314e3b00..4ad1216e6 100644 --- a/letsencrypt/storage.py +++ b/letsencrypt/storage.py @@ -88,6 +88,7 @@ class RenewableCert(object): # pylint: disable=too-many-instance-attributes :param configobj.ConfigObj config_opts: systemwide defaults for renewal properties not otherwise specified in the individual renewal config file. + :param .RenewerConfiguration cli_config: :raises ValueError: if the configuration file's name didn't end in ".conf", or the file is missing or broken. diff --git a/letsencrypt/tests/client_test.py b/letsencrypt/tests/client_test.py index 1fb9c2a03..59657b627 100644 --- a/letsencrypt/tests/client_test.py +++ b/letsencrypt/tests/client_test.py @@ -21,7 +21,8 @@ class ClientTest(unittest.TestCase): """Tests for letsencrypt.client.Client.""" def setUp(self): - self.config = mock.MagicMock(no_verify_ssl=False) + self.config = mock.MagicMock( + no_verify_ssl=False, config_dir="/etc/letsencrypt") # pylint: disable=star-args self.account = mock.MagicMock(**{"key.pem": KEY}) @@ -39,7 +40,6 @@ class ClientTest(unittest.TestCase): @mock.patch("letsencrypt.client.zope.component.getUtility") def test_report_new_account(self, mock_zope): # pylint: disable=protected-access - self.config.config_dir = "/usr/bin/coffee" self.account.recovery_token = "ECCENTRIC INVISIBILITY RHINOCEROS" self.account.email = "rhino@jungle.io" @@ -54,32 +54,33 @@ class ClientTest(unittest.TestCase): # pylint: disable=protected-access cert = mock.MagicMock() cert.configuration = configobj.ConfigObj() - cert.configuration["renewal_configs_dir"] = "/etc/letsencrypt/configs" + cert.cli_config = configuration.RenewerConfiguration(self.config) cert.configuration["autorenew"] = "True" cert.configuration["autodeploy"] = "True" self.client._report_renewal_status(cert) msg = mock_zope().add_message.call_args[0][0] self.assertTrue("renewal and deployment has been" in msg) - self.assertTrue(cert.configuration["renewal_configs_dir"] in msg) + self.assertTrue(cert.cli_config.renewal_configs_dir in msg) cert.configuration["autorenew"] = "False" self.client._report_renewal_status(cert) msg = mock_zope().add_message.call_args[0][0] self.assertTrue("deployment but not automatic renewal" in msg) - self.assertTrue(cert.configuration["renewal_configs_dir"] in msg) + self.assertTrue(cert.cli_config.renewal_configs_dir in msg) cert.configuration["autodeploy"] = "False" self.client._report_renewal_status(cert) msg = mock_zope().add_message.call_args[0][0] self.assertTrue("renewal and deployment has not" in msg) - self.assertTrue(cert.configuration["renewal_configs_dir"] in msg) + self.assertTrue(cert.cli_config.renewal_configs_dir in msg) cert.configuration["autorenew"] = "True" self.client._report_renewal_status(cert) msg = mock_zope().add_message.call_args[0][0] self.assertTrue("renewal but not automatic deployment" in msg) - self.assertTrue(cert.configuration["renewal_configs_dir"] in msg) + self.assertTrue(cert.cli_config.renewal_configs_dir in msg) + class DetermineAccountTest(unittest.TestCase): """Tests for letsencrypt.client.determine_authenticator.""" diff --git a/letsencrypt/tests/configuration_test.py b/letsencrypt/tests/configuration_test.py index 38fea140a..3dee41d85 100644 --- a/letsencrypt/tests/configuration_test.py +++ b/letsencrypt/tests/configuration_test.py @@ -9,10 +9,10 @@ class NamespaceConfigTest(unittest.TestCase): """Tests for letsencrypt.configuration.NamespaceConfig.""" def setUp(self): - from letsencrypt.configuration import NamespaceConfig self.namespace = mock.MagicMock( config_dir='/tmp/config', work_dir='/tmp/foo', foo='bar', server='https://acme-server.org:443/new') + from letsencrypt.configuration import NamespaceConfig self.config = NamespaceConfig(self.namespace) def test_proxy_getattr(self): @@ -38,7 +38,6 @@ class NamespaceConfigTest(unittest.TestCase): constants.IN_PROGRESS_DIR = '../p' constants.KEY_DIR = 'keys' constants.REC_TOKEN_DIR = '/r' - constants.RENEWER_CONFIG_FILENAME = 'r.conf' constants.TEMP_CHECKPOINT_DIR = 't' self.assertEqual( @@ -53,9 +52,30 @@ class NamespaceConfigTest(unittest.TestCase): self.assertEqual(self.config.in_progress_dir, '/tmp/foo/../p') self.assertEqual(self.config.key_dir, '/tmp/config/keys') self.assertEqual(self.config.rec_token_dir, '/r') - self.assertEqual(self.config.renewer_config_file, '/tmp/config/r.conf') self.assertEqual(self.config.temp_checkpoint_dir, '/tmp/foo/t') +class RenewerConfigurationTest(unittest.TestCase): + """Test for letsencrypt.configuration.RenewerConfiguration.""" + + def setUp(self): + self.namespace = mock.MagicMock(config_dir='/tmp/config') + from letsencrypt.configuration import RenewerConfiguration + self.config = RenewerConfiguration(self.namespace) + + @mock.patch('letsencrypt.configuration.constants') + def test_dynamic_dirs(self, constants): + constants.ARCHIVE_DIR = "a" + constants.LIVE_DIR = 'l' + constants.RENEWAL_CONFIGS_DIR = "renewal_configs" + constants.RENEWER_CONFIG_FILENAME = 'r.conf' + + self.assertEqual(self.config.archive_dir, '/tmp/config/a') + self.assertEqual(self.config.live_dir, '/tmp/config/l') + self.assertEqual( + self.config.renewal_configs_dir, '/tmp/config/renewal_configs') + self.assertEqual(self.config.renewer_config_file, '/tmp/config/r.conf') + + if __name__ == '__main__': unittest.main() # pragma: no cover