mirror of
https://github.com/certbot/certbot.git
synced 2026-08-01 19:02:52 +02:00
Add report_config_interaction
This commit is contained in:
@@ -104,6 +104,27 @@ VAR_MODIFIERS = {"account": ["server"], "server": ["dry_run", "staging"],
|
|||||||
"webroot_map": ["webroot_path"]}
|
"webroot_map": ["webroot_path"]}
|
||||||
|
|
||||||
|
|
||||||
|
def report_config_interaction(modified, modifiers):
|
||||||
|
"""Registers config option interaction to be checked by set_by_cli.
|
||||||
|
|
||||||
|
This function can be called by during the __init__ method of plugins
|
||||||
|
to register interactions between config options.
|
||||||
|
|
||||||
|
:param modified: config options that can be modified by modifiers
|
||||||
|
:type modified: iterable or str
|
||||||
|
:param modifiers: config options that modify modified
|
||||||
|
:type modifiers: iterable or str
|
||||||
|
|
||||||
|
"""
|
||||||
|
if isinstance(modified, str):
|
||||||
|
modified = [modified]
|
||||||
|
if isinstance(modifiers, str):
|
||||||
|
modifiers = [modifiers]
|
||||||
|
|
||||||
|
for var in modified:
|
||||||
|
VAR_MODIFIERS.setdefault(var, []).extend(modifiers)
|
||||||
|
|
||||||
|
|
||||||
def usage_strings(plugins):
|
def usage_strings(plugins):
|
||||||
"""Make usage strings late so that plugins can be initialised late"""
|
"""Make usage strings late so that plugins can be initialised late"""
|
||||||
if "nginx" in plugins:
|
if "nginx" in plugins:
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import unittest
|
|||||||
|
|
||||||
import mock
|
import mock
|
||||||
import six
|
import six
|
||||||
|
from six.moves import reload_module # pylint: disable=import-error
|
||||||
|
|
||||||
from acme import jose
|
from acme import jose
|
||||||
|
|
||||||
@@ -1042,5 +1043,60 @@ class DefaultTest(unittest.TestCase):
|
|||||||
self.assertEqual(hash(self.default1), hash(self.default2))
|
self.assertEqual(hash(self.default1), hash(self.default2))
|
||||||
|
|
||||||
|
|
||||||
|
class SetByCliTest(unittest.TestCase):
|
||||||
|
"""Tests for letsencrypt.set_by_cli and related functions."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
reload_module(cli)
|
||||||
|
|
||||||
|
def test_webroot_map(self):
|
||||||
|
args = '-w /var/www/html -d example.com'.split()
|
||||||
|
verb = 'renew'
|
||||||
|
self.assertTrue(_call_set_by_cli('webroot_map', args, verb))
|
||||||
|
|
||||||
|
def test_report_config_interaction_str(self):
|
||||||
|
cli.report_config_interaction('manual_public_ip_logging_ok',
|
||||||
|
'manual_test_mode')
|
||||||
|
cli.report_config_interaction('manual_test_mode', 'manual')
|
||||||
|
|
||||||
|
self._test_report_config_interaction_common()
|
||||||
|
|
||||||
|
def test_report_config_interaction_iterable(self):
|
||||||
|
cli.report_config_interaction(('manual_public_ip_logging_ok',),
|
||||||
|
('manual_test_mode',))
|
||||||
|
cli.report_config_interaction(('manual_test_mode',), ('manual',))
|
||||||
|
|
||||||
|
self._test_report_config_interaction_common()
|
||||||
|
|
||||||
|
def _test_report_config_interaction_common(self):
|
||||||
|
"""Tests implied interaction between manual flags.
|
||||||
|
|
||||||
|
--manual implies --manual-test-mode which implies
|
||||||
|
--manual-public-ip-logging-ok. These interactions don't actually
|
||||||
|
exist in the client, but are used here for testing purposes.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
args = ['--manual']
|
||||||
|
verb = 'renew'
|
||||||
|
for v in ('manual', 'manual_test_mode', 'manual_public_ip_logging_ok'):
|
||||||
|
self.assertTrue(_call_set_by_cli(v, args, verb))
|
||||||
|
|
||||||
|
cli.set_by_cli.detector = None
|
||||||
|
|
||||||
|
args = ['--manual-test-mode']
|
||||||
|
for v in ('manual_test_mode', 'manual_public_ip_logging_ok'):
|
||||||
|
self.assertTrue(_call_set_by_cli(v, args, verb))
|
||||||
|
|
||||||
|
self.assertFalse(_call_set_by_cli('manual', args, verb))
|
||||||
|
|
||||||
|
|
||||||
|
def _call_set_by_cli(var, args, verb):
|
||||||
|
with mock.patch('letsencrypt.cli.helpful_parser') as mock_parser:
|
||||||
|
mock_parser.args = args
|
||||||
|
mock_parser.verb = verb
|
||||||
|
return cli.set_by_cli(var)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main() # pragma: no cover
|
unittest.main() # pragma: no cover
|
||||||
|
|||||||
Reference in New Issue
Block a user