mirror of
https://github.com/certbot/certbot.git
synced 2026-08-01 19:14:54 +02:00
Made methods private and updated tests
This commit is contained in:
@@ -129,7 +129,7 @@ class RenewableCert(object): # pylint: disable=too-many-instance-attributes
|
|||||||
self.chain = self.configuration["chain"]
|
self.chain = self.configuration["chain"]
|
||||||
self.fullchain = self.configuration["fullchain"]
|
self.fullchain = self.configuration["fullchain"]
|
||||||
|
|
||||||
def consistent(self):
|
def _consistent(self):
|
||||||
"""Are the files associated with this lineage self-consistent?
|
"""Are the files associated with this lineage self-consistent?
|
||||||
|
|
||||||
:returns: Whether the files stored in connection with this
|
:returns: Whether the files stored in connection with this
|
||||||
@@ -187,7 +187,7 @@ class RenewableCert(object): # pylint: disable=too-many-instance-attributes
|
|||||||
# for x in ALL_FOUR))) == 1
|
# for x in ALL_FOUR))) == 1
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def fix(self):
|
def _fix(self):
|
||||||
"""Attempt to fix defects or inconsistencies in this lineage.
|
"""Attempt to fix defects or inconsistencies in this lineage.
|
||||||
|
|
||||||
.. todo:: Currently unimplemented.
|
.. todo:: Currently unimplemented.
|
||||||
@@ -347,7 +347,7 @@ class RenewableCert(object): # pylint: disable=too-many-instance-attributes
|
|||||||
smallest_current = min(self.current_version(x) for x in ALL_FOUR)
|
smallest_current = min(self.current_version(x) for x in ALL_FOUR)
|
||||||
return smallest_current < self.latest_common_version()
|
return smallest_current < self.latest_common_version()
|
||||||
|
|
||||||
def update_link_to(self, kind, version):
|
def _update_link_to(self, kind, version):
|
||||||
"""Make the specified item point at the specified version.
|
"""Make the specified item point at the specified version.
|
||||||
|
|
||||||
(Note that this method doesn't verify that the specified version
|
(Note that this method doesn't verify that the specified version
|
||||||
@@ -379,7 +379,7 @@ class RenewableCert(object): # pylint: disable=too-many-instance-attributes
|
|||||||
:param int version: the desired version"""
|
:param int version: the desired version"""
|
||||||
|
|
||||||
for kind in ALL_FOUR:
|
for kind in ALL_FOUR:
|
||||||
self.update_link_to(kind, version)
|
self._update_link_to(kind, version)
|
||||||
|
|
||||||
def _notafterbefore(self, method, version):
|
def _notafterbefore(self, method, version):
|
||||||
"""Internal helper function for finding notbefore/notafter."""
|
"""Internal helper function for finding notbefore/notafter."""
|
||||||
|
|||||||
@@ -4,14 +4,12 @@ import shutil
|
|||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import configobj
|
|
||||||
import OpenSSL
|
import OpenSSL
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from acme import jose
|
from acme import jose
|
||||||
|
|
||||||
from letsencrypt import account
|
from letsencrypt import account
|
||||||
from letsencrypt import configuration
|
|
||||||
from letsencrypt import errors
|
from letsencrypt import errors
|
||||||
from letsencrypt import le_util
|
from letsencrypt import le_util
|
||||||
|
|
||||||
@@ -120,29 +118,28 @@ class ClientTest(unittest.TestCase):
|
|||||||
def test_report_renewal_status(self, mock_zope):
|
def test_report_renewal_status(self, mock_zope):
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
cert = mock.MagicMock()
|
cert = mock.MagicMock()
|
||||||
cert.configuration = configobj.ConfigObj()
|
cert.cli_config.renewal_configs_dir = "/foo/bar/baz"
|
||||||
cert.cli_config = configuration.RenewerConfiguration(self.config)
|
|
||||||
|
|
||||||
cert.configuration["autorenew"] = "True"
|
cert.autorenewal_is_enabled.return_value = True
|
||||||
cert.configuration["autodeploy"] = "True"
|
cert.autodeployment_is_enabled.return_value = True
|
||||||
self.client._report_renewal_status(cert)
|
self.client._report_renewal_status(cert)
|
||||||
msg = mock_zope().add_message.call_args[0][0]
|
msg = mock_zope().add_message.call_args[0][0]
|
||||||
self.assertTrue("renewal and deployment has been" in msg)
|
self.assertTrue("renewal and deployment has been" in msg)
|
||||||
self.assertTrue(cert.cli_config.renewal_configs_dir in msg)
|
self.assertTrue(cert.cli_config.renewal_configs_dir in msg)
|
||||||
|
|
||||||
cert.configuration["autorenew"] = "False"
|
cert.autorenewal_is_enabled.return_value = False
|
||||||
self.client._report_renewal_status(cert)
|
self.client._report_renewal_status(cert)
|
||||||
msg = mock_zope().add_message.call_args[0][0]
|
msg = mock_zope().add_message.call_args[0][0]
|
||||||
self.assertTrue("deployment but not automatic renewal" in msg)
|
self.assertTrue("deployment but not automatic renewal" in msg)
|
||||||
self.assertTrue(cert.cli_config.renewal_configs_dir in msg)
|
self.assertTrue(cert.cli_config.renewal_configs_dir in msg)
|
||||||
|
|
||||||
cert.configuration["autodeploy"] = "False"
|
cert.autodeployment_is_enabled.return_value = False
|
||||||
self.client._report_renewal_status(cert)
|
self.client._report_renewal_status(cert)
|
||||||
msg = mock_zope().add_message.call_args[0][0]
|
msg = mock_zope().add_message.call_args[0][0]
|
||||||
self.assertTrue("renewal and deployment has not" in msg)
|
self.assertTrue("renewal and deployment has not" in msg)
|
||||||
self.assertTrue(cert.cli_config.renewal_configs_dir in msg)
|
self.assertTrue(cert.cli_config.renewal_configs_dir in msg)
|
||||||
|
|
||||||
cert.configuration["autorenew"] = "True"
|
cert.autorenewal_is_enabled.return_value = True
|
||||||
self.client._report_renewal_status(cert)
|
self.client._report_renewal_status(cert)
|
||||||
msg = mock_zope().add_message.call_args[0][0]
|
msg = mock_zope().add_message.call_args[0][0]
|
||||||
self.assertTrue("renewal but not automatic deployment" in msg)
|
self.assertTrue("renewal but not automatic deployment" in msg)
|
||||||
|
|||||||
@@ -123,46 +123,47 @@ class RenewableCertTests(BaseRenewableCertTest):
|
|||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
errors.CertStorageError, storage.RenewableCert, config, defaults)
|
errors.CertStorageError, storage.RenewableCert, config, defaults)
|
||||||
|
|
||||||
def test_consistent(self): # pylint: disable=too-many-statements
|
def test_consistent(self):
|
||||||
|
# pylint: disable=too-many-statements,protected-access
|
||||||
oldcert = self.test_rc.cert
|
oldcert = self.test_rc.cert
|
||||||
self.test_rc.cert = "relative/path"
|
self.test_rc.cert = "relative/path"
|
||||||
# Absolute path for item requirement
|
# Absolute path for item requirement
|
||||||
self.assertFalse(self.test_rc.consistent())
|
self.assertFalse(self.test_rc._consistent())
|
||||||
self.test_rc.cert = oldcert
|
self.test_rc.cert = oldcert
|
||||||
# Items must exist requirement
|
# Items must exist requirement
|
||||||
self.assertFalse(self.test_rc.consistent())
|
self.assertFalse(self.test_rc._consistent())
|
||||||
# Items must be symlinks requirements
|
# Items must be symlinks requirements
|
||||||
fill_with_sample_data(self.test_rc)
|
fill_with_sample_data(self.test_rc)
|
||||||
self.assertFalse(self.test_rc.consistent())
|
self.assertFalse(self.test_rc._consistent())
|
||||||
unlink_all(self.test_rc)
|
unlink_all(self.test_rc)
|
||||||
# Items must point to desired place if they are relative
|
# Items must point to desired place if they are relative
|
||||||
for kind in ALL_FOUR:
|
for kind in ALL_FOUR:
|
||||||
os.symlink(os.path.join("..", kind + "17.pem"),
|
os.symlink(os.path.join("..", kind + "17.pem"),
|
||||||
getattr(self.test_rc, kind))
|
getattr(self.test_rc, kind))
|
||||||
self.assertFalse(self.test_rc.consistent())
|
self.assertFalse(self.test_rc._consistent())
|
||||||
unlink_all(self.test_rc)
|
unlink_all(self.test_rc)
|
||||||
# Items must point to desired place if they are absolute
|
# Items must point to desired place if they are absolute
|
||||||
for kind in ALL_FOUR:
|
for kind in ALL_FOUR:
|
||||||
os.symlink(os.path.join(self.tempdir, kind + "17.pem"),
|
os.symlink(os.path.join(self.tempdir, kind + "17.pem"),
|
||||||
getattr(self.test_rc, kind))
|
getattr(self.test_rc, kind))
|
||||||
self.assertFalse(self.test_rc.consistent())
|
self.assertFalse(self.test_rc._consistent())
|
||||||
unlink_all(self.test_rc)
|
unlink_all(self.test_rc)
|
||||||
# Items must point to things that exist
|
# Items must point to things that exist
|
||||||
for kind in ALL_FOUR:
|
for kind in ALL_FOUR:
|
||||||
os.symlink(os.path.join("..", "..", "archive", "example.org",
|
os.symlink(os.path.join("..", "..", "archive", "example.org",
|
||||||
kind + "17.pem"),
|
kind + "17.pem"),
|
||||||
getattr(self.test_rc, kind))
|
getattr(self.test_rc, kind))
|
||||||
self.assertFalse(self.test_rc.consistent())
|
self.assertFalse(self.test_rc._consistent())
|
||||||
# This version should work
|
# This version should work
|
||||||
fill_with_sample_data(self.test_rc)
|
fill_with_sample_data(self.test_rc)
|
||||||
self.assertTrue(self.test_rc.consistent())
|
self.assertTrue(self.test_rc._consistent())
|
||||||
# Items must point to things that follow the naming convention
|
# Items must point to things that follow the naming convention
|
||||||
os.unlink(self.test_rc.fullchain)
|
os.unlink(self.test_rc.fullchain)
|
||||||
os.symlink(os.path.join("..", "..", "archive", "example.org",
|
os.symlink(os.path.join("..", "..", "archive", "example.org",
|
||||||
"fullchain_17.pem"), self.test_rc.fullchain)
|
"fullchain_17.pem"), self.test_rc.fullchain)
|
||||||
with open(self.test_rc.fullchain, "w") as f:
|
with open(self.test_rc.fullchain, "w") as f:
|
||||||
f.write("wrongly-named fullchain")
|
f.write("wrongly-named fullchain")
|
||||||
self.assertFalse(self.test_rc.consistent())
|
self.assertFalse(self.test_rc._consistent())
|
||||||
|
|
||||||
def test_current_target(self):
|
def test_current_target(self):
|
||||||
# Relative path logic
|
# Relative path logic
|
||||||
@@ -259,14 +260,15 @@ class RenewableCertTests(BaseRenewableCertTest):
|
|||||||
with open(where, "w") as f:
|
with open(where, "w") as f:
|
||||||
f.write(kind)
|
f.write(kind)
|
||||||
self.assertEqual(ver, self.test_rc.current_version(kind))
|
self.assertEqual(ver, self.test_rc.current_version(kind))
|
||||||
self.test_rc.update_link_to("cert", 3)
|
# pylint: disable=protected-access
|
||||||
self.test_rc.update_link_to("privkey", 2)
|
self.test_rc._update_link_to("cert", 3)
|
||||||
|
self.test_rc._update_link_to("privkey", 2)
|
||||||
self.assertEqual(3, self.test_rc.current_version("cert"))
|
self.assertEqual(3, self.test_rc.current_version("cert"))
|
||||||
self.assertEqual(2, self.test_rc.current_version("privkey"))
|
self.assertEqual(2, self.test_rc.current_version("privkey"))
|
||||||
self.assertEqual(5, self.test_rc.current_version("chain"))
|
self.assertEqual(5, self.test_rc.current_version("chain"))
|
||||||
self.assertEqual(5, self.test_rc.current_version("fullchain"))
|
self.assertEqual(5, self.test_rc.current_version("fullchain"))
|
||||||
# Currently we are allowed to update to a version that doesn't exist
|
# Currently we are allowed to update to a version that doesn't exist
|
||||||
self.test_rc.update_link_to("chain", 3000)
|
self.test_rc._update_link_to("chain", 3000)
|
||||||
# However, current_version doesn't allow querying the resulting
|
# However, current_version doesn't allow querying the resulting
|
||||||
# version (because it's a broken link).
|
# version (because it's a broken link).
|
||||||
self.assertEqual(os.path.basename(os.readlink(self.test_rc.chain)),
|
self.assertEqual(os.path.basename(os.readlink(self.test_rc.chain)),
|
||||||
@@ -507,7 +509,8 @@ class RenewableCertTests(BaseRenewableCertTest):
|
|||||||
self.defaults, self.cli_config)
|
self.defaults, self.cli_config)
|
||||||
# This consistency check tests most relevant properties about the
|
# This consistency check tests most relevant properties about the
|
||||||
# newly created cert lineage.
|
# newly created cert lineage.
|
||||||
self.assertTrue(result.consistent())
|
# pylint: disable=protected-access
|
||||||
|
self.assertTrue(result._consistent())
|
||||||
self.assertTrue(os.path.exists(os.path.join(
|
self.assertTrue(os.path.exists(os.path.join(
|
||||||
self.cli_config.renewal_configs_dir, "the-lineage.com.conf")))
|
self.cli_config.renewal_configs_dir, "the-lineage.com.conf")))
|
||||||
with open(result.fullchain) as f:
|
with open(result.fullchain) as f:
|
||||||
@@ -578,9 +581,10 @@ class RenewableCertTests(BaseRenewableCertTest):
|
|||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
errors.CertStorageError,
|
errors.CertStorageError,
|
||||||
self.test_rc.newest_available_version, "elephant")
|
self.test_rc.newest_available_version, "elephant")
|
||||||
|
# pylint: disable=protected-access
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
errors.CertStorageError,
|
errors.CertStorageError,
|
||||||
self.test_rc.update_link_to, "elephant", 17)
|
self.test_rc._update_link_to, "elephant", 17)
|
||||||
|
|
||||||
def test_ocsp_revoked(self):
|
def test_ocsp_revoked(self):
|
||||||
# XXX: This is currently hardcoded to False due to a lack of an
|
# XXX: This is currently hardcoded to False due to a lack of an
|
||||||
|
|||||||
Reference in New Issue
Block a user