mirror of
https://github.com/certbot/certbot.git
synced 2026-08-03 00:22:04 +02:00
Move configuration.py to _internal (#7542)
Part of #5775. Methodology similar to #7528. Also refactors NGINX test util to use certbot.tests.util.ConfigTestCase. * refactor nginx tests to no longer rely on certbot.configuration internals * Move configuration.py to _internal
This commit is contained in:
+1
-1
@@ -6,7 +6,7 @@ import subprocess
|
|||||||
import mock
|
import mock
|
||||||
import zope.interface
|
import zope.interface
|
||||||
|
|
||||||
from certbot import configuration
|
from certbot._internal import configuration
|
||||||
from certbot import errors as le_errors
|
from certbot import errors as le_errors
|
||||||
from certbot import util as certbot_util
|
from certbot import util as certbot_util
|
||||||
from certbot_apache import entrypoint
|
from certbot_apache import entrypoint
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import zope.interface
|
|||||||
|
|
||||||
from acme.magic_typing import Set # pylint: disable=unused-import, no-name-in-module
|
from acme.magic_typing import Set # pylint: disable=unused-import, no-name-in-module
|
||||||
|
|
||||||
from certbot import configuration
|
from certbot._internal import configuration
|
||||||
from certbot_nginx import configurator
|
from certbot_nginx import configurator
|
||||||
from certbot_nginx import constants
|
from certbot_nginx import constants
|
||||||
from certbot_compatibility_test import errors
|
from certbot_compatibility_test import errors
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class NginxConfiguratorTest(util.NginxTest):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(NginxConfiguratorTest, self).setUp()
|
super(NginxConfiguratorTest, self).setUp()
|
||||||
|
|
||||||
self.config = util.get_nginx_configurator(
|
self.config = self.get_nginx_configurator(
|
||||||
self.config_path, self.config_dir, self.work_dir, self.logs_dir)
|
self.config_path, self.config_dir, self.work_dir, self.logs_dir)
|
||||||
|
|
||||||
@mock.patch("certbot_nginx.configurator.util.exe_exists")
|
@mock.patch("certbot_nginx.configurator.util.exe_exists")
|
||||||
@@ -935,7 +935,7 @@ class InstallSslOptionsConfTest(util.NginxTest):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(InstallSslOptionsConfTest, self).setUp()
|
super(InstallSslOptionsConfTest, self).setUp()
|
||||||
|
|
||||||
self.config = util.get_nginx_configurator(
|
self.config = self.get_nginx_configurator(
|
||||||
self.config_path, self.config_dir, self.work_dir, self.logs_dir)
|
self.config_path, self.config_dir, self.work_dir, self.logs_dir)
|
||||||
|
|
||||||
def _call(self):
|
def _call(self):
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class HttpPerformTest(util.NginxTest):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(HttpPerformTest, self).setUp()
|
super(HttpPerformTest, self).setUp()
|
||||||
|
|
||||||
config = util.get_nginx_configurator(
|
config = self.get_nginx_configurator(
|
||||||
self.config_path, self.config_dir, self.work_dir, self.logs_dir)
|
self.config_path, self.config_dir, self.work_dir, self.logs_dir)
|
||||||
|
|
||||||
from certbot_nginx import http_01
|
from certbot_nginx import http_01
|
||||||
|
|||||||
@@ -2,14 +2,12 @@
|
|||||||
import copy
|
import copy
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
|
||||||
|
|
||||||
import josepy as jose
|
import josepy as jose
|
||||||
import mock
|
import mock
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import zope.component
|
import zope.component
|
||||||
|
|
||||||
from certbot import configuration
|
|
||||||
from certbot import util
|
from certbot import util
|
||||||
from certbot.compat import os
|
from certbot.compat import os
|
||||||
from certbot.plugins import common
|
from certbot.plugins import common
|
||||||
@@ -19,11 +17,14 @@ from certbot_nginx import configurator
|
|||||||
from certbot_nginx import nginxparser
|
from certbot_nginx import nginxparser
|
||||||
|
|
||||||
|
|
||||||
class NginxTest(unittest.TestCase): # pylint: disable=too-few-public-methods
|
class NginxTest(test_util.ConfigTestCase): # pylint: disable=too-few-public-methods
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(NginxTest, self).setUp()
|
super(NginxTest, self).setUp()
|
||||||
|
|
||||||
|
self.configuration = self.config
|
||||||
|
self.config = None
|
||||||
|
|
||||||
self.temp_dir, self.config_dir, self.work_dir = common.dir_setup(
|
self.temp_dir, self.config_dir, self.work_dir = common.dir_setup(
|
||||||
"etc_nginx", "certbot_nginx.tests")
|
"etc_nginx", "certbot_nginx.tests")
|
||||||
self.logs_dir = tempfile.mkdtemp('logs')
|
self.logs_dir = tempfile.mkdtemp('logs')
|
||||||
@@ -45,6 +46,42 @@ class NginxTest(unittest.TestCase): # pylint: disable=too-few-public-methods
|
|||||||
shutil.rmtree(self.work_dir)
|
shutil.rmtree(self.work_dir)
|
||||||
shutil.rmtree(self.logs_dir)
|
shutil.rmtree(self.logs_dir)
|
||||||
|
|
||||||
|
# pylint: disable=too-many-arguments
|
||||||
|
def get_nginx_configurator(self, config_path, config_dir, work_dir, logs_dir,
|
||||||
|
version=(1, 6, 2), openssl_version="1.0.2g"):
|
||||||
|
"""Create an Nginx Configurator with the specified options."""
|
||||||
|
|
||||||
|
backups = os.path.join(work_dir, "backups")
|
||||||
|
|
||||||
|
self.configuration.nginx_server_root = config_path
|
||||||
|
self.configuration.le_vhost_ext = "-le-ssl.conf"
|
||||||
|
self.configuration.config_dir = config_dir
|
||||||
|
self.configuration.work_dir = work_dir
|
||||||
|
self.configuration.logs_dir = logs_dir
|
||||||
|
self.configuration.backup_dir = backups
|
||||||
|
self.configuration.temp_checkpoint_dir = os.path.join(work_dir, "temp_checkpoints")
|
||||||
|
self.configuration.in_progress_dir = os.path.join(backups, "IN_PROGRESS")
|
||||||
|
self.configuration.server = "https://acme-server.org:443/new"
|
||||||
|
self.configuration.http01_port = 80
|
||||||
|
self.configuration.https_port = 5001
|
||||||
|
|
||||||
|
with mock.patch("certbot_nginx.configurator.NginxConfigurator."
|
||||||
|
"config_test"):
|
||||||
|
with mock.patch("certbot_nginx.configurator.util."
|
||||||
|
"exe_exists") as mock_exe_exists:
|
||||||
|
mock_exe_exists.return_value = True
|
||||||
|
config = configurator.NginxConfigurator(
|
||||||
|
self.configuration,
|
||||||
|
name="nginx",
|
||||||
|
version=version,
|
||||||
|
openssl_version=openssl_version)
|
||||||
|
config.prepare()
|
||||||
|
|
||||||
|
# Provide general config utility.
|
||||||
|
zope.component.provideUtility(self.configuration)
|
||||||
|
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
def get_data_filename(filename):
|
def get_data_filename(filename):
|
||||||
"""Gets the filename of a test data file."""
|
"""Gets the filename of a test data file."""
|
||||||
@@ -53,43 +90,6 @@ def get_data_filename(filename):
|
|||||||
"testdata", "etc_nginx", filename))
|
"testdata", "etc_nginx", filename))
|
||||||
|
|
||||||
|
|
||||||
def get_nginx_configurator(
|
|
||||||
config_path, config_dir, work_dir, logs_dir, version=(1, 6, 2), openssl_version="1.0.2g"):
|
|
||||||
"""Create an Nginx Configurator with the specified options."""
|
|
||||||
|
|
||||||
backups = os.path.join(work_dir, "backups")
|
|
||||||
|
|
||||||
with mock.patch("certbot_nginx.configurator.NginxConfigurator."
|
|
||||||
"config_test"):
|
|
||||||
with mock.patch("certbot_nginx.configurator.util."
|
|
||||||
"exe_exists") as mock_exe_exists:
|
|
||||||
mock_exe_exists.return_value = True
|
|
||||||
config = configurator.NginxConfigurator(
|
|
||||||
config=mock.MagicMock(
|
|
||||||
nginx_server_root=config_path,
|
|
||||||
le_vhost_ext="-le-ssl.conf",
|
|
||||||
config_dir=config_dir,
|
|
||||||
work_dir=work_dir,
|
|
||||||
logs_dir=logs_dir,
|
|
||||||
backup_dir=backups,
|
|
||||||
temp_checkpoint_dir=os.path.join(work_dir, "temp_checkpoints"),
|
|
||||||
in_progress_dir=os.path.join(backups, "IN_PROGRESS"),
|
|
||||||
server="https://acme-server.org:443/new",
|
|
||||||
http01_port=80,
|
|
||||||
https_port=5001,
|
|
||||||
),
|
|
||||||
name="nginx",
|
|
||||||
version=version,
|
|
||||||
openssl_version=openssl_version)
|
|
||||||
config.prepare()
|
|
||||||
|
|
||||||
# Provide general config utility.
|
|
||||||
nsconfig = configuration.NamespaceConfig(config.config)
|
|
||||||
zope.component.provideUtility(nsconfig)
|
|
||||||
|
|
||||||
return config
|
|
||||||
|
|
||||||
|
|
||||||
def filter_comments(tree):
|
def filter_comments(tree):
|
||||||
"""Filter comment nodes from parsed configurations."""
|
"""Filter comment nodes from parsed configurations."""
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ def update_live_symlinks(config):
|
|||||||
.. note:: This assumes that the installation is using a Reverter object.
|
.. note:: This assumes that the installation is using a Reverter object.
|
||||||
|
|
||||||
:param config: Configuration.
|
:param config: Configuration.
|
||||||
:type config: :class:`certbot.configuration.NamespaceConfig`
|
:type config: :class:`certbot._internal.configuration.NamespaceConfig`
|
||||||
|
|
||||||
"""
|
"""
|
||||||
for renewal_file in storage.renewal_conf_files(config):
|
for renewal_file in storage.renewal_conf_files(config):
|
||||||
@@ -43,7 +43,7 @@ def rename_lineage(config):
|
|||||||
"""Rename the specified lineage to the new name.
|
"""Rename the specified lineage to the new name.
|
||||||
|
|
||||||
:param config: Configuration.
|
:param config: Configuration.
|
||||||
:type config: :class:`certbot.configuration.NamespaceConfig`
|
:type config: :class:`certbot._internal.configuration.NamespaceConfig`
|
||||||
|
|
||||||
"""
|
"""
|
||||||
disp = zope.component.getUtility(interfaces.IDisplay)
|
disp = zope.component.getUtility(interfaces.IDisplay)
|
||||||
@@ -70,7 +70,7 @@ def certificates(config):
|
|||||||
"""Display information about certs configured with Certbot
|
"""Display information about certs configured with Certbot
|
||||||
|
|
||||||
:param config: Configuration.
|
:param config: Configuration.
|
||||||
:type config: :class:`certbot.configuration.NamespaceConfig`
|
:type config: :class:`certbot._internal.configuration.NamespaceConfig`
|
||||||
"""
|
"""
|
||||||
parsed_certs = []
|
parsed_certs = []
|
||||||
parse_failures = []
|
parse_failures = []
|
||||||
@@ -136,7 +136,7 @@ def find_duplicative_certs(config, domains):
|
|||||||
undefined.
|
undefined.
|
||||||
|
|
||||||
:param config: Configuration.
|
:param config: Configuration.
|
||||||
:type config: :class:`certbot.configuration.NamespaceConfig`
|
:type config: :class:`certbot._internal.configuration.NamespaceConfig`
|
||||||
:param domains: List of domain names
|
:param domains: List of domain names
|
||||||
:type domains: `list` of `str`
|
:type domains: `list` of `str`
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from certbot._internal import account
|
|||||||
from certbot._internal import cert_manager
|
from certbot._internal import cert_manager
|
||||||
from certbot import cli
|
from certbot import cli
|
||||||
from certbot._internal import client
|
from certbot._internal import client
|
||||||
from certbot import configuration
|
from certbot._internal import configuration
|
||||||
from certbot._internal import constants
|
from certbot._internal import constants
|
||||||
from certbot import crypto_util
|
from certbot import crypto_util
|
||||||
from certbot._internal import eff
|
from certbot._internal import eff
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import unittest
|
|||||||
import configobj
|
import configobj
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from certbot import configuration
|
from certbot._internal import configuration
|
||||||
from certbot import errors
|
from certbot import errors
|
||||||
from certbot.compat import os
|
from certbot.compat import os
|
||||||
from certbot.compat import filesystem
|
from certbot.compat import filesystem
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
"""Tests for certbot.configuration."""
|
"""Tests for certbot._internal.configuration."""
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
@@ -11,18 +11,18 @@ from certbot.tests import util as test_util
|
|||||||
|
|
||||||
|
|
||||||
class NamespaceConfigTest(test_util.ConfigTestCase):
|
class NamespaceConfigTest(test_util.ConfigTestCase):
|
||||||
"""Tests for certbot.configuration.NamespaceConfig."""
|
"""Tests for certbot._internal.configuration.NamespaceConfig."""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(NamespaceConfigTest, self).setUp()
|
super(NamespaceConfigTest, self).setUp()
|
||||||
self.config.foo = 'bar'
|
self.config.foo = 'bar' # pylint: disable=blacklisted-name
|
||||||
self.config.server = 'https://acme-server.org:443/new'
|
self.config.server = 'https://acme-server.org:443/new'
|
||||||
self.config.https_port = 1234
|
self.config.https_port = 1234
|
||||||
self.config.http01_port = 4321
|
self.config.http01_port = 4321
|
||||||
|
|
||||||
def test_init_same_ports(self):
|
def test_init_same_ports(self):
|
||||||
self.config.namespace.https_port = 4321
|
self.config.namespace.https_port = 4321
|
||||||
from certbot.configuration import NamespaceConfig
|
from certbot._internal.configuration import NamespaceConfig
|
||||||
self.assertRaises(errors.Error, NamespaceConfig, self.config.namespace)
|
self.assertRaises(errors.Error, NamespaceConfig, self.config.namespace)
|
||||||
|
|
||||||
def test_proxy_getattr(self):
|
def test_proxy_getattr(self):
|
||||||
@@ -38,7 +38,7 @@ class NamespaceConfigTest(test_util.ConfigTestCase):
|
|||||||
self.assertEqual(['user:pass@acme.server:443', 'p', 'a', 't', 'h'],
|
self.assertEqual(['user:pass@acme.server:443', 'p', 'a', 't', 'h'],
|
||||||
self.config.server_path.split(os.path.sep))
|
self.config.server_path.split(os.path.sep))
|
||||||
|
|
||||||
@mock.patch('certbot.configuration.constants')
|
@mock.patch('certbot._internal.configuration.constants')
|
||||||
def test_dynamic_dirs(self, mock_constants):
|
def test_dynamic_dirs(self, mock_constants):
|
||||||
mock_constants.ACCOUNTS_DIR = 'acc'
|
mock_constants.ACCOUNTS_DIR = 'acc'
|
||||||
mock_constants.BACKUP_DIR = 'backups'
|
mock_constants.BACKUP_DIR = 'backups'
|
||||||
@@ -70,7 +70,7 @@ class NamespaceConfigTest(test_util.ConfigTestCase):
|
|||||||
os.path.normpath(os.path.join(self.config.work_dir, 't')))
|
os.path.normpath(os.path.join(self.config.work_dir, 't')))
|
||||||
|
|
||||||
def test_absolute_paths(self):
|
def test_absolute_paths(self):
|
||||||
from certbot.configuration import NamespaceConfig
|
from certbot._internal.configuration import NamespaceConfig
|
||||||
|
|
||||||
config_base = "foo"
|
config_base = "foo"
|
||||||
work_base = "bar"
|
work_base = "bar"
|
||||||
@@ -103,7 +103,7 @@ class NamespaceConfigTest(test_util.ConfigTestCase):
|
|||||||
self.assertTrue(os.path.isabs(config.key_dir))
|
self.assertTrue(os.path.isabs(config.key_dir))
|
||||||
self.assertTrue(os.path.isabs(config.temp_checkpoint_dir))
|
self.assertTrue(os.path.isabs(config.temp_checkpoint_dir))
|
||||||
|
|
||||||
@mock.patch('certbot.configuration.constants')
|
@mock.patch('certbot._internal.configuration.constants')
|
||||||
def test_renewal_dynamic_dirs(self, mock_constants):
|
def test_renewal_dynamic_dirs(self, mock_constants):
|
||||||
mock_constants.ARCHIVE_DIR = 'a'
|
mock_constants.ARCHIVE_DIR = 'a'
|
||||||
mock_constants.LIVE_DIR = 'l'
|
mock_constants.LIVE_DIR = 'l'
|
||||||
@@ -118,7 +118,7 @@ class NamespaceConfigTest(test_util.ConfigTestCase):
|
|||||||
self.config.config_dir, 'renewal_configs'))
|
self.config.config_dir, 'renewal_configs'))
|
||||||
|
|
||||||
def test_renewal_absolute_paths(self):
|
def test_renewal_absolute_paths(self):
|
||||||
from certbot.configuration import NamespaceConfig
|
from certbot._internal.configuration import NamespaceConfig
|
||||||
|
|
||||||
config_base = "foo"
|
config_base = "foo"
|
||||||
work_base = "bar"
|
work_base = "bar"
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ from acme.magic_typing import List # pylint: disable=unused-import, no-name-in-
|
|||||||
import certbot.tests.util as test_util
|
import certbot.tests.util as test_util
|
||||||
from certbot._internal import account
|
from certbot._internal import account
|
||||||
from certbot import cli
|
from certbot import cli
|
||||||
from certbot import configuration
|
from certbot._internal import configuration
|
||||||
from certbot._internal import constants
|
from certbot._internal import constants
|
||||||
from certbot import crypto_util
|
from certbot import crypto_util
|
||||||
from certbot import errors
|
from certbot import errors
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import mock
|
|||||||
|
|
||||||
from acme import challenges
|
from acme import challenges
|
||||||
|
|
||||||
from certbot import configuration
|
from certbot._internal import configuration
|
||||||
from certbot import errors
|
from certbot import errors
|
||||||
from certbot._internal import storage
|
from certbot._internal import storage
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ from six.moves import reload_module # pylint: disable=import-error
|
|||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
from cryptography.hazmat.primitives import serialization
|
from cryptography.hazmat.primitives import serialization
|
||||||
|
|
||||||
from certbot import configuration
|
from certbot._internal import configuration
|
||||||
from certbot._internal import constants
|
from certbot._internal import constants
|
||||||
from certbot import interfaces
|
from certbot import interfaces
|
||||||
from certbot._internal import lock
|
from certbot._internal import lock
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
:mod:`certbot.configuration`
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
.. automodule:: certbot.configuration
|
|
||||||
:members:
|
|
||||||
Reference in New Issue
Block a user