def renew_cert(config, domains, le_client, lineage): "Renew a certificate lineage." original_server = lineage.configuration["renewalparams"]["server"] _avoid_invalidating_lineage(config, lineage, original_server) new_certr, new_chain, new_key, _ = le_client.obtain_certificate(domains) if config.dry_run: logger.info("Dry run: skipping updating lineage at %s", os.path.dirname(lineage.cert)) else: prior_version = lineage.latest_common_version() new_cert = OpenSSL.crypto.dump_certificate( OpenSSL.crypto.FILETYPE_PEM, new_certr.body.wrapped) new_chain = crypto_util.dump_pyopenssl_chain(new_chain) renewal_conf = configuration.RenewerConfiguration(config.namespace) lineage.save_successor(prior_version, new_cert, new_key.pem, new_chain, renewal_conf) lineage.update_all_links_to(lineage.latest_common_version()) hooks.renew_hook(config, domains, lineage.live_dir)
def test_renew_hook(self): with mock.patch.dict('os.environ', {}): domains = ["a", "b"] lineage = "thing" rhook = lambda x: hooks.renew_hook(x, domains, lineage) config = mock.MagicMock(renew_hook="true", dry_run=False) self._test_a_hook(config, rhook, 2) self.assertEqual(os.environ["RENEWED_DOMAINS"], "a b") self.assertEqual(os.environ["RENEWED_LINEAGE"], "thing") config = mock.MagicMock(renew_hook="true", dry_run=True) mock_warn = self._test_a_hook(config, rhook, 0) self.assertEqual(mock_warn.call_count, 2)
def test_renew_hook(self): with mock.patch.dict('os.environ', {}): domains = ["a", "b"] lineage = "thing" rhook = lambda x: hooks.renew_hook(x, domains, lineage) config = mock.MagicMock(renew_hook="true", dry_run=False) self._test_a_hook(config, rhook, 2) self.assertEqual(os.environ["RENEWED_DOMAINS"], "a b") self.assertEqual(os.environ["RENEWED_LINEAGE"], "thing") config = mock.MagicMock(renew_hook="true", dry_run=True) if sys.version_info < (2, 7): # the print() function is not mockable in py26 self._test_a_hook(config, rhook, 0) else: with mock.patch("letsencrypt.hooks.print") as mock_print: self._test_a_hook(config, rhook, 0) self.assertEqual(mock_print.call_count, 2)