Make the contents of the apache plugin private (#7579)

Part of #5775.

Tree:
```
certbot-apache/certbot_apache
├── __init__.py
├── _internal
│   ├── apache_util.py
│   ├── augeas_lens
│   │   ├── httpd.aug
│   │   └── README
│   ├── centos-options-ssl-apache.conf
│   ├── configurator.py
│   ├── constants.py
│   ├── display_ops.py
│   ├── entrypoint.py
│   ├── http_01.py
│   ├── __init__.py
│   ├── obj.py
│   ├── options-ssl-apache.conf
│   ├── override_arch.py
│   ├── override_centos.py
│   ├── override_darwin.py
│   ├── override_debian.py
│   ├── override_fedora.py
│   ├── override_gentoo.py
│   ├── override_suse.py
│   └── parser.py
└── tests
    ├── ...
```

* Create _internal folder for certbot_apache

* Move apache_util.py to _internal

* Move display_ops.py to _internal

* Move override_centos.py to _internal

* Move override_gentoo.py to _internal

* Move override_darwin.py to _internal

* Move override_suse.py to _internal

* Move override_debian.py to _internal

* Move override_fedora.py to _internal

* Move override_arch.py to _internal

* Move parser.py to _internal

* Move obj.py to _internal

* Move http_01.py to _internal

* Move entrypoint.py to _internal

* Move constants.py to _internal

* Move configurator.py to _internal

* Move augeas_lens to _internal

* Move options-ssl-apache.conf files to _internal

* move augeas_lens in MANIFEST

* Clean up some stray references to certbot_apache that could use _internal

* Correct imports and lint
This commit is contained in:
ohemorange
2019-11-25 09:44:40 -08:00
committed by Brad Warren
parent a27b1137a5
commit 8139689d4c
42 changed files with 286 additions and 275 deletions
+3 -3
View File
@@ -1,6 +1,6 @@
include LICENSE.txt include LICENSE.txt
include README.rst include README.rst
recursive-include certbot_apache/tests/testdata * recursive-include certbot_apache/tests/testdata *
include certbot_apache/centos-options-ssl-apache.conf include certbot_apache/_internal/centos-options-ssl-apache.conf
include certbot_apache/options-ssl-apache.conf include certbot_apache/_internal/options-ssl-apache.conf
recursive-include certbot_apache/augeas_lens *.aug recursive-include certbot_apache/_internal/augeas_lens *.aug
@@ -0,0 +1 @@
"""Certbot Apache plugin."""
@@ -29,12 +29,12 @@ from certbot.plugins import common
from certbot.plugins.util import path_surgery from certbot.plugins.util import path_surgery
from certbot.plugins.enhancements import AutoHSTSEnhancement from certbot.plugins.enhancements import AutoHSTSEnhancement
from certbot_apache import apache_util from certbot_apache._internal import apache_util
from certbot_apache import constants from certbot_apache._internal import constants
from certbot_apache import display_ops from certbot_apache._internal import display_ops
from certbot_apache import http_01 from certbot_apache._internal import http_01
from certbot_apache import obj from certbot_apache._internal import obj
from certbot_apache import parser from certbot_apache._internal import parser
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -77,11 +77,11 @@ class ApacheConfigurator(common.Installer):
:type config: :class:`~certbot.interfaces.IConfig` :type config: :class:`~certbot.interfaces.IConfig`
:ivar parser: Handles low level parsing :ivar parser: Handles low level parsing
:type parser: :class:`~certbot_apache.parser` :type parser: :class:`~certbot_apache._internal.parser`
:ivar tup version: version of Apache :ivar tup version: version of Apache
:ivar list vhosts: All vhosts found in the configuration :ivar list vhosts: All vhosts found in the configuration
(:class:`list` of :class:`~certbot_apache.obj.VirtualHost`) (:class:`list` of :class:`~certbot_apache._internal.obj.VirtualHost`)
:ivar dict assoc: Mapping between domains and vhosts :ivar dict assoc: Mapping between domains and vhosts
@@ -110,7 +110,7 @@ class ApacheConfigurator(common.Installer):
handle_sites=False, handle_sites=False,
challenge_location="/etc/apache2", challenge_location="/etc/apache2",
MOD_SSL_CONF_SRC=pkg_resources.resource_filename( MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
"certbot_apache", "options-ssl-apache.conf") "certbot_apache", os.path.join("_internal", "options-ssl-apache.conf"))
) )
def option(self, key): def option(self, key):
@@ -391,7 +391,7 @@ class ApacheConfigurator(common.Installer):
counterpart, should one get created counterpart, should one get created
:returns: List of VirtualHosts or None :returns: List of VirtualHosts or None
:rtype: `list` of :class:`~certbot_apache.obj.VirtualHost` :rtype: `list` of :class:`~certbot_apache._internal.obj.VirtualHost`
""" """
if self._wildcard_domain(domain): if self._wildcard_domain(domain):
@@ -566,7 +566,7 @@ class ApacheConfigurator(common.Installer):
counterpart, should one get created counterpart, should one get created
:returns: vhost associated with name :returns: vhost associated with name
:rtype: :class:`~certbot_apache.obj.VirtualHost` :rtype: :class:`~certbot_apache._internal.obj.VirtualHost`
:raises .errors.PluginError: If no vhost is available or chosen :raises .errors.PluginError: If no vhost is available or chosen
@@ -669,7 +669,7 @@ class ApacheConfigurator(common.Installer):
:param str target_name: domain handled by the desired vhost :param str target_name: domain handled by the desired vhost
:param vhosts: vhosts to consider :param vhosts: vhosts to consider
:type vhosts: `collections.Iterable` of :class:`~certbot_apache.obj.VirtualHost` :type vhosts: `collections.Iterable` of :class:`~certbot_apache._internal.obj.VirtualHost`
:param bool filter_defaults: whether a vhost with a _default_ :param bool filter_defaults: whether a vhost with a _default_
addr is acceptable addr is acceptable
@@ -811,7 +811,7 @@ class ApacheConfigurator(common.Installer):
"""Helper function for get_virtual_hosts(). """Helper function for get_virtual_hosts().
:param host: In progress vhost whose names will be added :param host: In progress vhost whose names will be added
:type host: :class:`~certbot_apache.obj.VirtualHost` :type host: :class:`~certbot_apache._internal.obj.VirtualHost`
""" """
@@ -830,7 +830,7 @@ class ApacheConfigurator(common.Installer):
:param str path: Augeas path to virtual host :param str path: Augeas path to virtual host
:returns: newly created vhost :returns: newly created vhost
:rtype: :class:`~certbot_apache.obj.VirtualHost` :rtype: :class:`~certbot_apache._internal.obj.VirtualHost`
""" """
addrs = set() addrs = set()
@@ -871,7 +871,7 @@ class ApacheConfigurator(common.Installer):
def get_virtual_hosts(self): def get_virtual_hosts(self):
"""Returns list of virtual hosts found in the Apache configuration. """Returns list of virtual hosts found in the Apache configuration.
:returns: List of :class:`~certbot_apache.obj.VirtualHost` :returns: List of :class:`~certbot_apache._internal.obj.VirtualHost`
objects found in configuration objects found in configuration
:rtype: list :rtype: list
@@ -928,7 +928,7 @@ class ApacheConfigurator(common.Installer):
now NameVirtualHosts. If version is earlier than 2.4, check if addr now NameVirtualHosts. If version is earlier than 2.4, check if addr
has a NameVirtualHost directive in the Apache config has a NameVirtualHost directive in the Apache config
:param certbot_apache.obj.Addr target_addr: vhost address :param certbot_apache._internal.obj.Addr target_addr: vhost address
:returns: Success :returns: Success
:rtype: bool :rtype: bool
@@ -946,7 +946,7 @@ class ApacheConfigurator(common.Installer):
"""Adds NameVirtualHost directive for given address. """Adds NameVirtualHost directive for given address.
:param addr: Address that will be added as NameVirtualHost directive :param addr: Address that will be added as NameVirtualHost directive
:type addr: :class:`~certbot_apache.obj.Addr` :type addr: :class:`~certbot_apache._internal.obj.Addr`
""" """
@@ -1125,10 +1125,10 @@ class ApacheConfigurator(common.Installer):
.. note:: This function saves the configuration .. note:: This function saves the configuration
:param nonssl_vhost: Valid VH that doesn't have SSLEngine on :param nonssl_vhost: Valid VH that doesn't have SSLEngine on
:type nonssl_vhost: :class:`~certbot_apache.obj.VirtualHost` :type nonssl_vhost: :class:`~certbot_apache._internal.obj.VirtualHost`
:returns: SSL vhost :returns: SSL vhost
:rtype: :class:`~certbot_apache.obj.VirtualHost` :rtype: :class:`~certbot_apache._internal.obj.VirtualHost`
:raises .errors.PluginError: If more than one virtual host is in :raises .errors.PluginError: If more than one virtual host is in
the file or if plugin is unable to write/read vhost files. the file or if plugin is unable to write/read vhost files.
@@ -1499,7 +1499,7 @@ class ApacheConfigurator(common.Installer):
https://httpd.apache.org/docs/2.2/mod/core.html#namevirtualhost https://httpd.apache.org/docs/2.2/mod/core.html#namevirtualhost
:param vhost: New virtual host that was recently created. :param vhost: New virtual host that was recently created.
:type vhost: :class:`~certbot_apache.obj.VirtualHost` :type vhost: :class:`~certbot_apache._internal.obj.VirtualHost`
""" """
need_to_save = False need_to_save = False
@@ -1534,7 +1534,7 @@ class ApacheConfigurator(common.Installer):
:param str id_str: Id string for matching :param str id_str: Id string for matching
:returns: The matched VirtualHost or None :returns: The matched VirtualHost or None
:rtype: :class:`~certbot_apache.obj.VirtualHost` or None :rtype: :class:`~certbot_apache._internal.obj.VirtualHost` or None
:raises .errors.PluginError: If no VirtualHost is found :raises .errors.PluginError: If no VirtualHost is found
""" """
@@ -1551,7 +1551,7 @@ class ApacheConfigurator(common.Installer):
used for keeping track of VirtualHost directive over time. used for keeping track of VirtualHost directive over time.
:param vhost: Virtual host to add the id :param vhost: Virtual host to add the id
:type vhost: :class:`~certbot_apache.obj.VirtualHost` :type vhost: :class:`~certbot_apache._internal.obj.VirtualHost`
:returns: The unique ID or None :returns: The unique ID or None
:rtype: str or None :rtype: str or None
@@ -1573,7 +1573,7 @@ class ApacheConfigurator(common.Installer):
If ID already exists, returns that instead. If ID already exists, returns that instead.
:param vhost: Virtual host to add or find the id :param vhost: Virtual host to add or find the id
:type vhost: :class:`~certbot_apache.obj.VirtualHost` :type vhost: :class:`~certbot_apache._internal.obj.VirtualHost`
:returns: The unique ID for vhost :returns: The unique ID for vhost
:rtype: str or None :rtype: str or None
@@ -1651,7 +1651,7 @@ class ApacheConfigurator(common.Installer):
"""Increase the AutoHSTS max-age value """Increase the AutoHSTS max-age value
:param vhost: Virtual host object to modify :param vhost: Virtual host object to modify
:type vhost: :class:`~certbot_apache.obj.VirtualHost` :type vhost: :class:`~certbot_apache._internal.obj.VirtualHost`
:param str id_str: The unique ID string of VirtualHost :param str id_str: The unique ID string of VirtualHost
@@ -1735,13 +1735,13 @@ class ApacheConfigurator(common.Installer):
.. note:: This function saves the configuration .. note:: This function saves the configuration
:param ssl_vhost: Destination of traffic, an ssl enabled vhost :param ssl_vhost: Destination of traffic, an ssl enabled vhost
:type ssl_vhost: :class:`~certbot_apache.obj.VirtualHost` :type ssl_vhost: :class:`~certbot_apache._internal.obj.VirtualHost`
:param unused_options: Not currently used :param unused_options: Not currently used
:type unused_options: Not Available :type unused_options: Not Available
:returns: Success, general_vhost (HTTP vhost) :returns: Success, general_vhost (HTTP vhost)
:rtype: (bool, :class:`~certbot_apache.obj.VirtualHost`) :rtype: (bool, :class:`~certbot_apache._internal.obj.VirtualHost`)
""" """
min_apache_ver = (2, 3, 3) min_apache_ver = (2, 3, 3)
@@ -1791,14 +1791,14 @@ class ApacheConfigurator(common.Installer):
.. note:: This function saves the configuration .. note:: This function saves the configuration
:param ssl_vhost: Destination of traffic, an ssl enabled vhost :param ssl_vhost: Destination of traffic, an ssl enabled vhost
:type ssl_vhost: :class:`~certbot_apache.obj.VirtualHost` :type ssl_vhost: :class:`~certbot_apache._internal.obj.VirtualHost`
:param header_substring: string that uniquely identifies a header. :param header_substring: string that uniquely identifies a header.
e.g: Strict-Transport-Security, Upgrade-Insecure-Requests. e.g: Strict-Transport-Security, Upgrade-Insecure-Requests.
:type str :type str
:returns: Success, general_vhost (HTTP vhost) :returns: Success, general_vhost (HTTP vhost)
:rtype: (bool, :class:`~certbot_apache.obj.VirtualHost`) :rtype: (bool, :class:`~certbot_apache._internal.obj.VirtualHost`)
:raises .errors.PluginError: If no viable HTTP host can be created or :raises .errors.PluginError: If no viable HTTP host can be created or
set with header header_substring. set with header header_substring.
@@ -1826,7 +1826,7 @@ class ApacheConfigurator(common.Installer):
contains the string header_substring. contains the string header_substring.
:param ssl_vhost: vhost to check :param ssl_vhost: vhost to check
:type vhost: :class:`~certbot_apache.obj.VirtualHost` :type vhost: :class:`~certbot_apache._internal.obj.VirtualHost`
:param header_substring: string that uniquely identifies a header. :param header_substring: string that uniquely identifies a header.
e.g: Strict-Transport-Security, Upgrade-Insecure-Requests. e.g: Strict-Transport-Security, Upgrade-Insecure-Requests.
@@ -1863,7 +1863,7 @@ class ApacheConfigurator(common.Installer):
.. note:: This function saves the configuration .. note:: This function saves the configuration
:param ssl_vhost: Destination of traffic, an ssl enabled vhost :param ssl_vhost: Destination of traffic, an ssl enabled vhost
:type ssl_vhost: :class:`~certbot_apache.obj.VirtualHost` :type ssl_vhost: :class:`~certbot_apache._internal.obj.VirtualHost`
:param unused_options: Not currently used :param unused_options: Not currently used
:type unused_options: Not Available :type unused_options: Not Available
@@ -1948,7 +1948,7 @@ class ApacheConfigurator(common.Installer):
delete certbot's old rewrite rules and set the new one instead. delete certbot's old rewrite rules and set the new one instead.
:param vhost: vhost to check :param vhost: vhost to check
:type vhost: :class:`~certbot_apache.obj.VirtualHost` :type vhost: :class:`~certbot_apache._internal.obj.VirtualHost`
:raises errors.PluginEnhancementAlreadyPresent: When the exact :raises errors.PluginEnhancementAlreadyPresent: When the exact
certbot redirection WriteRule exists in virtual host. certbot redirection WriteRule exists in virtual host.
@@ -1990,7 +1990,7 @@ class ApacheConfigurator(common.Installer):
"""Checks if there exists a RewriteRule directive in vhost """Checks if there exists a RewriteRule directive in vhost
:param vhost: vhost to check :param vhost: vhost to check
:type vhost: :class:`~certbot_apache.obj.VirtualHost` :type vhost: :class:`~certbot_apache._internal.obj.VirtualHost`
:returns: True if a RewriteRule directive exists. :returns: True if a RewriteRule directive exists.
:rtype: bool :rtype: bool
@@ -2004,7 +2004,7 @@ class ApacheConfigurator(common.Installer):
"""Checks if a RewriteEngine directive is on """Checks if a RewriteEngine directive is on
:param vhost: vhost to check :param vhost: vhost to check
:type vhost: :class:`~certbot_apache.obj.VirtualHost` :type vhost: :class:`~certbot_apache._internal.obj.VirtualHost`
""" """
rewrite_engine_path_list = self.parser.find_dir("RewriteEngine", "on", rewrite_engine_path_list = self.parser.find_dir("RewriteEngine", "on",
@@ -2021,10 +2021,10 @@ class ApacheConfigurator(common.Installer):
"""Creates an http_vhost specifically to redirect for the ssl_vhost. """Creates an http_vhost specifically to redirect for the ssl_vhost.
:param ssl_vhost: ssl vhost :param ssl_vhost: ssl vhost
:type ssl_vhost: :class:`~certbot_apache.obj.VirtualHost` :type ssl_vhost: :class:`~certbot_apache._internal.obj.VirtualHost`
:returns: tuple of the form :returns: tuple of the form
(`success`, :class:`~certbot_apache.obj.VirtualHost`) (`success`, :class:`~certbot_apache._internal.obj.VirtualHost`)
:rtype: tuple :rtype: tuple
""" """
@@ -2150,7 +2150,7 @@ class ApacheConfigurator(common.Installer):
of this method where available. of this method where available.
:param vhost: vhost to enable :param vhost: vhost to enable
:type vhost: :class:`~certbot_apache.obj.VirtualHost` :type vhost: :class:`~certbot_apache._internal.obj.VirtualHost`
:raises .errors.NotSupportedError: If filesystem layout is not :raises .errors.NotSupportedError: If filesystem layout is not
supported. supported.
@@ -2387,7 +2387,7 @@ class ApacheConfigurator(common.Installer):
"""Do the initial AutoHSTS deployment to a vhost """Do the initial AutoHSTS deployment to a vhost
:param ssl_vhost: The VirtualHost object to deploy the AutoHSTS :param ssl_vhost: The VirtualHost object to deploy the AutoHSTS
:type ssl_vhost: :class:`~certbot_apache.obj.VirtualHost` or None :type ssl_vhost: :class:`~certbot_apache._internal.obj.VirtualHost` or None
:raises errors.PluginEnhancementAlreadyPresent: When already enhanced :raises errors.PluginEnhancementAlreadyPresent: When already enhanced
@@ -1,6 +1,8 @@
"""Apache plugin constants.""" """Apache plugin constants."""
import pkg_resources import pkg_resources
from certbot.compat import os
MOD_SSL_CONF_DEST = "options-ssl-apache.conf" MOD_SSL_CONF_DEST = "options-ssl-apache.conf"
"""Name of the mod_ssl config file as saved in `IConfig.config_dir`.""" """Name of the mod_ssl config file as saved in `IConfig.config_dir`."""
@@ -27,7 +29,7 @@ ALL_SSL_OPTIONS_HASHES = [
"""SHA256 hashes of the contents of previous versions of all versions of MOD_SSL_CONF_SRC""" """SHA256 hashes of the contents of previous versions of all versions of MOD_SSL_CONF_SRC"""
AUGEAS_LENS_DIR = pkg_resources.resource_filename( AUGEAS_LENS_DIR = pkg_resources.resource_filename(
"certbot_apache", "augeas_lens") "certbot_apache", os.path.join("_internal", "augeas_lens"))
"""Path to the Augeas lens directory""" """Path to the Augeas lens directory"""
REWRITE_HTTPS_ARGS = [ REWRITE_HTTPS_ARGS = [
@@ -77,7 +77,7 @@ def _vhost_menu(domain, vhosts):
if free_chars < 2: if free_chars < 2:
logger.debug("Display size is too small for " logger.debug("Display size is too small for "
"certbot_apache.display_ops._vhost_menu()") "certbot_apache._internal.display_ops._vhost_menu()")
# This runs the edge off the screen, but it doesn't cause an "error" # This runs the edge off the screen, but it doesn't cause an "error"
filename_size = 1 filename_size = 1
disp_name_size = 1 disp_name_size = 1
@@ -5,14 +5,14 @@ from distutils.version import LooseVersion # pylint: disable=no-name-in-module,
from certbot import util from certbot import util
from certbot_apache import configurator from certbot_apache._internal import configurator
from certbot_apache import override_arch from certbot_apache._internal import override_arch
from certbot_apache import override_fedora from certbot_apache._internal import override_fedora
from certbot_apache import override_darwin from certbot_apache._internal import override_darwin
from certbot_apache import override_debian from certbot_apache._internal import override_debian
from certbot_apache import override_centos from certbot_apache._internal import override_centos
from certbot_apache import override_gentoo from certbot_apache._internal import override_gentoo
from certbot_apache import override_suse from certbot_apache._internal import override_suse
OVERRIDE_CLASSES = { OVERRIDE_CLASSES = {
"arch": override_arch.ArchConfigurator, "arch": override_arch.ArchConfigurator,
@@ -8,8 +8,8 @@ from certbot.compat import os
from certbot.compat import filesystem from certbot.compat import filesystem
from certbot.plugins import common from certbot.plugins import common
from certbot_apache.obj import VirtualHost # pylint: disable=unused-import from certbot_apache._internal.obj import VirtualHost # pylint: disable=unused-import
from certbot_apache.parser import get_aug_path from certbot_apache._internal.parser import get_aug_path
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -24,7 +24,7 @@ class Addr(common.Addr):
return not self.__eq__(other) return not self.__eq__(other)
def __repr__(self): def __repr__(self):
return "certbot_apache.obj.Addr(" + repr(self.tup) + ")" return "certbot_apache._internal.obj.Addr(" + repr(self.tup) + ")"
def __hash__(self): # pylint: disable=useless-super-delegation def __hash__(self): # pylint: disable=useless-super-delegation
# Python 3 requires explicit overridden for __hash__ if __eq__ or # Python 3 requires explicit overridden for __hash__ if __eq__ or
@@ -4,8 +4,9 @@ import pkg_resources
import zope.interface import zope.interface
from certbot import interfaces from certbot import interfaces
from certbot.compat import os
from certbot_apache import configurator from certbot_apache._internal import configurator
@zope.interface.provider(interfaces.IPluginFactory) @zope.interface.provider(interfaces.IPluginFactory)
class ArchConfigurator(configurator.ApacheConfigurator): class ArchConfigurator(configurator.ApacheConfigurator):
@@ -27,5 +28,5 @@ class ArchConfigurator(configurator.ApacheConfigurator):
handle_sites=False, handle_sites=False,
challenge_location="/etc/httpd/conf", challenge_location="/etc/httpd/conf",
MOD_SSL_CONF_SRC=pkg_resources.resource_filename( MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
"certbot_apache", "options-ssl-apache.conf") "certbot_apache", os.path.join("_internal", "options-ssl-apache.conf"))
) )
@@ -7,13 +7,14 @@ import zope.interface
from certbot import errors from certbot import errors
from certbot import interfaces from certbot import interfaces
from certbot import util from certbot import util
from certbot.compat import os
from certbot.errors import MisconfigurationError from certbot.errors import MisconfigurationError
from acme.magic_typing import List # pylint: disable=unused-import, no-name-in-module from acme.magic_typing import List # pylint: disable=unused-import, no-name-in-module
from certbot_apache import apache_util from certbot_apache._internal import apache_util
from certbot_apache import configurator from certbot_apache._internal import configurator
from certbot_apache import parser from certbot_apache._internal import parser
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -40,7 +41,7 @@ class CentOSConfigurator(configurator.ApacheConfigurator):
handle_sites=False, handle_sites=False,
challenge_location="/etc/httpd/conf.d", challenge_location="/etc/httpd/conf.d",
MOD_SSL_CONF_SRC=pkg_resources.resource_filename( MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
"certbot_apache", "centos-options-ssl-apache.conf") "certbot_apache", os.path.join("_internal", "centos-options-ssl-apache.conf"))
) )
def config_test(self): def config_test(self):
@@ -4,8 +4,9 @@ import pkg_resources
import zope.interface import zope.interface
from certbot import interfaces from certbot import interfaces
from certbot.compat import os
from certbot_apache import configurator from certbot_apache._internal import configurator
@zope.interface.provider(interfaces.IPluginFactory) @zope.interface.provider(interfaces.IPluginFactory)
class DarwinConfigurator(configurator.ApacheConfigurator): class DarwinConfigurator(configurator.ApacheConfigurator):
@@ -27,5 +28,5 @@ class DarwinConfigurator(configurator.ApacheConfigurator):
handle_sites=False, handle_sites=False,
challenge_location="/etc/apache2/other", challenge_location="/etc/apache2/other",
MOD_SSL_CONF_SRC=pkg_resources.resource_filename( MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
"certbot_apache", "options-ssl-apache.conf") "certbot_apache", os.path.join("_internal", "options-ssl-apache.conf"))
) )
@@ -10,8 +10,8 @@ from certbot import util
from certbot.compat import filesystem from certbot.compat import filesystem
from certbot.compat import os from certbot.compat import os
from certbot_apache import apache_util from certbot_apache._internal import apache_util
from certbot_apache import configurator from certbot_apache._internal import configurator
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -36,7 +36,7 @@ class DebianConfigurator(configurator.ApacheConfigurator):
handle_sites=True, handle_sites=True,
challenge_location="/etc/apache2", challenge_location="/etc/apache2",
MOD_SSL_CONF_SRC=pkg_resources.resource_filename( MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
"certbot_apache", "options-ssl-apache.conf") "certbot_apache", os.path.join("_internal", "options-ssl-apache.conf"))
) )
def enable_site(self, vhost): def enable_site(self, vhost):
@@ -46,7 +46,7 @@ class DebianConfigurator(configurator.ApacheConfigurator):
modules are enabled appropriately. modules are enabled appropriately.
:param vhost: vhost to enable :param vhost: vhost to enable
:type vhost: :class:`~certbot_apache.obj.VirtualHost` :type vhost: :class:`~certbot_apache._internal.obj.VirtualHost`
:raises .errors.NotSupportedError: If filesystem layout is not :raises .errors.NotSupportedError: If filesystem layout is not
supported. supported.
@@ -5,10 +5,11 @@ import zope.interface
from certbot import errors from certbot import errors
from certbot import interfaces from certbot import interfaces
from certbot import util from certbot import util
from certbot.compat import os
from certbot_apache import apache_util from certbot_apache._internal import apache_util
from certbot_apache import configurator from certbot_apache._internal import configurator
from certbot_apache import parser from certbot_apache._internal import parser
@zope.interface.provider(interfaces.IPluginFactory) @zope.interface.provider(interfaces.IPluginFactory)
@@ -33,7 +34,7 @@ class FedoraConfigurator(configurator.ApacheConfigurator):
challenge_location="/etc/httpd/conf.d", challenge_location="/etc/httpd/conf.d",
MOD_SSL_CONF_SRC=pkg_resources.resource_filename( MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
# TODO: eventually newest version of Fedora will need their own config # TODO: eventually newest version of Fedora will need their own config
"certbot_apache", "centos-options-ssl-apache.conf") "certbot_apache", os.path.join("_internal", "centos-options-ssl-apache.conf"))
) )
def config_test(self): def config_test(self):
@@ -4,10 +4,11 @@ import pkg_resources
import zope.interface import zope.interface
from certbot import interfaces from certbot import interfaces
from certbot.compat import os
from certbot_apache import apache_util from certbot_apache._internal import apache_util
from certbot_apache import configurator from certbot_apache._internal import configurator
from certbot_apache import parser from certbot_apache._internal import parser
@zope.interface.provider(interfaces.IPluginFactory) @zope.interface.provider(interfaces.IPluginFactory)
class GentooConfigurator(configurator.ApacheConfigurator): class GentooConfigurator(configurator.ApacheConfigurator):
@@ -30,7 +31,7 @@ class GentooConfigurator(configurator.ApacheConfigurator):
handle_sites=False, handle_sites=False,
challenge_location="/etc/apache2/vhosts.d", challenge_location="/etc/apache2/vhosts.d",
MOD_SSL_CONF_SRC=pkg_resources.resource_filename( MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
"certbot_apache", "options-ssl-apache.conf") "certbot_apache", os.path.join("_internal", "options-ssl-apache.conf"))
) )
def _prepare_options(self): def _prepare_options(self):
@@ -4,8 +4,9 @@ import pkg_resources
import zope.interface import zope.interface
from certbot import interfaces from certbot import interfaces
from certbot.compat import os
from certbot_apache import configurator from certbot_apache._internal import configurator
@zope.interface.provider(interfaces.IPluginFactory) @zope.interface.provider(interfaces.IPluginFactory)
class OpenSUSEConfigurator(configurator.ApacheConfigurator): class OpenSUSEConfigurator(configurator.ApacheConfigurator):
@@ -27,5 +28,5 @@ class OpenSUSEConfigurator(configurator.ApacheConfigurator):
handle_sites=False, handle_sites=False,
challenge_location="/etc/apache2/vhosts.d", challenge_location="/etc/apache2/vhosts.d",
MOD_SSL_CONF_SRC=pkg_resources.resource_filename( MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
"certbot_apache", "options-ssl-apache.conf") "certbot_apache", os.path.join("_internal", "options-ssl-apache.conf"))
) )
@@ -13,7 +13,7 @@ from acme.magic_typing import Dict, List, Set # pylint: disable=unused-import,
from certbot import errors from certbot import errors
from certbot.compat import os from certbot.compat import os
from certbot_apache import constants from certbot_apache._internal import constants
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -1,5 +1,5 @@
# pylint: disable=too-many-lines # pylint: disable=too-many-lines
"""Test for certbot_apache.configurator AutoHSTS functionality""" """Test for certbot_apache._internal.configurator AutoHSTS functionality"""
import re import re
import unittest import unittest
import mock import mock
@@ -7,7 +7,7 @@ import mock
import six # pylint: disable=unused-import import six # pylint: disable=unused-import
from certbot import errors from certbot import errors
from certbot_apache import constants from certbot_apache._internal import constants
from certbot_apache.tests import util from certbot_apache.tests import util
@@ -39,24 +39,24 @@ class AutoHSTSTest(util.ApacheTest):
head.replace("arg[3]", "arg[4]")) head.replace("arg[3]", "arg[4]"))
return None # pragma: no cover return None # pragma: no cover
@mock.patch("certbot_apache.configurator.ApacheConfigurator.restart") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.restart")
@mock.patch("certbot_apache.configurator.ApacheConfigurator.enable_mod") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.enable_mod")
def test_autohsts_enable_headers_mod(self, mock_enable, _restart): def test_autohsts_enable_headers_mod(self, mock_enable, _restart):
self.config.parser.modules.discard("headers_module") self.config.parser.modules.discard("headers_module")
self.config.parser.modules.discard("mod_header.c") self.config.parser.modules.discard("mod_header.c")
self.config.enable_autohsts(mock.MagicMock(), ["ocspvhost.com"]) self.config.enable_autohsts(mock.MagicMock(), ["ocspvhost.com"])
self.assertTrue(mock_enable.called) self.assertTrue(mock_enable.called)
@mock.patch("certbot_apache.configurator.ApacheConfigurator.restart") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.restart")
def test_autohsts_deploy_already_exists(self, _restart): def test_autohsts_deploy_already_exists(self, _restart):
self.config.enable_autohsts(mock.MagicMock(), ["ocspvhost.com"]) self.config.enable_autohsts(mock.MagicMock(), ["ocspvhost.com"])
self.assertRaises(errors.PluginEnhancementAlreadyPresent, self.assertRaises(errors.PluginEnhancementAlreadyPresent,
self.config.enable_autohsts, self.config.enable_autohsts,
mock.MagicMock(), ["ocspvhost.com"]) mock.MagicMock(), ["ocspvhost.com"])
@mock.patch("certbot_apache.constants.AUTOHSTS_FREQ", 0) @mock.patch("certbot_apache._internal.constants.AUTOHSTS_FREQ", 0)
@mock.patch("certbot_apache.configurator.ApacheConfigurator.restart") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.restart")
@mock.patch("certbot_apache.configurator.ApacheConfigurator.prepare") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.prepare")
def test_autohsts_increase(self, mock_prepare, _mock_restart): def test_autohsts_increase(self, mock_prepare, _mock_restart):
self.config._prepared = False self.config._prepared = False
maxage = "\"max-age={0}\"" maxage = "\"max-age={0}\""
@@ -74,8 +74,8 @@ class AutoHSTSTest(util.ApacheTest):
inc_val) inc_val)
self.assertTrue(mock_prepare.called) self.assertTrue(mock_prepare.called)
@mock.patch("certbot_apache.configurator.ApacheConfigurator.restart") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.restart")
@mock.patch("certbot_apache.configurator.ApacheConfigurator._autohsts_increase") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator._autohsts_increase")
def test_autohsts_increase_noop(self, mock_increase, _restart): def test_autohsts_increase_noop(self, mock_increase, _restart):
maxage = "\"max-age={0}\"" maxage = "\"max-age={0}\""
initial_val = maxage.format(constants.AUTOHSTS_STEPS[0]) initial_val = maxage.format(constants.AUTOHSTS_STEPS[0])
@@ -89,8 +89,8 @@ class AutoHSTSTest(util.ApacheTest):
self.assertFalse(mock_increase.called) self.assertFalse(mock_increase.called)
@mock.patch("certbot_apache.configurator.ApacheConfigurator.restart") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.restart")
@mock.patch("certbot_apache.constants.AUTOHSTS_FREQ", 0) @mock.patch("certbot_apache._internal.constants.AUTOHSTS_FREQ", 0)
def test_autohsts_increase_no_header(self, _restart): def test_autohsts_increase_no_header(self, _restart):
self.config.enable_autohsts(mock.MagicMock(), ["ocspvhost.com"]) self.config.enable_autohsts(mock.MagicMock(), ["ocspvhost.com"])
# Remove the header # Remove the header
@@ -102,8 +102,8 @@ class AutoHSTSTest(util.ApacheTest):
self.config.update_autohsts, self.config.update_autohsts,
mock.MagicMock()) mock.MagicMock())
@mock.patch("certbot_apache.constants.AUTOHSTS_FREQ", 0) @mock.patch("certbot_apache._internal.constants.AUTOHSTS_FREQ", 0)
@mock.patch("certbot_apache.configurator.ApacheConfigurator.restart") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.restart")
def test_autohsts_increase_and_make_permanent(self, _mock_restart): def test_autohsts_increase_and_make_permanent(self, _mock_restart):
maxage = "\"max-age={0}\"" maxage = "\"max-age={0}\""
max_val = maxage.format(constants.AUTOHSTS_PERMANENT) max_val = maxage.format(constants.AUTOHSTS_PERMANENT)
@@ -141,18 +141,18 @@ class AutoHSTSTest(util.ApacheTest):
# Make sure that the execution does not continue when no entries in store # Make sure that the execution does not continue when no entries in store
self.assertFalse(self.config.storage.put.called) self.assertFalse(self.config.storage.put.called)
@mock.patch("certbot_apache.display_ops.select_vhost") @mock.patch("certbot_apache._internal.display_ops.select_vhost")
def test_autohsts_no_ssl_vhost(self, mock_select): def test_autohsts_no_ssl_vhost(self, mock_select):
mock_select.return_value = self.vh_truth[0] mock_select.return_value = self.vh_truth[0]
with mock.patch("certbot_apache.configurator.logger.warning") as mock_log: with mock.patch("certbot_apache._internal.configurator.logger.warning") as mock_log:
self.assertRaises(errors.PluginError, self.assertRaises(errors.PluginError,
self.config.enable_autohsts, self.config.enable_autohsts,
mock.MagicMock(), "invalid.example.com") mock.MagicMock(), "invalid.example.com")
self.assertTrue( self.assertTrue(
"Certbot was not able to find SSL" in mock_log.call_args[0][0]) "Certbot was not able to find SSL" in mock_log.call_args[0][0])
@mock.patch("certbot_apache.configurator.ApacheConfigurator.restart") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.restart")
@mock.patch("certbot_apache.configurator.ApacheConfigurator.add_vhost_id") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.add_vhost_id")
def test_autohsts_dont_enhance_twice(self, mock_id, _restart): def test_autohsts_dont_enhance_twice(self, mock_id, _restart):
mock_id.return_value = "1234567" mock_id.return_value = "1234567"
self.config.enable_autohsts(mock.MagicMock(), self.config.enable_autohsts(mock.MagicMock(),
@@ -177,7 +177,7 @@ class AutoHSTSTest(util.ApacheTest):
self.config._autohsts_fetch_state() self.config._autohsts_fetch_state()
self.config._autohsts["orphan_id"] = {"laststep": 999, "timestamp": 0} self.config._autohsts["orphan_id"] = {"laststep": 999, "timestamp": 0}
self.config._autohsts_save_state() self.config._autohsts_save_state()
with mock.patch("certbot_apache.configurator.logger.warning") as mock_log: with mock.patch("certbot_apache._internal.configurator.logger.warning") as mock_log:
self.config.deploy_autohsts(mock.MagicMock()) self.config.deploy_autohsts(mock.MagicMock())
self.assertTrue(mock_log.called) self.assertTrue(mock_log.called)
self.assertTrue( self.assertTrue(
@@ -1,12 +1,12 @@
"""Test for certbot_apache.configurator for CentOS 6 overrides""" """Test for certbot_apache._internal.configurator for CentOS 6 overrides"""
import unittest import unittest
from certbot.compat import os from certbot.compat import os
from certbot.errors import MisconfigurationError from certbot.errors import MisconfigurationError
from certbot_apache import obj from certbot_apache._internal import obj
from certbot_apache import override_centos from certbot_apache._internal import override_centos
from certbot_apache import parser from certbot_apache._internal import parser
from certbot_apache.tests import util from certbot_apache.tests import util
@@ -1,4 +1,4 @@
"""Test for certbot_apache.configurator for Centos overrides""" """Test for certbot_apache._internal.configurator for Centos overrides"""
import unittest import unittest
import mock import mock
@@ -7,8 +7,8 @@ from certbot import errors
from certbot.compat import filesystem from certbot.compat import filesystem
from certbot.compat import os from certbot.compat import os
from certbot_apache import obj from certbot_apache._internal import obj
from certbot_apache import override_centos from certbot_apache._internal import override_centos
from certbot_apache.tests import util from certbot_apache.tests import util
@@ -55,7 +55,7 @@ class FedoraRestartTest(util.ApacheTest):
self.config.config_test() self.config.config_test()
def test_non_fedora_error(self): def test_non_fedora_error(self):
c_test = "certbot_apache.configurator.ApacheConfigurator.config_test" c_test = "certbot_apache._internal.configurator.ApacheConfigurator.config_test"
with mock.patch(c_test) as mock_test: with mock.patch(c_test) as mock_test:
mock_test.side_effect = errors.MisconfigurationError mock_test.side_effect = errors.MisconfigurationError
with mock.patch("certbot.util.get_os_info") as mock_info: with mock.patch("certbot.util.get_os_info") as mock_info:
@@ -64,7 +64,7 @@ class FedoraRestartTest(util.ApacheTest):
self.config.config_test) self.config.config_test)
def test_fedora_restart_error(self): def test_fedora_restart_error(self):
c_test = "certbot_apache.configurator.ApacheConfigurator.config_test" c_test = "certbot_apache._internal.configurator.ApacheConfigurator.config_test"
with mock.patch(c_test) as mock_test: with mock.patch(c_test) as mock_test:
# First call raises error, second doesn't # First call raises error, second doesn't
mock_test.side_effect = [errors.MisconfigurationError, ''] mock_test.side_effect = [errors.MisconfigurationError, '']
@@ -74,7 +74,7 @@ class FedoraRestartTest(util.ApacheTest):
self._run_fedora_test) self._run_fedora_test)
def test_fedora_restart(self): def test_fedora_restart(self):
c_test = "certbot_apache.configurator.ApacheConfigurator.config_test" c_test = "certbot_apache._internal.configurator.ApacheConfigurator.config_test"
with mock.patch(c_test) as mock_test: with mock.patch(c_test) as mock_test:
with mock.patch("certbot.util.run_script") as mock_run: with mock.patch("certbot.util.run_script") as mock_run:
# First call raises error, second doesn't # First call raises error, second doesn't
@@ -107,7 +107,7 @@ class MultipleVhostsTestCentOS(util.ApacheTest):
def test_get_parser(self): def test_get_parser(self):
self.assertIsInstance(self.config.parser, override_centos.CentOSParser) self.assertIsInstance(self.config.parser, override_centos.CentOSParser)
@mock.patch("certbot_apache.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
def test_opportunistic_httpd_runtime_parsing(self, mock_get): def test_opportunistic_httpd_runtime_parsing(self, mock_get):
define_val = ( define_val = (
'Define: TEST1\n' 'Define: TEST1\n'
@@ -156,7 +156,7 @@ class MultipleVhostsTestCentOS(util.ApacheTest):
raise Exception("Missed: %s" % vhost) # pragma: no cover raise Exception("Missed: %s" % vhost) # pragma: no cover
self.assertEqual(found, 2) self.assertEqual(found, 2)
@mock.patch("certbot_apache.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
def test_get_sysconfig_vars(self, mock_cfg): def test_get_sysconfig_vars(self, mock_cfg):
"""Make sure we read the sysconfig OPTIONS variable correctly""" """Make sure we read the sysconfig OPTIONS variable correctly"""
# Return nothing for the process calls # Return nothing for the process calls
@@ -177,13 +177,13 @@ class MultipleVhostsTestCentOS(util.ApacheTest):
self.assertTrue("MOCK_NOSEP" in self.config.parser.variables.keys()) self.assertTrue("MOCK_NOSEP" in self.config.parser.variables.keys())
self.assertEqual("NOSEP_VAL", self.config.parser.variables["NOSEP_TWO"]) self.assertEqual("NOSEP_VAL", self.config.parser.variables["NOSEP_TWO"])
@mock.patch("certbot_apache.configurator.util.run_script") @mock.patch("certbot_apache._internal.configurator.util.run_script")
def test_alt_restart_works(self, mock_run_script): def test_alt_restart_works(self, mock_run_script):
mock_run_script.side_effect = [None, errors.SubprocessError, None] mock_run_script.side_effect = [None, errors.SubprocessError, None]
self.config.restart() self.config.restart()
self.assertEqual(mock_run_script.call_count, 3) self.assertEqual(mock_run_script.call_count, 3)
@mock.patch("certbot_apache.configurator.util.run_script") @mock.patch("certbot_apache._internal.configurator.util.run_script")
def test_alt_restart_errors(self, mock_run_script): def test_alt_restart_errors(self, mock_run_script):
mock_run_script.side_effect = [None, mock_run_script.side_effect = [None,
errors.SubprocessError, errors.SubprocessError,
@@ -1,4 +1,4 @@
"""Tests for certbot_apache.parser.""" """Tests for certbot_apache._internal.parser."""
import shutil import shutil
import unittest import unittest
@@ -88,7 +88,7 @@ class ComplexParserTest(util.ParserTest):
def verify_fnmatch(self, arg, hit=True): def verify_fnmatch(self, arg, hit=True):
"""Test if Include was correctly parsed.""" """Test if Include was correctly parsed."""
from certbot_apache import parser from certbot_apache._internal import parser
self.parser.add_dir(parser.get_aug_path(self.parser.loc["default"]), self.parser.add_dir(parser.get_aug_path(self.parser.loc["default"]),
"Include", [arg]) "Include", [arg])
if hit: if hit:
@@ -1,4 +1,4 @@
"""Test for certbot_apache.configurator implementations of reverter""" """Test for certbot_apache._internal.configurator implementations of reverter"""
import shutil import shutil
import unittest import unittest
@@ -1,5 +1,5 @@
# pylint: disable=too-many-lines # pylint: disable=too-many-lines
"""Test for certbot_apache.configurator.""" """Test for certbot_apache._internal.configurator."""
import copy import copy
import shutil import shutil
import socket import socket
@@ -20,10 +20,10 @@ from certbot.compat import filesystem
from certbot.tests import acme_util from certbot.tests import acme_util
from certbot.tests import util as certbot_util from certbot.tests import util as certbot_util
from certbot_apache import apache_util from certbot_apache._internal import apache_util
from certbot_apache import constants from certbot_apache._internal import constants
from certbot_apache import obj from certbot_apache._internal import obj
from certbot_apache import parser from certbot_apache._internal import parser
from certbot_apache.tests import util from certbot_apache.tests import util
@@ -45,13 +45,13 @@ class MultipleVhostsTest(util.ApacheTest):
def mocked_deploy_cert(*args, **kwargs): def mocked_deploy_cert(*args, **kwargs):
"""a helper to mock a deployed cert""" """a helper to mock a deployed cert"""
g_mod = "certbot_apache.configurator.ApacheConfigurator.enable_mod" g_mod = "certbot_apache._internal.configurator.ApacheConfigurator.enable_mod"
with mock.patch(g_mod): with mock.patch(g_mod):
config.real_deploy_cert(*args, **kwargs) config.real_deploy_cert(*args, **kwargs)
self.config.deploy_cert = mocked_deploy_cert self.config.deploy_cert = mocked_deploy_cert
return self.config return self.config
@mock.patch("certbot_apache.configurator.path_surgery") @mock.patch("certbot_apache._internal.configurator.path_surgery")
def test_prepare_no_install(self, mock_surgery): def test_prepare_no_install(self, mock_surgery):
silly_path = {"PATH": "/tmp/nothingness2342"} silly_path = {"PATH": "/tmp/nothingness2342"}
mock_surgery.return_value = False mock_surgery.return_value = False
@@ -59,8 +59,8 @@ class MultipleVhostsTest(util.ApacheTest):
self.assertRaises(errors.NoInstallationError, self.config.prepare) self.assertRaises(errors.NoInstallationError, self.config.prepare)
self.assertEqual(mock_surgery.call_count, 1) self.assertEqual(mock_surgery.call_count, 1)
@mock.patch("certbot_apache.parser.ApacheParser") @mock.patch("certbot_apache._internal.parser.ApacheParser")
@mock.patch("certbot_apache.configurator.util.exe_exists") @mock.patch("certbot_apache._internal.configurator.util.exe_exists")
def test_prepare_version(self, mock_exe_exists, _): def test_prepare_version(self, mock_exe_exists, _):
mock_exe_exists.return_value = True mock_exe_exists.return_value = True
self.config.version = None self.config.version = None
@@ -76,8 +76,8 @@ class MultipleVhostsTest(util.ApacheTest):
os.remove(os.path.join(server_root, ".certbot.lock")) os.remove(os.path.join(server_root, ".certbot.lock"))
certbot_util.lock_and_call(self._test_prepare_locked, server_root) certbot_util.lock_and_call(self._test_prepare_locked, server_root)
@mock.patch("certbot_apache.parser.ApacheParser") @mock.patch("certbot_apache._internal.parser.ApacheParser")
@mock.patch("certbot_apache.configurator.util.exe_exists") @mock.patch("certbot_apache._internal.configurator.util.exe_exists")
def _test_prepare_locked(self, unused_parser, unused_exe_exists): def _test_prepare_locked(self, unused_parser, unused_exe_exists):
try: try:
self.config.prepare() self.config.prepare()
@@ -89,13 +89,13 @@ class MultipleVhostsTest(util.ApacheTest):
self.fail("Exception wasn't raised!") self.fail("Exception wasn't raised!")
def test_add_parser_arguments(self): # pylint: disable=no-self-use def test_add_parser_arguments(self): # pylint: disable=no-self-use
from certbot_apache.configurator import ApacheConfigurator from certbot_apache._internal.configurator import ApacheConfigurator
# Weak test.. # Weak test..
ApacheConfigurator.add_parser_arguments(mock.MagicMock()) ApacheConfigurator.add_parser_arguments(mock.MagicMock())
def test_docs_parser_arguments(self): def test_docs_parser_arguments(self):
os.environ["CERTBOT_DOCS"] = "1" os.environ["CERTBOT_DOCS"] = "1"
from certbot_apache.configurator import ApacheConfigurator from certbot_apache._internal.configurator import ApacheConfigurator
mock_add = mock.MagicMock() mock_add = mock.MagicMock()
ApacheConfigurator.add_parser_arguments(mock_add) ApacheConfigurator.add_parser_arguments(mock_add)
parserargs = ["server_root", "enmod", "dismod", "le_vhost_ext", parserargs = ["server_root", "enmod", "dismod", "le_vhost_ext",
@@ -121,13 +121,13 @@ class MultipleVhostsTest(util.ApacheTest):
del os.environ["CERTBOT_DOCS"] del os.environ["CERTBOT_DOCS"]
def test_add_parser_arguments_all_configurators(self): # pylint: disable=no-self-use def test_add_parser_arguments_all_configurators(self): # pylint: disable=no-self-use
from certbot_apache.entrypoint import OVERRIDE_CLASSES from certbot_apache._internal.entrypoint import OVERRIDE_CLASSES
for cls in OVERRIDE_CLASSES.values(): for cls in OVERRIDE_CLASSES.values():
cls.add_parser_arguments(mock.MagicMock()) cls.add_parser_arguments(mock.MagicMock())
def test_all_configurators_defaults_defined(self): def test_all_configurators_defaults_defined(self):
from certbot_apache.entrypoint import OVERRIDE_CLASSES from certbot_apache._internal.entrypoint import OVERRIDE_CLASSES
from certbot_apache.configurator import ApacheConfigurator from certbot_apache._internal.configurator import ApacheConfigurator
parameters = set(ApacheConfigurator.OS_DEFAULTS.keys()) parameters = set(ApacheConfigurator.OS_DEFAULTS.keys())
for cls in OVERRIDE_CLASSES.values(): for cls in OVERRIDE_CLASSES.values():
self.assertTrue(parameters.issubset(set(cls.OS_DEFAULTS.keys()))) self.assertTrue(parameters.issubset(set(cls.OS_DEFAULTS.keys())))
@@ -149,7 +149,7 @@ class MultipleVhostsTest(util.ApacheTest):
)) ))
@certbot_util.patch_get_utility() @certbot_util.patch_get_utility()
@mock.patch("certbot_apache.configurator.socket.gethostbyaddr") @mock.patch("certbot_apache._internal.configurator.socket.gethostbyaddr")
def test_get_all_names_addrs(self, mock_gethost, mock_getutility): def test_get_all_names_addrs(self, mock_gethost, mock_getutility):
mock_gethost.side_effect = [("google.com", "", ""), socket.error] mock_gethost.side_effect = [("google.com", "", ""), socket.error]
mock_utility = mock_getutility() mock_utility = mock_getutility()
@@ -175,7 +175,7 @@ class MultipleVhostsTest(util.ApacheTest):
self.assertEqual(self.config._create_vhost("nonexistent"), None) # pylint: disable=protected-access self.assertEqual(self.config._create_vhost("nonexistent"), None) # pylint: disable=protected-access
def test_get_aug_internal_path(self): def test_get_aug_internal_path(self):
from certbot_apache.apache_util import get_internal_aug_path from certbot_apache._internal.apache_util import get_internal_aug_path
internal_paths = [ internal_paths = [
"Virtualhost", "IfModule/VirtualHost", "VirtualHost", "VirtualHost", "Virtualhost", "IfModule/VirtualHost", "VirtualHost", "VirtualHost",
"Macro/VirtualHost", "IfModule/VirtualHost", "VirtualHost", "Macro/VirtualHost", "IfModule/VirtualHost", "VirtualHost",
@@ -220,26 +220,26 @@ class MultipleVhostsTest(util.ApacheTest):
# Handle case of non-debian layout get_virtual_hosts # Handle case of non-debian layout get_virtual_hosts
with mock.patch( with mock.patch(
"certbot_apache.configurator.ApacheConfigurator.conf" "certbot_apache._internal.configurator.ApacheConfigurator.conf"
) as mock_conf: ) as mock_conf:
mock_conf.return_value = False mock_conf.return_value = False
vhs = self.config.get_virtual_hosts() vhs = self.config.get_virtual_hosts()
self.assertEqual(len(vhs), 12) self.assertEqual(len(vhs), 12)
@mock.patch("certbot_apache.display_ops.select_vhost") @mock.patch("certbot_apache._internal.display_ops.select_vhost")
def test_choose_vhost_none_avail(self, mock_select): def test_choose_vhost_none_avail(self, mock_select):
mock_select.return_value = None mock_select.return_value = None
self.assertRaises( self.assertRaises(
errors.PluginError, self.config.choose_vhost, "none.com") errors.PluginError, self.config.choose_vhost, "none.com")
@mock.patch("certbot_apache.display_ops.select_vhost") @mock.patch("certbot_apache._internal.display_ops.select_vhost")
def test_choose_vhost_select_vhost_ssl(self, mock_select): def test_choose_vhost_select_vhost_ssl(self, mock_select):
mock_select.return_value = self.vh_truth[1] mock_select.return_value = self.vh_truth[1]
self.assertEqual( self.assertEqual(
self.vh_truth[1], self.config.choose_vhost("none.com")) self.vh_truth[1], self.config.choose_vhost("none.com"))
@mock.patch("certbot_apache.display_ops.select_vhost") @mock.patch("certbot_apache._internal.display_ops.select_vhost")
@mock.patch("certbot_apache.obj.VirtualHost.conflicts") @mock.patch("certbot_apache._internal.obj.VirtualHost.conflicts")
def test_choose_vhost_select_vhost_non_ssl(self, mock_conf, mock_select): def test_choose_vhost_select_vhost_non_ssl(self, mock_conf, mock_select):
mock_select.return_value = self.vh_truth[0] mock_select.return_value = self.vh_truth[0]
mock_conf.return_value = False mock_conf.return_value = False
@@ -252,8 +252,8 @@ class MultipleVhostsTest(util.ApacheTest):
self.assertFalse(self.vh_truth[0].ssl) self.assertFalse(self.vh_truth[0].ssl)
self.assertTrue(chosen_vhost.ssl) self.assertTrue(chosen_vhost.ssl)
@mock.patch("certbot_apache.configurator.ApacheConfigurator._find_best_vhost") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator._find_best_vhost")
@mock.patch("certbot_apache.parser.ApacheParser.add_dir") @mock.patch("certbot_apache._internal.parser.ApacheParser.add_dir")
def test_choose_vhost_and_servername_addition(self, mock_add, mock_find): def test_choose_vhost_and_servername_addition(self, mock_add, mock_find):
ret_vh = self.vh_truth[8] ret_vh = self.vh_truth[8]
ret_vh.enabled = False ret_vh.enabled = False
@@ -261,13 +261,13 @@ class MultipleVhostsTest(util.ApacheTest):
self.config.choose_vhost("whatever.com") self.config.choose_vhost("whatever.com")
self.assertTrue(mock_add.called) self.assertTrue(mock_add.called)
@mock.patch("certbot_apache.display_ops.select_vhost") @mock.patch("certbot_apache._internal.display_ops.select_vhost")
def test_choose_vhost_select_vhost_with_temp(self, mock_select): def test_choose_vhost_select_vhost_with_temp(self, mock_select):
mock_select.return_value = self.vh_truth[0] mock_select.return_value = self.vh_truth[0]
chosen_vhost = self.config.choose_vhost("none.com", create_if_no_ssl=False) chosen_vhost = self.config.choose_vhost("none.com", create_if_no_ssl=False)
self.assertEqual(self.vh_truth[0], chosen_vhost) self.assertEqual(self.vh_truth[0], chosen_vhost)
@mock.patch("certbot_apache.display_ops.select_vhost") @mock.patch("certbot_apache._internal.display_ops.select_vhost")
def test_choose_vhost_select_vhost_conflicting_non_ssl(self, mock_select): def test_choose_vhost_select_vhost_conflicting_non_ssl(self, mock_select):
mock_select.return_value = self.vh_truth[3] mock_select.return_value = self.vh_truth[3]
conflicting_vhost = obj.VirtualHost( conflicting_vhost = obj.VirtualHost(
@@ -784,8 +784,8 @@ class MultipleVhostsTest(util.ApacheTest):
self.config._add_name_vhost_if_necessary(self.vh_truth[0]) self.config._add_name_vhost_if_necessary(self.vh_truth[0])
self.assertEqual(self.config.add_name_vhost.call_count, 2) self.assertEqual(self.config.add_name_vhost.call_count, 2)
@mock.patch("certbot_apache.configurator.http_01.ApacheHttp01.perform") @mock.patch("certbot_apache._internal.configurator.http_01.ApacheHttp01.perform")
@mock.patch("certbot_apache.configurator.ApacheConfigurator.restart") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.restart")
def test_perform(self, mock_restart, mock_http_perform): def test_perform(self, mock_restart, mock_http_perform):
# Only tests functionality specific to configurator.perform # Only tests functionality specific to configurator.perform
# Note: As more challenges are offered this will have to be expanded # Note: As more challenges are offered this will have to be expanded
@@ -801,8 +801,8 @@ class MultipleVhostsTest(util.ApacheTest):
self.assertEqual(mock_restart.call_count, 1) self.assertEqual(mock_restart.call_count, 1)
@mock.patch("certbot_apache.configurator.ApacheConfigurator.restart") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.restart")
@mock.patch("certbot_apache.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
def test_cleanup(self, mock_cfg, mock_restart): def test_cleanup(self, mock_cfg, mock_restart):
mock_cfg.return_value = "" mock_cfg.return_value = ""
_, achalls = self.get_key_and_achalls() _, achalls = self.get_key_and_achalls()
@@ -817,8 +817,8 @@ class MultipleVhostsTest(util.ApacheTest):
else: else:
self.assertFalse(mock_restart.called) self.assertFalse(mock_restart.called)
@mock.patch("certbot_apache.configurator.ApacheConfigurator.restart") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.restart")
@mock.patch("certbot_apache.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
def test_cleanup_no_errors(self, mock_cfg, mock_restart): def test_cleanup_no_errors(self, mock_cfg, mock_restart):
mock_cfg.return_value = "" mock_cfg.return_value = ""
_, achalls = self.get_key_and_achalls() _, achalls = self.get_key_and_achalls()
@@ -855,11 +855,11 @@ class MultipleVhostsTest(util.ApacheTest):
mock_script.side_effect = errors.SubprocessError("Can't find program") mock_script.side_effect = errors.SubprocessError("Can't find program")
self.assertRaises(errors.PluginError, self.config.get_version) self.assertRaises(errors.PluginError, self.config.get_version)
@mock.patch("certbot_apache.configurator.util.run_script") @mock.patch("certbot_apache._internal.configurator.util.run_script")
def test_restart(self, _): def test_restart(self, _):
self.config.restart() self.config.restart()
@mock.patch("certbot_apache.configurator.util.run_script") @mock.patch("certbot_apache._internal.configurator.util.run_script")
def test_restart_bad_process(self, mock_run_script): def test_restart_bad_process(self, mock_run_script):
mock_run_script.side_effect = [None, errors.SubprocessError] mock_run_script.side_effect = [None, errors.SubprocessError]
@@ -902,8 +902,8 @@ class MultipleVhostsTest(util.ApacheTest):
self.assertEqual(self.vh_truth[0].name, res.name) self.assertEqual(self.vh_truth[0].name, res.name)
self.assertEqual(self.vh_truth[0].aliases, res.aliases) self.assertEqual(self.vh_truth[0].aliases, res.aliases)
@mock.patch("certbot_apache.configurator.ApacheConfigurator._get_http_vhost") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator._get_http_vhost")
@mock.patch("certbot_apache.display_ops.select_vhost") @mock.patch("certbot_apache._internal.display_ops.select_vhost")
@mock.patch("certbot.util.exe_exists") @mock.patch("certbot.util.exe_exists")
def test_enhance_unknown_vhost(self, mock_exe, mock_sel_vhost, mock_get): def test_enhance_unknown_vhost(self, mock_exe, mock_sel_vhost, mock_get):
self.config.parser.modules.add("rewrite_module") self.config.parser.modules.add("rewrite_module")
@@ -926,7 +926,7 @@ class MultipleVhostsTest(util.ApacheTest):
self.config.enhance, "certbot.demo", "unknown_enhancement") self.config.enhance, "certbot.demo", "unknown_enhancement")
def test_enhance_no_ssl_vhost(self): def test_enhance_no_ssl_vhost(self):
with mock.patch("certbot_apache.configurator.logger.warning") as mock_log: with mock.patch("certbot_apache._internal.configurator.logger.warning") as mock_log:
self.assertRaises(errors.PluginError, self.config.enhance, self.assertRaises(errors.PluginError, self.config.enhance,
"certbot.demo", "redirect") "certbot.demo", "redirect")
# Check that correct logger.warning was printed # Check that correct logger.warning was printed
@@ -1231,7 +1231,7 @@ class MultipleVhostsTest(util.ApacheTest):
self.config.choose_vhost("red.blue.purple.com") self.config.choose_vhost("red.blue.purple.com")
self.config.enhance("red.blue.purple.com", "redirect") self.config.enhance("red.blue.purple.com", "redirect")
verify_no_redirect = ("certbot_apache.configurator." verify_no_redirect = ("certbot_apache._internal.configurator."
"ApacheConfigurator._verify_no_certbot_redirect") "ApacheConfigurator._verify_no_certbot_redirect")
with mock.patch(verify_no_redirect) as mock_verify: with mock.patch(verify_no_redirect) as mock_verify:
self.config.enhance("green.blue.purple.com", "redirect") self.config.enhance("green.blue.purple.com", "redirect")
@@ -1333,8 +1333,8 @@ class MultipleVhostsTest(util.ApacheTest):
self.config.parser.modules.add("socache_shmcb_module") self.config.parser.modules.add("socache_shmcb_module")
tmp_path = filesystem.realpath(tempfile.mkdtemp("vhostroot")) tmp_path = filesystem.realpath(tempfile.mkdtemp("vhostroot"))
filesystem.chmod(tmp_path, 0o755) filesystem.chmod(tmp_path, 0o755)
mock_p = "certbot_apache.configurator.ApacheConfigurator._get_ssl_vhost_path" mock_p = "certbot_apache._internal.configurator.ApacheConfigurator._get_ssl_vhost_path"
mock_a = "certbot_apache.parser.ApacheParser.add_include" mock_a = "certbot_apache._internal.parser.ApacheParser.add_include"
with mock.patch(mock_p) as mock_path: with mock.patch(mock_p) as mock_path:
mock_path.return_value = os.path.join(tmp_path, "whatever.conf") mock_path.return_value = os.path.join(tmp_path, "whatever.conf")
@@ -1347,7 +1347,7 @@ class MultipleVhostsTest(util.ApacheTest):
self.assertTrue(mock_add.called) self.assertTrue(mock_add.called)
shutil.rmtree(tmp_path) shutil.rmtree(tmp_path)
@mock.patch("certbot_apache.parser.ApacheParser.parsed_in_original") @mock.patch("certbot_apache._internal.parser.ApacheParser.parsed_in_original")
def test_choose_vhost_and_servername_addition_parsed(self, mock_parsed): def test_choose_vhost_and_servername_addition_parsed(self, mock_parsed):
ret_vh = self.vh_truth[8] ret_vh = self.vh_truth[8]
ret_vh.enabled = True ret_vh.enabled = True
@@ -1369,7 +1369,7 @@ class MultipleVhostsTest(util.ApacheTest):
def test_choose_vhosts_wildcard(self): def test_choose_vhosts_wildcard(self):
# pylint: disable=protected-access # pylint: disable=protected-access
mock_path = "certbot_apache.display_ops.select_vhost_multiple" mock_path = "certbot_apache._internal.display_ops.select_vhost_multiple"
with mock.patch(mock_path) as mock_select_vhs: with mock.patch(mock_path) as mock_select_vhs:
mock_select_vhs.return_value = [self.vh_truth[3]] mock_select_vhs.return_value = [self.vh_truth[3]]
vhs = self.config._choose_vhosts_wildcard("*.certbot.demo", vhs = self.config._choose_vhosts_wildcard("*.certbot.demo",
@@ -1385,10 +1385,10 @@ class MultipleVhostsTest(util.ApacheTest):
self.assertFalse(vhs[0] == self.vh_truth[3]) self.assertFalse(vhs[0] == self.vh_truth[3])
@mock.patch("certbot_apache.configurator.ApacheConfigurator.make_vhost_ssl") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.make_vhost_ssl")
def test_choose_vhosts_wildcard_no_ssl(self, mock_makessl): def test_choose_vhosts_wildcard_no_ssl(self, mock_makessl):
# pylint: disable=protected-access # pylint: disable=protected-access
mock_path = "certbot_apache.display_ops.select_vhost_multiple" mock_path = "certbot_apache._internal.display_ops.select_vhost_multiple"
with mock.patch(mock_path) as mock_select_vhs: with mock.patch(mock_path) as mock_select_vhs:
mock_select_vhs.return_value = [self.vh_truth[1]] mock_select_vhs.return_value = [self.vh_truth[1]]
vhs = self.config._choose_vhosts_wildcard("*.certbot.demo", vhs = self.config._choose_vhosts_wildcard("*.certbot.demo",
@@ -1396,13 +1396,13 @@ class MultipleVhostsTest(util.ApacheTest):
self.assertFalse(mock_makessl.called) self.assertFalse(mock_makessl.called)
self.assertEqual(vhs[0], self.vh_truth[1]) self.assertEqual(vhs[0], self.vh_truth[1])
@mock.patch("certbot_apache.configurator.ApacheConfigurator._vhosts_for_wildcard") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator._vhosts_for_wildcard")
@mock.patch("certbot_apache.configurator.ApacheConfigurator.make_vhost_ssl") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.make_vhost_ssl")
def test_choose_vhosts_wildcard_already_ssl(self, mock_makessl, mock_vh_for_w): def test_choose_vhosts_wildcard_already_ssl(self, mock_makessl, mock_vh_for_w):
# pylint: disable=protected-access # pylint: disable=protected-access
# Already SSL vhost # Already SSL vhost
mock_vh_for_w.return_value = [self.vh_truth[7]] mock_vh_for_w.return_value = [self.vh_truth[7]]
mock_path = "certbot_apache.display_ops.select_vhost_multiple" mock_path = "certbot_apache._internal.display_ops.select_vhost_multiple"
with mock.patch(mock_path) as mock_select_vhs: with mock.patch(mock_path) as mock_select_vhs:
mock_select_vhs.return_value = [self.vh_truth[7]] mock_select_vhs.return_value = [self.vh_truth[7]]
vhs = self.config._choose_vhosts_wildcard("whatever", vhs = self.config._choose_vhosts_wildcard("whatever",
@@ -1423,7 +1423,7 @@ class MultipleVhostsTest(util.ApacheTest):
mock_choose_vhosts = mock.MagicMock() mock_choose_vhosts = mock.MagicMock()
mock_choose_vhosts.return_value = [self.vh_truth[7]] mock_choose_vhosts.return_value = [self.vh_truth[7]]
self.config._choose_vhosts_wildcard = mock_choose_vhosts self.config._choose_vhosts_wildcard = mock_choose_vhosts
mock_d = "certbot_apache.configurator.ApacheConfigurator._deploy_cert" mock_d = "certbot_apache._internal.configurator.ApacheConfigurator._deploy_cert"
with mock.patch(mock_d) as mock_dep: with mock.patch(mock_d) as mock_dep:
self.config.deploy_cert("*.wildcard.example.org", "/tmp/path", self.config.deploy_cert("*.wildcard.example.org", "/tmp/path",
"/tmp/path", "/tmp/path", "/tmp/path") "/tmp/path", "/tmp/path", "/tmp/path")
@@ -1431,7 +1431,7 @@ class MultipleVhostsTest(util.ApacheTest):
self.assertEqual(len(mock_dep.call_args_list), 1) self.assertEqual(len(mock_dep.call_args_list), 1)
self.assertEqual(self.vh_truth[7], mock_dep.call_args_list[0][0][0]) self.assertEqual(self.vh_truth[7], mock_dep.call_args_list[0][0][0])
@mock.patch("certbot_apache.display_ops.select_vhost_multiple") @mock.patch("certbot_apache._internal.display_ops.select_vhost_multiple")
def test_deploy_cert_wildcard_no_vhosts(self, mock_dialog): def test_deploy_cert_wildcard_no_vhosts(self, mock_dialog):
# pylint: disable=protected-access # pylint: disable=protected-access
mock_dialog.return_value = [] mock_dialog.return_value = []
@@ -1440,7 +1440,7 @@ class MultipleVhostsTest(util.ApacheTest):
"*.wild.cat", "/tmp/path", "/tmp/path", "*.wild.cat", "/tmp/path", "/tmp/path",
"/tmp/path", "/tmp/path") "/tmp/path", "/tmp/path")
@mock.patch("certbot_apache.configurator.ApacheConfigurator._choose_vhosts_wildcard") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator._choose_vhosts_wildcard")
def test_enhance_wildcard_after_install(self, mock_choose): def test_enhance_wildcard_after_install(self, mock_choose):
# pylint: disable=protected-access # pylint: disable=protected-access
self.config.parser.modules.add("mod_ssl.c") self.config.parser.modules.add("mod_ssl.c")
@@ -1451,7 +1451,7 @@ class MultipleVhostsTest(util.ApacheTest):
"Upgrade-Insecure-Requests") "Upgrade-Insecure-Requests")
self.assertFalse(mock_choose.called) self.assertFalse(mock_choose.called)
@mock.patch("certbot_apache.configurator.ApacheConfigurator._choose_vhosts_wildcard") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator._choose_vhosts_wildcard")
def test_enhance_wildcard_no_install(self, mock_choose): def test_enhance_wildcard_no_install(self, mock_choose):
self.vh_truth[3].ssl = True self.vh_truth[3].ssl = True
mock_choose.return_value = [self.vh_truth[3]] mock_choose.return_value = [self.vh_truth[3]]
@@ -1528,7 +1528,7 @@ class AugeasVhostsTest(util.ApacheTest):
chosen_vhost = self.config._create_vhost(path) chosen_vhost = self.config._create_vhost(path)
self.assertTrue(chosen_vhost is None or chosen_vhost.path == path) self.assertTrue(chosen_vhost is None or chosen_vhost.path == path)
@mock.patch("certbot_apache.configurator.ApacheConfigurator._create_vhost") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator._create_vhost")
def test_get_vhost_continue(self, mock_vhost): def test_get_vhost_continue(self, mock_vhost):
mock_vhost.return_value = None mock_vhost.return_value = None
vhs = self.config.get_virtual_hosts() vhs = self.config.get_virtual_hosts()
@@ -1540,18 +1540,18 @@ class AugeasVhostsTest(util.ApacheTest):
for name in names: for name in names:
self.assertFalse(name in self.config.choose_vhost(name).aliases) self.assertFalse(name in self.config.choose_vhost(name).aliases)
@mock.patch("certbot_apache.obj.VirtualHost.conflicts") @mock.patch("certbot_apache._internal.obj.VirtualHost.conflicts")
def test_choose_vhost_without_matching_wildcard(self, mock_conflicts): def test_choose_vhost_without_matching_wildcard(self, mock_conflicts):
mock_conflicts.return_value = False mock_conflicts.return_value = False
mock_path = "certbot_apache.display_ops.select_vhost" mock_path = "certbot_apache._internal.display_ops.select_vhost"
with mock.patch(mock_path, lambda _, vhosts: vhosts[0]): with mock.patch(mock_path, lambda _, vhosts: vhosts[0]):
for name in ("a.example.net", "other.example.net"): for name in ("a.example.net", "other.example.net"):
self.assertTrue(name in self.config.choose_vhost(name).aliases) self.assertTrue(name in self.config.choose_vhost(name).aliases)
@mock.patch("certbot_apache.obj.VirtualHost.conflicts") @mock.patch("certbot_apache._internal.obj.VirtualHost.conflicts")
def test_choose_vhost_wildcard_not_found(self, mock_conflicts): def test_choose_vhost_wildcard_not_found(self, mock_conflicts):
mock_conflicts.return_value = False mock_conflicts.return_value = False
mock_path = "certbot_apache.display_ops.select_vhost" mock_path = "certbot_apache._internal.display_ops.select_vhost"
names = ( names = (
"abc.example.net", "not.there.tld", "aa.wildcard.tld" "abc.example.net", "not.there.tld", "aa.wildcard.tld"
) )
@@ -1563,7 +1563,7 @@ class AugeasVhostsTest(util.ApacheTest):
self.assertEqual(mock_select.call_count - orig_cc, 1) self.assertEqual(mock_select.call_count - orig_cc, 1)
def test_choose_vhost_wildcard_found(self): def test_choose_vhost_wildcard_found(self):
mock_path = "certbot_apache.display_ops.select_vhost" mock_path = "certbot_apache._internal.display_ops.select_vhost"
names = ( names = (
"ab.example.net", "a.wildcard.tld", "yetanother.example.net" "ab.example.net", "a.wildcard.tld", "yetanother.example.net"
) )
@@ -1617,7 +1617,7 @@ class MultiVhostsTest(util.ApacheTest):
self.assertEqual(self.config.is_name_vhost(self.vh_truth[1]), self.assertEqual(self.config.is_name_vhost(self.vh_truth[1]),
self.config.is_name_vhost(ssl_vhost)) self.config.is_name_vhost(ssl_vhost))
mock_path = "certbot_apache.configurator.ApacheConfigurator._get_new_vh_path" mock_path = "certbot_apache._internal.configurator.ApacheConfigurator._get_new_vh_path"
with mock.patch(mock_path) as mock_getpath: with mock.patch(mock_path) as mock_getpath:
mock_getpath.return_value = None mock_getpath.return_value = None
self.assertRaises(errors.PluginError, self.config.make_vhost_ssl, self.assertRaises(errors.PluginError, self.config.make_vhost_ssl,
@@ -1723,7 +1723,7 @@ class InstallSslOptionsConfTest(util.ApacheTest):
self._assert_current_file() self._assert_current_file()
def test_prev_file_updates_to_current(self): def test_prev_file_updates_to_current(self):
from certbot_apache.constants import ALL_SSL_OPTIONS_HASHES from certbot_apache._internal.constants import ALL_SSL_OPTIONS_HASHES
ALL_SSL_OPTIONS_HASHES.insert(0, "test_hash_does_not_match") ALL_SSL_OPTIONS_HASHES.insert(0, "test_hash_does_not_match")
with mock.patch('certbot.crypto_util.sha256sum') as mock_sha256: with mock.patch('certbot.crypto_util.sha256sum') as mock_sha256:
mock_sha256.return_value = ALL_SSL_OPTIONS_HASHES[0] mock_sha256.return_value = ALL_SSL_OPTIONS_HASHES[0]
@@ -1762,7 +1762,7 @@ class InstallSslOptionsConfTest(util.ApacheTest):
self.assertFalse(mock_logger.warning.called) self.assertFalse(mock_logger.warning.called)
def test_current_file_hash_in_all_hashes(self): def test_current_file_hash_in_all_hashes(self):
from certbot_apache.constants import ALL_SSL_OPTIONS_HASHES from certbot_apache._internal.constants import ALL_SSL_OPTIONS_HASHES
self.assertTrue(self._current_ssl_options_hash() in ALL_SSL_OPTIONS_HASHES, self.assertTrue(self._current_ssl_options_hash() in ALL_SSL_OPTIONS_HASHES,
"Constants.ALL_SSL_OPTIONS_HASHES must be appended" "Constants.ALL_SSL_OPTIONS_HASHES must be appended"
" with the sha256 hash of self.config.mod_ssl_conf when it is updated.") " with the sha256 hash of self.config.mod_ssl_conf when it is updated.")
@@ -1,4 +1,4 @@
"""Test for certbot_apache.configurator for Debian overrides""" """Test for certbot_apache._internal.configurator for Debian overrides"""
import shutil import shutil
import unittest import unittest
@@ -7,8 +7,8 @@ import mock
from certbot import errors from certbot import errors
from certbot.compat import os from certbot.compat import os
from certbot_apache import apache_util from certbot_apache._internal import apache_util
from certbot_apache import obj from certbot_apache._internal import obj
from certbot_apache.tests import util from certbot_apache.tests import util
@@ -32,8 +32,8 @@ class MultipleVhostsTestDebian(util.ApacheTest):
def mocked_deploy_cert(*args, **kwargs): def mocked_deploy_cert(*args, **kwargs):
"""a helper to mock a deployed cert""" """a helper to mock a deployed cert"""
g_mod = "certbot_apache.configurator.ApacheConfigurator.enable_mod" g_mod = "certbot_apache._internal.configurator.ApacheConfigurator.enable_mod"
d_mod = "certbot_apache.override_debian.DebianConfigurator.enable_mod" d_mod = "certbot_apache._internal.override_debian.DebianConfigurator.enable_mod"
with mock.patch(g_mod): with mock.patch(g_mod):
with mock.patch(d_mod): with mock.patch(d_mod):
config.real_deploy_cert(*args, **kwargs) config.real_deploy_cert(*args, **kwargs)
@@ -47,7 +47,7 @@ class MultipleVhostsTestDebian(util.ApacheTest):
@mock.patch("certbot.util.run_script") @mock.patch("certbot.util.run_script")
@mock.patch("certbot.util.exe_exists") @mock.patch("certbot.util.exe_exists")
@mock.patch("certbot_apache.parser.subprocess.Popen") @mock.patch("certbot_apache._internal.parser.subprocess.Popen")
def test_enable_mod(self, mock_popen, mock_exe_exists, mock_run_script): def test_enable_mod(self, mock_popen, mock_exe_exists, mock_run_script):
mock_popen().communicate.return_value = ("Define: DUMP_RUN_CFG", "") mock_popen().communicate.return_value = ("Define: DUMP_RUN_CFG", "")
mock_popen().returncode = 0 mock_popen().returncode = 0
@@ -196,7 +196,7 @@ class MultipleVhostsTestDebian(util.ApacheTest):
def test_enable_site_call_parent(self): def test_enable_site_call_parent(self):
with mock.patch( with mock.patch(
"certbot_apache.configurator.ApacheConfigurator.enable_site") as e_s: "certbot_apache._internal.configurator.ApacheConfigurator.enable_site") as e_s:
self.config.parser.root = "/tmp/nonexistent" self.config.parser.root = "/tmp/nonexistent"
vh = self.vh_truth[0] vh = self.vh_truth[0]
vh.enabled = False vh.enabled = False
@@ -1,4 +1,4 @@
"""Test certbot_apache.display_ops.""" """Test certbot_apache._internal.display_ops."""
import unittest import unittest
import mock import mock
@@ -9,14 +9,14 @@ from certbot.display import util as display_util
from certbot.tests import util as certbot_util from certbot.tests import util as certbot_util
from certbot_apache import obj from certbot_apache._internal import obj
from certbot_apache.display_ops import select_vhost_multiple from certbot_apache._internal.display_ops import select_vhost_multiple
from certbot_apache.tests import util from certbot_apache.tests import util
class SelectVhostMultiTest(unittest.TestCase): class SelectVhostMultiTest(unittest.TestCase):
"""Tests for certbot_apache.display_ops.select_vhost_multiple.""" """Tests for certbot_apache._internal.display_ops.select_vhost_multiple."""
def setUp(self): def setUp(self):
self.base_dir = "/example_path" self.base_dir = "/example_path"
@@ -45,7 +45,7 @@ class SelectVhostMultiTest(unittest.TestCase):
self.assertFalse(vhs) self.assertFalse(vhs)
class SelectVhostTest(unittest.TestCase): class SelectVhostTest(unittest.TestCase):
"""Tests for certbot_apache.display_ops.select_vhost.""" """Tests for certbot_apache._internal.display_ops.select_vhost."""
def setUp(self): def setUp(self):
self.base_dir = "/example_path" self.base_dir = "/example_path"
@@ -54,7 +54,7 @@ class SelectVhostTest(unittest.TestCase):
@classmethod @classmethod
def _call(cls, vhosts): def _call(cls, vhosts):
from certbot_apache.display_ops import select_vhost from certbot_apache._internal.display_ops import select_vhost
return select_vhost("example.com", vhosts) return select_vhost("example.com", vhosts)
@certbot_util.patch_get_utility() @certbot_util.patch_get_utility()
@@ -81,9 +81,9 @@ class SelectVhostTest(unittest.TestCase):
def test_no_vhosts(self): def test_no_vhosts(self):
self.assertEqual(self._call([]), None) self.assertEqual(self._call([]), None)
@mock.patch("certbot_apache.display_ops.display_util") @mock.patch("certbot_apache._internal.display_ops.display_util")
@certbot_util.patch_get_utility() @certbot_util.patch_get_utility()
@mock.patch("certbot_apache.display_ops.logger") @mock.patch("certbot_apache._internal.display_ops.logger")
def test_small_display(self, mock_logger, mock_util, mock_display_util): def test_small_display(self, mock_logger, mock_util, mock_display_util):
mock_display_util.WIDTH = 20 mock_display_util.WIDTH = 20
mock_util().menu.return_value = (display_util.OK, 0) mock_util().menu.return_value = (display_util.OK, 0)
@@ -1,10 +1,10 @@
"""Test for certbot_apache.entrypoint for override class resolution""" """Test for certbot_apache._internal.entrypoint for override class resolution"""
import unittest import unittest
import mock import mock
from certbot_apache import configurator from certbot_apache._internal import configurator
from certbot_apache import entrypoint from certbot_apache._internal import entrypoint
class EntryPointTest(unittest.TestCase): class EntryPointTest(unittest.TestCase):
@@ -1,4 +1,4 @@
"""Test for certbot_apache.configurator for Fedora 29+ overrides""" """Test for certbot_apache._internal.configurator for Fedora 29+ overrides"""
import unittest import unittest
import mock import mock
@@ -7,8 +7,8 @@ from certbot import errors
from certbot.compat import filesystem from certbot.compat import filesystem
from certbot.compat import os from certbot.compat import os
from certbot_apache import obj from certbot_apache._internal import obj
from certbot_apache import override_fedora from certbot_apache._internal import override_fedora
from certbot_apache.tests import util from certbot_apache.tests import util
@@ -58,7 +58,7 @@ class FedoraRestartTest(util.ApacheTest):
self.config.config_test() self.config.config_test()
def test_fedora_restart_error(self): def test_fedora_restart_error(self):
c_test = "certbot_apache.configurator.ApacheConfigurator.config_test" c_test = "certbot_apache._internal.configurator.ApacheConfigurator.config_test"
with mock.patch(c_test) as mock_test: with mock.patch(c_test) as mock_test:
# First call raises error, second doesn't # First call raises error, second doesn't
mock_test.side_effect = [errors.MisconfigurationError, ''] mock_test.side_effect = [errors.MisconfigurationError, '']
@@ -68,7 +68,7 @@ class FedoraRestartTest(util.ApacheTest):
self._run_fedora_test) self._run_fedora_test)
def test_fedora_restart(self): def test_fedora_restart(self):
c_test = "certbot_apache.configurator.ApacheConfigurator.config_test" c_test = "certbot_apache._internal.configurator.ApacheConfigurator.config_test"
with mock.patch(c_test) as mock_test: with mock.patch(c_test) as mock_test:
with mock.patch("certbot.util.run_script") as mock_run: with mock.patch("certbot.util.run_script") as mock_run:
# First call raises error, second doesn't # First call raises error, second doesn't
@@ -101,7 +101,7 @@ class MultipleVhostsTestFedora(util.ApacheTest):
def test_get_parser(self): def test_get_parser(self):
self.assertIsInstance(self.config.parser, override_fedora.FedoraParser) self.assertIsInstance(self.config.parser, override_fedora.FedoraParser)
@mock.patch("certbot_apache.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
def test_opportunistic_httpd_runtime_parsing(self, mock_get): def test_opportunistic_httpd_runtime_parsing(self, mock_get):
define_val = ( define_val = (
'Define: TEST1\n' 'Define: TEST1\n'
@@ -135,7 +135,7 @@ class MultipleVhostsTestFedora(util.ApacheTest):
self.assertTrue("TEST2" in self.config.parser.variables.keys()) self.assertTrue("TEST2" in self.config.parser.variables.keys())
self.assertTrue("mod_another.c" in self.config.parser.modules) self.assertTrue("mod_another.c" in self.config.parser.modules)
@mock.patch("certbot_apache.configurator.util.run_script") @mock.patch("certbot_apache._internal.configurator.util.run_script")
def test_get_version(self, mock_run_script): def test_get_version(self, mock_run_script):
mock_run_script.return_value = ('', None) mock_run_script.return_value = ('', None)
self.assertRaises(errors.PluginError, self.config.get_version) self.assertRaises(errors.PluginError, self.config.get_version)
@@ -156,7 +156,7 @@ class MultipleVhostsTestFedora(util.ApacheTest):
raise Exception("Missed: %s" % vhost) # pragma: no cover raise Exception("Missed: %s" % vhost) # pragma: no cover
self.assertEqual(found, 2) self.assertEqual(found, 2)
@mock.patch("certbot_apache.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
def test_get_sysconfig_vars(self, mock_cfg): def test_get_sysconfig_vars(self, mock_cfg):
"""Make sure we read the sysconfig OPTIONS variable correctly""" """Make sure we read the sysconfig OPTIONS variable correctly"""
# Return nothing for the process calls # Return nothing for the process calls
@@ -177,13 +177,13 @@ class MultipleVhostsTestFedora(util.ApacheTest):
self.assertTrue("MOCK_NOSEP" in self.config.parser.variables.keys()) self.assertTrue("MOCK_NOSEP" in self.config.parser.variables.keys())
self.assertEqual("NOSEP_VAL", self.config.parser.variables["NOSEP_TWO"]) self.assertEqual("NOSEP_VAL", self.config.parser.variables["NOSEP_TWO"])
@mock.patch("certbot_apache.configurator.util.run_script") @mock.patch("certbot_apache._internal.configurator.util.run_script")
def test_alt_restart_works(self, mock_run_script): def test_alt_restart_works(self, mock_run_script):
mock_run_script.side_effect = [None, errors.SubprocessError, None] mock_run_script.side_effect = [None, errors.SubprocessError, None]
self.config.restart() self.config.restart()
self.assertEqual(mock_run_script.call_count, 3) self.assertEqual(mock_run_script.call_count, 3)
@mock.patch("certbot_apache.configurator.util.run_script") @mock.patch("certbot_apache._internal.configurator.util.run_script")
def test_alt_restart_errors(self, mock_run_script): def test_alt_restart_errors(self, mock_run_script):
mock_run_script.side_effect = [None, mock_run_script.side_effect = [None,
errors.SubprocessError, errors.SubprocessError,
@@ -1,4 +1,4 @@
"""Test for certbot_apache.configurator for Gentoo overrides""" """Test for certbot_apache._internal.configurator for Gentoo overrides"""
import unittest import unittest
import mock import mock
@@ -7,8 +7,8 @@ from certbot import errors
from certbot.compat import filesystem from certbot.compat import filesystem
from certbot.compat import os from certbot.compat import os
from certbot_apache import obj from certbot_apache._internal import obj
from certbot_apache import override_gentoo from certbot_apache._internal import override_gentoo
from certbot_apache.tests import util from certbot_apache.tests import util
@@ -52,7 +52,8 @@ class MultipleVhostsTestGentoo(util.ApacheTest):
config_root=config_root, config_root=config_root,
vhost_root=vhost_root) vhost_root=vhost_root)
with mock.patch("certbot_apache.override_gentoo.GentooParser.update_runtime_variables"): # pylint: disable=line-too-long
with mock.patch("certbot_apache._internal.override_gentoo.GentooParser.update_runtime_variables"):
self.config = util.get_apache_configurator( self.config = util.get_apache_configurator(
self.config_path, self.vhost_path, self.config_dir, self.work_dir, self.config_path, self.vhost_path, self.config_dir, self.work_dir,
os_info="gentoo") os_info="gentoo")
@@ -85,17 +86,17 @@ class MultipleVhostsTestGentoo(util.ApacheTest):
self.config.parser.apacheconfig_filep = filesystem.realpath( self.config.parser.apacheconfig_filep = filesystem.realpath(
os.path.join(self.config.parser.root, "../conf.d/apache2")) os.path.join(self.config.parser.root, "../conf.d/apache2"))
self.config.parser.variables = {} self.config.parser.variables = {}
with mock.patch("certbot_apache.override_gentoo.GentooParser.update_modules"): with mock.patch("certbot_apache._internal.override_gentoo.GentooParser.update_modules"):
self.config.parser.update_runtime_variables() self.config.parser.update_runtime_variables()
for define in defines: for define in defines:
self.assertTrue(define in self.config.parser.variables.keys()) self.assertTrue(define in self.config.parser.variables.keys())
@mock.patch("certbot_apache.parser.ApacheParser.parse_from_subprocess") @mock.patch("certbot_apache._internal.parser.ApacheParser.parse_from_subprocess")
def test_no_binary_configdump(self, mock_subprocess): def test_no_binary_configdump(self, mock_subprocess):
"""Make sure we don't call binary dumps other than modules from Apache """Make sure we don't call binary dumps other than modules from Apache
as this is not supported in Gentoo currently""" as this is not supported in Gentoo currently"""
with mock.patch("certbot_apache.override_gentoo.GentooParser.update_modules"): with mock.patch("certbot_apache._internal.override_gentoo.GentooParser.update_modules"):
self.config.parser.update_runtime_variables() self.config.parser.update_runtime_variables()
self.config.parser.reset_modules() self.config.parser.reset_modules()
self.assertFalse(mock_subprocess.called) self.assertFalse(mock_subprocess.called)
@@ -104,7 +105,7 @@ class MultipleVhostsTestGentoo(util.ApacheTest):
self.config.parser.reset_modules() self.config.parser.reset_modules()
self.assertTrue(mock_subprocess.called) self.assertTrue(mock_subprocess.called)
@mock.patch("certbot_apache.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
def test_opportunistic_httpd_runtime_parsing(self, mock_get): def test_opportunistic_httpd_runtime_parsing(self, mock_get):
mod_val = ( mod_val = (
'Loaded Modules:\n' 'Loaded Modules:\n'
@@ -128,7 +129,7 @@ class MultipleVhostsTestGentoo(util.ApacheTest):
self.assertEqual(len(self.config.parser.modules), 4) self.assertEqual(len(self.config.parser.modules), 4)
self.assertTrue("mod_another.c" in self.config.parser.modules) self.assertTrue("mod_another.c" in self.config.parser.modules)
@mock.patch("certbot_apache.configurator.util.run_script") @mock.patch("certbot_apache._internal.configurator.util.run_script")
def test_alt_restart_works(self, mock_run_script): def test_alt_restart_works(self, mock_run_script):
mock_run_script.side_effect = [None, errors.SubprocessError, None] mock_run_script.side_effect = [None, errors.SubprocessError, None]
self.config.restart() self.config.restart()
@@ -1,4 +1,4 @@
"""Test for certbot_apache.http_01.""" """Test for certbot_apache._internal.http_01."""
import unittest import unittest
import mock import mock
@@ -11,7 +11,7 @@ from certbot.compat import filesystem
from certbot.compat import os from certbot.compat import os
from certbot.tests import acme_util from certbot.tests import acme_util
from certbot_apache.parser import get_aug_path from certbot_apache._internal.parser import get_aug_path
from certbot_apache.tests import util from certbot_apache.tests import util
@@ -19,7 +19,7 @@ NUM_ACHALLS = 3
class ApacheHttp01Test(util.ApacheTest): class ApacheHttp01Test(util.ApacheTest):
"""Test for certbot_apache.http_01.ApacheHttp01.""" """Test for certbot_apache._internal.http_01.ApacheHttp01."""
def setUp(self, *args, **kwargs): # pylint: disable=arguments-differ def setUp(self, *args, **kwargs): # pylint: disable=arguments-differ
super(ApacheHttp01Test, self).setUp(*args, **kwargs) super(ApacheHttp01Test, self).setUp(*args, **kwargs)
@@ -45,13 +45,13 @@ class ApacheHttp01Test(util.ApacheTest):
self.config.parser.modules.add("mod_{0}.c".format(mod)) self.config.parser.modules.add("mod_{0}.c".format(mod))
self.config.parser.modules.add(mod + "_module") self.config.parser.modules.add(mod + "_module")
from certbot_apache.http_01 import ApacheHttp01 from certbot_apache._internal.http_01 import ApacheHttp01
self.http = ApacheHttp01(self.config) self.http = ApacheHttp01(self.config)
def test_empty_perform(self): def test_empty_perform(self):
self.assertFalse(self.http.perform()) self.assertFalse(self.http.perform())
@mock.patch("certbot_apache.configurator.ApacheConfigurator.enable_mod") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.enable_mod")
def test_enable_modules_apache_2_2(self, mock_enmod): def test_enable_modules_apache_2_2(self, mock_enmod):
self.config.version = (2, 2) self.config.version = (2, 2)
self.config.parser.modules.remove("authz_host_module") self.config.parser.modules.remove("authz_host_module")
@@ -60,7 +60,7 @@ class ApacheHttp01Test(util.ApacheTest):
enmod_calls = self.common_enable_modules_test(mock_enmod) enmod_calls = self.common_enable_modules_test(mock_enmod)
self.assertEqual(enmod_calls[0][0][0], "authz_host") self.assertEqual(enmod_calls[0][0][0], "authz_host")
@mock.patch("certbot_apache.configurator.ApacheConfigurator.enable_mod") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.enable_mod")
def test_enable_modules_apache_2_4(self, mock_enmod): def test_enable_modules_apache_2_4(self, mock_enmod):
self.config.parser.modules.remove("authz_core_module") self.config.parser.modules.remove("authz_core_module")
self.config.parser.modules.remove("mod_authz_core.c") self.config.parser.modules.remove("mod_authz_core.c")
@@ -1,4 +1,4 @@
"""Tests for certbot_apache.obj.""" """Tests for certbot_apache._internal.obj."""
import unittest import unittest
@@ -6,8 +6,8 @@ class VirtualHostTest(unittest.TestCase):
"""Test the VirtualHost class.""" """Test the VirtualHost class."""
def setUp(self): def setUp(self):
from certbot_apache.obj import Addr from certbot_apache._internal.obj import Addr
from certbot_apache.obj import VirtualHost from certbot_apache._internal.obj import VirtualHost
self.addr1 = Addr.fromstring("127.0.0.1") self.addr1 = Addr.fromstring("127.0.0.1")
self.addr2 = Addr.fromstring("127.0.0.1:443") self.addr2 = Addr.fromstring("127.0.0.1:443")
@@ -23,7 +23,8 @@ class VirtualHostTest(unittest.TestCase):
"fp", "vhp", set([self.addr2]), False, False, "localhost") "fp", "vhp", set([self.addr2]), False, False, "localhost")
def test_repr(self): def test_repr(self):
self.assertEqual(repr(self.addr2), "certbot_apache.obj.Addr(('127.0.0.1', '443'))") self.assertEqual(repr(self.addr2),
"certbot_apache._internal.obj.Addr(('127.0.0.1', '443'))")
def test_eq(self): def test_eq(self):
self.assertTrue(self.vhost1b == self.vhost1) self.assertTrue(self.vhost1b == self.vhost1)
@@ -36,8 +37,8 @@ class VirtualHostTest(unittest.TestCase):
self.assertFalse(self.vhost1 != self.vhost1b) self.assertFalse(self.vhost1 != self.vhost1b)
def test_conflicts(self): def test_conflicts(self):
from certbot_apache.obj import Addr from certbot_apache._internal.obj import Addr
from certbot_apache.obj import VirtualHost from certbot_apache._internal.obj import VirtualHost
complex_vh = VirtualHost( complex_vh = VirtualHost(
"fp", "vhp", "fp", "vhp",
@@ -54,7 +55,7 @@ class VirtualHostTest(unittest.TestCase):
self.addr_default])) self.addr_default]))
def test_same_server(self): def test_same_server(self):
from certbot_apache.obj import VirtualHost from certbot_apache._internal.obj import VirtualHost
no_name1 = VirtualHost( no_name1 = VirtualHost(
"fp", "vhp", set([self.addr1]), False, False, None) "fp", "vhp", set([self.addr1]), False, False, None)
no_name2 = VirtualHost( no_name2 = VirtualHost(
@@ -77,7 +78,7 @@ class VirtualHostTest(unittest.TestCase):
class AddrTest(unittest.TestCase): class AddrTest(unittest.TestCase):
"""Test obj.Addr.""" """Test obj.Addr."""
def setUp(self): def setUp(self):
from certbot_apache.obj import Addr from certbot_apache._internal.obj import Addr
self.addr = Addr.fromstring("*:443") self.addr = Addr.fromstring("*:443")
self.addr1 = Addr.fromstring("127.0.0.1") self.addr1 = Addr.fromstring("127.0.0.1")
@@ -92,7 +93,7 @@ class AddrTest(unittest.TestCase):
self.assertTrue(self.addr2.is_wildcard()) self.assertTrue(self.addr2.is_wildcard())
def test_get_sni_addr(self): def test_get_sni_addr(self):
from certbot_apache.obj import Addr from certbot_apache._internal.obj import Addr
self.assertEqual( self.assertEqual(
self.addr.get_sni_addr("443"), Addr.fromstring("*:443")) self.addr.get_sni_addr("443"), Addr.fromstring("*:443"))
self.assertEqual( self.assertEqual(
@@ -1,4 +1,4 @@
"""Tests for certbot_apache.parser.""" """Tests for certbot_apache._internal.parser."""
import shutil import shutil
import unittest import unittest
@@ -113,7 +113,7 @@ class BasicParserTest(util.ParserTest):
Path must be valid before attempting to add to augeas Path must be valid before attempting to add to augeas
""" """
from certbot_apache.parser import get_aug_path from certbot_apache._internal.parser import get_aug_path
# This makes sure that find_dir will work # This makes sure that find_dir will work
self.parser.modules.add("mod_ssl.c") self.parser.modules.add("mod_ssl.c")
@@ -127,7 +127,7 @@ class BasicParserTest(util.ParserTest):
self.assertTrue("IfModule" in matches[0]) self.assertTrue("IfModule" in matches[0])
def test_add_dir_to_ifmodssl_multiple(self): def test_add_dir_to_ifmodssl_multiple(self):
from certbot_apache.parser import get_aug_path from certbot_apache._internal.parser import get_aug_path
# This makes sure that find_dir will work # This makes sure that find_dir will work
self.parser.modules.add("mod_ssl.c") self.parser.modules.add("mod_ssl.c")
@@ -141,11 +141,11 @@ class BasicParserTest(util.ParserTest):
self.assertTrue("IfModule" in matches[0]) self.assertTrue("IfModule" in matches[0])
def test_get_aug_path(self): def test_get_aug_path(self):
from certbot_apache.parser import get_aug_path from certbot_apache._internal.parser import get_aug_path
self.assertEqual("/files/etc/apache", get_aug_path("/etc/apache")) self.assertEqual("/files/etc/apache", get_aug_path("/etc/apache"))
def test_set_locations(self): def test_set_locations(self):
with mock.patch("certbot_apache.parser.os.path") as mock_path: with mock.patch("certbot_apache._internal.parser.os.path") as mock_path:
mock_path.isfile.side_effect = [False, False] mock_path.isfile.side_effect = [False, False]
@@ -155,18 +155,18 @@ class BasicParserTest(util.ParserTest):
self.assertEqual(results["default"], results["listen"]) self.assertEqual(results["default"], results["listen"])
self.assertEqual(results["default"], results["name"]) self.assertEqual(results["default"], results["name"])
@mock.patch("certbot_apache.parser.ApacheParser.find_dir") @mock.patch("certbot_apache._internal.parser.ApacheParser.find_dir")
@mock.patch("certbot_apache.parser.ApacheParser.get_arg") @mock.patch("certbot_apache._internal.parser.ApacheParser.get_arg")
def test_parse_modules_bad_syntax(self, mock_arg, mock_find): def test_parse_modules_bad_syntax(self, mock_arg, mock_find):
mock_find.return_value = ["1", "2", "3", "4", "5", "6", "7", "8"] mock_find.return_value = ["1", "2", "3", "4", "5", "6", "7", "8"]
mock_arg.return_value = None mock_arg.return_value = None
with mock.patch("certbot_apache.parser.logger") as mock_logger: with mock.patch("certbot_apache._internal.parser.logger") as mock_logger:
self.parser.parse_modules() self.parser.parse_modules()
# Make sure that we got None return value and logged the file # Make sure that we got None return value and logged the file
self.assertTrue(mock_logger.debug.called) self.assertTrue(mock_logger.debug.called)
@mock.patch("certbot_apache.parser.ApacheParser.find_dir") @mock.patch("certbot_apache._internal.parser.ApacheParser.find_dir")
@mock.patch("certbot_apache.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
def test_update_runtime_variables(self, mock_cfg, _): def test_update_runtime_variables(self, mock_cfg, _):
define_val = ( define_val = (
'ServerRoot: "/etc/apache2"\n' 'ServerRoot: "/etc/apache2"\n'
@@ -263,7 +263,7 @@ class BasicParserTest(util.ParserTest):
self.parser.modules = set() self.parser.modules = set()
with mock.patch( with mock.patch(
"certbot_apache.parser.ApacheParser.parse_file") as mock_parse: "certbot_apache._internal.parser.ApacheParser.parse_file") as mock_parse:
self.parser.update_runtime_variables() self.parser.update_runtime_variables()
self.assertEqual(self.parser.variables, expected_vars) self.assertEqual(self.parser.variables, expected_vars)
self.assertEqual(len(self.parser.modules), 58) self.assertEqual(len(self.parser.modules), 58)
@@ -271,8 +271,8 @@ class BasicParserTest(util.ParserTest):
# Make sure we tried to include them all. # Make sure we tried to include them all.
self.assertEqual(mock_parse.call_count, 25) self.assertEqual(mock_parse.call_count, 25)
@mock.patch("certbot_apache.parser.ApacheParser.find_dir") @mock.patch("certbot_apache._internal.parser.ApacheParser.find_dir")
@mock.patch("certbot_apache.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
def test_update_runtime_variables_alt_values(self, mock_cfg, _): def test_update_runtime_variables_alt_values(self, mock_cfg, _):
inc_val = ( inc_val = (
'Included configuration files:\n' 'Included configuration files:\n'
@@ -286,7 +286,7 @@ class BasicParserTest(util.ParserTest):
self.parser.modules = set() self.parser.modules = set()
with mock.patch( with mock.patch(
"certbot_apache.parser.ApacheParser.parse_file") as mock_parse: "certbot_apache._internal.parser.ApacheParser.parse_file") as mock_parse:
self.parser.update_runtime_variables() self.parser.update_runtime_variables()
# No matching modules should have been found # No matching modules should have been found
self.assertEqual(len(self.parser.modules), 0) self.assertEqual(len(self.parser.modules), 0)
@@ -294,7 +294,7 @@ class BasicParserTest(util.ParserTest):
# path derived from root configuration Include statements # path derived from root configuration Include statements
self.assertEqual(mock_parse.call_count, 1) self.assertEqual(mock_parse.call_count, 1)
@mock.patch("certbot_apache.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
def test_update_runtime_vars_bad_output(self, mock_cfg): def test_update_runtime_vars_bad_output(self, mock_cfg):
mock_cfg.return_value = "Define: TLS=443=24" mock_cfg.return_value = "Define: TLS=443=24"
self.parser.update_runtime_variables() self.parser.update_runtime_variables()
@@ -303,8 +303,8 @@ class BasicParserTest(util.ParserTest):
self.assertRaises( self.assertRaises(
errors.PluginError, self.parser.update_runtime_variables) errors.PluginError, self.parser.update_runtime_variables)
@mock.patch("certbot_apache.configurator.ApacheConfigurator.option") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.option")
@mock.patch("certbot_apache.parser.subprocess.Popen") @mock.patch("certbot_apache._internal.parser.subprocess.Popen")
def test_update_runtime_vars_bad_ctl(self, mock_popen, mock_opt): def test_update_runtime_vars_bad_ctl(self, mock_popen, mock_opt):
mock_popen.side_effect = OSError mock_popen.side_effect = OSError
mock_opt.return_value = "nonexistent" mock_opt.return_value = "nonexistent"
@@ -312,7 +312,7 @@ class BasicParserTest(util.ParserTest):
errors.MisconfigurationError, errors.MisconfigurationError,
self.parser.update_runtime_variables) self.parser.update_runtime_variables)
@mock.patch("certbot_apache.parser.subprocess.Popen") @mock.patch("certbot_apache._internal.parser.subprocess.Popen")
def test_update_runtime_vars_bad_exit(self, mock_popen): def test_update_runtime_vars_bad_exit(self, mock_popen):
mock_popen().communicate.return_value = ("", "") mock_popen().communicate.return_value = ("", "")
mock_popen.returncode = -1 mock_popen.returncode = -1
@@ -321,7 +321,7 @@ class BasicParserTest(util.ParserTest):
self.parser.update_runtime_variables) self.parser.update_runtime_variables)
def test_add_comment(self): def test_add_comment(self):
from certbot_apache.parser import get_aug_path from certbot_apache._internal.parser import get_aug_path
self.parser.add_comment(get_aug_path(self.parser.loc["name"]), "123456") self.parser.add_comment(get_aug_path(self.parser.loc["name"]), "123456")
comm = self.parser.find_comments("123456") comm = self.parser.find_comments("123456")
self.assertEqual(len(comm), 1) self.assertEqual(len(comm), 1)
@@ -337,9 +337,9 @@ class ParserInitTest(util.ApacheTest):
shutil.rmtree(self.config_dir) shutil.rmtree(self.config_dir)
shutil.rmtree(self.work_dir) shutil.rmtree(self.work_dir)
@mock.patch("certbot_apache.parser.ApacheParser.init_augeas") @mock.patch("certbot_apache._internal.parser.ApacheParser.init_augeas")
def test_prepare_no_augeas(self, mock_init_augeas): def test_prepare_no_augeas(self, mock_init_augeas):
from certbot_apache.parser import ApacheParser from certbot_apache._internal.parser import ApacheParser
mock_init_augeas.side_effect = errors.NoInstallationError mock_init_augeas.side_effect = errors.NoInstallationError
self.config.config_test = mock.Mock() self.config.config_test = mock.Mock()
self.assertRaises( self.assertRaises(
@@ -348,17 +348,17 @@ class ParserInitTest(util.ApacheTest):
version=(2, 4, 22), configurator=self.config) version=(2, 4, 22), configurator=self.config)
def test_init_old_aug(self): def test_init_old_aug(self):
from certbot_apache.parser import ApacheParser from certbot_apache._internal.parser import ApacheParser
with mock.patch("certbot_apache.parser.ApacheParser.check_aug_version") as mock_c: with mock.patch("certbot_apache._internal.parser.ApacheParser.check_aug_version") as mock_c:
mock_c.return_value = False mock_c.return_value = False
self.assertRaises( self.assertRaises(
errors.NotSupportedError, errors.NotSupportedError,
ApacheParser, os.path.relpath(self.config_path), ApacheParser, os.path.relpath(self.config_path),
"/dummy/vhostpath", version=(2, 4, 22), configurator=self.config) "/dummy/vhostpath", version=(2, 4, 22), configurator=self.config)
@mock.patch("certbot_apache.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg")
def test_unparseable(self, mock_cfg): def test_unparseable(self, mock_cfg):
from certbot_apache.parser import ApacheParser from certbot_apache._internal.parser import ApacheParser
mock_cfg.return_value = ('Define: TEST') mock_cfg.return_value = ('Define: TEST')
self.assertRaises( self.assertRaises(
errors.PluginError, errors.PluginError,
@@ -366,9 +366,9 @@ class ParserInitTest(util.ApacheTest):
"/dummy/vhostpath", version=(2, 2, 22), configurator=self.config) "/dummy/vhostpath", version=(2, 2, 22), configurator=self.config)
def test_root_normalized(self): def test_root_normalized(self):
from certbot_apache.parser import ApacheParser from certbot_apache._internal.parser import ApacheParser
with mock.patch("certbot_apache.parser.ApacheParser." with mock.patch("certbot_apache._internal.parser.ApacheParser."
"update_runtime_variables"): "update_runtime_variables"):
path = os.path.join( path = os.path.join(
self.temp_dir, self.temp_dir,
@@ -379,8 +379,8 @@ class ParserInitTest(util.ApacheTest):
self.assertEqual(parser.root, self.config_path) self.assertEqual(parser.root, self.config_path)
def test_root_absolute(self): def test_root_absolute(self):
from certbot_apache.parser import ApacheParser from certbot_apache._internal.parser import ApacheParser
with mock.patch("certbot_apache.parser.ApacheParser." with mock.patch("certbot_apache._internal.parser.ApacheParser."
"update_runtime_variables"): "update_runtime_variables"):
parser = ApacheParser( parser = ApacheParser(
os.path.relpath(self.config_path), os.path.relpath(self.config_path),
@@ -389,8 +389,8 @@ class ParserInitTest(util.ApacheTest):
self.assertEqual(parser.root, self.config_path) self.assertEqual(parser.root, self.config_path)
def test_root_no_trailing_slash(self): def test_root_no_trailing_slash(self):
from certbot_apache.parser import ApacheParser from certbot_apache._internal.parser import ApacheParser
with mock.patch("certbot_apache.parser.ApacheParser." with mock.patch("certbot_apache._internal.parser.ApacheParser."
"update_runtime_variables"): "update_runtime_variables"):
parser = ApacheParser( parser = ApacheParser(
self.config_path + os.path.sep, self.config_path + os.path.sep,
+8 -8
View File
@@ -13,9 +13,9 @@ from certbot.display import util as display_util
from certbot.plugins import common from certbot.plugins import common
from certbot.tests import util as test_util from certbot.tests import util as test_util
from certbot_apache import configurator from certbot_apache._internal import configurator
from certbot_apache import entrypoint from certbot_apache._internal import entrypoint
from certbot_apache import obj from certbot_apache._internal import obj
class ApacheTest(unittest.TestCase): class ApacheTest(unittest.TestCase):
@@ -72,10 +72,10 @@ class ParserTest(ApacheTest):
zope.component.provideUtility(display_util.FileDisplay(sys.stdout, zope.component.provideUtility(display_util.FileDisplay(sys.stdout,
False)) False))
from certbot_apache.parser import ApacheParser from certbot_apache._internal.parser import ApacheParser
self.aug = augeas.Augeas( self.aug = augeas.Augeas(
flags=augeas.Augeas.NONE | augeas.Augeas.NO_MODL_AUTOLOAD) flags=augeas.Augeas.NONE | augeas.Augeas.NO_MODL_AUTOLOAD)
with mock.patch("certbot_apache.parser.ApacheParser." with mock.patch("certbot_apache._internal.parser.ApacheParser."
"update_runtime_variables"): "update_runtime_variables"):
self.parser = ApacheParser( self.parser = ApacheParser(
self.config_path, self.vhost_path, configurator=self.config) self.config_path, self.vhost_path, configurator=self.config)
@@ -105,11 +105,11 @@ def get_apache_configurator(
in_progress_dir=os.path.join(backups, "IN_PROGRESS"), in_progress_dir=os.path.join(backups, "IN_PROGRESS"),
work_dir=work_dir) work_dir=work_dir)
with mock.patch("certbot_apache.configurator.util.run_script"): with mock.patch("certbot_apache._internal.configurator.util.run_script"):
with mock.patch("certbot_apache.configurator.util." with mock.patch("certbot_apache._internal.configurator.util."
"exe_exists") as mock_exe_exists: "exe_exists") as mock_exe_exists:
mock_exe_exists.return_value = True mock_exe_exists.return_value = True
with mock.patch("certbot_apache.parser.ApacheParser." with mock.patch("certbot_apache._internal.parser.ApacheParser."
"update_runtime_variables"): "update_runtime_variables"):
try: try:
config_class = entrypoint.OVERRIDE_CLASSES[os_info] config_class = entrypoint.OVERRIDE_CLASSES[os_info]
+1 -1
View File
@@ -71,7 +71,7 @@ setup(
install_requires=install_requires, install_requires=install_requires,
entry_points={ entry_points={
'certbot.plugins': [ 'certbot.plugins': [
'apache = certbot_apache.entrypoint:ENTRYPOINT', 'apache = certbot_apache._internal.entrypoint:ENTRYPOINT',
], ],
}, },
test_suite='certbot_apache', test_suite='certbot_apache',
@@ -9,7 +9,7 @@ import zope.interface
from certbot._internal import configuration from certbot._internal import configuration
from certbot import errors as le_errors from certbot import errors as le_errors
from certbot import util as certbot_util from certbot import util as certbot_util
from certbot_apache import entrypoint from certbot_apache._internal import entrypoint
from certbot_compatibility_test import errors from certbot_compatibility_test import errors
from certbot_compatibility_test import interfaces from certbot_compatibility_test import interfaces
from certbot_compatibility_test import util from certbot_compatibility_test import util
@@ -27,7 +27,7 @@ class Proxy(configurators_common.Proxy):
self.modules = self.server_root = self.test_conf = self.version = None self.modules = self.server_root = self.test_conf = self.version = None
patch = mock.patch( patch = mock.patch(
"certbot_apache.configurator.display_ops.select_vhost") "certbot_apache._internal.configurator.display_ops.select_vhost")
mock_display = patch.start() mock_display = patch.start()
mock_display.side_effect = le_errors.PluginError( mock_display.side_effect = le_errors.PluginError(
"Unable to determine vhost") "Unable to determine vhost")
+1 -1
View File
@@ -121,7 +121,7 @@ class Addr(common.Addr):
def __hash__(self): # pylint: disable=useless-super-delegation def __hash__(self): # pylint: disable=useless-super-delegation
# Python 3 requires explicit overridden for __hash__ # Python 3 requires explicit overridden for __hash__
# See certbot-apache/certbot_apache/obj.py for more information # See certbot-apache/certbot_apache/_internal/obj.py for more information
return super(Addr, self).__hash__() return super(Addr, self).__hash__()
def super_eq(self, other): def super_eq(self, other):
@@ -1,4 +1,4 @@
"""Test certbot_apache.display_ops.""" """Test certbot_nginx._internal.display_ops."""
import unittest import unittest
from certbot.display import util as display_util from certbot.display import util as display_util
+1 -1
View File
@@ -41,7 +41,7 @@ client as root, either `letsencrypt-nosudo
The Apache plugin currently requires an OS with augeas version 1.0; currently `it The Apache plugin currently requires an OS with augeas version 1.0; currently `it
supports supports
<https://github.com/certbot/certbot/blob/master/certbot-apache/certbot_apache/constants.py>`_ <https://github.com/certbot/certbot/blob/master/certbot-apache/certbot_apache/_internal/constants.py>`_
modern OSes based on Debian, Ubuntu, Fedora, SUSE, Gentoo and Darwin. modern OSes based on Debian, Ubuntu, Fedora, SUSE, Gentoo and Darwin.
+5 -5
View File
@@ -58,8 +58,8 @@ standalone_ Y N | Uses a "standalone" webserver to obtain a certificate.
| the only way to obtain wildcard certificates from Let's | the only way to obtain wildcard certificates from Let's
| Encrypt. | Encrypt.
manual_ Y N | Helps you obtain a certificate by giving you instructions to http-01_ (80) or manual_ Y N | Helps you obtain a certificate by giving you instructions to http-01_ (80) or
| perform domain validation yourself. Additionally allows you dns-01_ (53) | perform domain validation yourself. Additionally allows you dns-01_ (53)
| to specify scripts to automate the validation task in a | to specify scripts to automate the validation task in a
| customized way. | customized way.
=========== ==== ==== =============================================================== ============================= =========== ==== ==== =============================================================== =============================
@@ -83,7 +83,7 @@ Apache
------ ------
The Apache plugin currently `supports The Apache plugin currently `supports
<https://github.com/certbot/certbot/blob/master/certbot-apache/certbot_apache/entrypoint.py>`_ <https://github.com/certbot/certbot/blob/master/certbot-apache/certbot_apache/_internal/entrypoint.py>`_
modern OSes based on Debian, Fedora, SUSE, Gentoo and Darwin. modern OSes based on Debian, Fedora, SUSE, Gentoo and Darwin.
This automates both obtaining *and* installing certificates on an Apache This automates both obtaining *and* installing certificates on an Apache
webserver. To specify this plugin on the command line, simply include webserver. To specify this plugin on the command line, simply include
@@ -680,8 +680,8 @@ Where are my certificates?
========================== ==========================
All generated keys and issued certificates can be found in All generated keys and issued certificates can be found in
``/etc/letsencrypt/live/$domain``. In the case of creating a SAN certificate ``/etc/letsencrypt/live/$domain``. In the case of creating a SAN certificate
with multiple alternative names, ``$domain`` is the first domain passed in with multiple alternative names, ``$domain`` is the first domain passed in
via -d parameter. Rather than copying, please point via -d parameter. Rather than copying, please point
your (web) server configuration directly to those files (or create your (web) server configuration directly to those files (or create
symlinks). During the renewal_, ``/etc/letsencrypt/live`` is updated symlinks). During the renewal_, ``/etc/letsencrypt/live`` is updated