1
0
mirror of https://github.com/certbot/certbot.git synced 2026-01-24 19:22:07 +03:00

Merge remote-tracking branch 'origin/renew_verb' into renew_verb

This commit is contained in:
Seth Schoen
2016-02-03 13:25:10 -08:00
2 changed files with 15 additions and 4 deletions

View File

@@ -283,12 +283,15 @@ def _should_renew(config, lineage):
"Return true if any of the circumstances for automatic renewal apply."
if config.renew_by_default:
logger.info("Auto-renewal forced with --renew-by-default...")
print("forced")
return True
if lineage.should_autorenew(interactive=True):
logger.info("Cert is due for renewal, auto-renewing...")
print("due")
return True
if config.dry_run:
logger.info("Cert not due for renewal, but simulating renewal for dry run")
print("dry")
return True
return False

View File

@@ -531,10 +531,11 @@ class CLITest(unittest.TestCase): # pylint: disable=too-many-public-methods
self._certonly_new_request_common, mock_client)
@mock.patch('letsencrypt.cli._find_duplicative_certs')
def _test_certonly_renewal_common(self, extra_args, mock_fdc):
def _test_renewal_common(self, due_for_renewal, extra_args, outstring, mock_fdc):
cert_path = 'letsencrypt/tests/testdata/cert.pem'
chain_path = '/etc/letsencrypt/live/foo.bar/fullchain.pem'
mock_lineage = mock.MagicMock(cert=cert_path, fullchain=chain_path)
mock_lineage.should_autorenew.return_value = due_for_renewal
mock_certr = mock.MagicMock()
mock_key = mock.MagicMock(pem='pem_key')
mock_fdc.return_value = (mock_lineage, None)
@@ -553,12 +554,16 @@ class CLITest(unittest.TestCase): # pylint: disable=too-many-public-methods
args += extra_args
self._call(args)
if outstring:
with open(os.path.join(self.logs_dir, "letsencrypt.log")) as lf:
self.assertTrue(outstring in lf.read())
mock_client.obtain_certificate.assert_called_once_with(['foo.bar'])
return mock_lineage, mock_get_utility
def test_certonly_renewal(self):
lineage, get_utility = self._test_certonly_renewal_common([])
lineage, get_utility = self._test_renewal_common(True, [], None)
self.assertEqual(lineage.save_successor.call_count, 1)
lineage.update_all_links_to.assert_called_once_with(
lineage.latest_common_version())
@@ -566,11 +571,14 @@ class CLITest(unittest.TestCase): # pylint: disable=too-many-public-methods
self.assertTrue('fullchain.pem' in cert_msg)
self.assertTrue('donate' in get_utility().add_message.call_args[0][0])
def test_certonly_dry_run_reinstall_is_renewal(self):
_, get_utility = self._test_certonly_renewal_common(['--dry-run'])
def test_certonly_renewal_triggers(self):
# --dry-run should force renewal
_, get_utility = self._test_renewal_common(False, ['--dry-run'], None)
self.assertEqual(get_utility().add_message.call_count, 1)
self.assertTrue('dry run' in get_utility().add_message.call_args[0][0])
_, _ = self._test_renewal_common(False, ['--renew-by-default', '-tvv', '--debug'], "Auto-renewal forced")
self.assertEqual(get_utility().add_message.call_count, 1)
@mock.patch('letsencrypt.cli.zope.component.getUtility')
@mock.patch('letsencrypt.cli._treat_as_renewal')