standalone2: move alread_listening to perform

This commit is contained in:
Jakub Warmuz
2015-10-15 18:01:14 +00:00
parent e7809563b1
commit 6f44bcf117
2 changed files with 13 additions and 11 deletions
+7 -5
View File
@@ -182,11 +182,7 @@ class Authenticator(common.Plugin):
return self.__doc__
def prepare(self): # pylint: disable=missing-docstring
if any(util.already_listening(port) for port in
(self.config.dvsni_port, self.config.simple_http_port)):
raise errors.MisconfigurationError(
"At least one of the (possibly) required ports is "
"already taken.")
pass
def get_chall_pref(self, domain):
# pylint: disable=unused-argument,missing-docstring
@@ -195,6 +191,12 @@ 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)):
raise errors.MisconfigurationError(
"At least one of the (possibly) required ports is "
"already taken.")
try:
return self.perform2(achalls)
except errors.StandaloneBindError as error:
+6 -6
View File
@@ -101,16 +101,16 @@ class AuthenticatorTest(unittest.TestCase):
def test_more_info(self):
self.assertTrue(isinstance(self.auth.more_info(), six.string_types))
@mock.patch("letsencrypt.plugins.standalone.util")
def test_prepare_misconfiguration(self, mock_util):
mock_util.already_listening.return_value = True
self.assertRaises(errors.MisconfigurationError, self.auth.prepare)
mock_util.already_listening.assert_called_once_with(1234)
def test_get_chall_pref(self):
self.assertEqual(set(self.auth.get_chall_pref(domain=None)),
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)
@mock.patch("letsencrypt.plugins.standalone.zope.component.getUtility")
def test_perform(self, unused_mock_get_utility):
achalls = [1, 2, 3]