Skip to content

Commit 8bcf7f6

Browse files
jshawgreenberg
authored andcommitted
Fix --webroot-path action (#10509)
Fixes #10506. When --webroot-path was specified multiple times, Certbot was erroring with `DNSName SAN compared to non-SAN`. That's because, in the _WebrootPathAction that builds `namespace.webroot_path`, we were passing `domain` (type `san.DNSName`) as the keys. The other code that modifies or accesses `namespace.webroot_path` expects the keys to be of type `str`. In particular `webroot.Authenticator._set_webroots` does: ```python for achall in achalls: self.conf("map").setdefault(achall.domain, webroot_path) ``` Where `achall.domain` is a `str`. Two existing unittests would have caught this: `test_multiwebroot` and `test_webroot_map_partial_without_perform`. However, they faked out the parsing of the `--domains` flag, and that faked out code was not updated in #10468. Since this bug is caused by an interaction between the types produced by the `--domains` flag and those produced by the `--webroot-path` flag, the tests failed to catch the problem. I've updated the tests and confirmed that they fail before the fix is applied.
1 parent d3c30cf commit 8bcf7f6

3 files changed

Lines changed: 4 additions & 3 deletions

File tree

‎certbot/src/certbot/_internal/plugins/webroot.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def __call__(self, parser: argparse.ArgumentParser, namespace: argparse.Namespac
320320
# domains before setting the new webroot path
321321
prev_webroot = namespace.webroot_path[-1]
322322
for domain in namespace.domains:
323-
namespace.webroot_map.setdefault(domain, prev_webroot)
323+
namespace.webroot_map.setdefault(domain.dns_name, prev_webroot)
324324
elif namespace.domains:
325325
self._domain_before_webroot = True
326326

‎certbot/src/certbot/_internal/tests/plugins/webroot_test.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from certbot.compat import filesystem
2121
from certbot.compat import os
2222
from certbot.display import util as display_util
23+
from certbot._internal import cli
2324
from certbot.tests import acme_util
2425
from certbot.tests import util as test_util
2526

@@ -302,7 +303,6 @@ def test_cleanup_failure(self, mock_rmdir):
302303
assert not os.path.exists(self.validation_path)
303304
assert os.path.exists(self.root_challenge_path)
304305

305-
306306
class WebrootActionTest(unittest.TestCase):
307307
"""Tests for webroot argparse actions."""
308308

@@ -314,7 +314,7 @@ def setUp(self):
314314
self.path = tempfile.mkdtemp()
315315
self.parser = argparse.ArgumentParser()
316316
self.parser.add_argument("-d", "--domains",
317-
action="append", default=[])
317+
action=cli._DomainsAction, default=[])
318318
Authenticator.inject_parser_options(self.parser, "webroot")
319319

320320
def test_webroot_map_action(self):

‎newsfragments/10509.fixed‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed a regression that caused certbot to crash if multiple --webroot-path values were set on the command line.

0 commit comments

Comments
 (0)