From ff7f0c7ae75e8aa56a1ad338185004077a854e17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 17 Mar 2016 16:12:55 +0100 Subject: Added unit test for rsa.util.private_to_public() --- tests/test_cli.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests') diff --git a/tests/test_cli.py b/tests/test_cli.py index 511d25d..aad734a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -14,6 +14,7 @@ from io import StringIO, BytesIO import rsa import rsa.cli +import rsa.util from rsa._compat import b if sys.version_info[0] < 3: @@ -278,3 +279,21 @@ class SignVerifyTest(AbstractCliTest): with cli_args('-i', 'cleartext.txt', self.pub_fname, 'signature.txt'): with captured_output() as (out, err): self.assertExits('Verification failed.', rsa.cli.verify) + + +class PrivatePublicTest(AbstractCliTest): + """Test CLI command to convert a private to a public key.""" + + @cleanup_files('test_private_to_public.pem') + def test_private_to_public(self): + + with cli_args('-i', self.priv_fname, '-o', 'test_private_to_public.pem'): + with captured_output(): + rsa.util.private_to_public() + + # Check that the key is indeed valid. + with open('test_private_to_public.pem', 'rb') as pemfile: + key = rsa.PublicKey.load_pkcs1(pemfile.read()) + + self.assertEqual(self.priv_key.n, key.n) + self.assertEqual(self.priv_key.e, key.e) -- cgit v1.2.1