From cfe95323f6c8a51fedbaf47efc8e7f4b96ba3e89 Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Wed, 22 Apr 2015 09:02:38 +0000 Subject: [PATCH] Revert "Unit tests for setting authenticator via cmd line" This reverts commit 0d7f32fa984e2e82918d644dfe6913bfe765055f. --- letsencrypt/client/client.py | 7 ++-- letsencrypt/client/tests/client_test.py | 50 +++++++------------------ letsencrypt/scripts/main.py | 5 ++- 3 files changed, 21 insertions(+), 41 deletions(-) diff --git a/letsencrypt/client/client.py b/letsencrypt/client/client.py index 91b271784..19b982502 100644 --- a/letsencrypt/client/client.py +++ b/letsencrypt/client/client.py @@ -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: diff --git a/letsencrypt/client/tests/client_test.py b/letsencrypt/client/tests/client_test.py index 63170b517..2310dbe87 100644 --- a/letsencrypt/client/tests/client_test.py +++ b/letsencrypt/client/tests/client_test.py @@ -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): diff --git a/letsencrypt/scripts/main.py b/letsencrypt/scripts/main.py index 9da8c30b0..ae8eafc47 100644 --- a/letsencrypt/scripts/main.py +++ b/letsencrypt/scripts/main.py @@ -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: