mirror of
https://github.com/certbot/certbot.git
synced 2026-06-06 07:12:54 -04: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:
parent
595b1b212e
commit
46d5f7a860
14 changed files with 62 additions and 67 deletions
|
|
@ -6,7 +6,7 @@ import subprocess
|
|||
import mock
|
||||
import zope.interface
|
||||
|
||||
from certbot import configuration
|
||||
from certbot._internal import configuration
|
||||
from certbot import errors as le_errors
|
||||
from certbot import util as certbot_util
|
||||
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 certbot import configuration
|
||||
from certbot._internal import configuration
|
||||
from certbot_nginx import configurator
|
||||
from certbot_nginx import constants
|
||||
from certbot_compatibility_test import errors
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class NginxConfiguratorTest(util.NginxTest):
|
|||
def setUp(self):
|
||||
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)
|
||||
|
||||
@mock.patch("certbot_nginx.configurator.util.exe_exists")
|
||||
|
|
@ -935,7 +935,7 @@ class InstallSslOptionsConfTest(util.NginxTest):
|
|||
def setUp(self):
|
||||
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)
|
||||
|
||||
def _call(self):
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class HttpPerformTest(util.NginxTest):
|
|||
def setUp(self):
|
||||
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)
|
||||
|
||||
from certbot_nginx import http_01
|
||||
|
|
|
|||
|
|
@ -2,14 +2,12 @@
|
|||
import copy
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
import josepy as jose
|
||||
import mock
|
||||
import pkg_resources
|
||||
import zope.component
|
||||
|
||||
from certbot import configuration
|
||||
from certbot import util
|
||||
from certbot.compat import os
|
||||
from certbot.plugins import common
|
||||
|
|
@ -19,11 +17,14 @@ from certbot_nginx import configurator
|
|||
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):
|
||||
super(NginxTest, self).setUp()
|
||||
|
||||
self.configuration = self.config
|
||||
self.config = None
|
||||
|
||||
self.temp_dir, self.config_dir, self.work_dir = common.dir_setup(
|
||||
"etc_nginx", "certbot_nginx.tests")
|
||||
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.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):
|
||||
"""Gets the filename of a test data file."""
|
||||
|
|
@ -53,43 +90,6 @@ def get_data_filename(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):
|
||||
"""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.
|
||||
|
||||
: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):
|
||||
|
|
@ -43,7 +43,7 @@ def rename_lineage(config):
|
|||
"""Rename the specified lineage to the new name.
|
||||
|
||||
:param config: Configuration.
|
||||
:type config: :class:`certbot.configuration.NamespaceConfig`
|
||||
:type config: :class:`certbot._internal.configuration.NamespaceConfig`
|
||||
|
||||
"""
|
||||
disp = zope.component.getUtility(interfaces.IDisplay)
|
||||
|
|
@ -70,7 +70,7 @@ def certificates(config):
|
|||
"""Display information about certs configured with Certbot
|
||||
|
||||
:param config: Configuration.
|
||||
:type config: :class:`certbot.configuration.NamespaceConfig`
|
||||
:type config: :class:`certbot._internal.configuration.NamespaceConfig`
|
||||
"""
|
||||
parsed_certs = []
|
||||
parse_failures = []
|
||||
|
|
@ -136,7 +136,7 @@ def find_duplicative_certs(config, domains):
|
|||
undefined.
|
||||
|
||||
:param config: Configuration.
|
||||
:type config: :class:`certbot.configuration.NamespaceConfig`
|
||||
:type config: :class:`certbot._internal.configuration.NamespaceConfig`
|
||||
:param domains: List of domain names
|
||||
:type domains: `list` of `str`
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ from certbot._internal import account
|
|||
from certbot._internal import cert_manager
|
||||
from certbot import cli
|
||||
from certbot._internal import client
|
||||
from certbot import configuration
|
||||
from certbot._internal import configuration
|
||||
from certbot._internal import constants
|
||||
from certbot import crypto_util
|
||||
from certbot._internal import eff
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import unittest
|
|||
import configobj
|
||||
import mock
|
||||
|
||||
from certbot import configuration
|
||||
from certbot._internal import configuration
|
||||
from certbot import errors
|
||||
from certbot.compat import os
|
||||
from certbot.compat import filesystem
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
"""Tests for certbot.configuration."""
|
||||
"""Tests for certbot._internal.configuration."""
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
|
|
@ -11,18 +11,18 @@ from certbot.tests import util as test_util
|
|||
|
||||
|
||||
class NamespaceConfigTest(test_util.ConfigTestCase):
|
||||
"""Tests for certbot.configuration.NamespaceConfig."""
|
||||
"""Tests for certbot._internal.configuration.NamespaceConfig."""
|
||||
|
||||
def setUp(self):
|
||||
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.https_port = 1234
|
||||
self.config.http01_port = 4321
|
||||
|
||||
def test_init_same_ports(self):
|
||||
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)
|
||||
|
||||
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.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):
|
||||
mock_constants.ACCOUNTS_DIR = 'acc'
|
||||
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')))
|
||||
|
||||
def test_absolute_paths(self):
|
||||
from certbot.configuration import NamespaceConfig
|
||||
from certbot._internal.configuration import NamespaceConfig
|
||||
|
||||
config_base = "foo"
|
||||
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.temp_checkpoint_dir))
|
||||
|
||||
@mock.patch('certbot.configuration.constants')
|
||||
@mock.patch('certbot._internal.configuration.constants')
|
||||
def test_renewal_dynamic_dirs(self, mock_constants):
|
||||
mock_constants.ARCHIVE_DIR = 'a'
|
||||
mock_constants.LIVE_DIR = 'l'
|
||||
|
|
@ -118,7 +118,7 @@ class NamespaceConfigTest(test_util.ConfigTestCase):
|
|||
self.config.config_dir, 'renewal_configs'))
|
||||
|
||||
def test_renewal_absolute_paths(self):
|
||||
from certbot.configuration import NamespaceConfig
|
||||
from certbot._internal.configuration import NamespaceConfig
|
||||
|
||||
config_base = "foo"
|
||||
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
|
||||
from certbot._internal import account
|
||||
from certbot import cli
|
||||
from certbot import configuration
|
||||
from certbot._internal import configuration
|
||||
from certbot._internal import constants
|
||||
from certbot import crypto_util
|
||||
from certbot import errors
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import mock
|
|||
|
||||
from acme import challenges
|
||||
|
||||
from certbot import configuration
|
||||
from certbot._internal import configuration
|
||||
from certbot import errors
|
||||
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.primitives import serialization
|
||||
|
||||
from certbot import configuration
|
||||
from certbot._internal import configuration
|
||||
from certbot._internal import constants
|
||||
from certbot import interfaces
|
||||
from certbot._internal import lock
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
:mod:`certbot.configuration`
|
||||
--------------------------------
|
||||
|
||||
.. automodule:: certbot.configuration
|
||||
:members:
|
||||
Loading…
Reference in a new issue