mirror of
https://github.com/certbot/certbot.git
synced 2026-07-28 16:54:56 +02:00
Merge pull request #1160 from kuba/bugs/1149
Standalone verifies ports for supported challenges only (fixes #1149).
This commit is contained in:
@@ -181,6 +181,15 @@ class Authenticator(common.Plugin):
|
||||
return set(challenges.Challenge.TYPES[name] for name in
|
||||
self.conf("supported-challenges").split(","))
|
||||
|
||||
@property
|
||||
def _necessary_ports(self):
|
||||
necessary_ports = set()
|
||||
if challenges.SimpleHTTP in self.supported_challenges:
|
||||
necessary_ports.add(self.config.simple_http_port)
|
||||
if challenges.DVSNI in self.supported_challenges:
|
||||
necessary_ports.add(self.config.dvsni_port)
|
||||
return necessary_ports
|
||||
|
||||
def more_info(self): # pylint: disable=missing-docstring
|
||||
return self.__doc__
|
||||
|
||||
@@ -194,8 +203,7 @@ class Authenticator(common.Plugin):
|
||||
return chall_pref
|
||||
|
||||
def perform(self, achalls): # pylint: disable=missing-docstring
|
||||
if any(util.already_listening(port) for port in
|
||||
(self.config.dvsni_port, self.config.simple_http_port)):
|
||||
if any(util.already_listening(port) for port in self._necessary_ports):
|
||||
raise errors.MisconfigurationError(
|
||||
"At least one of the (possibly) required ports is "
|
||||
"already taken.")
|
||||
|
||||
@@ -107,10 +107,15 @@ class AuthenticatorTest(unittest.TestCase):
|
||||
set([challenges.DVSNI, challenges.SimpleHTTP]))
|
||||
|
||||
@mock.patch("letsencrypt.plugins.standalone.util")
|
||||
def test_perform_misconfiguration(self, mock_util):
|
||||
mock_util.already_listening.return_value = True
|
||||
self.assertRaises(errors.MisconfigurationError, self.auth.perform, [])
|
||||
mock_util.already_listening.assert_called_once_with(1234)
|
||||
def test_perform_alredy_listening(self, mock_util):
|
||||
for chall, port in ((challenges.DVSNI.typ, 1234),
|
||||
(challenges.SimpleHTTP.typ, 4321)):
|
||||
mock_util.already_listening.return_value = True
|
||||
self.config.standalone_supported_challenges = chall
|
||||
self.assertRaises(
|
||||
errors.MisconfigurationError, self.auth.perform, [])
|
||||
mock_util.already_listening.assert_called_once_with(port)
|
||||
mock_util.already_listening.reset_mock()
|
||||
|
||||
@mock.patch("letsencrypt.plugins.standalone.zope.component.getUtility")
|
||||
def test_perform(self, unused_mock_get_utility):
|
||||
|
||||
Reference in New Issue
Block a user