From 679887f6913072ce3280bdf5862d5dabc5c039f8 Mon Sep 17 00:00:00 2001 From: Daniel Huang Date: Sat, 18 Mar 2017 18:33:29 -0700 Subject: [PATCH] Add --debug-challenges flag (#1684) (#4385) * Add --debug-challenges flag (#1684) * Specify None as topic for --debug-challenges --- certbot/auth_handler.py | 5 +++++ certbot/cli.py | 5 +++++ certbot/constants.py | 1 + certbot/tests/auth_handler_test.py | 22 ++++++++++++++++++++++ 4 files changed, 33 insertions(+) diff --git a/certbot/auth_handler.py b/certbot/auth_handler.py index 53346a77c..a1f23a895 100644 --- a/certbot/auth_handler.py +++ b/certbot/auth_handler.py @@ -66,11 +66,16 @@ class AuthHandler(object): self.authzr[domain] = self.acme.request_domain_challenges(domain) self._choose_challenges(domains) + config = zope.component.getUtility(interfaces.IConfig) + notify = zope.component.getUtility(interfaces.IDisplay).notification # While there are still challenges remaining... while self.achalls: resp = self._solve_challenges() logger.info("Waiting for verification...") + if config.debug_challenges: + notify('Challenges loaded. Press continue to submit to CA. ' + 'Pass "-v" for more info about challenges.', pause=True) # Send all Responses - this modifies achalls self._respond(resp, best_effort) diff --git a/certbot/cli.py b/certbot/cli.py index c0af490d2..4fabd9a50 100644 --- a/certbot/cli.py +++ b/certbot/cli.py @@ -955,6 +955,11 @@ def prepare_and_parse_args(plugins, args, detect_defaults=False): # pylint: dis "testing", "--debug", action="store_true", help="Show tracebacks in case of errors, and allow certbot-auto " "execution on experimental platforms") + helpful.add( + [None, "certonly", "renew", "run"], "--debug-challenges", action="store_true", + default=flag_default("debug_challenges"), + help="After setting up challenges, wait for user input before " + "submitting to CA") helpful.add( "testing", "--no-verify-ssl", action="store_true", help=config_help("no_verify_ssl"), diff --git a/certbot/constants.py b/certbot/constants.py index c85992fc1..382b0afb3 100644 --- a/certbot/constants.py +++ b/certbot/constants.py @@ -33,6 +33,7 @@ CLI_DEFAULTS = dict( auth_cert_path="./cert.pem", auth_chain_path="./chain.pem", strict_permissions=False, + debug_challenges=False, ) STAGING_URI = "https://acme-staging.api.letsencrypt.org/directory" diff --git a/certbot/tests/auth_handler_test.py b/certbot/tests/auth_handler_test.py index 9d22843db..32c4c0d3b 100644 --- a/certbot/tests/auth_handler_test.py +++ b/certbot/tests/auth_handler_test.py @@ -5,6 +5,7 @@ import unittest import mock import six +import zope.component from acme import challenges from acme import client as acme_client @@ -12,6 +13,7 @@ from acme import messages from certbot import achallenges from certbot import errors +from certbot import interfaces from certbot import util from certbot.tests import acme_util @@ -65,6 +67,12 @@ class GetAuthorizationsTest(unittest.TestCase): def setUp(self): from certbot.auth_handler import AuthHandler + self.mock_display = mock.Mock() + zope.component.provideUtility( + self.mock_display, interfaces.IDisplay) + zope.component.provideUtility( + mock.Mock(debug_challenges=False), interfaces.IConfig) + self.mock_auth = mock.MagicMock(name="ApacheConfigurator") self.mock_auth.get_chall_pref.return_value = [challenges.TLSSNI01] @@ -157,6 +165,20 @@ class GetAuthorizationsTest(unittest.TestCase): self.assertEqual(len(authzr), 3) + @mock.patch("certbot.auth_handler.AuthHandler._poll_challenges") + def test_debug_challenges(self, mock_poll): + zope.component.provideUtility( + mock.Mock(debug_challenges=True), interfaces.IConfig) + self.mock_net.request_domain_challenges.side_effect = functools.partial( + gen_dom_authzr, challs=acme_util.CHALLENGES) + + mock_poll.side_effect = self._validate_all + + self.handler.get_authorizations(["0"]) + + self.assertEqual(self.mock_net.answer_challenge.call_count, 1) + self.assertEqual(self.mock_display.notification.call_count, 1) + def test_perform_failure(self): self.mock_net.request_domain_challenges.side_effect = functools.partial( gen_dom_authzr, challs=acme_util.CHALLENGES)