From c1a959de4532b3ca5ae1787338b45b3bf85dc6af Mon Sep 17 00:00:00 2001 From: James Kasten Date: Fri, 25 Sep 2015 22:44:33 -0700 Subject: [PATCH] Remove Revocation display --- letsencrypt/display/revocation.py | 77 ---------------- letsencrypt/tests/display/revocation_test.py | 97 -------------------- 2 files changed, 174 deletions(-) delete mode 100644 letsencrypt/display/revocation.py delete mode 100644 letsencrypt/tests/display/revocation_test.py diff --git a/letsencrypt/display/revocation.py b/letsencrypt/display/revocation.py deleted file mode 100644 index 02a253676..000000000 --- a/letsencrypt/display/revocation.py +++ /dev/null @@ -1,77 +0,0 @@ -"""Revocation UI class.""" -import os - -import zope.component - -from letsencrypt import interfaces -from letsencrypt.display import util as display_util - -# Define a helper function to avoid verbose code -util = zope.component.getUtility # pylint: disable=invalid-name - - -def display_certs(certs): - """Display the certificates in a menu for revocation. - - :param list certs: each is a :class:`letsencrypt.revoker.Cert` - - :returns: tuple of the form (code, selection) where - code is a display exit code - selection is the user's int selection - :rtype: tuple - - """ - list_choices = [ - "%s | %s | %s" % ( - str(cert.get_cn().ljust(display_util.WIDTH - 39)), - cert.get_not_before().strftime("%m-%d-%y"), - "Installed" if cert.installed and cert.installed != ["Unknown"] - else "") for cert in certs - ] - - code, tag = util(interfaces.IDisplay).menu( - "Which certificates would you like to revoke?", - list_choices, help_label="More Info", ok_label="Revoke", - cancel_label="Exit") - - return code, tag - - -def confirm_revocation(cert): - """Confirm revocation screen. - - :param cert: certificate object - :type cert: :class: - - :returns: True if user would like to revoke, False otherwise - :rtype: bool - - """ - return util(interfaces.IDisplay).yesno( - "Are you sure you would like to revoke the following " - "certificate:{0}{cert}This action cannot be reversed!".format( - os.linesep, cert=cert.pretty_print())) - - -def more_info_cert(cert): - """Displays more info about the cert. - - :param dict cert: cert dict used throughout revoker.py - - """ - util(interfaces.IDisplay).notification( - "Certificate Information:{0}{1}".format( - os.linesep, cert.pretty_print()), - height=display_util.HEIGHT) - - -def success_revocation(cert): - """Display a success message. - - :param cert: cert that was revoked - :type cert: :class:`letsencrypt.revoker.Cert` - - """ - util(interfaces.IDisplay).notification( - "You have successfully revoked the certificate for " - "%s" % cert.get_cn()) diff --git a/letsencrypt/tests/display/revocation_test.py b/letsencrypt/tests/display/revocation_test.py deleted file mode 100644 index 6e9763006..000000000 --- a/letsencrypt/tests/display/revocation_test.py +++ /dev/null @@ -1,97 +0,0 @@ -"""Test :mod:`letsencrypt.display.revocation`.""" -import sys -import unittest - -import mock -import zope.component - -from letsencrypt.display import util as display_util - -from letsencrypt.tests import test_util - - -class DisplayCertsTest(unittest.TestCase): - def setUp(self): - from letsencrypt.revoker import Cert - self.cert0 = Cert(test_util.vector_path("cert.pem")) - self.cert1 = Cert(test_util.vector_path("cert-san.pem")) - - self.certs = [self.cert0, self.cert1] - - zope.component.provideUtility(display_util.FileDisplay(sys.stdout)) - - @classmethod - def _call(cls, certs): - from letsencrypt.display.revocation import display_certs - return display_certs(certs) - - @mock.patch("letsencrypt.display.revocation.util") - def test_revocation(self, mock_util): - mock_util().menu.return_value = (display_util.OK, 0) - - code, choice = self._call(self.certs) - - self.assertEqual(display_util.OK, code) - self.assertEqual(self.certs[choice], self.cert0) - - @mock.patch("letsencrypt.display.revocation.util") - def test_cancel(self, mock_util): - mock_util().menu.return_value = (display_util.CANCEL, -1) - - code, _ = self._call(self.certs) - self.assertEqual(display_util.CANCEL, code) - - -class MoreInfoCertTest(unittest.TestCase): - # pylint: disable=too-few-public-methods - @classmethod - def _call(cls, cert): - from letsencrypt.display.revocation import more_info_cert - more_info_cert(cert) - - @mock.patch("letsencrypt.display.revocation.util") - def test_more_info(self, mock_util): - self._call(mock.MagicMock()) - - self.assertEqual(mock_util().notification.call_count, 1) - - -class SuccessRevocationTest(unittest.TestCase): - def setUp(self): - from letsencrypt.revoker import Cert - self.cert = Cert(test_util.vector_path("cert.pem")) - - @classmethod - def _call(cls, cert): - from letsencrypt.display.revocation import success_revocation - success_revocation(cert) - - # Pretty trivial test... something is displayed... - @mock.patch("letsencrypt.display.revocation.util") - def test_success_revocation(self, mock_util): - self._call(self.cert) - - self.assertEqual(mock_util().notification.call_count, 1) - - -class ConfirmRevocationTest(unittest.TestCase): - def setUp(self): - from letsencrypt.revoker import Cert - self.cert = Cert(test_util.vector_path("cert.pem")) - - @classmethod - def _call(cls, cert): - from letsencrypt.display.revocation import confirm_revocation - return confirm_revocation(cert) - - @mock.patch("letsencrypt.display.revocation.util") - def test_confirm_revocation(self, mock_util): - mock_util().yesno.return_value = True - self.assertTrue(self._call(self.cert)) - - mock_util().yesno.return_value = False - self.assertFalse(self._call(self.cert)) - - -if __name__ == "__main__": - unittest.main() # pragma: no cover