use updated plugins paths

This commit is contained in:
Will Greenberg
2026-03-17 17:58:53 -07:00
parent 2f647637b0
commit 998f72443c
60 changed files with 503 additions and 503 deletions
@@ -1,6 +1,6 @@
""" Entry point for Apache Plugin """
from certbot._internal.apache import entrypoint
from certbot._internal.plugins.apache import entrypoint
ENTRYPOINT = entrypoint.get_configurator()
@@ -2,10 +2,10 @@
# Avoid false warnings because certbot packages are not installed in the thread that executes
# the coverage: indeed, certbot is launched as a CLI from a subprocess.
disable_warnings = module-not-imported,no-data-collected
omit = **/*_test.py,**/tests/*,**/dns_common*,**/certbot/_internal/nginx/parser_obj.py
omit = **/*_test.py,**/tests/*,**/dns_common*,**/certbot/_internal/plugins/nginx/parser_obj.py
patch = subprocess
parallel = True
[report]
# Exclude unit tests in coverage during integration tests.
omit = **/*_test.py,**/tests/*,**/dns_common*,**/certbot/_internal/nginx/parser_obj.py
omit = **/*_test.py,**/tests/*,**/dns_common*,**/certbot/_internal/plugins/nginx/parser_obj.py
@@ -3,7 +3,7 @@
import os
import sys
from certbot._internal.nginx import nginxparser
from certbot._internal.plugins.nginx import nginxparser
def roundtrip(stuff):
@@ -24,7 +24,7 @@ class Proxy(configurators_common.Proxy):
self.modules = self.server_root = self.test_conf = self.version = None
patch = mock.patch(
"certbot._internal.apache.configurator.display_ops.select_vhost")
"certbot._internal.plugins.apache.configurator.display_ops.select_vhost")
mock_display = patch.start()
mock_display.side_effect = le_errors.PluginError(
"Unable to determine vhost")
@@ -4,8 +4,8 @@ import shutil
import subprocess
from certbot import configuration
from certbot._internal.nginx import configurator
from certbot._internal.nginx import constants
from certbot._internal.plugins.nginx import configurator
from certbot._internal.plugins.nginx import constants
from certbot_compatibility_test import errors
from certbot_compatibility_test import util
from certbot_compatibility_test.configurators import common as configurators_common
@@ -1,6 +1,6 @@
""" Entry point for Apache Plugin """
from certbot._internal.nginx import configurator
from certbot._internal.plugins.nginx import configurator
ENTRYPOINT = configurator.NginxConfigurator
+5 -5
View File
@@ -4,11 +4,11 @@ include LICENSE.txt
recursive-include docs *
recursive-include examples *
recursive-include src/certbot/tests/testdata *
recursive-include src/certbot/_internal/nginx/tls_configs *.conf
recursive-include src/certbot/_internal/nginx/tests/testdata *
recursive-include src/_internal/apache/augeas_lens *.aug
recursive-include src/_internal/apache/tls_configs *.conf
recursive-include src/_internal/apache/tests/testdata *
recursive-include src/certbot/_internal/plugins/nginx/tls_configs *.conf
recursive-include src/certbot/_internal/plugins/nginx/tests/testdata *
recursive-include src/_internal/plugins/apache/augeas_lens *.aug
recursive-include src/_internal/plugins/apache/tls_configs *.conf
recursive-include src/_internal/plugins/apache/tests/testdata *
include src/certbot/ssl-dhparams.pem
include src/certbot/py.typed
global-exclude __pycache__
@@ -3,10 +3,10 @@ from typing import Any
from typing import Iterable
from typing import Optional
from certbot._internal.apache import assertions
from certbot._internal.apache import interfaces
from certbot._internal.apache import parsernode_util as util
from certbot._internal.apache.interfaces import ParserNode
from certbot._internal.plugins.apache import assertions
from certbot._internal.plugins.apache import interfaces
from certbot._internal.plugins.apache import parsernode_util as util
from certbot._internal.plugins.apache.interfaces import ParserNode
class ApacheParserNode(interfaces.ParserNode):
@@ -5,11 +5,11 @@ from typing import Iterable
from typing import Optional
from typing import Union
from certbot._internal.apache import interfaces
from certbot._internal.apache.interfaces import CommentNode
from certbot._internal.apache.interfaces import DirectiveNode
from certbot._internal.apache.interfaces import ParserNode
from certbot._internal.apache.obj import VirtualHost
from certbot._internal.plugins.apache import interfaces
from certbot._internal.plugins.apache.interfaces import CommentNode
from certbot._internal.plugins.apache.interfaces import DirectiveNode
from certbot._internal.plugins.apache.interfaces import ParserNode
from certbot._internal.plugins.apache.obj import VirtualHost
PASS = "CERTBOT_PASS_ASSERT"
@@ -72,11 +72,11 @@ from typing import Union
from certbot import errors
from certbot.compat import os
from certbot._internal.apache import apache_util
from certbot._internal.apache import assertions
from certbot._internal.apache import interfaces
from certbot._internal.apache import parser
from certbot._internal.apache import parsernode_util as util
from certbot._internal.plugins.apache import apache_util
from certbot._internal.plugins.apache import assertions
from certbot._internal.plugins.apache import interfaces
from certbot._internal.plugins.apache import parser
from certbot._internal.plugins.apache import parsernode_util as util
class AugeasParserNode(interfaces.ParserNode):
@@ -26,15 +26,15 @@ from certbot.interfaces import RenewableCert
from certbot.plugins import common
from certbot.plugins.enhancements import AutoHSTSEnhancement
from certbot.plugins.util import path_surgery
from certbot._internal.apache import apache_util
from certbot._internal.apache import assertions
from certbot._internal.apache import constants
from certbot._internal.apache import display_ops
from certbot._internal.apache import dualparser
from certbot._internal.apache import http_01
from certbot._internal.apache import obj
from certbot._internal.apache import parser
from certbot._internal.apache.apacheparser import ApacheBlockNode
from certbot._internal.plugins.apache import apache_util
from certbot._internal.plugins.apache import assertions
from certbot._internal.plugins.apache import constants
from certbot._internal.plugins.apache import display_ops
from certbot._internal.plugins.apache import dualparser
from certbot._internal.plugins.apache import http_01
from certbot._internal.plugins.apache import obj
from certbot._internal.plugins.apache import parser
from certbot._internal.plugins.apache.apacheparser import ApacheBlockNode
try:
import apacheconfig
@@ -126,11 +126,11 @@ class ApacheConfigurator(common.Configurator):
:type config: certbot.configuration.NamespaceConfig
:ivar parser: Handles low level parsing
:type parser: :class:`~certbot._internal.apache.parser`
:type parser: :class:`~certbot._internal.plugins.apache.parser`
:ivar tup version: version of Apache
:ivar list vhosts: All vhosts found in the configuration
(:class:`list` of :class:`~certbot._internal.apache.obj.VirtualHost`)
(:class:`list` of :class:`~certbot._internal.plugins.apache.obj.VirtualHost`)
:ivar dict assoc: Mapping between domains and vhosts
@@ -542,7 +542,7 @@ class ApacheConfigurator(common.Configurator):
counterpart, should one get created
:returns: List of VirtualHosts or None
:rtype: `list` of :class:`~certbot._internal.apache.obj.VirtualHost`
:rtype: `list` of :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
"""
if util.is_wildcard_domain(domain):
@@ -720,7 +720,7 @@ class ApacheConfigurator(common.Configurator):
counterpart, should one get created
:returns: vhost associated with name
:rtype: :class:`~certbot._internal.apache.obj.VirtualHost`
:rtype: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
:raises .errors.PluginError: If no vhost is available or chosen
@@ -823,7 +823,7 @@ class ApacheConfigurator(common.Configurator):
:param str target_name: domain handled by the desired vhost
:param vhosts: vhosts to consider
:type vhosts: `collections.Iterable` of :class:`~certbot._internal.apache.obj.VirtualHost`
:type vhosts: `collections.Iterable` of :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
:param bool filter_defaults: whether a vhost with a _default_
addr is acceptable
@@ -965,7 +965,7 @@ class ApacheConfigurator(common.Configurator):
"""Helper function for get_virtual_hosts().
:param host: In progress vhost whose names will be added
:type host: :class:`~certbot._internal.apache.obj.VirtualHost`
:type host: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
"""
@@ -984,7 +984,7 @@ class ApacheConfigurator(common.Configurator):
:param str path: Augeas path to virtual host
:returns: newly created vhost
:rtype: :class:`~certbot._internal.apache.obj.VirtualHost`
:rtype: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
"""
addrs: set[obj.Addr] = set()
@@ -1050,7 +1050,7 @@ class ApacheConfigurator(common.Configurator):
def get_virtual_hosts_v1(self) -> list[obj.VirtualHost]:
"""Returns list of virtual hosts found in the Apache configuration.
:returns: List of :class:`~certbot._internal.apache.obj.VirtualHost`
:returns: List of :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
objects found in configuration
:rtype: list
@@ -1103,7 +1103,7 @@ class ApacheConfigurator(common.Configurator):
def get_virtual_hosts_v2(self) -> list[obj.VirtualHost]:
"""Returns list of virtual hosts found in the Apache configuration using
ParserNode interface.
:returns: List of :class:`~certbot._internal.apache.obj.VirtualHost`
:returns: List of :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
objects found in configuration
:rtype: list
"""
@@ -1122,7 +1122,7 @@ class ApacheConfigurator(common.Configurator):
interfaces.
:param ApacheBlockNode node: The BlockNode object of VirtualHost block
:returns: newly created vhost
:rtype: :class:`~certbot._internal.apache.obj.VirtualHost`
:rtype: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
"""
addrs = set()
for param in node.parameters:
@@ -1164,7 +1164,7 @@ class ApacheConfigurator(common.Configurator):
def _populate_vhost_names_v2(self, vhost: obj.VirtualHost) -> None:
"""Helper function that populates the VirtualHost names.
:param host: In progress vhost whose names will be added
:type host: :class:`~certbot._internal.apache.obj.VirtualHost`
:type host: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
"""
if not vhost.node:
raise errors.PluginError("Current VirtualHost has no node.") # pragma: no cover
@@ -1352,10 +1352,10 @@ class ApacheConfigurator(common.Configurator):
.. note:: This function saves the configuration
:param nonssl_vhost: Valid VH that doesn't have SSLEngine on
:type nonssl_vhost: :class:`~certbot._internal.apache.obj.VirtualHost`
:type nonssl_vhost: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
:returns: SSL vhost
:rtype: :class:`~certbot._internal.apache.obj.VirtualHost`
:rtype: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
:raises .errors.PluginError: If more than one virtual host is in
the file or if plugin is unable to write/read vhost files.
@@ -1720,7 +1720,7 @@ class ApacheConfigurator(common.Configurator):
:param str id_str: Id string for matching
:returns: The matched VirtualHost
:rtype: :class:`~certbot._internal.apache.obj.VirtualHost`
:rtype: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
:raises .errors.PluginError: If no VirtualHost is found
"""
@@ -1737,7 +1737,7 @@ class ApacheConfigurator(common.Configurator):
used for keeping track of VirtualHost directive over time.
:param vhost: Virtual host to add the id
:type vhost: :class:`~certbot._internal.apache.obj.VirtualHost`
:type vhost: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
:returns: The unique ID or None
:rtype: str or None
@@ -1759,7 +1759,7 @@ class ApacheConfigurator(common.Configurator):
If ID already exists, returns that instead.
:param vhost: Virtual host to add or find the id
:type vhost: :class:`~certbot._internal.apache.obj.VirtualHost`
:type vhost: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
:returns: The unique ID for vhost
:rtype: str or None
@@ -1840,7 +1840,7 @@ class ApacheConfigurator(common.Configurator):
"""Increase the AutoHSTS max-age value
:param vhost: Virtual host object to modify
:type vhost: :class:`~certbot._internal.apache.obj.VirtualHost`
:type vhost: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
:param str id_str: The unique ID string of VirtualHost
@@ -1923,7 +1923,7 @@ class ApacheConfigurator(common.Configurator):
.. note:: This function saves the configuration
:param ssl_vhost: Destination of traffic, an ssl enabled vhost
:type ssl_vhost: :class:`~certbot._internal.apache.obj.VirtualHost`
:type ssl_vhost: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
:param unused_options: Not currently used
:type unused_options: Not Available
@@ -1969,7 +1969,7 @@ class ApacheConfigurator(common.Configurator):
.. note:: This function saves the configuration
:param ssl_vhost: Destination of traffic, an ssl enabled vhost
:type ssl_vhost: :class:`~certbot._internal.apache.obj.VirtualHost`
:type ssl_vhost: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
:param header_substring: string that uniquely identifies a header.
e.g: Strict-Transport-Security, Upgrade-Insecure-Requests.
@@ -2003,7 +2003,7 @@ class ApacheConfigurator(common.Configurator):
contains the string header_substring.
:param ssl_vhost: vhost to check
:type vhost: :class:`~certbot._internal.apache.obj.VirtualHost`
:type vhost: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
:param header_substring: string that uniquely identifies a header.
e.g: Strict-Transport-Security, Upgrade-Insecure-Requests.
@@ -2040,7 +2040,7 @@ class ApacheConfigurator(common.Configurator):
.. note:: This function saves the configuration
:param ssl_vhost: Destination of traffic, an ssl enabled vhost
:type ssl_vhost: :class:`~certbot._internal.apache.obj.VirtualHost`
:type ssl_vhost: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
:param unused_options: Not currently used
:type unused_options: Not Available
@@ -2120,7 +2120,7 @@ class ApacheConfigurator(common.Configurator):
delete certbot's old rewrite rules and set the new one instead.
:param vhost: vhost to check
:type vhost: :class:`~certbot._internal.apache.obj.VirtualHost`
:type vhost: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
:raises errors.PluginEnhancementAlreadyPresent: When the exact
certbot redirection WriteRule exists in virtual host.
@@ -2159,7 +2159,7 @@ class ApacheConfigurator(common.Configurator):
"""Checks if there exists a RewriteRule directive in vhost
:param vhost: vhost to check
:type vhost: :class:`~certbot._internal.apache.obj.VirtualHost`
:type vhost: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
:returns: True if a RewriteRule directive exists.
:rtype: bool
@@ -2173,7 +2173,7 @@ class ApacheConfigurator(common.Configurator):
"""Checks if a RewriteEngine directive is on
:param vhost: vhost to check
:type vhost: :class:`~certbot._internal.apache.obj.VirtualHost`
:type vhost: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
"""
rewrite_engine_path_list = self.parser.find_dir("RewriteEngine", "on", start=vhost.path)
@@ -2189,7 +2189,7 @@ class ApacheConfigurator(common.Configurator):
"""Creates an http_vhost specifically to redirect for the ssl_vhost.
:param ssl_vhost: ssl vhost
:type ssl_vhost: :class:`~certbot._internal.apache.obj.VirtualHost`
:type ssl_vhost: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
"""
text = self._get_redirect_config_str(ssl_vhost)
@@ -2308,7 +2308,7 @@ class ApacheConfigurator(common.Configurator):
of this method where available.
:param vhost: vhost to enable
:type vhost: :class:`~certbot._internal.apache.obj.VirtualHost`
:type vhost: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
:raises .errors.NotSupportedError: If filesystem layout is not
supported.
@@ -2569,7 +2569,7 @@ class ApacheConfigurator(common.Configurator):
"""Do the initial AutoHSTS deployment to a vhost
:param ssl_vhost: The VirtualHost object to deploy the AutoHSTS
:type ssl_vhost: :class:`~certbot._internal.apache.obj.VirtualHost` or None
:type ssl_vhost: :class:`~certbot._internal.plugins.apache.obj.VirtualHost` or None
:raises errors.PluginEnhancementAlreadyPresent: When already enhanced
@@ -7,7 +7,7 @@ from typing import Sequence
from certbot import errors
from certbot.compat import os
from certbot.display import util as display_util
from certbot._internal.apache.obj import VirtualHost
from certbot._internal.plugins.apache.obj import VirtualHost
logger = logging.getLogger(__name__)
@@ -83,7 +83,7 @@ def _vhost_menu(domain: str, vhosts: Iterable[VirtualHost]) -> tuple[str, int]:
if free_chars < 2:
logger.debug("Display size is too small for "
"certbot._internal.apache.display_ops._vhost_menu()")
"certbot._internal.plugins.apache.display_ops._vhost_menu()")
# This runs the edge off the screen, but it doesn't cause an "error"
filename_size = 1
disp_name_size = 1
@@ -6,14 +6,14 @@ from typing import Optional
from typing import TYPE_CHECKING
from typing import TypeVar
from certbot._internal.apache import apacheparser
from certbot._internal.apache import assertions
from certbot._internal.apache import augeasparser
from certbot._internal.apache import interfaces
from certbot._internal.plugins.apache import apacheparser
from certbot._internal.plugins.apache import assertions
from certbot._internal.plugins.apache import augeasparser
from certbot._internal.plugins.apache import interfaces
if TYPE_CHECKING:
from certbot._internal.apache.apacheparser import ApacheParserNode # pragma: no cover
from certbot._internal.apache.augeasparser import AugeasParserNode # pragma: no cover
from certbot._internal.plugins.apache.apacheparser import ApacheParserNode # pragma: no cover
from certbot._internal.plugins.apache.augeasparser import AugeasParserNode # pragma: no cover
GenericAugeasParserNode = TypeVar("GenericAugeasParserNode", bound="AugeasParserNode")
GenericApacheParserNode = TypeVar("GenericApacheParserNode", bound="ApacheParserNode")
@@ -1,16 +1,16 @@
""" Entry point for Apache Plugin """
from certbot import util
from certbot._internal.apache import configurator
from certbot._internal.apache import override_alpine
from certbot._internal.apache import override_arch
from certbot._internal.apache import override_centos
from certbot._internal.apache import override_darwin
from certbot._internal.apache import override_debian
from certbot._internal.apache import override_fedora
from certbot._internal.apache import override_gentoo
from certbot._internal.apache import override_suse
from certbot._internal.apache import override_void
from certbot._internal.plugins.apache import configurator
from certbot._internal.plugins.apache import override_alpine
from certbot._internal.plugins.apache import override_arch
from certbot._internal.plugins.apache import override_centos
from certbot._internal.plugins.apache import override_darwin
from certbot._internal.plugins.apache import override_debian
from certbot._internal.plugins.apache import override_fedora
from certbot._internal.plugins.apache import override_gentoo
from certbot._internal.plugins.apache import override_suse
from certbot._internal.plugins.apache import override_void
OVERRIDE_CLASSES: dict[str, type[configurator.ApacheConfigurator]] = {
"alpine": override_alpine.AlpineConfigurator,
@@ -10,11 +10,11 @@ from certbot.achallenges import KeyAuthorizationAnnotatedChallenge
from certbot.compat import filesystem
from certbot.compat import os
from certbot.plugins import common
from certbot._internal.apache.obj import VirtualHost
from certbot._internal.apache.parser import get_aug_path
from certbot._internal.plugins.apache.obj import VirtualHost
from certbot._internal.plugins.apache.parser import get_aug_path
if TYPE_CHECKING:
from certbot._internal.apache.configurator import ApacheConfigurator # pragma: no cover
from certbot._internal.plugins.apache.configurator import ApacheConfigurator # pragma: no cover
logger = logging.getLogger(__name__)
@@ -6,9 +6,9 @@ from typing import Optional
from typing import Union
from certbot.plugins import common
from certbot._internal.apache.apacheparser import ApacheBlockNode
from certbot._internal.apache.augeasparser import AugeasBlockNode
from certbot._internal.apache.dualparser import DualBlockNode
from certbot._internal.plugins.apache.apacheparser import ApacheBlockNode
from certbot._internal.plugins.apache.augeasparser import AugeasBlockNode
from certbot._internal.plugins.apache.dualparser import DualBlockNode
class Addr(common.Addr):
@@ -27,7 +27,7 @@ class Addr(common.Addr):
return False
def __repr__(self) -> str:
return f"certbot._internal.apache.obj.Addr({repr(self.tup)})"
return f"certbot._internal.plugins.apache.obj.Addr({repr(self.tup)})"
def __hash__(self) -> int: # pylint: disable=useless-super-delegation
# Python 3 requires explicit overridden for __hash__ if __eq__ or
@@ -1,6 +1,6 @@
""" Distribution specific override class for Alpine Linux """
from certbot._internal.apache import configurator
from certbot._internal.apache.configurator import OsOptions
from certbot._internal.plugins.apache import configurator
from certbot._internal.plugins.apache.configurator import OsOptions
class AlpineConfigurator(configurator.ApacheConfigurator):
@@ -1,6 +1,6 @@
""" Distribution specific override class for Arch Linux """
from certbot._internal.apache import configurator
from certbot._internal.apache.configurator import OsOptions
from certbot._internal.plugins.apache import configurator
from certbot._internal.plugins.apache.configurator import OsOptions
class ArchConfigurator(configurator.ApacheConfigurator):
@@ -4,10 +4,10 @@ from typing import Any
from certbot import errors
from certbot import util
from certbot._internal.apache import apache_util
from certbot._internal.apache import configurator
from certbot._internal.apache import parser
from certbot._internal.apache.configurator import OsOptions
from certbot._internal.plugins.apache import apache_util
from certbot._internal.plugins.apache import configurator
from certbot._internal.plugins.apache import parser
from certbot._internal.plugins.apache.configurator import OsOptions
logger = logging.getLogger(__name__)
@@ -1,6 +1,6 @@
""" Distribution specific override class for macOS """
from certbot._internal.apache import configurator
from certbot._internal.apache.configurator import OsOptions
from certbot._internal.plugins.apache import configurator
from certbot._internal.plugins.apache.configurator import OsOptions
class DarwinConfigurator(configurator.ApacheConfigurator):
@@ -5,10 +5,10 @@ from certbot import errors
from certbot import util
from certbot.compat import filesystem
from certbot.compat import os
from certbot._internal.apache import apache_util
from certbot._internal.apache import configurator
from certbot._internal.apache.configurator import OsOptions
from certbot._internal.apache.obj import VirtualHost
from certbot._internal.plugins.apache import apache_util
from certbot._internal.plugins.apache import configurator
from certbot._internal.plugins.apache.configurator import OsOptions
from certbot._internal.plugins.apache.obj import VirtualHost
logger = logging.getLogger(__name__)
@@ -30,7 +30,7 @@ class DebianConfigurator(configurator.ApacheConfigurator):
modules are enabled appropriately.
:param vhost: vhost to enable
:type vhost: :class:`~certbot._internal.apache.obj.VirtualHost`
:type vhost: :class:`~certbot._internal.plugins.apache.obj.VirtualHost`
:raises .errors.NotSupportedError: If filesystem layout is not
supported.
@@ -3,10 +3,10 @@ from typing import Any
from certbot import errors
from certbot import util
from certbot._internal.apache import apache_util
from certbot._internal.apache import configurator
from certbot._internal.apache import parser
from certbot._internal.apache.configurator import OsOptions
from certbot._internal.plugins.apache import apache_util
from certbot._internal.plugins.apache import configurator
from certbot._internal.plugins.apache import parser
from certbot._internal.plugins.apache.configurator import OsOptions
class FedoraConfigurator(configurator.ApacheConfigurator):
@@ -1,10 +1,10 @@
""" Distribution specific override class for Gentoo Linux """
from typing import Any
from certbot._internal.apache import apache_util
from certbot._internal.apache import configurator
from certbot._internal.apache import parser
from certbot._internal.apache.configurator import OsOptions
from certbot._internal.plugins.apache import apache_util
from certbot._internal.plugins.apache import configurator
from certbot._internal.plugins.apache import parser
from certbot._internal.plugins.apache.configurator import OsOptions
class GentooConfigurator(configurator.ApacheConfigurator):
@@ -1,6 +1,6 @@
""" Distribution specific override class for OpenSUSE """
from certbot._internal.apache import configurator
from certbot._internal.apache.configurator import OsOptions
from certbot._internal.plugins.apache import configurator
from certbot._internal.plugins.apache.configurator import OsOptions
class OpenSUSEConfigurator(configurator.ApacheConfigurator):
@@ -1,6 +1,6 @@
""" Distribution specific override class for Void Linux """
from certbot._internal.apache import configurator
from certbot._internal.apache.configurator import OsOptions
from certbot._internal.plugins.apache import configurator
from certbot._internal.plugins.apache.configurator import OsOptions
class VoidConfigurator(configurator.ApacheConfigurator):
@@ -12,11 +12,11 @@ from typing import Union
from certbot import errors
from certbot.compat import os
from certbot._internal.apache import apache_util
from certbot._internal.apache import constants
from certbot._internal.plugins.apache import apache_util
from certbot._internal.plugins.apache import constants
if TYPE_CHECKING:
from certbot._internal.apache.configurator import ApacheConfigurator # pragma: no cover
from certbot._internal.plugins.apache.configurator import ApacheConfigurator # pragma: no cover
try:
from augeas import Augeas
@@ -3,7 +3,7 @@ from typing import Any
from typing import Iterable
from typing import Optional
from certbot._internal.apache.interfaces import ParserNode
from certbot._internal.plugins.apache.interfaces import ParserNode
def validate_kwargs(kwargs: dict[str, Any], required_names: Iterable[str]) -> dict[str, Any]:
@@ -5,9 +5,9 @@ from unittest import mock
import pytest
from certbot import errors
from certbot._internal.apache import assertions
from certbot._internal.apache import augeasparser
from certbot._internal.apache.tests import util
from certbot._internal.plugins.apache import assertions
from certbot._internal.plugins.apache import augeasparser
from certbot._internal.plugins.apache.tests import util
def _get_augeasnode_mock(filepath):
@@ -28,7 +28,7 @@ class AugeasParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-
super().setUp()
with mock.patch(
"certbot._internal.apache.configurator.ApacheConfigurator.get_parsernode_root"
"certbot._internal.plugins.apache.configurator.ApacheConfigurator.get_parsernode_root"
) as mock_parsernode:
mock_parsernode.side_effect = _get_augeasnode_mock(
os.path.join(self.config_path, "apache2.conf"))
@@ -40,19 +40,19 @@ class AugeasParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-
self.temp_dir, "debian_apache_2_4/multiple_vhosts")
def test_save(self):
with mock.patch('certbot._internal.apache.parser.ApacheParser.save') as mock_save:
with mock.patch('certbot._internal.plugins.apache.parser.ApacheParser.save') as mock_save:
self.config.parser_root.save("A save message")
assert mock_save.called is True
assert mock_save.call_args[0][0] == "A save message"
def test_unsaved_files(self):
with mock.patch('certbot._internal.apache.parser.ApacheParser.unsaved_files') as mock_uf:
with mock.patch('certbot._internal.plugins.apache.parser.ApacheParser.unsaved_files') as mock_uf:
mock_uf.return_value = ["first", "second"]
files = self.config.parser_root.unsaved_files()
assert files == ["first", "second"]
def test_get_block_node_name(self):
from certbot._internal.apache.augeasparser import AugeasBlockNode
from certbot._internal.plugins.apache.augeasparser import AugeasBlockNode
block = AugeasBlockNode(
name=assertions.PASS,
ancestor=None,
@@ -122,9 +122,9 @@ class AugeasParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-
assert "going_to_set_this" in names
def test_set_parameters_atinit(self):
from certbot._internal.apache.augeasparser import AugeasDirectiveNode
from certbot._internal.plugins.apache.augeasparser import AugeasDirectiveNode
servernames = self.config.parser_root.find_directives("servername")
setparam = "certbot._internal.apache.augeasparser.AugeasDirectiveNode.set_parameters"
setparam = "certbot._internal.plugins.apache.augeasparser.AugeasDirectiveNode.set_parameters"
with mock.patch(setparam) as mock_set:
AugeasDirectiveNode(
name=servernames[0].name,
@@ -252,7 +252,7 @@ class AugeasParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-
assert vh.metadata["augeaspath"].endswith("VirtualHost[2]") is True
def test_node_init_error_bad_augeaspath(self):
from certbot._internal.apache.augeasparser import AugeasBlockNode
from certbot._internal.plugins.apache.augeasparser import AugeasBlockNode
parameters = {
"name": assertions.PASS,
"ancestor": None,
@@ -266,7 +266,7 @@ class AugeasParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-
AugeasBlockNode(**parameters)
def test_node_init_error_missing_augeaspath(self):
from certbot._internal.apache.augeasparser import AugeasBlockNode
from certbot._internal.plugins.apache.augeasparser import AugeasBlockNode
parameters = {
"name": assertions.PASS,
"ancestor": None,
@@ -1,5 +1,5 @@
# pylint: disable=too-many-lines
"""Test for certbot._internal.apache.configurator AutoHSTS functionality"""
"""Test for certbot._internal.plugins.apache.configurator AutoHSTS functionality"""
import re
import sys
from unittest import mock
@@ -7,8 +7,8 @@ from unittest import mock
import pytest
from certbot import errors
from certbot._internal.apache import constants
from certbot._internal.apache.tests import util
from certbot._internal.plugins.apache import constants
from certbot._internal.plugins.apache.tests import util
class AutoHSTSTest(util.ApacheTest):
@@ -39,23 +39,23 @@ class AutoHSTSTest(util.ApacheTest):
head.replace("arg[3]", "arg[4]"))
return None # pragma: no cover
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator.restart")
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator.enable_mod")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator.restart")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator.enable_mod")
def test_autohsts_enable_headers_mod(self, mock_enable, _restart):
self.config.parser.modules.pop("headers_module", None)
self.config.parser.modules.pop("mod_header.c", None)
self.config.enable_autohsts(mock.MagicMock(), ["ocspvhost.com"])
assert mock_enable.called is True
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator.restart")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator.restart")
def test_autohsts_deploy_already_exists(self, _restart):
self.config.enable_autohsts(mock.MagicMock(), ["ocspvhost.com"])
with pytest.raises(errors.PluginEnhancementAlreadyPresent):
self.config.enable_autohsts(mock.MagicMock(), ["ocspvhost.com"])
@mock.patch("certbot._internal.apache.constants.AUTOHSTS_FREQ", 0)
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator.restart")
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator.prepare")
@mock.patch("certbot._internal.plugins.apache.constants.AUTOHSTS_FREQ", 0)
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator.restart")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator.prepare")
def test_autohsts_increase(self, mock_prepare, _mock_restart):
self.config._prepared = False
maxage = "\"max-age={0}\""
@@ -73,8 +73,8 @@ class AutoHSTSTest(util.ApacheTest):
inc_val
assert mock_prepare.called is True
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator.restart")
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator._autohsts_increase")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator.restart")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator._autohsts_increase")
def test_autohsts_increase_noop(self, mock_increase, _restart):
maxage = "\"max-age={0}\""
initial_val = maxage.format(constants.AUTOHSTS_STEPS[0])
@@ -88,8 +88,8 @@ class AutoHSTSTest(util.ApacheTest):
assert mock_increase.called is False
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator.restart")
@mock.patch("certbot._internal.apache.constants.AUTOHSTS_FREQ", 0)
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator.restart")
@mock.patch("certbot._internal.plugins.apache.constants.AUTOHSTS_FREQ", 0)
def test_autohsts_increase_no_header(self, _restart):
self.config.enable_autohsts(mock.MagicMock(), ["ocspvhost.com"])
# Remove the header
@@ -100,8 +100,8 @@ class AutoHSTSTest(util.ApacheTest):
with pytest.raises(errors.PluginError):
self.config.update_autohsts(mock.MagicMock())
@mock.patch("certbot._internal.apache.constants.AUTOHSTS_FREQ", 0)
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator.restart")
@mock.patch("certbot._internal.plugins.apache.constants.AUTOHSTS_FREQ", 0)
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator.restart")
def test_autohsts_increase_and_make_permanent(self, _mock_restart):
maxage = "\"max-age={0}\""
max_val = maxage.format(constants.AUTOHSTS_PERMANENT)
@@ -127,7 +127,7 @@ class AutoHSTSTest(util.ApacheTest):
max_val
def test_autohsts_update_noop(self):
with mock.patch("certbot._internal.apache.configurator.time") as mock_time_module:
with mock.patch("certbot._internal.plugins.apache.configurator.time") as mock_time_module:
# Time mock is used to make sure that the execution does not
# continue when no autohsts entries exist in pluginstorage
self.config.update_autohsts(mock.MagicMock())
@@ -139,16 +139,16 @@ class AutoHSTSTest(util.ApacheTest):
# Make sure that the execution does not continue when no entries in store
assert self.config.storage.put.called is False
@mock.patch("certbot._internal.apache.display_ops.select_vhost")
@mock.patch("certbot._internal.plugins.apache.display_ops.select_vhost")
def test_autohsts_no_ssl_vhost(self, mock_select):
mock_select.return_value = self.vh_truth[0]
with mock.patch("certbot._internal.apache.configurator.logger.error") as mock_log:
with mock.patch("certbot._internal.plugins.apache.configurator.logger.error") as mock_log:
with pytest.raises(errors.PluginError):
self.config.enable_autohsts(mock.MagicMock(), "invalid.example.com")
assert "Certbot was not able to find SSL" in mock_log.call_args[0][0]
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator.restart")
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator.add_vhost_id")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator.restart")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator.add_vhost_id")
def test_autohsts_dont_enhance_twice(self, mock_id, _restart):
mock_id.return_value = "1234567"
self.config.enable_autohsts(mock.MagicMock(), ["ocspvhost.com", "ocspvhost.com"])
@@ -172,7 +172,7 @@ class AutoHSTSTest(util.ApacheTest):
self.config._autohsts_fetch_state()
self.config._autohsts["orphan_id"] = {"laststep": 999, "timestamp": 0}
self.config._autohsts_save_state()
with mock.patch("certbot._internal.apache.configurator.logger.error") as mock_log:
with mock.patch("certbot._internal.plugins.apache.configurator.logger.error") as mock_log:
self.config.deploy_autohsts(mock.MagicMock())
assert mock_log.called is True
assert "VirtualHost with id orphan_id was not" in mock_log.call_args[0][0]
@@ -1,4 +1,4 @@
"""Test for certbot._internal.apache.configurator for Centos overrides"""
"""Test for certbot._internal.plugins.apache.configurator for Centos overrides"""
import sys
from unittest import mock
@@ -7,9 +7,9 @@ import pytest
from certbot import errors
from certbot.compat import filesystem
from certbot.compat import os
from certbot._internal.apache import obj
from certbot._internal.apache import override_centos
from certbot._internal.apache.tests import util
from certbot._internal.plugins.apache import obj
from certbot._internal.plugins.apache import override_centos
from certbot._internal.plugins.apache.tests import util
def get_vh_truth(temp_dir, config_name):
@@ -56,7 +56,7 @@ class FedoraRestartTest(util.ApacheTest):
self.config.config_test()
def test_non_fedora_error(self):
c_test = "certbot._internal.apache.configurator.ApacheConfigurator.config_test"
c_test = "certbot._internal.plugins.apache.configurator.ApacheConfigurator.config_test"
with mock.patch(c_test) as mock_test:
mock_test.side_effect = errors.MisconfigurationError
with mock.patch("certbot.util.get_os_info") as mock_info:
@@ -65,7 +65,7 @@ class FedoraRestartTest(util.ApacheTest):
self.config.config_test()
def test_fedora_restart_error(self):
c_test = "certbot._internal.apache.configurator.ApacheConfigurator.config_test"
c_test = "certbot._internal.plugins.apache.configurator.ApacheConfigurator.config_test"
with mock.patch(c_test) as mock_test:
# First call raises error, second doesn't
mock_test.side_effect = [errors.MisconfigurationError, '']
@@ -75,7 +75,7 @@ class FedoraRestartTest(util.ApacheTest):
self._run_fedora_test()
def test_fedora_restart(self):
c_test = "certbot._internal.apache.configurator.ApacheConfigurator.config_test"
c_test = "certbot._internal.plugins.apache.configurator.ApacheConfigurator.config_test"
with mock.patch(c_test) as mock_test:
with mock.patch("certbot.util.run_script") as mock_run:
# First call raises error, second doesn't
@@ -153,7 +153,7 @@ class MultipleVhostsTestCentOS(util.ApacheTest):
def test_get_parser(self):
assert isinstance(self.config.parser, override_centos.CentOSParser)
@mock.patch("certbot._internal.apache.apache_util._get_runtime_cfg")
@mock.patch("certbot._internal.plugins.apache.apache_util._get_runtime_cfg")
def test_opportunistic_httpd_runtime_parsing(self, mock_get):
define_val = (
'Define: TEST1\n'
@@ -202,7 +202,7 @@ class MultipleVhostsTestCentOS(util.ApacheTest):
raise Exception("Missed: %s" % vhost) # pragma: no cover
assert found == 2
@mock.patch("certbot._internal.apache.apache_util._get_runtime_cfg")
@mock.patch("certbot._internal.plugins.apache.apache_util._get_runtime_cfg")
def test_get_sysconfig_vars(self, mock_cfg):
"""Make sure we read the sysconfig OPTIONS variable correctly"""
# Return nothing for the process calls
@@ -223,13 +223,13 @@ class MultipleVhostsTestCentOS(util.ApacheTest):
assert "MOCK_NOSEP" in self.config.parser.variables
assert "NOSEP_VAL" == self.config.parser.variables["NOSEP_TWO"]
@mock.patch("certbot._internal.apache.configurator.util.run_script")
@mock.patch("certbot._internal.plugins.apache.configurator.util.run_script")
def test_alt_restart_works(self, mock_run_script):
mock_run_script.side_effect = [None, errors.SubprocessError, None]
self.config.restart()
assert mock_run_script.call_count == 3
@mock.patch("certbot._internal.apache.configurator.util.run_script")
@mock.patch("certbot._internal.plugins.apache.configurator.util.run_script")
def test_alt_restart_errors(self, mock_run_script):
mock_run_script.side_effect = [None,
errors.SubprocessError,
@@ -1,11 +1,11 @@
"""Tests for certbot._internal.apache.parser."""
"""Tests for certbot._internal.plugins.apache.parser."""
import sys
import pytest
from certbot import errors
from certbot.compat import os
from certbot._internal.apache.tests import util
from certbot._internal.plugins.apache.tests import util
class ComplexParserTest(util.ParserTest):
@@ -80,7 +80,7 @@ class ComplexParserTest(util.ParserTest):
def verify_fnmatch(self, arg, hit=True):
"""Test if Include was correctly parsed."""
from certbot._internal.apache import parser
from certbot._internal.plugins.apache import parser
self.parser.add_dir(parser.get_aug_path(self.parser.loc["default"]),
"Include", [arg])
if hit:
@@ -1,11 +1,11 @@
"""Test for certbot._internal.apache.configurator implementations of reverter"""
"""Test for certbot._internal.plugins.apache.configurator implementations of reverter"""
import sys
from unittest import mock
import pytest
from certbot import errors
from certbot._internal.apache.tests import util
from certbot._internal.plugins.apache.tests import util
class ConfiguratorReverterTest(util.ApacheTest):
@@ -1,5 +1,5 @@
# pylint: disable=too-many-lines
"""Test for certbot._internal.apache.configurator."""
"""Test for certbot._internal.plugins.apache.configurator."""
import copy
import shutil
import socket
@@ -17,11 +17,11 @@ from certbot.compat import filesystem
from certbot.compat import os
from certbot.tests import acme_util
from certbot.tests import util as certbot_util
from certbot._internal.apache import apache_util
from certbot._internal.apache import constants
from certbot._internal.apache import obj
from certbot._internal.apache import parser
from certbot._internal.apache.tests import util
from certbot._internal.plugins.apache import apache_util
from certbot._internal.plugins.apache import constants
from certbot._internal.plugins.apache import obj
from certbot._internal.plugins.apache import parser
from certbot._internal.plugins.apache.tests import util
class MultipleVhostsTest(util.ApacheTest):
@@ -42,13 +42,13 @@ class MultipleVhostsTest(util.ApacheTest):
def mocked_deploy_cert(*args, **kwargs):
"""a helper to mock a deployed cert"""
g_mod = "certbot._internal.apache.configurator.ApacheConfigurator.enable_mod"
g_mod = "certbot._internal.plugins.apache.configurator.ApacheConfigurator.enable_mod"
with mock.patch(g_mod):
config.real_deploy_cert(*args, **kwargs)
self.config.deploy_cert = mocked_deploy_cert
return self.config
@mock.patch("certbot._internal.apache.configurator.path_surgery")
@mock.patch("certbot._internal.plugins.apache.configurator.path_surgery")
def test_prepare_no_install(self, mock_surgery):
silly_path = {"PATH": "/tmp/nothingness2342"}
mock_surgery.return_value = False
@@ -57,8 +57,8 @@ class MultipleVhostsTest(util.ApacheTest):
self.config.prepare()
assert mock_surgery.call_count == 1
@mock.patch("certbot._internal.apache.parser.ApacheParser")
@mock.patch("certbot._internal.apache.configurator.util.exe_exists")
@mock.patch("certbot._internal.plugins.apache.parser.ApacheParser")
@mock.patch("certbot._internal.plugins.apache.configurator.util.exe_exists")
def test_prepare_version(self, mock_exe_exists, _):
mock_exe_exists.return_value = True
self.config.version = None
@@ -81,9 +81,9 @@ class MultipleVhostsTest(util.ApacheTest):
os.remove(os.path.join(server_root, ".certbot.lock"))
certbot_util.lock_and_call(self._test_prepare_locked, server_root)
@mock.patch("certbot._internal.apache.parser.ApacheParser")
@mock.patch("certbot._internal.apache.configurator.util.exe_exists")
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator.get_parsernode_root")
@mock.patch("certbot._internal.plugins.apache.parser.ApacheParser")
@mock.patch("certbot._internal.plugins.apache.configurator.util.exe_exists")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator.get_parsernode_root")
def _test_prepare_locked(self, _node, _exists, _parser):
try:
self.config.prepare()
@@ -95,14 +95,14 @@ class MultipleVhostsTest(util.ApacheTest):
self.fail("Exception wasn't raised!")
def test_add_parser_arguments(self): # pylint: disable=no-self-use
from certbot._internal.apache.configurator import ApacheConfigurator
from certbot._internal.plugins.apache.configurator import ApacheConfigurator
# Weak test..
ApacheConfigurator.add_parser_arguments(mock.MagicMock())
def test_docs_parser_arguments(self):
os.environ["CERTBOT_DOCS"] = "1"
from certbot._internal.apache.configurator import ApacheConfigurator
from certbot._internal.plugins.apache.configurator import ApacheConfigurator
mock_add = mock.MagicMock()
ApacheConfigurator.add_parser_arguments(mock_add)
parserargs = ["server_root", "enmod", "dismod", "le_vhost_ext",
@@ -129,13 +129,13 @@ class MultipleVhostsTest(util.ApacheTest):
del os.environ["CERTBOT_DOCS"]
def test_add_parser_arguments_all_configurators(self): # pylint: disable=no-self-use
from certbot._internal.apache.entrypoint import OVERRIDE_CLASSES
from certbot._internal.plugins.apache.entrypoint import OVERRIDE_CLASSES
for cls in OVERRIDE_CLASSES.values():
cls.add_parser_arguments(mock.MagicMock())
def test_all_configurators_defaults_defined(self):
from certbot._internal.apache.configurator import ApacheConfigurator
from certbot._internal.apache.entrypoint import OVERRIDE_CLASSES
from certbot._internal.plugins.apache.configurator import ApacheConfigurator
from certbot._internal.plugins.apache.entrypoint import OVERRIDE_CLASSES
parameters = set(ApacheConfigurator.OS_DEFAULTS.__dict__.keys())
for cls in OVERRIDE_CLASSES.values():
assert parameters.issubset(set(cls.OS_DEFAULTS.__dict__.keys())) is True
@@ -153,7 +153,7 @@ class MultipleVhostsTest(util.ApacheTest):
"duplicate.example.com"}
@certbot_util.patch_display_util()
@mock.patch("certbot._internal.apache.configurator.socket.gethostbyaddr")
@mock.patch("certbot._internal.plugins.apache.configurator.socket.gethostbyaddr")
def test_get_all_names_addrs(self, mock_gethost, mock_getutility):
mock_gethost.side_effect = [("google.com", "", ""), socket.error]
mock_utility = mock_getutility()
@@ -179,7 +179,7 @@ class MultipleVhostsTest(util.ApacheTest):
assert self.config._create_vhost("nonexistent") is None # pylint: disable=protected-access
def test_get_aug_internal_path(self):
from certbot._internal.apache.apache_util import get_internal_aug_path
from certbot._internal.plugins.apache.apache_util import get_internal_aug_path
internal_paths = [
"Virtualhost", "IfModule/VirtualHost", "VirtualHost", "VirtualHost",
"Macro/VirtualHost", "IfModule/VirtualHost", "VirtualHost",
@@ -221,25 +221,25 @@ class MultipleVhostsTest(util.ApacheTest):
# Handle case of non-debian layout get_virtual_hosts
with mock.patch(
"certbot._internal.apache.configurator.ApacheConfigurator.conf"
"certbot._internal.plugins.apache.configurator.ApacheConfigurator.conf"
) as mock_conf:
mock_conf.return_value = False
vhs = self.config.get_virtual_hosts()
assert len(vhs) == 12
@mock.patch("certbot._internal.apache.display_ops.select_vhost")
@mock.patch("certbot._internal.plugins.apache.display_ops.select_vhost")
def test_choose_vhost_none_avail(self, mock_select):
mock_select.return_value = None
with pytest.raises(errors.PluginError):
self.config.choose_vhost("none.com")
@mock.patch("certbot._internal.apache.display_ops.select_vhost")
@mock.patch("certbot._internal.plugins.apache.display_ops.select_vhost")
def test_choose_vhost_select_vhost_ssl(self, mock_select):
mock_select.return_value = self.vh_truth[1]
assert self.vh_truth[1] == self.config.choose_vhost("none.com")
@mock.patch("certbot._internal.apache.display_ops.select_vhost")
@mock.patch("certbot._internal.apache.obj.VirtualHost.conflicts")
@mock.patch("certbot._internal.plugins.apache.display_ops.select_vhost")
@mock.patch("certbot._internal.plugins.apache.obj.VirtualHost.conflicts")
def test_choose_vhost_select_vhost_non_ssl(self, mock_conf, mock_select):
mock_select.return_value = self.vh_truth[0]
mock_conf.return_value = False
@@ -251,8 +251,8 @@ class MultipleVhostsTest(util.ApacheTest):
assert self.vh_truth[0].ssl is False
assert chosen_vhost.ssl is True
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator._find_best_vhost")
@mock.patch("certbot._internal.apache.parser.ApacheParser.add_dir")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator._find_best_vhost")
@mock.patch("certbot._internal.plugins.apache.parser.ApacheParser.add_dir")
def test_choose_vhost_and_servername_addition(self, mock_add, mock_find):
ret_vh = self.vh_truth[8]
ret_vh.enabled = False
@@ -260,13 +260,13 @@ class MultipleVhostsTest(util.ApacheTest):
self.config.choose_vhost("whatever.com")
assert mock_add.called is True
@mock.patch("certbot._internal.apache.display_ops.select_vhost")
@mock.patch("certbot._internal.plugins.apache.display_ops.select_vhost")
def test_choose_vhost_select_vhost_with_temp(self, mock_select):
mock_select.return_value = self.vh_truth[0]
chosen_vhost = self.config.choose_vhost("none.com", create_if_no_ssl=False)
assert self.vh_truth[0] == chosen_vhost
@mock.patch("certbot._internal.apache.display_ops.select_vhost")
@mock.patch("certbot._internal.plugins.apache.display_ops.select_vhost")
def test_choose_vhost_select_vhost_conflicting_non_ssl(self, mock_select):
mock_select.return_value = self.vh_truth[3]
conflicting_vhost = obj.VirtualHost(
@@ -332,7 +332,7 @@ class MultipleVhostsTest(util.ApacheTest):
vhosts = self.config._non_default_vhosts(self.config.vhosts)
assert len(vhosts) == 10
@mock.patch('certbot._internal.apache.configurator.display_util.notify')
@mock.patch('certbot._internal.plugins.apache.configurator.display_util.notify')
def test_deploy_cert_enable_new_vhost(self, unused_mock_notify):
# Create
ssl_vhost = self.config.make_vhost_ssl(self.vh_truth[0])
@@ -371,7 +371,7 @@ class MultipleVhostsTest(util.ApacheTest):
self.fail("Include shouldn't be added, as patched find_dir 'finds' existing one") \
# pragma: no cover
@mock.patch('certbot._internal.apache.configurator.display_util.notify')
@mock.patch('certbot._internal.plugins.apache.configurator.display_util.notify')
def test_deploy_cert(self, unused_mock_notify):
self.config.parser.modules["ssl_module"] = None
self.config.parser.modules["mod_ssl.c"] = None
@@ -480,7 +480,7 @@ class MultipleVhostsTest(util.ApacheTest):
call_found = True
assert call_found is True
@mock.patch("certbot._internal.apache.parser.ApacheParser.reset_modules")
@mock.patch("certbot._internal.plugins.apache.parser.ApacheParser.reset_modules")
def test_prepare_server_https(self, mock_reset):
mock_enable = mock.Mock()
self.config.enable_mod = mock_enable
@@ -507,7 +507,7 @@ class MultipleVhostsTest(util.ApacheTest):
assert mock_add_dir.call_count == 2
@mock.patch("certbot._internal.apache.parser.ApacheParser.reset_modules")
@mock.patch("certbot._internal.plugins.apache.parser.ApacheParser.reset_modules")
def test_prepare_server_https_named_listen(self, mock_reset):
mock_find = mock.Mock()
mock_find.return_value = ["test1", "test2", "test3"]
@@ -545,7 +545,7 @@ class MultipleVhostsTest(util.ApacheTest):
# self.config.prepare_server_https("8080", temp=True)
# self.assertEqual(self.listens, 0)
@mock.patch("certbot._internal.apache.parser.ApacheParser.reset_modules")
@mock.patch("certbot._internal.plugins.apache.parser.ApacheParser.reset_modules")
def test_prepare_server_https_needed_listen(self, mock_reset):
mock_find = mock.Mock()
mock_find.return_value = ["test1", "test2"]
@@ -562,7 +562,7 @@ class MultipleVhostsTest(util.ApacheTest):
self.config.prepare_server_https("443")
assert mock_add_dir.call_count == 1
@mock.patch("certbot._internal.apache.parser.ApacheParser.reset_modules")
@mock.patch("certbot._internal.plugins.apache.parser.ApacheParser.reset_modules")
def test_prepare_server_https_mixed_listen(self, mock_reset):
mock_find = mock.Mock()
mock_find.return_value = ["test1", "test2"]
@@ -697,8 +697,8 @@ class MultipleVhostsTest(util.ApacheTest):
# pylint: disable=protected-access
assert self.config._get_ssl_vhost_path("example_path").endswith(".conf") is True
@mock.patch("certbot._internal.apache.configurator.http_01.ApacheHttp01.perform")
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator.restart")
@mock.patch("certbot._internal.plugins.apache.configurator.http_01.ApacheHttp01.perform")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator.restart")
def test_perform(self, mock_restart, mock_http_perform):
# Only tests functionality specific to configurator.perform
# Note: As more challenges are offered this will have to be expanded
@@ -714,8 +714,8 @@ class MultipleVhostsTest(util.ApacheTest):
assert mock_restart.call_count == 1
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator.restart")
@mock.patch("certbot._internal.apache.apache_util._get_runtime_cfg")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator.restart")
@mock.patch("certbot._internal.plugins.apache.apache_util._get_runtime_cfg")
def test_cleanup(self, mock_cfg, mock_restart):
mock_cfg.return_value = ""
_, achalls = self.get_key_and_achalls()
@@ -730,8 +730,8 @@ class MultipleVhostsTest(util.ApacheTest):
else:
assert mock_restart.called is False
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator.restart")
@mock.patch("certbot._internal.apache.apache_util._get_runtime_cfg")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator.restart")
@mock.patch("certbot._internal.plugins.apache.apache_util._get_runtime_cfg")
def test_cleanup_no_errors(self, mock_cfg, mock_restart):
mock_cfg.return_value = ""
_, achalls = self.get_key_and_achalls()
@@ -771,11 +771,11 @@ class MultipleVhostsTest(util.ApacheTest):
with pytest.raises(errors.PluginError):
self.config.get_version()
@mock.patch("certbot._internal.apache.configurator.util.run_script")
@mock.patch("certbot._internal.plugins.apache.configurator.util.run_script")
def test_restart(self, _):
self.config.restart()
@mock.patch("certbot._internal.apache.configurator.util.run_script")
@mock.patch("certbot._internal.plugins.apache.configurator.util.run_script")
def test_restart_bad_process(self, mock_run_script):
mock_run_script.side_effect = [None, errors.SubprocessError]
@@ -819,8 +819,8 @@ class MultipleVhostsTest(util.ApacheTest):
assert self.vh_truth[0].name == res.name
assert self.vh_truth[0].aliases == res.aliases
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator._get_http_vhost")
@mock.patch("certbot._internal.apache.display_ops.select_vhost")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator._get_http_vhost")
@mock.patch("certbot._internal.plugins.apache.display_ops.select_vhost")
@mock.patch("certbot.util.exe_exists")
def test_enhance_unknown_vhost(self, mock_exe, mock_sel_vhost, mock_get):
self.config.parser.modules["rewrite_module"] = None
@@ -841,7 +841,7 @@ class MultipleVhostsTest(util.ApacheTest):
self.config.enhance("certbot.demo", "unknown_enhancement")
def test_enhance_no_ssl_vhost(self):
with mock.patch("certbot._internal.apache.configurator.logger.error") as mock_log:
with mock.patch("certbot._internal.plugins.apache.configurator.logger.error") as mock_log:
with pytest.raises(errors.PluginError):
self.config.enhance("certbot.demo", "redirect")
# Check that correct logger.warning was printed
@@ -1130,7 +1130,7 @@ class MultipleVhostsTest(util.ApacheTest):
self.config.choose_vhost("red.blue.purple.com")
self.config.enhance("red.blue.purple.com", "redirect")
verify_no_redirect = ("certbot._internal.apache.configurator."
verify_no_redirect = ("certbot._internal.plugins.apache.configurator."
"ApacheConfigurator._verify_no_certbot_redirect")
with mock.patch(verify_no_redirect) as mock_verify:
self.config.enhance("green.blue.purple.com", "redirect")
@@ -1223,7 +1223,7 @@ class MultipleVhostsTest(util.ApacheTest):
assert os.path.basename(inc_path) in self.config.parser.existing_paths[
os.path.dirname(inc_path)]
@mock.patch('certbot._internal.apache.configurator.display_util.notify')
@mock.patch('certbot._internal.plugins.apache.configurator.display_util.notify')
def test_deploy_cert_not_parsed_path(self, unused_mock_notify):
# Make sure that we add include to root config for vhosts when
# handle-sites is false
@@ -1232,8 +1232,8 @@ class MultipleVhostsTest(util.ApacheTest):
self.config.parser.modules["socache_shmcb_module"] = None
tmp_path = filesystem.realpath(tempfile.mkdtemp("vhostroot"))
filesystem.chmod(tmp_path, 0o755)
mock_p = "certbot._internal.apache.configurator.ApacheConfigurator._get_ssl_vhost_path"
mock_a = "certbot._internal.apache.parser.ApacheParser.add_include"
mock_p = "certbot._internal.plugins.apache.configurator.ApacheConfigurator._get_ssl_vhost_path"
mock_a = "certbot._internal.plugins.apache.parser.ApacheParser.add_include"
with mock.patch(mock_p) as mock_path:
mock_path.return_value = os.path.join(tmp_path, "whatever.conf")
@@ -1256,7 +1256,7 @@ class MultipleVhostsTest(util.ApacheTest):
self.config.deploy_cert("encryption-example.demo", "example/cert.pem", "example/key.pem",
"example/cert_chain.pem", "example/fullchain.pem")
@mock.patch("certbot._internal.apache.parser.ApacheParser.parsed_in_original")
@mock.patch("certbot._internal.plugins.apache.parser.ApacheParser.parsed_in_original")
def test_choose_vhost_and_servername_addition_parsed(self, mock_parsed):
ret_vh = self.vh_truth[8]
ret_vh.enabled = True
@@ -1270,7 +1270,7 @@ class MultipleVhostsTest(util.ApacheTest):
def test_choose_vhosts_wildcard(self):
# pylint: disable=protected-access
mock_path = "certbot._internal.apache.display_ops.select_vhost_multiple"
mock_path = "certbot._internal.plugins.apache.display_ops.select_vhost_multiple"
with mock.patch(mock_path) as mock_select_vhs:
mock_select_vhs.return_value = [self.vh_truth[3]]
vhs = self.config._choose_vhosts_wildcard("*.certbot.demo",
@@ -1286,10 +1286,10 @@ class MultipleVhostsTest(util.ApacheTest):
assert vhs[0] != self.vh_truth[3]
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator.make_vhost_ssl")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator.make_vhost_ssl")
def test_choose_vhosts_wildcard_no_ssl(self, mock_makessl):
# pylint: disable=protected-access
mock_path = "certbot._internal.apache.display_ops.select_vhost_multiple"
mock_path = "certbot._internal.plugins.apache.display_ops.select_vhost_multiple"
with mock.patch(mock_path) as mock_select_vhs:
mock_select_vhs.return_value = [self.vh_truth[1]]
vhs = self.config._choose_vhosts_wildcard("*.certbot.demo",
@@ -1297,13 +1297,13 @@ class MultipleVhostsTest(util.ApacheTest):
assert mock_makessl.called is False
assert vhs[0] == self.vh_truth[1]
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator._vhosts_for_wildcard")
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator.make_vhost_ssl")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator._vhosts_for_wildcard")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator.make_vhost_ssl")
def test_choose_vhosts_wildcard_already_ssl(self, mock_makessl, mock_vh_for_w):
# pylint: disable=protected-access
# Already SSL vhost
mock_vh_for_w.return_value = [self.vh_truth[7]]
mock_path = "certbot._internal.apache.display_ops.select_vhost_multiple"
mock_path = "certbot._internal.plugins.apache.display_ops.select_vhost_multiple"
with mock.patch(mock_path) as mock_select_vhs:
mock_select_vhs.return_value = [self.vh_truth[7]]
vhs = self.config._choose_vhosts_wildcard("whatever",
@@ -1318,13 +1318,13 @@ class MultipleVhostsTest(util.ApacheTest):
assert vhs[0].ssl is True
assert vhs[0] == self.vh_truth[7]
@mock.patch('certbot._internal.apache.configurator.display_util.notify')
@mock.patch('certbot._internal.plugins.apache.configurator.display_util.notify')
def test_deploy_cert_wildcard(self, unused_mock_notify):
# pylint: disable=protected-access
mock_choose_vhosts = mock.MagicMock()
mock_choose_vhosts.return_value = [self.vh_truth[7]]
self.config._choose_vhosts_wildcard = mock_choose_vhosts
mock_d = "certbot._internal.apache.configurator.ApacheConfigurator._deploy_cert"
mock_d = "certbot._internal.plugins.apache.configurator.ApacheConfigurator._deploy_cert"
with mock.patch(mock_d) as mock_dep:
self.config.deploy_cert("*.wildcard.example.org", "/tmp/path",
"/tmp/path", "/tmp/path", "/tmp/path")
@@ -1332,7 +1332,7 @@ class MultipleVhostsTest(util.ApacheTest):
assert len(mock_dep.call_args_list) == 1
assert self.vh_truth[7] == mock_dep.call_args_list[0][0][0]
@mock.patch("certbot._internal.apache.display_ops.select_vhost_multiple")
@mock.patch("certbot._internal.plugins.apache.display_ops.select_vhost_multiple")
def test_deploy_cert_wildcard_no_vhosts(self, mock_dialog):
# pylint: disable=protected-access
mock_dialog.return_value = []
@@ -1340,7 +1340,7 @@ class MultipleVhostsTest(util.ApacheTest):
self.config.deploy_cert("*.wild.cat", "/tmp/path", "/tmp/path",
"/tmp/path", "/tmp/path")
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator._choose_vhosts_wildcard")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator._choose_vhosts_wildcard")
def test_enhance_wildcard_after_install(self, mock_choose):
# pylint: disable=protected-access
self.config.parser.modules["mod_ssl.c"] = None
@@ -1351,7 +1351,7 @@ class MultipleVhostsTest(util.ApacheTest):
"Upgrade-Insecure-Requests")
assert mock_choose.called is False
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator._choose_vhosts_wildcard")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator._choose_vhosts_wildcard")
def test_enhance_wildcard_no_install(self, mock_choose):
self.vh_truth[3].ssl = True
mock_choose.return_value = [self.vh_truth[3]]
@@ -1427,7 +1427,7 @@ class AugeasVhostsTest(util.ApacheTest):
chosen_vhost = self.config._create_vhost(path)
assert chosen_vhost is None or chosen_vhost.path == path
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator._create_vhost")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator._create_vhost")
def test_get_vhost_continue(self, mock_vhost):
mock_vhost.return_value = None
vhs = self.config.get_virtual_hosts()
@@ -1440,18 +1440,18 @@ class AugeasVhostsTest(util.ApacheTest):
with self.subTest(name=name):
assert name not in self.config.choose_vhost(name).aliases
@mock.patch("certbot._internal.apache.obj.VirtualHost.conflicts")
@mock.patch("certbot._internal.plugins.apache.obj.VirtualHost.conflicts")
def test_choose_vhost_without_matching_wildcard(self, mock_conflicts):
mock_conflicts.return_value = False
mock_path = "certbot._internal.apache.display_ops.select_vhost"
mock_path = "certbot._internal.plugins.apache.display_ops.select_vhost"
with mock.patch(mock_path, lambda _, vhosts: vhosts[0]):
for name in ("a.example.net", "other.example.net"):
assert name in self.config.choose_vhost(name).aliases
@mock.patch("certbot._internal.apache.obj.VirtualHost.conflicts")
@mock.patch("certbot._internal.plugins.apache.obj.VirtualHost.conflicts")
def test_choose_vhost_wildcard_not_found(self, mock_conflicts):
mock_conflicts.return_value = False
mock_path = "certbot._internal.apache.display_ops.select_vhost"
mock_path = "certbot._internal.plugins.apache.display_ops.select_vhost"
names = (
"abc.example.net", "not.there.tld", "aa.wildcard.tld"
)
@@ -1463,7 +1463,7 @@ class AugeasVhostsTest(util.ApacheTest):
assert mock_select.call_count - orig_cc == 1
def test_choose_vhost_wildcard_found(self):
mock_path = "certbot._internal.apache.display_ops.select_vhost"
mock_path = "certbot._internal.plugins.apache.display_ops.select_vhost"
names = (
"ab.example.net", "a.wildcard.tld", "yetanother.example.net"
)
@@ -1511,7 +1511,7 @@ class MultiVhostsTest(util.ApacheTest):
assert ssl_vhost.ssl is True
assert ssl_vhost.enabled is False
mock_path = "certbot._internal.apache.configurator.ApacheConfigurator._get_new_vh_path"
mock_path = "certbot._internal.plugins.apache.configurator.ApacheConfigurator._get_new_vh_path"
with mock.patch(mock_path) as mock_getpath:
mock_getpath.return_value = None
with pytest.raises(errors.PluginError):
@@ -1527,7 +1527,7 @@ class MultiVhostsTest(util.ApacheTest):
both = with_index_1 + with_index_2
assert self.config._get_new_vh_path(without_index, both) == with_index_2[0]
@mock.patch("certbot._internal.apache.configurator.display_util.notify")
@mock.patch("certbot._internal.plugins.apache.configurator.display_util.notify")
def test_make_vhost_ssl_with_existing_rewrite_rule(self, mock_notify):
self.config.parser.modules["rewrite_module"] = None
@@ -1546,7 +1546,7 @@ class MultiVhostsTest(util.ApacheTest):
assert mock_notify.call_count == 1
assert "Some rewrite rules" in mock_notify.call_args[0][0]
@mock.patch("certbot._internal.apache.configurator.display_util.notify")
@mock.patch("certbot._internal.plugins.apache.configurator.display_util.notify")
def test_make_vhost_ssl_with_existing_rewrite_conds(self, mock_notify):
self.config.parser.modules["rewrite_module"] = None
@@ -1611,7 +1611,7 @@ class InstallSslOptionsConfTest(util.ApacheTest):
self._assert_current_file()
def test_prev_file_updates_to_current(self):
from certbot._internal.apache.constants import ALL_SSL_OPTIONS_HASHES
from certbot._internal.plugins.apache.constants import ALL_SSL_OPTIONS_HASHES
ALL_SSL_OPTIONS_HASHES.insert(0, "test_hash_does_not_match")
with mock.patch('certbot.crypto_util.sha256sum') as mock_sha256:
mock_sha256.return_value = ALL_SSL_OPTIONS_HASHES[0]
@@ -1649,8 +1649,8 @@ class InstallSslOptionsConfTest(util.ApacheTest):
self._call()
assert mock_logger.warning.called is False
@mock.patch('certbot._internal.apache.configurator.logger.warning')
@mock.patch('certbot._internal.apache.configurator.ApacheConfigurator.openssl_version')
@mock.patch('certbot._internal.plugins.apache.configurator.logger.warning')
@mock.patch('certbot._internal.plugins.apache.configurator.ApacheConfigurator.openssl_version')
def test_pick_apache_config_versions_and_warnings(self, mock_openssl_version, mock_warning):
def has_logged_warning():
"""Returns True if a warning was logged about updating Apache."""
@@ -1702,7 +1702,7 @@ class InstallSslOptionsConfTest(util.ApacheTest):
"""
import importlib.resources
from certbot._internal.apache.constants import ALL_SSL_OPTIONS_HASHES
from certbot._internal.plugins.apache.constants import ALL_SSL_OPTIONS_HASHES
ref = importlib.resources.files("certbot") / "_internal" / "apache" / "tls_configs"
with importlib.resources.as_file(ref) as tls_configs_dir:
@@ -1730,7 +1730,7 @@ class InstallSslOptionsConfTest(util.ApacheTest):
"""
# ssl_module as a DSO
self.config.parser.modules['ssl_module'] = '/fake/path'
with mock.patch("certbot._internal.apache.configurator."
with mock.patch("certbot._internal.plugins.apache.configurator."
"ApacheConfigurator._open_module_file") as mock_omf:
mock_omf.return_value = some_string_contents
assert self.config.openssl_version() == "1.0.2g"
@@ -1739,7 +1739,7 @@ class InstallSslOptionsConfTest(util.ApacheTest):
self.config._openssl_version = None
self.config.parser.modules['ssl_module'] = None
self.config.options.bin = '/fake/path/to/httpd'
with mock.patch("certbot._internal.apache.configurator."
with mock.patch("certbot._internal.plugins.apache.configurator."
"ApacheConfigurator._open_module_file") as mock_omf:
mock_omf.return_value = some_string_contents
assert self.config.openssl_version() == "1.0.2g"
@@ -1749,14 +1749,14 @@ class InstallSslOptionsConfTest(util.ApacheTest):
assert self.config.openssl_version() == '1.0.2a'
self.config._openssl_version = None
with mock.patch("certbot._internal.apache.configurator.logger.warning") as mock_log:
with mock.patch("certbot._internal.plugins.apache.configurator.logger.warning") as mock_log:
assert self.config.openssl_version() is None
assert "Could not find ssl_module" in mock_log.call_args[0][0]
# When no ssl_module is present at all
self.config._openssl_version = None
assert "ssl_module" not in self.config.parser.modules
with mock.patch("certbot._internal.apache.configurator.logger.warning") as mock_log:
with mock.patch("certbot._internal.plugins.apache.configurator.logger.warning") as mock_log:
assert self.config.openssl_version() is None
assert "Could not find ssl_module" in mock_log.call_args[0][0]
@@ -1764,21 +1764,21 @@ class InstallSslOptionsConfTest(util.ApacheTest):
self.config._openssl_version = None
self.config.options.bin = None
self.config.parser.modules['ssl_module'] = None
with mock.patch("certbot._internal.apache.configurator.logger.warning") as mock_log:
with mock.patch("certbot._internal.plugins.apache.configurator.logger.warning") as mock_log:
assert self.config.openssl_version() is None
assert "ssl_module is statically linked but" in mock_log.call_args[0][0]
self.config.parser.modules['ssl_module'] = "/fake/path"
with mock.patch("certbot._internal.apache.configurator.logger.warning") as mock_log:
with mock.patch("certbot._internal.plugins.apache.configurator.logger.warning") as mock_log:
# Check that correct logger.warning was printed
assert self.config.openssl_version() is None
assert "Unable to read" in mock_log.call_args[0][0]
contents_missing_openssl = b"these contents won't match the regex"
with mock.patch("certbot._internal.apache.configurator."
with mock.patch("certbot._internal.plugins.apache.configurator."
"ApacheConfigurator._open_module_file") as mock_omf:
mock_omf.return_value = contents_missing_openssl
with mock.patch("certbot._internal.apache.configurator.logger.warning") as mock_log:
with mock.patch("certbot._internal.plugins.apache.configurator.logger.warning") as mock_log:
# Check that correct logger.warning was printed
assert self.config.openssl_version() is None
assert "Could not find OpenSSL" in mock_log.call_args[0][0]
@@ -1,4 +1,4 @@
"""Test for certbot._internal.apache.configurator for Debian overrides"""
"""Test for certbot._internal.plugins.apache.configurator for Debian overrides"""
import shutil
import sys
from unittest import mock
@@ -8,9 +8,9 @@ import pytest
from certbot import errors
from certbot.compat import os
from certbot.tests import util as certbot_util
from certbot._internal.apache import apache_util
from certbot._internal.apache import obj
from certbot._internal.apache.tests import util
from certbot._internal.plugins.apache import apache_util
from certbot._internal.plugins.apache import obj
from certbot._internal.plugins.apache.tests import util
class MultipleVhostsTestDebian(util.ApacheTest):
@@ -31,8 +31,8 @@ class MultipleVhostsTestDebian(util.ApacheTest):
def mocked_deploy_cert(*args, **kwargs):
"""a helper to mock a deployed cert"""
g_mod = "certbot._internal.apache.configurator.ApacheConfigurator.enable_mod"
d_mod = "certbot._internal.apache.override_debian.DebianConfigurator.enable_mod"
g_mod = "certbot._internal.plugins.apache.configurator.ApacheConfigurator.enable_mod"
d_mod = "certbot._internal.plugins.apache.override_debian.DebianConfigurator.enable_mod"
with mock.patch(g_mod):
with mock.patch(d_mod):
config.real_deploy_cert(*args, **kwargs)
@@ -46,7 +46,7 @@ class MultipleVhostsTestDebian(util.ApacheTest):
@mock.patch("certbot.util.run_script")
@mock.patch("certbot.util.exe_exists")
@mock.patch("certbot._internal.apache.apache_util.subprocess.run")
@mock.patch("certbot._internal.plugins.apache.apache_util.subprocess.run")
def test_enable_mod(self, mock_run, mock_exe_exists, mock_run_script):
mock_run.return_value.stdout = "Define: DUMP_RUN_CFG"
mock_run.return_value.stderr = ""
@@ -194,7 +194,7 @@ class MultipleVhostsTestDebian(util.ApacheTest):
def test_enable_site_call_parent(self):
with mock.patch(
"certbot._internal.apache.configurator.ApacheConfigurator.enable_site") as e_s:
"certbot._internal.plugins.apache.configurator.ApacheConfigurator.enable_site") as e_s:
self.config.parser.root = "/tmp/nonexistent"
vh = self.vh_truth[0]
vh.enabled = False
@@ -1,4 +1,4 @@
"""Test certbot._internal.apache.display_ops."""
"""Test certbot._internal.plugins.apache.display_ops."""
import sys
import unittest
from unittest import mock
@@ -8,13 +8,13 @@ import pytest
from certbot import errors
from certbot.display import util as display_util
from certbot.tests import util as certbot_util
from certbot._internal.apache import obj
from certbot._internal.apache.display_ops import select_vhost_multiple
from certbot._internal.apache.tests import util
from certbot._internal.plugins.apache import obj
from certbot._internal.plugins.apache.display_ops import select_vhost_multiple
from certbot._internal.plugins.apache.tests import util
class SelectVhostMultiTest(unittest.TestCase):
"""Tests for certbot._internal.apache.display_ops.select_vhost_multiple."""
"""Tests for certbot._internal.plugins.apache.display_ops.select_vhost_multiple."""
def setUp(self):
self.base_dir = "/example_path"
@@ -44,7 +44,7 @@ class SelectVhostMultiTest(unittest.TestCase):
class SelectVhostTest(unittest.TestCase):
"""Tests for certbot._internal.apache.display_ops.select_vhost."""
"""Tests for certbot._internal.plugins.apache.display_ops.select_vhost."""
def setUp(self):
self.base_dir = "/example_path"
@@ -53,7 +53,7 @@ class SelectVhostTest(unittest.TestCase):
@classmethod
def _call(cls, vhosts):
from certbot._internal.apache.display_ops import select_vhost
from certbot._internal.plugins.apache.display_ops import select_vhost
return select_vhost("example.com", vhosts)
@certbot_util.patch_display_util()
@@ -80,8 +80,8 @@ class SelectVhostTest(unittest.TestCase):
def test_no_vhosts(self):
assert self._call([]) is None
@mock.patch("certbot._internal.apache.display_ops.display_util")
@mock.patch("certbot._internal.apache.display_ops.logger")
@mock.patch("certbot._internal.plugins.apache.display_ops.display_util")
@mock.patch("certbot._internal.plugins.apache.display_ops.logger")
def test_small_display(self, mock_logger, mock_display_util):
mock_display_util.WIDTH = 20
mock_display_util.menu.return_value = (display_util.OK, 0)
@@ -2,9 +2,9 @@
import unittest
from unittest import mock
from certbot._internal.apache import assertions
from certbot._internal.apache import augeasparser
from certbot._internal.apache import dualparser
from certbot._internal.plugins.apache import assertions
from certbot._internal.plugins.apache import augeasparser
from certbot._internal.plugins.apache import dualparser
import pytest
@@ -1,11 +1,11 @@
"""Test for certbot._internal.apache.entrypoint for override class resolution"""
"""Test for certbot._internal.plugins.apache.entrypoint for override class resolution"""
import sys
from unittest import mock
import pytest
from certbot._internal.apache import configurator
from certbot._internal.apache import entrypoint
from certbot._internal.plugins.apache import configurator
from certbot._internal.plugins.apache import entrypoint
def test_get_configurator():
@@ -1,4 +1,4 @@
"""Test for certbot._internal.apache.configurator for Fedora 29+ overrides"""
"""Test for certbot._internal.plugins.apache.configurator for Fedora 29+ overrides"""
import sys
from unittest import mock
@@ -7,9 +7,9 @@ import pytest
from certbot import errors
from certbot.compat import filesystem
from certbot.compat import os
from certbot._internal.apache import obj
from certbot._internal.apache import override_fedora
from certbot._internal.apache.tests import util
from certbot._internal.plugins.apache import obj
from certbot._internal.plugins.apache import override_fedora
from certbot._internal.plugins.apache.tests import util
def get_vh_truth(temp_dir, config_name):
@@ -58,7 +58,7 @@ class FedoraRestartTest(util.ApacheTest):
self.config.config_test()
def test_fedora_restart_error(self):
c_test = "certbot._internal.apache.configurator.ApacheConfigurator.config_test"
c_test = "certbot._internal.plugins.apache.configurator.ApacheConfigurator.config_test"
with mock.patch(c_test) as mock_test:
# First call raises error, second doesn't
mock_test.side_effect = [errors.MisconfigurationError, '']
@@ -68,7 +68,7 @@ class FedoraRestartTest(util.ApacheTest):
self._run_fedora_test()
def test_fedora_restart(self):
c_test = "certbot._internal.apache.configurator.ApacheConfigurator.config_test"
c_test = "certbot._internal.plugins.apache.configurator.ApacheConfigurator.config_test"
with mock.patch(c_test) as mock_test:
with mock.patch("certbot.util.run_script") as mock_run:
# First call raises error, second doesn't
@@ -99,7 +99,7 @@ class MultipleVhostsTestFedora(util.ApacheTest):
def test_get_parser(self):
assert isinstance(self.config.parser, override_fedora.FedoraParser)
@mock.patch("certbot._internal.apache.apache_util._get_runtime_cfg")
@mock.patch("certbot._internal.plugins.apache.apache_util._get_runtime_cfg")
def test_opportunistic_httpd_runtime_parsing(self, mock_get):
define_val = (
'Define: TEST1\n'
@@ -133,7 +133,7 @@ class MultipleVhostsTestFedora(util.ApacheTest):
assert "TEST2" in self.config.parser.variables
assert "mod_another.c" in self.config.parser.modules
@mock.patch("certbot._internal.apache.configurator.util.run_script")
@mock.patch("certbot._internal.plugins.apache.configurator.util.run_script")
def test_get_version(self, mock_run_script):
mock_run_script.return_value = ('', None)
with pytest.raises(errors.PluginError):
@@ -155,7 +155,7 @@ class MultipleVhostsTestFedora(util.ApacheTest):
raise Exception("Missed: %s" % vhost) # pragma: no cover
assert found == 2
@mock.patch("certbot._internal.apache.apache_util._get_runtime_cfg")
@mock.patch("certbot._internal.plugins.apache.apache_util._get_runtime_cfg")
def test_get_sysconfig_vars(self, mock_cfg):
"""Make sure we read the sysconfig OPTIONS variable correctly"""
# Return nothing for the process calls
@@ -176,13 +176,13 @@ class MultipleVhostsTestFedora(util.ApacheTest):
assert "MOCK_NOSEP" in self.config.parser.variables
assert "NOSEP_VAL" == self.config.parser.variables["NOSEP_TWO"]
@mock.patch("certbot._internal.apache.configurator.util.run_script")
@mock.patch("certbot._internal.plugins.apache.configurator.util.run_script")
def test_alt_restart_works(self, mock_run_script):
mock_run_script.side_effect = [None, errors.SubprocessError, None]
self.config.restart()
assert mock_run_script.call_count == 3
@mock.patch("certbot._internal.apache.configurator.util.run_script")
@mock.patch("certbot._internal.plugins.apache.configurator.util.run_script")
def test_alt_restart_errors(self, mock_run_script):
mock_run_script.side_effect = [None,
errors.SubprocessError,
@@ -1,4 +1,4 @@
"""Test for certbot._internal.apache.configurator for Gentoo overrides"""
"""Test for certbot._internal.plugins.apache.configurator for Gentoo overrides"""
import sys
from unittest import mock
@@ -7,9 +7,9 @@ import pytest
from certbot import errors
from certbot.compat import filesystem
from certbot.compat import os
from certbot._internal.apache import obj
from certbot._internal.apache import override_gentoo
from certbot._internal.apache.tests import util
from certbot._internal.plugins.apache import obj
from certbot._internal.plugins.apache import override_gentoo
from certbot._internal.plugins.apache.tests import util
def get_vh_truth(temp_dir, config_name):
@@ -51,7 +51,7 @@ class MultipleVhostsTestGentoo(util.ApacheTest):
vhost_root=vhost_root)
# pylint: disable=line-too-long
with mock.patch("certbot._internal.apache.override_gentoo.GentooParser.update_runtime_variables"):
with mock.patch("certbot._internal.plugins.apache.override_gentoo.GentooParser.update_runtime_variables"):
self.config = util.get_apache_configurator(
self.config_path, self.vhost_path, self.config_dir, self.work_dir,
os_info="gentoo")
@@ -83,17 +83,17 @@ class MultipleVhostsTestGentoo(util.ApacheTest):
self.config.parser.apacheconfig_filep = filesystem.realpath(
os.path.join(self.config.parser.root, "../conf.d/apache2"))
self.config.parser.variables = {}
with mock.patch("certbot._internal.apache.override_gentoo.GentooParser.update_modules"):
with mock.patch("certbot._internal.plugins.apache.override_gentoo.GentooParser.update_modules"):
self.config.parser.update_runtime_variables()
for define in defines:
assert define in self.config.parser.variables
@mock.patch("certbot._internal.apache.apache_util.parse_from_subprocess")
@mock.patch("certbot._internal.plugins.apache.apache_util.parse_from_subprocess")
def test_no_binary_configdump(self, mock_subprocess):
"""Make sure we don't call binary dumps other than modules from Apache
as this is not supported in Gentoo currently"""
with mock.patch("certbot._internal.apache.override_gentoo.GentooParser.update_modules"):
with mock.patch("certbot._internal.plugins.apache.override_gentoo.GentooParser.update_modules"):
self.config.parser.update_runtime_variables()
self.config.parser.reset_modules()
assert mock_subprocess.called is False
@@ -102,7 +102,7 @@ class MultipleVhostsTestGentoo(util.ApacheTest):
self.config.parser.reset_modules()
assert mock_subprocess.called is True
@mock.patch("certbot._internal.apache.apache_util._get_runtime_cfg")
@mock.patch("certbot._internal.plugins.apache.apache_util._get_runtime_cfg")
def test_opportunistic_httpd_runtime_parsing(self, mock_get):
mod_val = (
'Loaded Modules:\n'
@@ -126,7 +126,7 @@ class MultipleVhostsTestGentoo(util.ApacheTest):
assert len(self.config.parser.modules) == 4
assert "mod_another.c" in self.config.parser.modules
@mock.patch("certbot._internal.apache.configurator.util.run_script")
@mock.patch("certbot._internal.plugins.apache.configurator.util.run_script")
def test_alt_restart_works(self, mock_run_script):
mock_run_script.side_effect = [None, errors.SubprocessError, None]
self.config.restart()
@@ -1,4 +1,4 @@
"""Test for certbot._internal.apache.http_01."""
"""Test for certbot._internal.plugins.apache.http_01."""
import errno
import sys
from unittest import mock
@@ -11,14 +11,14 @@ from certbot import errors
from certbot.compat import filesystem
from certbot.compat import os
from certbot.tests import acme_util
from certbot._internal.apache.parser import get_aug_path
from certbot._internal.apache.tests import util
from certbot._internal.plugins.apache.parser import get_aug_path
from certbot._internal.plugins.apache.tests import util
NUM_ACHALLS = 3
class ApacheHttp01Test(util.ApacheTest):
"""Test for certbot._internal.apache.http_01.ApacheHttp01."""
"""Test for certbot._internal.plugins.apache.http_01.ApacheHttp01."""
def setUp(self, *args, **kwargs): # pylint: disable=arguments-differ
super().setUp(*args, **kwargs)
@@ -45,7 +45,7 @@ class ApacheHttp01Test(util.ApacheTest):
self.config.parser.modules["mod_{0}.c".format(mod)] = None
self.config.parser.modules[mod + "_module"] = None
from certbot._internal.apache.http_01 import ApacheHttp01
from certbot._internal.plugins.apache.http_01 import ApacheHttp01
self.http = ApacheHttp01(self.config)
def test_empty_perform(self):
@@ -61,7 +61,7 @@ class ApacheHttp01Test(util.ApacheTest):
with pytest.raises(errors.ConfigurationError):
self.http.perform()
@mock.patch("certbot._internal.apache.configurator.ApacheConfigurator.enable_mod")
@mock.patch("certbot._internal.plugins.apache.configurator.ApacheConfigurator.enable_mod")
def test_enable_modules_apache_2_4(self, mock_enmod):
del self.config.parser.modules["authz_core_module"]
del self.config.parser.modules["mod_authz_host.c"]
@@ -210,7 +210,7 @@ class ApacheHttp01Test(util.ApacheTest):
assert os.path.exists(challenge_dir) is True
@mock.patch("certbot._internal.apache.http_01.filesystem.makedirs")
@mock.patch("certbot._internal.plugins.apache.http_01.filesystem.makedirs")
def test_failed_makedirs(self, mock_makedirs):
mock_makedirs.side_effect = OSError(errno.EACCES, "msg")
self.http.add_chall(self.achalls[0])
@@ -1,4 +1,4 @@
"""Tests for certbot._internal.apache.obj."""
"""Tests for certbot._internal.plugins.apache.obj."""
import sys
import unittest
@@ -9,8 +9,8 @@ class VirtualHostTest(unittest.TestCase):
"""Test the VirtualHost class."""
def setUp(self):
from certbot._internal.apache.obj import Addr
from certbot._internal.apache.obj import VirtualHost
from certbot._internal.plugins.apache.obj import Addr
from certbot._internal.plugins.apache.obj import VirtualHost
self.addr1 = Addr.fromstring("127.0.0.1")
self.addr2 = Addr.fromstring("127.0.0.1:443")
@@ -27,7 +27,7 @@ class VirtualHostTest(unittest.TestCase):
def test_repr(self):
assert repr(self.addr2) == \
"certbot._internal.apache.obj.Addr(('127.0.0.1', '443'))"
"certbot._internal.plugins.apache.obj.Addr(('127.0.0.1', '443'))"
def test_eq(self):
assert self.vhost1b == self.vhost1
@@ -40,8 +40,8 @@ class VirtualHostTest(unittest.TestCase):
assert self.vhost1 == self.vhost1b
def test_conflicts(self):
from certbot._internal.apache.obj import Addr
from certbot._internal.apache.obj import VirtualHost
from certbot._internal.plugins.apache.obj import Addr
from certbot._internal.plugins.apache.obj import VirtualHost
complex_vh = VirtualHost(
"fp", "vhp",
@@ -57,7 +57,7 @@ class VirtualHostTest(unittest.TestCase):
assert self.vhost2.conflicts([self.addr1, self.addr_default]) is False
def test_same_server(self):
from certbot._internal.apache.obj import VirtualHost
from certbot._internal.plugins.apache.obj import VirtualHost
no_name1 = VirtualHost(
"fp", "vhp", {self.addr1}, False, False, None)
no_name2 = VirtualHost(
@@ -80,7 +80,7 @@ class VirtualHostTest(unittest.TestCase):
class AddrTest(unittest.TestCase):
"""Test obj.Addr."""
def setUp(self):
from certbot._internal.apache.obj import Addr
from certbot._internal.plugins.apache.obj import Addr
self.addr = Addr.fromstring("*:443")
self.addr1 = Addr.fromstring("127.0.0.1")
@@ -95,7 +95,7 @@ class AddrTest(unittest.TestCase):
assert self.addr2.is_wildcard() is True
def test_get_sni_addr(self):
from certbot._internal.apache.obj import Addr
from certbot._internal.plugins.apache.obj import Addr
assert self.addr.get_sni_addr("443") == Addr.fromstring("*:443")
assert self.addr.get_sni_addr("225") == Addr.fromstring("*:225")
assert self.addr1.get_sni_addr("443") == Addr.fromstring("127.0.0.1")
@@ -1,4 +1,4 @@
"""Tests for certbot._internal.apache.parser."""
"""Tests for certbot._internal.plugins.apache.parser."""
import sys
from unittest import mock
@@ -6,7 +6,7 @@ import pytest
from certbot import errors
from certbot.compat import os
from certbot._internal.apache.tests import util
from certbot._internal.plugins.apache.tests import util
class BasicParserTest(util.ParserTest):
@@ -25,7 +25,7 @@ class BasicParserTest(util.ParserTest):
with pytest.raises(errors.PluginError):
self.parser.unsaved_files()
@mock.patch("certbot._internal.apache.parser.logger")
@mock.patch("certbot._internal.plugins.apache.parser.logger")
def test_bad_save_errors(self, mock_logger):
nx_path = "/non/existent/path.conf"
self.parser.aug.set("/augeas/load/Httpd/incl[last()]", nx_path)
@@ -120,7 +120,7 @@ class BasicParserTest(util.ParserTest):
Path must be valid before attempting to add to augeas
"""
from certbot._internal.apache.parser import get_aug_path
from certbot._internal.plugins.apache.parser import get_aug_path
# This makes sure that find_dir will work
self.parser.modules["mod_ssl.c"] = "/fake/path"
@@ -135,7 +135,7 @@ class BasicParserTest(util.ParserTest):
assert "IfModule" in matches[0]
def test_add_dir_to_ifmodssl_multiple(self):
from certbot._internal.apache.parser import get_aug_path
from certbot._internal.plugins.apache.parser import get_aug_path
# This makes sure that find_dir will work
self.parser.modules["mod_ssl.c"] = "/fake/path"
@@ -150,11 +150,11 @@ class BasicParserTest(util.ParserTest):
assert "IfModule" in matches[0]
def test_get_aug_path(self):
from certbot._internal.apache.parser import get_aug_path
from certbot._internal.plugins.apache.parser import get_aug_path
assert "/files/etc/apache" == get_aug_path("/etc/apache")
def test_set_locations(self):
with mock.patch("certbot._internal.apache.parser.os.path") as mock_path:
with mock.patch("certbot._internal.plugins.apache.parser.os.path") as mock_path:
mock_path.isfile.side_effect = [False, False]
@@ -164,18 +164,18 @@ class BasicParserTest(util.ParserTest):
assert results["default"] == results["listen"]
assert results["default"] == results["name"]
@mock.patch("certbot._internal.apache.parser.ApacheParser.find_dir")
@mock.patch("certbot._internal.apache.parser.ApacheParser.get_arg")
@mock.patch("certbot._internal.plugins.apache.parser.ApacheParser.find_dir")
@mock.patch("certbot._internal.plugins.apache.parser.ApacheParser.get_arg")
def test_parse_modules_bad_syntax(self, mock_arg, mock_find):
mock_find.return_value = ["1", "2", "3", "4", "5", "6", "7", "8"]
mock_arg.return_value = None
with mock.patch("certbot._internal.apache.parser.logger") as mock_logger:
with mock.patch("certbot._internal.plugins.apache.parser.logger") as mock_logger:
self.parser.parse_modules()
# Make sure that we got None return value and logged the file
assert mock_logger.debug.called is True
@mock.patch("certbot._internal.apache.parser.ApacheParser.find_dir")
@mock.patch("certbot._internal.apache.apache_util._get_runtime_cfg")
@mock.patch("certbot._internal.plugins.apache.parser.ApacheParser.find_dir")
@mock.patch("certbot._internal.plugins.apache.apache_util._get_runtime_cfg")
def test_update_runtime_variables(self, mock_cfg, _):
define_val = (
'ServerRoot: "/etc/apache2"\n'
@@ -277,7 +277,7 @@ class BasicParserTest(util.ParserTest):
self.parser.modules = {}
with mock.patch(
"certbot._internal.apache.parser.ApacheParser.parse_file") as mock_parse:
"certbot._internal.plugins.apache.parser.ApacheParser.parse_file") as mock_parse:
self.parser.update_runtime_variables()
assert self.parser.variables == expected_vars
assert len(self.parser.modules) == 58
@@ -285,8 +285,8 @@ class BasicParserTest(util.ParserTest):
# Make sure we tried to include them all.
assert mock_parse.call_count == 25
@mock.patch("certbot._internal.apache.parser.ApacheParser.find_dir")
@mock.patch("certbot._internal.apache.apache_util._get_runtime_cfg")
@mock.patch("certbot._internal.plugins.apache.parser.ApacheParser.find_dir")
@mock.patch("certbot._internal.plugins.apache.apache_util._get_runtime_cfg")
def test_update_runtime_variables_alt_values(self, mock_cfg, _):
inc_val = (
'Included configuration files:\n'
@@ -300,7 +300,7 @@ class BasicParserTest(util.ParserTest):
self.parser.modules = {}
with mock.patch(
"certbot._internal.apache.parser.ApacheParser.parse_file") as mock_parse:
"certbot._internal.plugins.apache.parser.ApacheParser.parse_file") as mock_parse:
self.parser.update_runtime_variables()
# No matching modules should have been found
assert len(self.parser.modules) == 0
@@ -308,13 +308,13 @@ class BasicParserTest(util.ParserTest):
# path derived from root configuration Include statements
assert mock_parse.call_count == 1
@mock.patch("certbot._internal.apache.apache_util.subprocess.run")
@mock.patch("certbot._internal.plugins.apache.apache_util.subprocess.run")
def test_update_runtime_vars_bad_ctl(self, mock_run):
mock_run.side_effect = OSError
with pytest.raises(errors.MisconfigurationError):
self.parser.update_runtime_variables()
@mock.patch("certbot._internal.apache.apache_util.subprocess.run")
@mock.patch("certbot._internal.plugins.apache.apache_util.subprocess.run")
def test_update_runtime_vars_bad_exit(self, mock_run):
mock_proc = mock_run.return_value
mock_proc.stdout = ""
@@ -324,7 +324,7 @@ class BasicParserTest(util.ParserTest):
self.parser.update_runtime_variables()
def test_add_comment(self):
from certbot._internal.apache.parser import get_aug_path
from certbot._internal.plugins.apache.parser import get_aug_path
self.parser.add_comment(get_aug_path(self.parser.loc["name"]), "123456")
comm = self.parser.find_comments("123456")
assert len(comm) == 1
@@ -333,9 +333,9 @@ class BasicParserTest(util.ParserTest):
class ParserInitTest(util.ApacheTest):
@mock.patch("certbot._internal.apache.parser.init_augeas")
@mock.patch("certbot._internal.plugins.apache.parser.init_augeas")
def test_prepare_no_augeas(self, mock_init_augeas):
from certbot._internal.apache.parser import ApacheParser
from certbot._internal.plugins.apache.parser import ApacheParser
mock_init_augeas.side_effect = errors.NoInstallationError
self.config.config_test = mock.Mock()
with pytest.raises(errors.NoInstallationError):
@@ -343,17 +343,17 @@ class ParserInitTest(util.ApacheTest):
"/dummy/vhostpath", version=(2, 4, 22))
def test_init_old_aug(self):
from certbot._internal.apache.parser import ApacheParser
with mock.patch("certbot._internal.apache.parser.ApacheParser.check_aug_version") as mock_c:
from certbot._internal.plugins.apache.parser import ApacheParser
with mock.patch("certbot._internal.plugins.apache.parser.ApacheParser.check_aug_version") as mock_c:
mock_c.return_value = False
with pytest.raises(errors.NotSupportedError):
ApacheParser(os.path.relpath(self.config_path), self.config,
"/dummy/vhostpath", version=(2, 4, 22))
def test_root_normalized(self):
from certbot._internal.apache.parser import ApacheParser
from certbot._internal.plugins.apache.parser import ApacheParser
with mock.patch("certbot._internal.apache.parser.ApacheParser."
with mock.patch("certbot._internal.plugins.apache.parser.ApacheParser."
"update_runtime_variables"):
path = os.path.join(
self.temp_dir,
@@ -364,8 +364,8 @@ class ParserInitTest(util.ApacheTest):
assert parser.root == self.config_path
def test_root_absolute(self):
from certbot._internal.apache.parser import ApacheParser
with mock.patch("certbot._internal.apache.parser.ApacheParser."
from certbot._internal.plugins.apache.parser import ApacheParser
with mock.patch("certbot._internal.plugins.apache.parser.ApacheParser."
"update_runtime_variables"):
parser = ApacheParser(
os.path.relpath(self.config_path), self.config, "/dummy/vhostpath")
@@ -373,8 +373,8 @@ class ParserInitTest(util.ApacheTest):
assert parser.root == self.config_path
def test_root_no_trailing_slash(self):
from certbot._internal.apache.parser import ApacheParser
with mock.patch("certbot._internal.apache.parser.ApacheParser."
from certbot._internal.plugins.apache.parser import ApacheParser
with mock.patch("certbot._internal.plugins.apache.parser.ApacheParser."
"update_runtime_variables"):
parser = ApacheParser(
self.config_path + os.path.sep, self.config, "/dummy/vhostpath")
@@ -6,7 +6,7 @@ from unittest import mock
import pytest
from certbot._internal.apache.tests import util
from certbot._internal.plugins.apache.tests import util
if importlib.util.find_spec('apacheconfig'):
@@ -4,8 +4,8 @@ import sys
import pytest
from certbot._internal.apache import interfaces
from certbot._internal.apache import parsernode_util as util
from certbot._internal.plugins.apache import interfaces
from certbot._internal.plugins.apache import parsernode_util as util
class DummyParserNode(interfaces.ParserNode):
@@ -3,7 +3,7 @@ import sys
import pytest
from certbot._internal.apache import parsernode_util as util
from certbot._internal.plugins.apache import parsernode_util as util
def _setup_parsernode():
@@ -11,9 +11,9 @@ from certbot import util
from certbot.compat import os
from certbot.plugins import common
from certbot.tests import util as test_util
from certbot._internal.apache import configurator
from certbot._internal.apache import entrypoint
from certbot._internal.apache import obj
from certbot._internal.plugins.apache import configurator
from certbot._internal.plugins.apache import entrypoint
from certbot._internal.plugins.apache import obj
class ApacheTest(unittest.TestCase):
@@ -68,10 +68,10 @@ class ParserTest(ApacheTest):
) -> None:
super().setUp(test_dir, config_root, vhost_root)
from certbot._internal.apache.parser import ApacheParser
from certbot._internal.plugins.apache.parser import ApacheParser
self.aug = augeas.Augeas(
flags=augeas.Augeas.NONE | augeas.Augeas.NO_MODL_AUTOLOAD)
with mock.patch("certbot._internal.apache.parser.ApacheParser."
with mock.patch("certbot._internal.plugins.apache.parser.ApacheParser."
"update_runtime_variables"):
self.parser = ApacheParser(
self.config_path, self.config, self.vhost_path)
@@ -103,13 +103,13 @@ def get_apache_configurator(
in_progress_dir=os.path.join(backups, "IN_PROGRESS"),
work_dir=work_dir)
with mock.patch("certbot._internal.apache.configurator.util.run_script"):
with mock.patch("certbot._internal.apache.configurator.util."
with mock.patch("certbot._internal.plugins.apache.configurator.util.run_script"):
with mock.patch("certbot._internal.plugins.apache.configurator.util."
"exe_exists") as mock_exe_exists:
mock_exe_exists.return_value = True
with mock.patch("certbot._internal.apache.parser.ApacheParser."
with mock.patch("certbot._internal.plugins.apache.parser.ApacheParser."
"update_runtime_variables"):
with mock.patch("certbot._internal.apache.apache_util.parse_from_subprocess") as mock_sp:
with mock.patch("certbot._internal.plugins.apache.apache_util.parse_from_subprocess") as mock_sp:
mock_sp.return_value = []
try:
config_class = entrypoint.OVERRIDE_CLASSES[os_info]
@@ -25,12 +25,12 @@ from certbot import util
from certbot.compat import os
from certbot.display import util as display_util
from certbot.plugins import common
from certbot._internal.nginx import constants
from certbot._internal.nginx import display_ops
from certbot._internal.nginx import http_01
from certbot._internal.nginx import nginxparser
from certbot._internal.nginx import obj
from certbot._internal.nginx import parser
from certbot._internal.plugins.nginx import constants
from certbot._internal.plugins.nginx import display_ops
from certbot._internal.plugins.nginx import http_01
from certbot._internal.plugins.nginx import nginxparser
from certbot._internal.plugins.nginx import obj
from certbot._internal.plugins.nginx import parser
NAME_RANK = 0
START_WILDCARD_RANK = 1
@@ -52,7 +52,7 @@ class NginxConfigurator(common.Configurator):
:type config: certbot.configuration.NamespaceConfig
:ivar parser: Handles low level parsing
:type parser: :class:`~certbot._internal.nginx.parser`
:type parser: :class:`~certbot._internal.plugins.nginx.parser`
:ivar str save_notes: Human-readable config change notes
@@ -348,7 +348,7 @@ class NginxConfigurator(common.Configurator):
:param str target_name: domain name
:returns: ssl vhosts associated with name
:rtype: list of :class:`~certbot._internal.nginx.obj.VirtualHost`
:rtype: list of :class:`~certbot._internal.plugins.nginx.obj.VirtualHost`
"""
return [vhost for vhost in self._choose_vhosts_common(target_name) if vhost.ssl]
@@ -369,7 +369,7 @@ class NginxConfigurator(common.Configurator):
:param str fullchain_path: certificates to use when creating SSL vhosts
:returns: ssl vhosts associated with name
:rtype: list of :class:`~certbot._internal.nginx.obj.VirtualHost`
:rtype: list of :class:`~certbot._internal.plugins.nginx.obj.VirtualHost`
"""
vhosts = self._choose_vhosts_common(target_name)
@@ -478,7 +478,7 @@ class NginxConfigurator(common.Configurator):
:param list matches: list of dicts containing the vhost, the matching name,
and the numerical rank
:returns: the most matching vhost
:rtype: :class:`~certbot._internal.nginx.obj.VirtualHost`
:rtype: :class:`~certbot._internal.plugins.nginx.obj.VirtualHost`
"""
if not matches:
@@ -564,7 +564,7 @@ class NginxConfigurator(common.Configurator):
:param str port: port number
:returns: vhosts associated with name
:rtype: list of :class:`~certbot._internal.nginx.obj.VirtualHost`
:rtype: list of :class:`~certbot._internal.plugins.nginx.obj.VirtualHost`
"""
if util.is_wildcard_domain(target_name):
@@ -586,7 +586,7 @@ class NginxConfigurator(common.Configurator):
:param str target_name: non-wildcard domain name
:returns: tuple of HTTP and HTTPS virtualhosts
:rtype: tuple of :class:`~certbot._internal.nginx.obj.VirtualHost`
:rtype: tuple of :class:`~certbot._internal.plugins.nginx.obj.VirtualHost`
"""
vhosts = [m['vhost'] for m in self._get_ranked_matches(target_name) if m and 'vhost' in m]
@@ -712,7 +712,7 @@ class NginxConfigurator(common.Configurator):
Make a server SSL by adding new listen and SSL directives.
:param vhost: The vhost to add SSL to.
:type vhost: :class:`~certbot._internal.nginx.obj.VirtualHost`
:type vhost: :class:`~certbot._internal.plugins.nginx.obj.VirtualHost`
:param str key_path: key to use for SSL
:param str fullchain_path: certificates to use for SSL
@@ -868,9 +868,9 @@ class NginxConfigurator(common.Configurator):
:param vhost: The server block to break up into two.
:param list only_directives: If this exists, only duplicate these directives
when splitting the block.
:type vhost: :class:`~certbot._internal.nginx.obj.VirtualHost`
:type vhost: :class:`~certbot._internal.plugins.nginx.obj.VirtualHost`
:returns: tuple (http_vhost, https_vhost)
:rtype: tuple of type :class:`~certbot._internal.nginx.obj.VirtualHost`
:rtype: tuple of type :class:`~certbot._internal.plugins.nginx.obj.VirtualHost`
"""
http_vhost = self.parser.duplicate_vhost(vhost, only_directives=only_directives)
@@ -4,7 +4,7 @@ from typing import Iterable
from typing import Optional
from certbot.display import util as display_util
from certbot._internal.nginx.obj import VirtualHost
from certbot._internal.plugins.nginx.obj import VirtualHost
logger = logging.getLogger(__name__)
@@ -11,11 +11,11 @@ from certbot import errors
from certbot.achallenges import KeyAuthorizationAnnotatedChallenge
from certbot.compat import os
from certbot.plugins import common
from certbot._internal.nginx import nginxparser
from certbot._internal.nginx.obj import Addr
from certbot._internal.plugins.nginx import nginxparser
from certbot._internal.plugins.nginx.obj import Addr
if TYPE_CHECKING:
from certbot._internal.nginx.configurator import NginxConfigurator
from certbot._internal.plugins.nginx.configurator import NginxConfigurator
logger = logging.getLogger(__name__)
@@ -146,7 +146,7 @@ class NginxHttp01(common.ChallengePerformer):
def _default_listen_addresses(self) -> list[Addr]:
"""Finds addresses for a challenge block to listen on.
:returns: list of :class:`certbot._internal.nginx.obj.Addr` to apply
:returns: list of :class:`certbot._internal.plugins.nginx.obj.Addr` to apply
:rtype: list
"""
addresses: list[Addr] = []
@@ -136,7 +136,7 @@ class Addr(common.Addr):
def __hash__(self) -> int: # pylint: disable=useless-super-delegation
# Python 3 requires explicit overridden for __hash__
# See certbot-apache/src/certbot._internal.apache/obj.py for more information
# See certbot-apache/src/certbot._internal.plugins.apache/obj.py for more information
return super().__hash__()
def super_eq(self, other: "Addr") -> bool:
@@ -18,9 +18,9 @@ import pyparsing
from certbot import errors
from certbot.compat import os
from certbot._internal.nginx import nginxparser
from certbot._internal.nginx import obj
from certbot._internal.nginx.nginxparser import UnspacedList
from certbot._internal.plugins.nginx import nginxparser
from certbot._internal.plugins.nginx import obj
from certbot._internal.plugins.nginx.nginxparser import UnspacedList
logger = logging.getLogger(__name__)
@@ -145,7 +145,7 @@ class NginxParser:
Technically this is a misnomer because Nginx does not have virtual
hosts, it has 'server blocks'.
:returns: List of :class:`~certbot._internal.nginx.obj.VirtualHost`
:returns: List of :class:`~certbot._internal.plugins.nginx.obj.VirtualHost`
objects found in configuration
:rtype: list
@@ -286,7 +286,7 @@ class NginxParser:
def has_ssl_on_directive(self, vhost: obj.VirtualHost) -> bool:
"""Does vhost have ssl on for all ports?
:param :class:`~certbot._internal.nginx.obj.VirtualHost` vhost: The vhost in question
:param :class:`~certbot._internal.plugins.nginx.obj.VirtualHost` vhost: The vhost in question
:returns: True if 'ssl on' directive is included
:rtype: bool
@@ -313,7 +313,7 @@ class NginxParser:
..todo :: Doesn't match server blocks whose server_name directives are
split across multiple conf files.
:param :class:`~certbot._internal.nginx.obj.VirtualHost` vhost: The vhost
:param :class:`~certbot._internal.plugins.nginx.obj.VirtualHost` vhost: The vhost
whose information we use to match on
:param list directives: The directives to add
:param bool insert_at_top: True if the directives need to be inserted at the top
@@ -336,7 +336,7 @@ class NginxParser:
..todo :: Doesn't match server blocks whose server_name directives are
split across multiple conf files.
:param :class:`~certbot._internal.nginx.obj.VirtualHost` vhost: The vhost
:param :class:`~certbot._internal.plugins.nginx.obj.VirtualHost` vhost: The vhost
whose information we use to match on
:param list directives: The directives to add
:param bool insert_at_top: True if the directives need to be inserted at the top
@@ -350,7 +350,7 @@ class NginxParser:
match_func: Optional[Callable[[Any], bool]] = None) -> None:
"""Remove all directives of type directive_name.
:param :class:`~certbot._internal.nginx.obj.VirtualHost` vhost: The vhost
:param :class:`~certbot._internal.plugins.nginx.obj.VirtualHost` vhost: The vhost
to remove directives from
:param string directive_name: The directive type to remove
:param callable match_func: Function of the directive that returns true for directives
@@ -389,7 +389,7 @@ class NginxParser:
only_directives: Optional[list[Any]] = None) -> obj.VirtualHost:
"""Duplicate the vhost in the configuration files.
:param :class:`~certbot._internal.nginx.obj.VirtualHost` vhost_template: The vhost
:param :class:`~certbot._internal.plugins.nginx.obj.VirtualHost` vhost_template: The vhost
whose information we copy
:param bool remove_singleton_listen_params: If we should remove parameters
from listen directives in the block that can only be used once per address
@@ -397,7 +397,7 @@ class NginxParser:
looks at first level of depth; does not expand includes.
:returns: A vhost object for the newly created vhost
:rtype: :class:`~certbot._internal.nginx.obj.VirtualHost`
:rtype: :class:`~certbot._internal.plugins.nginx.obj.VirtualHost`
"""
# TODO: https://github.com/certbot/certbot/issues/5185
# put it in the same file as the template, at the same level
@@ -1,4 +1,4 @@
"""Test for certbot._internal.nginx.configurator."""
"""Test for certbot._internal.plugins.nginx.configurator."""
import sys
from unittest import mock
@@ -11,11 +11,11 @@ from certbot import crypto_util
from certbot import errors
from certbot.compat import os
from certbot.tests import util as certbot_test_util
from certbot._internal.nginx import obj
from certbot._internal.nginx import parser
from certbot._internal.nginx.configurator import _redirect_block_for_domain
from certbot._internal.nginx.nginxparser import UnspacedList
from certbot._internal.nginx.tests import test_util as util
from certbot._internal.plugins.nginx import obj
from certbot._internal.plugins.nginx import parser
from certbot._internal.plugins.nginx.configurator import _redirect_block_for_domain
from certbot._internal.plugins.nginx.nginxparser import UnspacedList
from certbot._internal.plugins.nginx.tests import test_util as util
class NginxConfiguratorTest(util.NginxTest):
@@ -27,11 +27,11 @@ class NginxConfiguratorTest(util.NginxTest):
self.config = self.get_nginx_configurator(
self.config_path, self.config_dir, self.work_dir, self.logs_dir)
patch = mock.patch('certbot._internal.nginx.configurator.display_util.notify')
patch = mock.patch('certbot._internal.plugins.nginx.configurator.display_util.notify')
self.mock_notify = patch.start()
self.addCleanup(patch.stop)
@mock.patch("certbot._internal.nginx.configurator.util.exe_exists")
@mock.patch("certbot._internal.plugins.nginx.configurator.util.exe_exists")
def test_prepare_no_install(self, mock_exe_exists):
mock_exe_exists.return_value = False
with pytest.raises(errors.NoInstallationError):
@@ -41,8 +41,8 @@ class NginxConfiguratorTest(util.NginxTest):
assert (1, 6, 2) == self.config.version
assert 16 == len(self.config.parser.parsed)
@mock.patch("certbot._internal.nginx.configurator.util.exe_exists")
@mock.patch("certbot._internal.nginx.configurator.subprocess.run")
@mock.patch("certbot._internal.plugins.nginx.configurator.util.exe_exists")
@mock.patch("certbot._internal.plugins.nginx.configurator.subprocess.run")
def test_prepare_initializes_version(self, mock_run, mock_exe_exists):
mock_run.return_value.stdout = ""
mock_run.return_value.stderr = "\n".join(
@@ -76,7 +76,7 @@ class NginxConfiguratorTest(util.NginxTest):
self.config.config_test = mock.Mock()
certbot_test_util.lock_and_call(self._test_prepare_locked, server_root)
@mock.patch("certbot._internal.nginx.configurator.util.exe_exists")
@mock.patch("certbot._internal.plugins.nginx.configurator.util.exe_exists")
def _test_prepare_locked(self, unused_exe_exists):
try:
self.config.prepare()
@@ -87,8 +87,8 @@ class NginxConfiguratorTest(util.NginxTest):
else: # pragma: no cover
self.fail("Exception wasn't raised!")
@mock.patch("certbot._internal.nginx.configurator.socket.gethostname")
@mock.patch("certbot._internal.nginx.configurator.socket.gethostbyaddr")
@mock.patch("certbot._internal.plugins.nginx.configurator.socket.gethostname")
@mock.patch("certbot._internal.plugins.nginx.configurator.socket.gethostbyaddr")
def test_get_all_names(self, mock_gethostbyaddr, mock_gethostname):
mock_gethostbyaddr.return_value = ('155.225.50.69.nephoscale.net', [], [])
mock_gethostname.return_value = ('example.net')
@@ -268,7 +268,7 @@ class NginxConfiguratorTest(util.NginxTest):
"example/chain.pem",
None)
@mock.patch('certbot._internal.nginx.parser.NginxParser.update_or_add_server_directives')
@mock.patch('certbot._internal.plugins.nginx.parser.NginxParser.update_or_add_server_directives')
def test_deploy_cert_raise_on_add_error(self, mock_update_or_add_server_directives):
mock_update_or_add_server_directives.side_effect = errors.MisconfigurationError()
with pytest.raises(errors.PluginError):
@@ -364,9 +364,9 @@ class NginxConfiguratorTest(util.NginxTest):
]] == \
parsed_migration_conf[0]
@mock.patch("certbot._internal.nginx.configurator.http_01.NginxHttp01.perform")
@mock.patch("certbot._internal.nginx.configurator.NginxConfigurator.restart")
@mock.patch("certbot._internal.nginx.configurator.NginxConfigurator.revert_challenge_config")
@mock.patch("certbot._internal.plugins.nginx.configurator.http_01.NginxHttp01.perform")
@mock.patch("certbot._internal.plugins.nginx.configurator.NginxConfigurator.restart")
@mock.patch("certbot._internal.plugins.nginx.configurator.NginxConfigurator.revert_challenge_config")
def test_perform_and_cleanup(self, mock_revert, mock_restart, mock_http_perform):
# Only tests functionality specific to configurator.perform
# Note: As more challenges are offered this will have to be expanded
@@ -394,7 +394,7 @@ class NginxConfiguratorTest(util.NginxTest):
assert mock_revert.call_count == 1
assert mock_restart.call_count == 2
@mock.patch("certbot._internal.nginx.configurator.subprocess.run")
@mock.patch("certbot._internal.plugins.nginx.configurator.subprocess.run")
def test_get_version(self, mock_run):
mock_run.return_value.stdout = ""
mock_run.return_value.stderr = "\n".join(
@@ -455,7 +455,7 @@ class NginxConfiguratorTest(util.NginxTest):
with pytest.raises(errors.PluginError):
self.config.get_version()
@mock.patch("certbot._internal.nginx.configurator.subprocess.run")
@mock.patch("certbot._internal.plugins.nginx.configurator.subprocess.run")
def test_get_openssl_version(self, mock_run):
# pylint: disable=protected-access
mock_run.return_value.stdout = ""
@@ -517,8 +517,8 @@ class NginxConfiguratorTest(util.NginxTest):
"""
assert self.config._get_openssl_version() == ""
@mock.patch("certbot._internal.nginx.configurator.subprocess.run")
@mock.patch("certbot._internal.nginx.configurator.time")
@mock.patch("certbot._internal.plugins.nginx.configurator.subprocess.run")
@mock.patch("certbot._internal.plugins.nginx.configurator.time")
def test_nginx_restart(self, mock_time, mock_run):
mocked = mock_run.return_value
mocked.stdout = ''
@@ -528,8 +528,8 @@ class NginxConfiguratorTest(util.NginxTest):
assert mock_run.call_count == 1
mock_time.sleep.assert_called_once_with(0.1234)
@mock.patch("certbot._internal.nginx.configurator.subprocess.run")
@mock.patch("certbot._internal.nginx.configurator.logger.debug")
@mock.patch("certbot._internal.plugins.nginx.configurator.subprocess.run")
@mock.patch("certbot._internal.plugins.nginx.configurator.logger.debug")
def test_nginx_restart_fail(self, mock_log_debug, mock_run):
mocked = mock_run.return_value
mocked.stdout = ''
@@ -540,7 +540,7 @@ class NginxConfiguratorTest(util.NginxTest):
assert mock_run.call_count == 2
mock_log_debug.assert_called_once_with("nginx reload failed:\n%s", "")
@mock.patch("certbot._internal.nginx.configurator.subprocess.run")
@mock.patch("certbot._internal.plugins.nginx.configurator.subprocess.run")
def test_no_nginx_start(self, mock_run):
mock_run.side_effect = OSError("Can't find program")
with pytest.raises(errors.MisconfigurationError):
@@ -687,20 +687,20 @@ class NginxConfiguratorTest(util.NginxTest):
self.config.enhance("migration.com",
"ensure-http-header", "Strict-Transport-Security")
@mock.patch('certbot._internal.nginx.obj.VirtualHost.contains_list')
@mock.patch('certbot._internal.plugins.nginx.obj.VirtualHost.contains_list')
def test_certbot_redirect_exists(self, mock_contains_list):
# Test that we add no redirect statement if there is already a
# redirect in the block that is managed by certbot
# Has a certbot redirect
mock_contains_list.return_value = True
with mock.patch("certbot._internal.nginx.configurator.logger") as mock_logger:
with mock.patch("certbot._internal.plugins.nginx.configurator.logger") as mock_logger:
self.config.enhance("www.example.com", "redirect")
assert mock_logger.info.call_args[0][0] == \
"Traffic on port %s already redirecting to ssl in %s"
def test_redirect_dont_enhance(self):
# Test that we don't accidentally add redirect to ssl-only block
with mock.patch("certbot._internal.nginx.configurator.logger") as mock_logger:
with mock.patch("certbot._internal.plugins.nginx.configurator.logger") as mock_logger:
self.config.enhance("geese.com", "redirect")
assert mock_logger.info.call_args[0][0] == \
'No matching insecure server blocks listening on port %s found.'
@@ -895,7 +895,7 @@ class NginxConfiguratorTest(util.NginxTest):
assert util.contains_at_depth(generated_conf, expected, 2)
@mock.patch('certbot.reverter.logger')
@mock.patch('certbot._internal.nginx.parser.NginxParser.load')
@mock.patch('certbot._internal.plugins.nginx.parser.NginxParser.load')
def test_parser_reload_after_config_changes(self, mock_parser_load, unused_mock_logger):
self.config.recovery_routine()
self.config.revert_challenge_config()
@@ -904,7 +904,7 @@ class NginxConfiguratorTest(util.NginxTest):
def test_choose_vhosts_wildcard(self):
# pylint: disable=protected-access
mock_path = "certbot._internal.nginx.display_ops.select_vhost_multiple"
mock_path = "certbot._internal.plugins.nginx.display_ops.select_vhost_multiple"
with mock.patch(mock_path) as mock_select_vhs:
vhost = [x for x in self.config.parser.get_vhosts()
if 'summer.com' in x.names][0]
@@ -920,7 +920,7 @@ class NginxConfiguratorTest(util.NginxTest):
def test_choose_vhosts_wildcard_redirect(self):
# pylint: disable=protected-access
mock_path = "certbot._internal.nginx.display_ops.select_vhost_multiple"
mock_path = "certbot._internal.plugins.nginx.display_ops.select_vhost_multiple"
with mock.patch(mock_path) as mock_select_vhs:
vhost = [x for x in self.config.parser.get_vhosts()
if 'summer.com' in x.names][0]
@@ -941,7 +941,7 @@ class NginxConfiguratorTest(util.NginxTest):
if 'geese.com' in x.names][0]
mock_choose_vhosts.return_value = [vhost]
self.config._choose_vhosts_wildcard = mock_choose_vhosts
mock_d = "certbot._internal.nginx.configurator.NginxConfigurator._deploy_cert"
mock_d = "certbot._internal.plugins.nginx.configurator.NginxConfigurator._deploy_cert"
with mock.patch(mock_d) as mock_dep:
self.config.deploy_cert("*.com", "/tmp/path",
"/tmp/path", "/tmp/path", "/tmp/path")
@@ -949,7 +949,7 @@ class NginxConfiguratorTest(util.NginxTest):
assert len(mock_dep.call_args_list) == 1
assert vhost == mock_dep.call_args_list[0][0][0]
@mock.patch("certbot._internal.nginx.display_ops.select_vhost_multiple")
@mock.patch("certbot._internal.plugins.nginx.display_ops.select_vhost_multiple")
def test_deploy_cert_wildcard_no_vhosts(self, mock_dialog):
# pylint: disable=protected-access
mock_dialog.return_value = []
@@ -957,7 +957,7 @@ class NginxConfiguratorTest(util.NginxTest):
self.config.deploy_cert("*.wild.cat", "/tmp/path", "/tmp/path",
"/tmp/path", "/tmp/path")
@mock.patch("certbot._internal.nginx.display_ops.select_vhost_multiple")
@mock.patch("certbot._internal.plugins.nginx.display_ops.select_vhost_multiple")
def test_enhance_wildcard_ocsp_after_install(self, mock_dialog):
# pylint: disable=protected-access
vhost = [x for x in self.config.parser.get_vhosts()
@@ -966,7 +966,7 @@ class NginxConfiguratorTest(util.NginxTest):
self.config.enhance("*.com", "staple-ocsp", "example/chain.pem")
assert not mock_dialog.called
@mock.patch("certbot._internal.nginx.display_ops.select_vhost_multiple")
@mock.patch("certbot._internal.plugins.nginx.display_ops.select_vhost_multiple")
def test_enhance_wildcard_redirect_or_ocsp_no_install(self, mock_dialog):
# we need to select an SSL enabled vhost here for the OCSP stapling
# enhancement
@@ -976,7 +976,7 @@ class NginxConfiguratorTest(util.NginxTest):
self.config.enhance("*.com", "staple-ocsp", "example/chain.pem")
assert mock_dialog.called is True
@mock.patch("certbot._internal.nginx.display_ops.select_vhost_multiple")
@mock.patch("certbot._internal.plugins.nginx.display_ops.select_vhost_multiple")
def test_enhance_wildcard_double_redirect(self, mock_dialog):
# pylint: disable=protected-access
vhost = [x for x in self.config.parser.get_vhosts()
@@ -987,7 +987,7 @@ class NginxConfiguratorTest(util.NginxTest):
def test_choose_vhosts_wildcard_no_ssl_filter_port(self):
# pylint: disable=protected-access
mock_path = "certbot._internal.nginx.display_ops.select_vhost_multiple"
mock_path = "certbot._internal.plugins.nginx.display_ops.select_vhost_multiple"
with mock.patch(mock_path) as mock_select_vhs:
mock_select_vhs.return_value = []
self.config._choose_vhosts_wildcard("*.com",
@@ -1055,14 +1055,14 @@ class InstallSslOptionsConfTest(util.NginxTest):
return _hash
def test_prev_file_updates_to_current(self):
from certbot._internal.nginx.constants import ALL_SSL_OPTIONS_HASHES
from certbot._internal.plugins.nginx.constants import ALL_SSL_OPTIONS_HASHES
with mock.patch('certbot.crypto_util.sha256sum',
new=self._mock_hash_except_ssl_conf_src(ALL_SSL_OPTIONS_HASHES[0])):
self._call()
self._assert_current_file()
def test_prev_file_updates_to_current_old_nginx(self):
from certbot._internal.nginx.constants import ALL_SSL_OPTIONS_HASHES
from certbot._internal.plugins.nginx.constants import ALL_SSL_OPTIONS_HASHES
self.config.version = (1, 5, 8)
with mock.patch('certbot.crypto_util.sha256sum',
new=self._mock_hash_except_ssl_conf_src(ALL_SSL_OPTIONS_HASHES[0])):
@@ -1099,7 +1099,7 @@ class InstallSslOptionsConfTest(util.NginxTest):
assert not mock_logger.warning.called
def test_current_file_hash_in_all_hashes(self):
from certbot._internal.nginx.constants import ALL_SSL_OPTIONS_HASHES
from certbot._internal.plugins.nginx.constants import ALL_SSL_OPTIONS_HASHES
assert self._current_ssl_options_hash() in ALL_SSL_OPTIONS_HASHES, \
"Constants.ALL_SSL_OPTIONS_HASHES must be appended" \
" with the sha256 hash of self.config.mod_ssl_conf when it is updated."
@@ -1113,7 +1113,7 @@ class InstallSslOptionsConfTest(util.NginxTest):
"""
import importlib.resources
from certbot._internal.nginx.constants import ALL_SSL_OPTIONS_HASHES
from certbot._internal.plugins.nginx.constants import ALL_SSL_OPTIONS_HASHES
tls_configs_ref = importlib.resources.files("certbot").joinpath(
"_internal", "nginx", "tls_configs")
@@ -1149,10 +1149,10 @@ class InstallSslOptionsConfTest(util.NginxTest):
class DetermineDefaultServerRootTest(certbot_test_util.ConfigTestCase):
"""Tests for certbot._internal.nginx.configurator._determine_default_server_root."""
"""Tests for certbot._internal.plugins.nginx.configurator._determine_default_server_root."""
def _call(self):
from certbot._internal.nginx.configurator import _determine_default_server_root
from certbot._internal.plugins.nginx.configurator import _determine_default_server_root
return _determine_default_server_root()
@mock.patch.dict(os.environ, {"CERTBOT_DOCS": "1"})
@@ -1,17 +1,17 @@
"""Test certbot._internal.nginx.display_ops."""
"""Test certbot._internal.plugins.nginx.display_ops."""
import sys
import pytest
from certbot.display import util as display_util
from certbot.tests import util as certbot_util
from certbot._internal.nginx import parser
from certbot._internal.nginx.display_ops import select_vhost_multiple
from certbot._internal.nginx.tests import test_util as util
from certbot._internal.plugins.nginx import parser
from certbot._internal.plugins.nginx.display_ops import select_vhost_multiple
from certbot._internal.plugins.nginx.tests import test_util as util
class SelectVhostMultiTest(util.NginxTest):
"""Tests for certbot._internal.nginx.display_ops.select_vhost_multiple."""
"""Tests for certbot._internal.plugins.nginx.display_ops.select_vhost_multiple."""
def setUp(self):
super().setUp()
@@ -1,4 +1,4 @@
"""Tests for certbot._internal.nginx.http_01"""
"""Tests for certbot._internal.plugins.nginx.http_01"""
import sys
from unittest import mock
@@ -9,8 +9,8 @@ from acme import challenges, messages
from certbot import achallenges
from certbot.tests import acme_util
from certbot.tests import util as test_util
from certbot._internal.nginx.obj import Addr
from certbot._internal.nginx.tests import test_util as util
from certbot._internal.plugins.nginx.obj import Addr
from certbot._internal.plugins.nginx.tests import test_util as util
AUTH_KEY = jose.JWKRSA.load(test_util.load_vector("rsa512_key.pem"))
@@ -59,14 +59,14 @@ class HttpPerformTest(util.NginxTest):
config = self.get_nginx_configurator(
self.config_path, self.config_dir, self.work_dir, self.logs_dir)
from certbot._internal.nginx import http_01
from certbot._internal.plugins.nginx import http_01
self.http01 = http_01.NginxHttp01(config)
def test_perform0(self):
responses = self.http01.perform()
assert [] == responses
@mock.patch("certbot._internal.nginx.configurator.NginxConfigurator.save")
@mock.patch("certbot._internal.plugins.nginx.configurator.NginxConfigurator.save")
def test_perform1(self, mock_save):
self.http01.add_chall(self.achalls[0])
response = self.achalls[0].response(self.account_key)
@@ -112,7 +112,7 @@ class HttpPerformTest(util.NginxTest):
# self.assertEqual(vhost.addrs, set(v_addr2_print))
# self.assertEqual(vhost.names, set([response.z_domain.decode('ascii')]))
@mock.patch('certbot._internal.nginx.parser.NginxParser.add_server_directives')
@mock.patch('certbot._internal.plugins.nginx.parser.NginxParser.add_server_directives')
def test_mod_config_http_and_https(self, mock_add_server_directives):
"""A server_name with both HTTP and HTTPS vhosts should get modded in both vhosts"""
self.configuration.https_port = 443
@@ -123,8 +123,8 @@ class HttpPerformTest(util.NginxTest):
# 2 * 'rewrite' + 2 * 'return 200 keyauthz' = 4
assert mock_add_server_directives.call_count == 4
@mock.patch('certbot._internal.nginx.parser.nginxparser.dump')
@mock.patch('certbot._internal.nginx.parser.NginxParser.add_server_directives')
@mock.patch('certbot._internal.plugins.nginx.parser.nginxparser.dump')
@mock.patch('certbot._internal.plugins.nginx.parser.NginxParser.add_server_directives')
def test_mod_config_only_https(self, mock_add_server_directives, mock_dump):
"""A server_name with only an HTTPS vhost should get modded"""
self.http01.add_chall(self.achalls[4]) # ipv6ssl.com
@@ -136,7 +136,7 @@ class HttpPerformTest(util.NginxTest):
# should have been created and written to the challenge conf file
assert mock_dump.call_args[0][0] != []
@mock.patch('certbot._internal.nginx.parser.NginxParser.add_server_directives')
@mock.patch('certbot._internal.plugins.nginx.parser.NginxParser.add_server_directives')
def test_mod_config_deduplicate(self, mock_add_server_directives):
"""A vhost that appears in both HTTP and HTTPS vhosts only gets modded once"""
achall = achallenges.KeyAuthorizationAnnotatedChallenge(
@@ -198,7 +198,7 @@ class HttpPerformTest(util.NginxTest):
f.write(original_example_com)
self.http01.configurator.parser.load()
@mock.patch("certbot._internal.nginx.configurator.NginxConfigurator.ipv6_info")
@mock.patch("certbot._internal.plugins.nginx.configurator.NginxConfigurator.ipv6_info")
def test_default_listen_addresses_no_memoization(self, ipv6_info):
# pylint: disable=protected-access
ipv6_info.return_value = (True, True)
@@ -208,7 +208,7 @@ class HttpPerformTest(util.NginxTest):
self.http01._default_listen_addresses()
assert ipv6_info.call_count == 2
@mock.patch("certbot._internal.nginx.configurator.NginxConfigurator.ipv6_info")
@mock.patch("certbot._internal.plugins.nginx.configurator.NginxConfigurator.ipv6_info")
def test_default_listen_addresses_t_t(self, ipv6_info):
# pylint: disable=protected-access
ipv6_info.return_value = (True, True)
@@ -217,7 +217,7 @@ class HttpPerformTest(util.NginxTest):
http_ipv6_addr = Addr.fromstring("[::]:80")
assert addrs == [http_addr, http_ipv6_addr]
@mock.patch("certbot._internal.nginx.configurator.NginxConfigurator.ipv6_info")
@mock.patch("certbot._internal.plugins.nginx.configurator.NginxConfigurator.ipv6_info")
def test_default_listen_addresses_t_f(self, ipv6_info):
# pylint: disable=protected-access
ipv6_info.return_value = (True, False)
@@ -226,7 +226,7 @@ class HttpPerformTest(util.NginxTest):
http_ipv6_addr = Addr.fromstring("[::]:80 ipv6only=on")
assert addrs == [http_addr, http_ipv6_addr]
@mock.patch("certbot._internal.nginx.configurator.NginxConfigurator.ipv6_info")
@mock.patch("certbot._internal.plugins.nginx.configurator.NginxConfigurator.ipv6_info")
def test_default_listen_addresses_f_f(self, ipv6_info):
# pylint: disable=protected-access
ipv6_info.return_value = (False, False)
@@ -1,4 +1,4 @@
"""Test for certbot._internal.nginx.nginxparser."""
"""Test for certbot._internal.plugins.nginx.nginxparser."""
import copy
import operator
import sys
@@ -8,13 +8,13 @@ import unittest
from pyparsing import ParseException
import pytest
from certbot._internal.nginx.nginxparser import dump
from certbot._internal.nginx.nginxparser import dumps
from certbot._internal.nginx.nginxparser import load
from certbot._internal.nginx.nginxparser import loads
from certbot._internal.nginx.nginxparser import RawNginxParser
from certbot._internal.nginx.nginxparser import UnspacedList
from certbot._internal.nginx.tests import test_util as util
from certbot._internal.plugins.nginx.nginxparser import dump
from certbot._internal.plugins.nginx.nginxparser import dumps
from certbot._internal.plugins.nginx.nginxparser import load
from certbot._internal.plugins.nginx.nginxparser import loads
from certbot._internal.plugins.nginx.nginxparser import RawNginxParser
from certbot._internal.plugins.nginx.nginxparser import UnspacedList
from certbot._internal.plugins.nginx.tests import test_util as util
FIRST = operator.itemgetter(0)
@@ -1,4 +1,4 @@
"""Test the helper objects in certbot._internal.nginx.obj."""
"""Test the helper objects in certbot._internal.plugins.nginx.obj."""
import itertools
import sys
import unittest
@@ -9,7 +9,7 @@ import pytest
class AddrTest(unittest.TestCase):
"""Test the Addr class."""
def setUp(self):
from certbot._internal.nginx.obj import Addr
from certbot._internal.plugins.nginx.obj import Addr
self.addr1 = Addr.fromstring("192.168.1.1")
self.addr2 = Addr.fromstring("192.168.1.1:* ssl")
self.addr3 = Addr.fromstring("192.168.1.1:80")
@@ -52,7 +52,7 @@ class AddrTest(unittest.TestCase):
assert self.addr7.default is True
def test_fromstring_socket(self):
from certbot._internal.nginx.obj import Addr, SocketAddrError
from certbot._internal.plugins.nginx.obj import Addr, SocketAddrError
socket_string = r"unix:/var/run/nginx.sock"
with pytest.raises(SocketAddrError, match=socket_string):
Addr.fromstring(socket_string)
@@ -77,14 +77,14 @@ class AddrTest(unittest.TestCase):
assert self.addr6.to_string(include_default=False) == "80"
def test_eq(self):
from certbot._internal.nginx.obj import Addr
from certbot._internal.plugins.nginx.obj import Addr
new_addr1 = Addr.fromstring("192.168.1.1 spdy")
assert self.addr1 == new_addr1
assert self.addr1 != self.addr2
assert self.addr1 != 3333
def test_equivalent_any_addresses(self):
from certbot._internal.nginx.obj import Addr
from certbot._internal.plugins.nginx.obj import Addr
any_addresses = ("0.0.0.0:80 default_server ssl",
"80 default_server ssl",
"*:80 default_server ssl",
@@ -102,7 +102,7 @@ class AddrTest(unittest.TestCase):
Addr.fromstring(any_address)
def test_set_inclusion(self):
from certbot._internal.nginx.obj import Addr
from certbot._internal.plugins.nginx.obj import Addr
set_a = {self.addr1, self.addr2}
addr1b = Addr.fromstring("192.168.1.1")
addr2b = Addr.fromstring("192.168.1.1:* ssl")
@@ -114,8 +114,8 @@ class AddrTest(unittest.TestCase):
class VirtualHostTest(unittest.TestCase):
"""Test the VirtualHost class."""
def setUp(self):
from certbot._internal.nginx.obj import Addr
from certbot._internal.nginx.obj import VirtualHost
from certbot._internal.plugins.nginx.obj import Addr
from certbot._internal.plugins.nginx.obj import VirtualHost
raw1 = [
['listen', '69.50.225.155:9000'],
[['if', '($scheme', '!=', '"https") '],
@@ -164,8 +164,8 @@ class VirtualHostTest(unittest.TestCase):
{'localhost'}, raw_has_hsts, [])
def test_eq(self):
from certbot._internal.nginx.obj import Addr
from certbot._internal.nginx.obj import VirtualHost
from certbot._internal.plugins.nginx.obj import Addr
from certbot._internal.plugins.nginx.obj import VirtualHost
vhost1b = VirtualHost(
"filep",
{Addr.fromstring("localhost blah")}, False, False,
@@ -188,9 +188,9 @@ class VirtualHostTest(unittest.TestCase):
assert self.vhost1.has_header('Bogus-Header') is False
def test_contains_list(self):
from certbot._internal.nginx.configurator import _test_block_from_block
from certbot._internal.nginx.obj import Addr
from certbot._internal.nginx.obj import VirtualHost
from certbot._internal.plugins.nginx.configurator import _test_block_from_block
from certbot._internal.plugins.nginx.obj import Addr
from certbot._internal.plugins.nginx.obj import VirtualHost
test_block = [
['\n ', 'return', ' ', '301', ' ', 'https://$host$request_uri'],
['\n']
@@ -9,19 +9,19 @@ from unittest import mock
import pytest
from certbot._internal.nginx.parser_obj import COMMENT_BLOCK
from certbot._internal.nginx.parser_obj import parse_raw
from certbot._internal.plugins.nginx.parser_obj import COMMENT_BLOCK
from certbot._internal.plugins.nginx.parser_obj import parse_raw
class CommentHelpersTest(unittest.TestCase):
def test_is_comment(self):
from certbot._internal.nginx.parser_obj import _is_comment
from certbot._internal.plugins.nginx.parser_obj import _is_comment
assert _is_comment(parse_raw(['#']))
assert _is_comment(parse_raw(['#', ' literally anything else']))
assert not _is_comment(parse_raw(['not', 'even', 'a', 'comment']))
def test_is_certbot_comment(self):
from certbot._internal.nginx.parser_obj import _is_certbot_comment
from certbot._internal.plugins.nginx.parser_obj import _is_certbot_comment
assert _is_certbot_comment(
parse_raw(COMMENT_BLOCK))
assert not _is_certbot_comment(
@@ -32,8 +32,8 @@ class CommentHelpersTest(unittest.TestCase):
parse_raw(['not', 'even', 'a', 'comment']))
def test_certbot_comment(self):
from certbot._internal.nginx.parser_obj import _certbot_comment
from certbot._internal.nginx.parser_obj import _is_certbot_comment
from certbot._internal.plugins.nginx.parser_obj import _certbot_comment
from certbot._internal.plugins.nginx.parser_obj import _is_certbot_comment
comment = _certbot_comment(None)
assert _is_certbot_comment(comment)
assert comment.dump() == COMMENT_BLOCK
@@ -43,7 +43,7 @@ class CommentHelpersTest(unittest.TestCase):
class ParsingHooksTest(unittest.TestCase):
def test_is_sentence(self):
from certbot._internal.nginx.parser_obj import Sentence
from certbot._internal.plugins.nginx.parser_obj import Sentence
assert not Sentence.should_parse([])
assert Sentence.should_parse([''])
assert Sentence.should_parse(['word'])
@@ -52,7 +52,7 @@ class ParsingHooksTest(unittest.TestCase):
assert not Sentence.should_parse(['word', []])
def test_is_block(self):
from certbot._internal.nginx.parser_obj import Block
from certbot._internal.plugins.nginx.parser_obj import Block
assert not Block.should_parse([])
assert not Block.should_parse([''])
assert not Block.should_parse(['two', 'words'])
@@ -64,7 +64,7 @@ class ParsingHooksTest(unittest.TestCase):
assert Block.should_parse([['block_name'], [['many'], ['statements'], 'here']])
assert Block.should_parse([['if', ' ', '(whatever)'], ['hi']])
@mock.patch("certbot._internal.nginx.parser_obj.Parsable.parsing_hooks")
@mock.patch("certbot._internal.plugins.nginx.parser_obj.Parsable.parsing_hooks")
def test_parse_raw(self, parsing_hooks):
fake_parser1 = mock.Mock()
fake_parser1.should_parse = lambda x: True
@@ -82,7 +82,7 @@ class ParsingHooksTest(unittest.TestCase):
fake_parser1().parse.assert_not_called()
fake_parser2().parse.assert_called_once()
@mock.patch("certbot._internal.nginx.parser_obj.Parsable.parsing_hooks")
@mock.patch("certbot._internal.plugins.nginx.parser_obj.Parsable.parsing_hooks")
def test_parse_raw_no_match(self, parsing_hooks):
from certbot import errors
fake_parser1 = mock.Mock()
@@ -94,7 +94,7 @@ class ParsingHooksTest(unittest.TestCase):
with pytest.raises(errors.MisconfigurationError):
parse_raw([])
@mock.patch("certbot._internal.nginx.parser_obj.Parsable.parsing_hooks")
@mock.patch("certbot._internal.plugins.nginx.parser_obj.Parsable.parsing_hooks")
def test_parse_raw_passes_add_spaces(self, parsing_hooks):
fake_parser1 = mock.Mock()
fake_parser1.should_parse = lambda x: True
@@ -107,7 +107,7 @@ class ParsingHooksTest(unittest.TestCase):
class SentenceTest(unittest.TestCase):
def setUp(self):
from certbot._internal.nginx.parser_obj import Sentence
from certbot._internal.plugins.nginx.parser_obj import Sentence
self.sentence = Sentence(None)
def test_parse_bad_sentence_raises_error(self):
@@ -157,7 +157,7 @@ class SentenceTest(unittest.TestCase):
class BlockTest(unittest.TestCase):
def setUp(self):
from certbot._internal.nginx.parser_obj import Block
from certbot._internal.plugins.nginx.parser_obj import Block
self.bloc = Block(None)
self.name = ['server', 'name']
self.contents = [['thing', '1'], ['thing', '2'], ['another', 'one']]
@@ -173,8 +173,8 @@ class BlockTest(unittest.TestCase):
def test_iterate_match(self):
# can match on contents while expanded
from certbot._internal.nginx.parser_obj import Block
from certbot._internal.nginx.parser_obj import Sentence
from certbot._internal.plugins.nginx.parser_obj import Block
from certbot._internal.plugins.nginx.parser_obj import Sentence
expected = [['thing', '1'], ['thing', '2']]
for i, elem in enumerate(self.bloc.iterate(expanded=True,
match=lambda x: isinstance(x, Sentence) and 'thing' in x.words)):
@@ -216,7 +216,7 @@ class BlockTest(unittest.TestCase):
class StatementsTest(unittest.TestCase):
def setUp(self):
from certbot._internal.nginx.parser_obj import Statements
from certbot._internal.plugins.nginx.parser_obj import Statements
self.statements = Statements(None)
self.raw = [
['sentence', 'one'],
@@ -1,4 +1,4 @@
"""Tests for certbot._internal.nginx.parser."""
"""Tests for certbot._internal.plugins.nginx.parser."""
import glob
import re
import shutil
@@ -8,10 +8,10 @@ import pytest
from certbot import errors
from certbot.compat import os
from certbot._internal.nginx import nginxparser
from certbot._internal.nginx import obj
from certbot._internal.nginx import parser
from certbot._internal.nginx.tests import test_util as util
from certbot._internal.plugins.nginx import nginxparser
from certbot._internal.plugins.nginx import obj
from certbot._internal.plugins.nginx import parser
from certbot._internal.plugins.nginx.tests import test_util as util
class NginxParserTest(util.NginxTest):
@@ -264,7 +264,7 @@ class NginxParserTest(util.NginxTest):
[['foo', 'bar'], ['ssl_certificate',
'/etc/ssl/cert2.pem']])
nparser.add_server_directives(mock_vhost, [['foo', 'bar']])
from certbot._internal.nginx.parser import COMMENT
from certbot._internal.plugins.nginx.parser import COMMENT
assert nparser.parsed[example_com] == \
[[['server'], [['listen', '69.50.225.155:9000'],
['listen', '127.0.0.1'],
@@ -298,7 +298,7 @@ class NginxParserTest(util.NginxTest):
nparser.add_server_directives(mock_vhost,
[['\n ', 'include', ' ',
nparser.abs_path('comment_in_file.conf')]])
from certbot._internal.nginx.parser import COMMENT
from certbot._internal.plugins.nginx.parser import COMMENT
assert nparser.parsed[example_com] == \
[[['server'], [['listen', '69.50.225.155:9000'],
['listen', '127.0.0.1'],
@@ -317,7 +317,7 @@ class NginxParserTest(util.NginxTest):
mock_vhost = obj.VirtualHost(filep, None, None, None, target, None, [0])
nparser.update_or_add_server_directives(
mock_vhost, [['server_name', 'foobar.com']])
from certbot._internal.nginx.parser import COMMENT
from certbot._internal.plugins.nginx.parser import COMMENT
assert nparser.parsed[filep] == \
[[['server'], [['listen', '69.50.225.155:9000'],
['listen', '127.0.0.1'],
@@ -378,8 +378,8 @@ class NginxParserTest(util.NginxTest):
["\n", "a", " ", "b", "\n"],
["c", " ", "d"],
["\n", "e", " ", "f"]])
from certbot._internal.nginx.parser import COMMENT_BLOCK
from certbot._internal.nginx.parser import comment_directive
from certbot._internal.plugins.nginx.parser import COMMENT_BLOCK
from certbot._internal.plugins.nginx.parser import comment_directive
comment_directive(block, 1)
comment_directive(block, 0)
assert block.spaced == [
@@ -403,7 +403,7 @@ class NginxParserTest(util.NginxTest):
ssl_prefer_server_ciphers on;
}""")
block = server_block[0][1]
from certbot._internal.nginx.parser import _comment_out_directive
from certbot._internal.plugins.nginx.parser import _comment_out_directive
_comment_out_directive(block, 4, "blah1")
_comment_out_directive(block, 5, "blah2")
_comment_out_directive(block, 6, "blah3")
@@ -12,8 +12,8 @@ from certbot import util
from certbot.compat import os
from certbot.plugins import common
from certbot.tests import util as test_util
from certbot._internal.nginx import configurator
from certbot._internal.nginx import nginxparser
from certbot._internal.plugins.nginx import configurator
from certbot._internal.plugins.nginx import nginxparser
class NginxTest(test_util.ConfigTestCase):
@@ -63,9 +63,9 @@ class NginxTest(test_util.ConfigTestCase):
self.configuration.http01_port = 80
self.configuration.https_port = 5001
with mock.patch("certbot._internal.nginx.configurator.NginxConfigurator."
with mock.patch("certbot._internal.plugins.nginx.configurator.NginxConfigurator."
"config_test"):
with mock.patch("certbot._internal.nginx.configurator.util."
with mock.patch("certbot._internal.plugins.nginx.configurator.util."
"exe_exists") as mock_exe_exists:
mock_exe_exists.return_value = True
config = configurator.NginxConfigurator(
+8 -8
View File
@@ -123,7 +123,7 @@ deps =
{[testenv:isolated-acme]deps}
-e certbot[test]
# we ignore apache/nginx since those tests depend on their respective extra dependencies (which are pulled in by their plugin)
commands = {[base]pytest} certbot --ignore certbot/src/certbot/_internal/apache --ignore certbot/src/certbot/_internal/nginx
commands = {[base]pytest} certbot --ignore certbot/src/certbot/_internal/plugins/apache --ignore certbot/src/certbot/_internal/plugins/nginx
[testenv:isolated-{apache,cloudflare,digitalocean,dnsimple,dnsmadeeasy,gehirn,google,linode,luadns,nsone,ovh,rfc2136,route53,sakuracloud,nginx}]
description = Tests the plugin without installing any other plugins
@@ -145,7 +145,7 @@ deps =
sakuracloud: -e certbot-dns-sakuracloud
nginx: -e certbot-nginx
commands =
apache: {[base]pytest} certbot/src/certbot/_internal/apache
apache: {[base]pytest} certbot/src/certbot/_internal/plugins/apache
cloudflare: {[base]pytest} certbot-dns-cloudflare
digitalocean: {[base]pytest} certbot-dns-digitalocean
dnsimple: {[base]pytest} certbot-dns-dnsimple
@@ -159,7 +159,7 @@ commands =
rfc2136: {[base]pytest} certbot-dns-rfc2136
route53: {[base]pytest} certbot-dns-route53
sakuracloud: {[base]pytest} certbot-dns-sakuracloud
nginx: {[base]pytest} certbot/src/certbot/_internal/nginx
nginx: {[base]pytest} certbot/src/certbot/_internal/plugins/nginx
[testenv:apacheconftest]
deps =
@@ -167,27 +167,27 @@ deps =
-e certbot
-e certbot-apache
commands =
{toxinidir}/certbot/src/certbot/_internal/apache/tests/apache-conf-files/apache-conf-test --debian-modules
{toxinidir}/certbot/src/certbot/_internal/plugins/apache/tests/apache-conf-files/apache-conf-test --debian-modules
passenv =
SERVER
allowlist_externals =
{toxinidir}/certbot/src/certbot/_internal/apache/tests/apache-conf-files/apache-conf-test
{toxinidir}/certbot/src/certbot/_internal/plugins/apache/tests/apache-conf-files/apache-conf-test
[testenv:apacheconftest-external-with-pebble]
description = Run apacheconftest with pebble and Certbot outside of the tox virtual environment.
deps =
-e certbot-ci
allowlist_externals =
{toxinidir}/certbot/src/certbot/_internal/apache/tests/apache-conf-files/apache-conf-test-pebble.py
{toxinidir}/certbot/src/certbot/_internal/plugins/apache/tests/apache-conf-files/apache-conf-test-pebble.py
commands =
{toxinidir}/certbot/src/certbot/_internal/apache/tests/apache-conf-files/apache-conf-test-pebble.py --debian-modules
{toxinidir}/certbot/src/certbot/_internal/plugins/apache/tests/apache-conf-files/apache-conf-test-pebble.py --debian-modules
[testenv:apacheconftest-with-pebble]
deps =
{[testenv:apacheconftest]deps}
{[testenv:apacheconftest-external-with-pebble]deps}
allowlist_externals =
{toxinidir}/certbot/src/certbot/_internal/apache/tests/apache-conf-files/apache-conf-test-pebble.py
{toxinidir}/certbot/src/certbot/_internal/plugins/apache/tests/apache-conf-files/apache-conf-test-pebble.py
commands = {[testenv:apacheconftest-external-with-pebble]commands}
[testenv:nginxroundtrip]