certonly: hide "NEXT STEPS" for dry-runs (#8901)

* certonly: hide "NEXT STEPS" for dry-runs

* add a test
This commit is contained in:
alexzorin 2021-06-15 07:25:43 +10:00 committed by GitHub
parent 1b025e84e8
commit 60a91eb688
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View file

@ -1398,7 +1398,7 @@ def certonly(config, plugins):
if config.csr:
cert_path, chain_path, fullchain_path = _csr_get_and_save_cert(config, le_client)
_csr_report_new_cert(config, cert_path, chain_path, fullchain_path)
_report_next_steps(config, None, None)
_report_next_steps(config, None, None, new_or_renewed_cert=not config.dry_run)
_suggest_donation_if_appropriate(config)
eff.handle_subscription(config, le_client.account)
return
@ -1417,7 +1417,8 @@ def certonly(config, plugins):
fullchain_path = lineage.fullchain_path if lineage else None
key_path = lineage.key_path if lineage else None
_report_new_cert(config, cert_path, fullchain_path, key_path)
_report_next_steps(config, None, lineage, new_or_renewed_cert=should_get_cert)
_report_next_steps(config, None, lineage,
new_or_renewed_cert=should_get_cert and not config.dry_run)
_suggest_donation_if_appropriate(config)
eff.handle_subscription(config, le_client.account)

View file

@ -271,6 +271,21 @@ class CertonlyTest(unittest.TestCase):
self._call(('certonly --webroot --cert-name example.com').split())
self.assertIs(mock_choose_names.called, True)
@mock.patch('certbot._internal.main._report_next_steps')
@mock.patch('certbot._internal.main._get_and_save_cert')
@mock.patch('certbot._internal.main._csr_get_and_save_cert')
@mock.patch('certbot._internal.cert_manager.lineage_for_certname')
def test_dryrun_next_steps_no_cert_saved(self, mock_lineage, mock_csr_get_cert,
unused_mock_get_cert, mock_report_next_steps):
"""certonly --dry-run shouldn't report creation of a certificate in NEXT STEPS."""
mock_lineage.return_value = None
mock_csr_get_cert.return_value = ("/cert", "/chain", "/fullchain")
for flag in (f"--csr {CSR}", "-d example.com"):
self._call(f"certonly {flag} --webroot --cert-name example.com --dry-run".split())
mock_report_next_steps.assert_called_once_with(
mock.ANY, mock.ANY, mock.ANY, new_or_renewed_cert=False)
mock_report_next_steps.reset_mock()
class FindDomainsOrCertnameTest(unittest.TestCase):
"""Tests for certbot._internal.main._find_domains_or_certname."""