mirror of
https://github.com/certbot/certbot.git
synced 2026-01-21 19:01:07 +03:00
Conflicts: letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/foo.conf letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/nginx.conf letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/nginx.new.conf letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/server.conf letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/sites-enabled/default letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/sites-enabled/example.com letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/ubuntu_nginx_1_4_6/default_vhost/nginx/fastcgi_params letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/ubuntu_nginx_1_4_6/default_vhost/nginx/koi-utf letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/ubuntu_nginx_1_4_6/default_vhost/nginx/koi-win letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/ubuntu_nginx_1_4_6/default_vhost/nginx/mime.types letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/ubuntu_nginx_1_4_6/default_vhost/nginx/naxsi-ui.conf.1.4.1 letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/ubuntu_nginx_1_4_6/default_vhost/nginx/naxsi.rules letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/ubuntu_nginx_1_4_6/default_vhost/nginx/naxsi_core.rules letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/ubuntu_nginx_1_4_6/default_vhost/nginx/nginx.conf letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/ubuntu_nginx_1_4_6/default_vhost/nginx/proxy_params letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/ubuntu_nginx_1_4_6/default_vhost/nginx/scgi_params letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/ubuntu_nginx_1_4_6/default_vhost/nginx/sites-available/default letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/ubuntu_nginx_1_4_6/default_vhost/nginx/sites-enabled/default letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/ubuntu_nginx_1_4_6/default_vhost/nginx/uwsgi_params letsencrypt/client/plugins/nginx/tests/testdata/etc_nginx/ubuntu_nginx_1_4_6/default_vhost/nginx/win-utf letsencrypt/client/plugins/nginx/tests/testdata/foo.conf letsencrypt/client/plugins/nginx/tests/testdata/nginx.conf letsencrypt/client/plugins/nginx/tests/testdata/nginx.new.conf letsencrypt/client/plugins/nginx/tests/testdata/server.conf letsencrypt/client/plugins/nginx/tests/testdata/sites-enabled/default letsencrypt/client/plugins/nginx/tests/testdata/sites-enabled/example.com letsencrypt/client/plugins/nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/fastcgi_params letsencrypt/client/plugins/nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/koi-utf letsencrypt/client/plugins/nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/koi-win letsencrypt/client/plugins/nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/mime.types letsencrypt/client/plugins/nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/naxsi-ui.conf.1.4.1 letsencrypt/client/plugins/nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/naxsi.rules letsencrypt/client/plugins/nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/naxsi_core.rules letsencrypt/client/plugins/nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/nginx.conf letsencrypt/client/plugins/nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/proxy_params letsencrypt/client/plugins/nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/scgi_params letsencrypt/client/plugins/nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/sites-available/default letsencrypt/client/plugins/nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/sites-enabled/default letsencrypt/client/plugins/nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/uwsgi_params letsencrypt/client/plugins/nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/win-utf letsencrypt_apache/tests/util.py letsencrypt_nginx/tests/testdata/foo.conf letsencrypt_nginx/tests/testdata/nginx.conf letsencrypt_nginx/tests/testdata/nginx.new.conf letsencrypt_nginx/tests/testdata/server.conf letsencrypt_nginx/tests/testdata/sites-enabled/default letsencrypt_nginx/tests/testdata/sites-enabled/example.com letsencrypt_nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/fastcgi_params letsencrypt_nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/koi-utf letsencrypt_nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/koi-win letsencrypt_nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/mime.types letsencrypt_nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/naxsi-ui.conf.1.4.1 letsencrypt_nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/naxsi.rules letsencrypt_nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/naxsi_core.rules letsencrypt_nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/nginx.conf letsencrypt_nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/proxy_params letsencrypt_nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/scgi_params letsencrypt_nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/sites-available/default letsencrypt_nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/sites-enabled/default letsencrypt_nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/uwsgi_params letsencrypt_nginx/tests/testdata/ubuntu_nginx_1_4_6/default_vhost/nginx/win-utf letsencrypt_nginx/tests/util.py
122 lines
4.3 KiB
Python
122 lines
4.3 KiB
Python
"""Common utilities for letsencrypt_apache."""
|
|
import os
|
|
import pkg_resources
|
|
import shutil
|
|
import tempfile
|
|
import unittest
|
|
|
|
import mock
|
|
|
|
from letsencrypt import constants as core_constants
|
|
|
|
from letsencrypt_apache import configurator
|
|
from letsencrypt_apache import constants
|
|
from letsencrypt_apache import obj
|
|
|
|
|
|
class ApacheTest(unittest.TestCase): # pylint: disable=too-few-public-methods
|
|
|
|
def setUp(self):
|
|
super(ApacheTest, self).setUp()
|
|
|
|
self.temp_dir, self.config_dir, self.work_dir = dir_setup(
|
|
"debian_apache_2_4/two_vhost_80")
|
|
|
|
self.ssl_options = setup_ssl_options(self.config_dir)
|
|
|
|
self.config_path = os.path.join(
|
|
self.temp_dir, "debian_apache_2_4/two_vhost_80/apache2")
|
|
|
|
self.rsa256_file = pkg_resources.resource_filename(
|
|
"acme.jose", "testdata/rsa256_key.pem")
|
|
self.rsa256_pem = pkg_resources.resource_string(
|
|
"acme.jose", "testdata/rsa256_key.pem")
|
|
|
|
|
|
def dir_setup(test_dir="debian_apache_2_4/two_vhost_80",
|
|
pkg="letsencrypt_apache.tests"):
|
|
"""Setup the directories necessary for the configurator."""
|
|
temp_dir = tempfile.mkdtemp("temp")
|
|
config_dir = tempfile.mkdtemp("config")
|
|
work_dir = tempfile.mkdtemp("work")
|
|
|
|
os.chmod(temp_dir, core_constants.CONFIG_DIRS_MODE)
|
|
os.chmod(config_dir, core_constants.CONFIG_DIRS_MODE)
|
|
os.chmod(work_dir, core_constants.CONFIG_DIRS_MODE)
|
|
|
|
test_configs = pkg_resources.resource_filename(
|
|
pkg, os.path.join("testdata", test_dir))
|
|
|
|
shutil.copytree(
|
|
test_configs, os.path.join(temp_dir, test_dir), symlinks=True)
|
|
|
|
return temp_dir, config_dir, work_dir
|
|
|
|
|
|
def setup_ssl_options(
|
|
config_dir, mod_ssl_conf=constants.MOD_SSL_CONF):
|
|
"""Move the ssl_options into position and return the path."""
|
|
option_path = os.path.join(config_dir, "options-ssl.conf")
|
|
shutil.copyfile(mod_ssl_conf, option_path)
|
|
return option_path
|
|
|
|
|
|
def get_apache_configurator(
|
|
config_path, config_dir, work_dir, ssl_options, version=(2, 4, 7)):
|
|
"""Create an Apache Configurator with the specified options."""
|
|
|
|
backups = os.path.join(work_dir, "backups")
|
|
|
|
with mock.patch("letsencrypt_apache.configurator."
|
|
"subprocess.Popen") as mock_popen:
|
|
# This just states that the ssl module is already loaded
|
|
mock_popen().communicate.return_value = ("ssl_module", "")
|
|
config = configurator.ApacheConfigurator(
|
|
config=mock.MagicMock(
|
|
apache_server_root=config_path,
|
|
apache_mod_ssl_conf=ssl_options,
|
|
le_vhost_ext="-le-ssl.conf",
|
|
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),
|
|
name="apache",
|
|
version=version)
|
|
|
|
config.prepare()
|
|
|
|
return config
|
|
|
|
|
|
def get_vh_truth(temp_dir, config_name):
|
|
"""Return the ground truth for the specified directory."""
|
|
if config_name == "debian_apache_2_4/two_vhost_80":
|
|
prefix = os.path.join(
|
|
temp_dir, config_name, "apache2/sites-available")
|
|
aug_pre = "/files" + prefix
|
|
vh_truth = [
|
|
obj.VirtualHost(
|
|
os.path.join(prefix, "encryption-example.conf"),
|
|
os.path.join(aug_pre, "encryption-example.conf/VirtualHost"),
|
|
set([obj.Addr.fromstring("*:80")]),
|
|
False, True, set(["encryption-example.demo"])),
|
|
obj.VirtualHost(
|
|
os.path.join(prefix, "default-ssl.conf"),
|
|
os.path.join(aug_pre, "default-ssl.conf/IfModule/VirtualHost"),
|
|
set([obj.Addr.fromstring("_default_:443")]), True, False),
|
|
obj.VirtualHost(
|
|
os.path.join(prefix, "000-default.conf"),
|
|
os.path.join(aug_pre, "000-default.conf/VirtualHost"),
|
|
set([obj.Addr.fromstring("*:80")]), False, True,
|
|
set(["ip-172-30-0-17"])),
|
|
obj.VirtualHost(
|
|
os.path.join(prefix, "letsencrypt.conf"),
|
|
os.path.join(aug_pre, "letsencrypt.conf/VirtualHost"),
|
|
set([obj.Addr.fromstring("*:80")]), False, True,
|
|
set(["letsencrypt.demo"])),
|
|
]
|
|
return vh_truth
|
|
|
|
return None
|