mirror of
https://github.com/certbot/certbot.git
synced 2026-06-07 07:42:08 -04:00
Revert "Unit tests for setting authenticator via cmd line"
This reverts commit 0d7f32fa98.
This commit is contained in:
parent
ea88fc6401
commit
cfe95323f6
3 changed files with 21 additions and 41 deletions
|
|
@ -397,10 +397,11 @@ def determine_authenticator(all_auths, config):
|
|||
try:
|
||||
auth = avail_auths[config.authenticator]
|
||||
except KeyError:
|
||||
logging.info(list_available_authenticators(avail_auths))
|
||||
raise errors.LetsEncryptClientError(
|
||||
"The specified authenticator '%s' could not be found" %
|
||||
logging.error(
|
||||
"The specified authenticator '%s' could not be found",
|
||||
config.authenticator)
|
||||
logging.info(list_available_authenticators(avail_auths))
|
||||
return
|
||||
elif len(avail_auths) > 1:
|
||||
auth = display_ops.choose_authenticator(avail_auths.values(), errs)
|
||||
elif len(avail_auths.keys()) == 1:
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
"""letsencrypt.client.client.py tests."""
|
||||
from collections import namedtuple
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
|
||||
from letsencrypt.client import configuration
|
||||
from letsencrypt.client import errors
|
||||
|
||||
|
||||
|
|
@ -19,8 +19,7 @@ class DetermineAuthenticatorTest(unittest.TestCase):
|
|||
self.mock_apache = mock.MagicMock(
|
||||
spec=ApacheConfigurator, description="Standalone Authenticator")
|
||||
|
||||
self.mock_config = mock.MagicMock(
|
||||
spec=configuration.NamespaceConfig, authenticator=None)
|
||||
self.mock_config = mock.Mock()
|
||||
|
||||
self.all_auths = {
|
||||
'apache': self.mock_apache,
|
||||
|
|
@ -28,30 +27,29 @@ class DetermineAuthenticatorTest(unittest.TestCase):
|
|||
}
|
||||
|
||||
@classmethod
|
||||
def _call(cls, all_auths, config):
|
||||
def _call(cls, all_auths):
|
||||
from letsencrypt.client.client import determine_authenticator
|
||||
return determine_authenticator(all_auths, config)
|
||||
# TODO: add tests for setting the authenticator via the command line
|
||||
mock_config = namedtuple("Config", ['authenticator'])
|
||||
return determine_authenticator(all_auths,
|
||||
mock_config(authenticator=None))
|
||||
|
||||
@mock.patch("letsencrypt.client.client.display_ops.choose_authenticator")
|
||||
def test_accept_two(self, mock_choose):
|
||||
mock_choose.return_value = self.mock_stand()
|
||||
self.assertEqual(self._call(self.all_auths, self.mock_config),
|
||||
self.mock_stand())
|
||||
self.assertEqual(self._call(self.all_auths), self.mock_stand())
|
||||
|
||||
def test_accept_one(self):
|
||||
self.mock_apache.prepare.return_value = self.mock_apache
|
||||
one_avail_auth = {
|
||||
'apache': self.mock_apache
|
||||
}
|
||||
self.assertEqual(self._call(one_avail_auth, self.mock_config),
|
||||
self.mock_apache)
|
||||
self.assertEqual(
|
||||
self._call(dict(apache=self.all_auths['apache'])),
|
||||
self.mock_apache)
|
||||
|
||||
def test_no_installation_one(self):
|
||||
self.mock_apache.prepare.side_effect = (
|
||||
errors.LetsEncryptNoInstallationError)
|
||||
|
||||
self.assertEqual(self._call(self.all_auths, self.mock_config),
|
||||
self.mock_stand)
|
||||
self.assertEqual(self._call(self.all_auths), self.mock_stand)
|
||||
|
||||
def test_no_installations(self):
|
||||
self.mock_apache.prepare.side_effect = (
|
||||
|
|
@ -61,8 +59,7 @@ class DetermineAuthenticatorTest(unittest.TestCase):
|
|||
|
||||
self.assertRaises(errors.LetsEncryptClientError,
|
||||
self._call,
|
||||
self.all_auths,
|
||||
self.mock_config)
|
||||
self.all_auths)
|
||||
|
||||
@mock.patch("letsencrypt.client.client.logging")
|
||||
@mock.patch("letsencrypt.client.client.display_ops.choose_authenticator")
|
||||
|
|
@ -71,26 +68,7 @@ class DetermineAuthenticatorTest(unittest.TestCase):
|
|||
errors.LetsEncryptMisconfigurationError)
|
||||
mock_choose.return_value = self.mock_apache
|
||||
|
||||
self.assertTrue(self._call(self.all_auths, self.mock_config) is None)
|
||||
|
||||
def test_choose_valid_auth_from_cmd_line(self):
|
||||
standalone_config = mock.MagicMock(spec=configuration.NamespaceConfig,
|
||||
authenticator='standalone')
|
||||
self.assertEqual(self._call(self.all_auths, standalone_config),
|
||||
self.mock_stand)
|
||||
|
||||
apache_config = mock.MagicMock(spec=configuration.NamespaceConfig,
|
||||
authenticator='apache')
|
||||
self.assertEqual(self._call(self.all_auths, apache_config),
|
||||
self.mock_apache)
|
||||
|
||||
def test_choose_invalid_auth_from_cmd_line(self):
|
||||
invalid_config = mock.MagicMock(spec=configuration.NamespaceConfig,
|
||||
authenticator='foobar')
|
||||
self.assertRaises(errors.LetsEncryptClientError,
|
||||
self._call,
|
||||
self.all_auths,
|
||||
invalid_config)
|
||||
self.assertTrue(self._call(self.all_auths) is None)
|
||||
|
||||
|
||||
class RollbackTest(unittest.TestCase):
|
||||
|
|
|
|||
|
|
@ -178,8 +178,9 @@ def main(): # pylint: disable=too-many-branches, too-many-statements
|
|||
try:
|
||||
auth = client.determine_authenticator(all_auths, config)
|
||||
logging.debug("Selected authenticator: %s", auth)
|
||||
except errors.LetsEncryptClientError as err:
|
||||
logging.critical(str(err))
|
||||
except errors.LetsEncryptClientError:
|
||||
logging.critical("No authentication mechanisms were found on your "
|
||||
"system.")
|
||||
sys.exit(1)
|
||||
|
||||
if auth is None:
|
||||
|
|
|
|||
Loading…
Reference in a new issue