mirror of
https://github.com/certbot/certbot.git
synced 2026-07-27 08:09:10 +02:00
Do not accept -d first in the presence of multiple -w flags
* informal testing suggested that many people found this behaviour confusing
This commit is contained in:
@@ -1043,6 +1043,10 @@ def _plugins_parsing(helpful, plugins):
|
||||
|
||||
|
||||
class WebrootPathProcessor(argparse.Action): # pylint: disable=missing-docstring
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.domain_before_webroot = False
|
||||
argparse.Action.__init__(self, *args, **kwargs)
|
||||
|
||||
def __call__(self, parser, config, webroot, option_string=None):
|
||||
"""
|
||||
Keep a record of --webroot-path / -w flags during processing, so that
|
||||
@@ -1055,8 +1059,12 @@ class WebrootPathProcessor(argparse.Action): # pylint: disable=missing-docstring
|
||||
# config.webroot_map are filled in by cli.DomainFlagProcessor
|
||||
if config.domains:
|
||||
config.webroot_map = dict([(d, webroot) for d in config.domains])
|
||||
self.domain_before_webroot = True
|
||||
else:
|
||||
config.webroot_map = {}
|
||||
elif self.domain_before_webroot:
|
||||
raise errors.Error("If you specify multiple webroot paths, one of "
|
||||
"them must precede all domain flags")
|
||||
config.webroot_path.append(webroot)
|
||||
|
||||
|
||||
|
||||
@@ -343,17 +343,20 @@ class CLITest(unittest.TestCase): # pylint: disable=too-many-public-methods
|
||||
|
||||
def test_parse_webroot(self):
|
||||
plugins = disco.PluginsRegistry.find_all()
|
||||
webroot_args = ['--webroot', '-d', 'stray.example.com', '-w',
|
||||
'/var/www/example', '-d', 'example.com,www.example.com', '-w',
|
||||
'/var/www/superfluous', '-d', 'superfluo.us', '-d', 'www.superfluo.us']
|
||||
webroot_args = ['--webroot', '-w', '/var/www/example',
|
||||
'-d', 'example.com,www.example.com', '-w', '/var/www/superfluous',
|
||||
'-d', 'superfluo.us', '-d', 'www.superfluo.us']
|
||||
namespace = cli.prepare_and_parse_args(plugins, webroot_args)
|
||||
self.assertEqual(namespace.webroot_map, {
|
||||
'example.com': '/var/www/example',
|
||||
'stray.example.com': '/var/www/example',
|
||||
'www.example.com': '/var/www/example',
|
||||
'www.superfluo.us': '/var/www/superfluous',
|
||||
'superfluo.us': '/var/www/superfluous'})
|
||||
|
||||
webroot_args = ['-d', 'stray.example.com'] + webroot_args
|
||||
with self.assertRaises(errors.Error):
|
||||
cli.prepare_and_parse_args(plugins, webroot_args)
|
||||
|
||||
webroot_map_args = ['--webroot-map', '{"eg.com" : "/tmp"}']
|
||||
namespace = cli.prepare_and_parse_args(plugins, webroot_map_args)
|
||||
self.assertEqual(namespace.webroot_map, {u"eg.com": u"/tmp"})
|
||||
|
||||
Reference in New Issue
Block a user