Compare commits

...

4 Commits

Author SHA1 Message Date
Joona Hoikkala
541bd720d9 Broken tests 2019-01-23 21:50:00 +02:00
Joona Hoikkala
70d868ab5e Fixed the environment checks 2019-01-23 21:48:59 +02:00
Joona Hoikkala
7031d66622 Merge remote-tracking branch 'origin/master' into apache_docs_options 2019-01-21 18:34:35 +02:00
Joona Hoikkala
1527a7e4a2 Apache: respect CERTBOT_DOCS environment variable 2018-12-12 20:58:30 +02:00
3 changed files with 97 additions and 9 deletions

View File

@@ -50,6 +50,8 @@ More details about these changes can be found on our GitHub repo.
to the `update_account` subcommand.
* Marked usage `register --update-registration` for deprecation and
removal in a future release.
* Apache plugin now respects CERTBOT_DOCS environment variable when adding
command line defaults.
### Fixed

View File

@@ -92,6 +92,11 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
"""
description = "Apache Web Server plugin"
if os.environ.get("CERTBOT_DOCS") == "1":
description += (
"(Please note that the default values of the Apache plugin options"
" change depending on the operating system Certbot is run on.)"
)
OS_DEFAULTS = dict(
server_root="/etc/apache2",
@@ -141,28 +146,36 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
# When adding, modifying or deleting command line arguments, be sure to
# include the changes in the list used in method _prepare_options() to
# ensure consistent behavior.
add("enmod", default=cls.OS_DEFAULTS["enmod"],
# Respect CERTBOT_DOCS environment variable and use default values from
# base class regardless of the underlying distribution (overrides).
if os.environ.get("CERTBOT_DOCS") == "1":
DEFAULTS = ApacheConfigurator.OS_DEFAULTS
else:
# cls.OS_DEFAULTS can be distribution specific, see override classes
DEFAULTS = cls.OS_DEFAULTS
add("enmod", default=DEFAULTS["enmod"],
help="Path to the Apache 'a2enmod' binary")
add("dismod", default=cls.OS_DEFAULTS["dismod"],
add("dismod", default=DEFAULTS["dismod"],
help="Path to the Apache 'a2dismod' binary")
add("le-vhost-ext", default=cls.OS_DEFAULTS["le_vhost_ext"],
add("le-vhost-ext", default=DEFAULTS["le_vhost_ext"],
help="SSL vhost configuration extension")
add("server-root", default=cls.OS_DEFAULTS["server_root"],
add("server-root", default=DEFAULTS["server_root"],
help="Apache server root directory")
add("vhost-root", default=None,
help="Apache server VirtualHost configuration root")
add("logs-root", default=cls.OS_DEFAULTS["logs_root"],
add("logs-root", default=DEFAULTS["logs_root"],
help="Apache server logs directory")
add("challenge-location",
default=cls.OS_DEFAULTS["challenge_location"],
default=DEFAULTS["challenge_location"],
help="Directory path for challenge configuration")
add("handle-modules", default=cls.OS_DEFAULTS["handle_modules"],
add("handle-modules", default=DEFAULTS["handle_modules"],
help="Let installer handle enabling required modules for you " +
"(Only Ubuntu/Debian currently)")
add("handle-sites", default=cls.OS_DEFAULTS["handle_sites"],
add("handle-sites", default=DEFAULTS["handle_sites"],
help="Let installer handle enabling sites for you " +
"(Only Ubuntu/Debian currently)")
add("ctl", default=cls.OS_DEFAULTS["ctl"],
add("ctl", default=DEFAULTS["ctl"],
help="Full path to Apache control script")
util.add_deprecated_argument(
add, argument_name="init-script", nargs=1)

View File

@@ -0,0 +1,73 @@
"""Tests for help text when invoked with environmental variable CERTBOT_DOCS=1"""
import itertools
import os
import pkg_resources
import unittest
import mock
import six
from certbot import cli, constants
from certbot.plugins import disco
import certbot.tests.util as test_util
class CertbotDocsTest(test_util.ConfigTestCase):
"""Tests for CERTBOT_DOCS=1"""
@staticmethod
def _parse(*args, **kwargs):
"""Get result of cli.prepare_and_parse_args."""
plugins = disco.PluginsRegistry.find_all()
return cli.prepare_and_parse_args(plugins, *args, **kwargs)
def _help_output(self):
"Get output of certbot --help all"
output = six.StringIO()
def write_msg(message, *args, **kwargs): # pylint: disable=missing-docstring,unused-argument
output.write(message)
with mock.patch('certbot.main.sys.stdout', new=output):
with test_util.patch_get_utility() as mock_get_utility:
mock_get_utility().notification.side_effect = write_msg
with mock.patch('certbot.main.sys.stderr'):
self.assertRaises(SystemExit, self._parse, ["help", "all"], output)
return output.getvalue()
def test_help_certbot_docs(self):
"""Test that a consistent help text is printed when CERTBOT_DOCS=1
environmental variable is set."""
os.environ["CERTBOT_DOCS"] = "1"
entry_points = itertools.chain(
pkg_resources.iter_entry_points(
constants.SETUPTOOLS_PLUGINS_ENTRY_POINT),
pkg_resources.iter_entry_points(
constants.OLD_SETUPTOOLS_PLUGINS_ENTRY_POINT),)
apache_ep = None
for ep in entry_points:
if ep.name == "apache":
apache_ep = disco.PluginEntryPoint(ep)
mock_add = mock.MagicMock()
with mock.patch("certbot.util.exe_exists") as mock_exe:
mock_exe.return_value = True
apache_plugin = apache_ep.init(config=self.config)
apache_plugin._prepare_options()
apache_plugin.add_parser_arguments(mock_add)
expected_srv_root = {'default': '/etc/apache2',
'help': 'Apache server root directory'}
found = False
for c in mock_add.mock_calls:
if c[2] == expected_srv_root:
found = True
self.assertTrue(found)
self.assertTrue("Please note that the default values of the Apache" in apache_plugin.description)
if __name__ == '__main__':
unittest.main() # pragma: no cover