mirror of
https://github.com/certbot/certbot.git
synced 2026-06-08 16:22:18 -04:00
Added tests
This commit is contained in:
parent
f8f80f5392
commit
b90827dc98
2 changed files with 37 additions and 5 deletions
|
|
@ -208,8 +208,8 @@ class RenewableCert(object): # pylint: disable=too-many-instance-attributes
|
|||
# happen as a result of random tampering by a sysadmin, or
|
||||
# filesystem errors, or crashes.)
|
||||
|
||||
def _lockfiles(self):
|
||||
"""Returns the kind and path of all used lockfiles.
|
||||
def _symlink_lockfiles(self):
|
||||
"""Returns the kind and path of all symlink lockfiles.
|
||||
|
||||
:returns: list of (kind, lockfile) tuples
|
||||
:rtype: list
|
||||
|
|
@ -230,7 +230,7 @@ class RenewableCert(object): # pylint: disable=too-many-instance-attributes
|
|||
has no effect.
|
||||
|
||||
"""
|
||||
lockfiles = self._lockfiles()
|
||||
lockfiles = self._symlink_lockfiles()
|
||||
if all(os.path.exists(lockfile[1]) for lockfile in lockfiles):
|
||||
for kind, lockfile in lockfiles:
|
||||
link = getattr(self, kind)
|
||||
|
|
@ -418,7 +418,7 @@ class RenewableCert(object): # pylint: disable=too-many-instance-attributes
|
|||
|
||||
"""
|
||||
with error_handler.ErrorHandler(self._fix_symlinks):
|
||||
lockfiles = self._lockfiles()
|
||||
lockfiles = self._symlink_lockfiles()
|
||||
for kind, lockfile in lockfiles:
|
||||
with open(lockfile, "w") as f:
|
||||
f.write("{0}\n".format(self.current_target(kind)))
|
||||
|
|
|
|||
|
|
@ -290,7 +290,7 @@ class RenewableCertTests(BaseRenewableCertTest):
|
|||
self.assertEqual("cert8.pem",
|
||||
os.path.basename(self.test_rc.version("cert", 8)))
|
||||
|
||||
def test_update_all_links_to(self):
|
||||
def test_update_all_links_to_success(self):
|
||||
for ver in xrange(1, 6):
|
||||
for kind in ALL_FOUR:
|
||||
where = getattr(self.test_rc, kind)
|
||||
|
|
@ -308,6 +308,38 @@ class RenewableCertTests(BaseRenewableCertTest):
|
|||
self.assertEqual(ver, self.test_rc.current_version(kind))
|
||||
self.assertEqual(self.test_rc.latest_common_version(), 5)
|
||||
|
||||
def test_update_all_links_to_partial_failure(self):
|
||||
def unlink_or_raise(path, real_unlink=os.unlink):
|
||||
# pylint: disable=missing-docstring
|
||||
if "fullchain" in path and not path.endswith(".pem"):
|
||||
raise ValueError
|
||||
else:
|
||||
real_unlink(path)
|
||||
|
||||
self._write_out_ex_kinds()
|
||||
with mock.patch("letsencrypt.storage.os.unlink") as mock_unlink:
|
||||
mock_unlink.side_effect = unlink_or_raise
|
||||
self.assertRaises(ValueError, self.test_rc.update_all_links_to, 12)
|
||||
|
||||
for kind in ALL_FOUR:
|
||||
self.assertEqual(self.test_rc.current_version(kind), 12)
|
||||
|
||||
def test_update_all_links_to_full_failure(self):
|
||||
def unlink_or_raise(path, real_unlink=os.unlink):
|
||||
# pylint: disable=missing-docstring
|
||||
if "fullchain" in path:
|
||||
raise ValueError
|
||||
else:
|
||||
real_unlink(path)
|
||||
|
||||
self._write_out_ex_kinds()
|
||||
with mock.patch("letsencrypt.storage.os.unlink") as mock_unlink:
|
||||
mock_unlink.side_effect = unlink_or_raise
|
||||
self.assertRaises(ValueError, self.test_rc.update_all_links_to, 12)
|
||||
|
||||
for kind in ALL_FOUR:
|
||||
self.assertEqual(self.test_rc.current_version(kind), 11)
|
||||
|
||||
def test_has_pending_deployment(self):
|
||||
for ver in xrange(1, 6):
|
||||
for kind in ALL_FOUR:
|
||||
|
|
|
|||
Loading…
Reference in a new issue