Example #1
0
def get_apache_configurator(  # pylint: disable=too-many-arguments, too-many-locals
        config_path,
        vhost_path,
        config_dir,
        work_dir,
        version=(2, 4, 7),
        conf=None,
        os_info="generic",
        conf_vhost_path=None):
    """Create an Apache Configurator with the specified options.

    :param conf: Function that returns binary paths. self.conf in Configurator

    """
    backups = os.path.join(work_dir, "backups")
    mock_le_config = mock.MagicMock(
        apache_server_root=config_path,
        apache_vhost_root=conf_vhost_path,
        apache_le_vhost_ext="-le-ssl.conf",
        apache_challenge_location=config_path,
        backup_dir=backups,
        config_dir=config_dir,
        http01_port=80,
        temp_checkpoint_dir=os.path.join(work_dir, "temp_checkpoints"),
        in_progress_dir=os.path.join(backups, "IN_PROGRESS"),
        work_dir=work_dir)

    orig_os_constant = configurator.ApacheConfigurator(
        mock_le_config, name="apache", version=version).constant

    def mock_os_constant(key, vhost_path=vhost_path):
        """Mock default vhost path"""
        if key == "vhost_root":
            return vhost_path
        else:
            return orig_os_constant(key)

    with mock.patch("certbot_apache.configurator.ApacheConfigurator.constant"
                    ) as mock_cons:
        mock_cons.side_effect = mock_os_constant
        with mock.patch("certbot_apache.configurator.util.run_script"):
            with mock.patch("certbot_apache.configurator.util."
                            "exe_exists") as mock_exe_exists:
                mock_exe_exists.return_value = True
                with mock.patch("certbot_apache.parser.ApacheParser."
                                "update_runtime_variables"):
                    try:
                        config_class = entrypoint.OVERRIDE_CLASSES[os_info]
                    except KeyError:
                        config_class = configurator.ApacheConfigurator
                    config = config_class(config=mock_le_config,
                                          name="apache",
                                          version=version)
                    # This allows testing scripts to set it a bit more
                    # quickly
                    if conf is not None:
                        config.conf = conf  # pragma: no cover

                    config.prepare()
    return config
Example #2
0
    def _prepare_configurator(self):
        """Prepares the Apache plugin for testing"""
        for k in constants.CLI_DEFAULTS_DEBIAN.keys():
            setattr(self.le_config, "apache_" + k, constants.os_constant(k))

        # An alias
        self.le_config.apache_handle_modules = self.le_config.apache_handle_mods

        self._configurator = configurator.ApacheConfigurator(
            config=configuration.NamespaceConfig(self.le_config),
            name="apache")
        self._configurator.prepare()
Example #3
0
    def _prepare_configurator(self, server_root, config_file):
        """Prepares the Apache plugin for testing"""
        self.le_config.apache_server_root = server_root
        self.le_config.apache_ctl = "apachectl -d {0} -f {1}".format(
            server_root, config_file)
        self.le_config.apache_enmod = "a2enmod.sh {0}".format(server_root)
        self.le_config.apache_dismod = "a2dismod.sh {0}".format(server_root)
        self.le_config.apache_init_script = self.le_config.apache_ctl + " -k"

        self._apache_configurator = configurator.ApacheConfigurator(
            config=configuration.NamespaceConfig(self.le_config),
            name="apache")
        self._apache_configurator.prepare()
Example #4
0
def get_apache_configurator(config_path,
                            vhost_path,
                            config_dir,
                            work_dir,
                            version=(2, 4, 7),
                            conf=None):
    """Create an Apache Configurator with the specified options.

    :param conf: Function that returns binary paths. self.conf in Configurator

    """
    backups = os.path.join(work_dir, "backups")
    mock_le_config = mock.MagicMock(
        apache_server_root=config_path,
        apache_vhost_root=vhost_path,
        apache_le_vhost_ext=constants.os_constant("le_vhost_ext"),
        apache_challenge_location=config_path,
        backup_dir=backups,
        config_dir=config_dir,
        temp_checkpoint_dir=os.path.join(work_dir, "temp_checkpoints"),
        in_progress_dir=os.path.join(backups, "IN_PROGRESS"),
        work_dir=work_dir)

    with mock.patch("certbot_apache.configurator.le_util.run_script"):
        with mock.patch("certbot_apache.configurator.le_util."
                        "exe_exists") as mock_exe_exists:
            mock_exe_exists.return_value = True
            with mock.patch("certbot_apache.parser.ApacheParser."
                            "update_runtime_variables"):
                config = configurator.ApacheConfigurator(config=mock_le_config,
                                                         name="apache",
                                                         version=version)
                # This allows testing scripts to set it a bit more quickly
                if conf is not None:
                    config.conf = conf  # pragma: no cover

                config.prepare()

    return config