From 9727be03c49d0bf6b9c2f28e125fc68147602161 Mon Sep 17 00:00:00 2001 From: J08nY Date: Mon, 31 Jul 2017 03:37:51 +0200 Subject: More test coverage for wrappers. --- src/mailman_pgp/pgp/tests/test_inline.py | 15 +++++++++++++++ src/mailman_pgp/pgp/tests/test_mime.py | 9 +++++++++ src/mailman_pgp/pgp/tests/test_wrapper.py | 14 ++++++++++++++ src/mailman_pgp/pgp/wrapper.py | 2 +- src/mailman_pgp/testing/pgp.py | 4 ++++ 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/mailman_pgp/pgp/tests/test_inline.py b/src/mailman_pgp/pgp/tests/test_inline.py index 4009a4b..7f82ab4 100644 --- a/src/mailman_pgp/pgp/tests/test_inline.py +++ b/src/mailman_pgp/pgp/tests/test_inline.py @@ -76,6 +76,12 @@ class TestSigning(InlineWrapperTestCase): load_key('rsa_1024.priv.asc'), load_key('rsa_1024.pub.asc')), (load_message('clear_multipart.eml'), + load_key('ecc_p256.priv.asc'), + load_key('ecc_p256.pub.asc')), + (load_message('inline_signed.eml'), + load_key('ecc_p256.priv.asc'), + load_key('ecc_p256.pub.asc')), + (load_message('inline_signed_multipart.eml'), load_key('ecc_p256.priv.asc'), load_key('ecc_p256.pub.asc')) ]) @@ -190,6 +196,15 @@ class TestKeys(InlineWrapperTestCase): def test_has_keys(self, message, has_keys): self.has_keys(message, has_keys) + @parameterized.expand([ + (load_message('inline_privkey.eml'), + True), + (load_message('inline_pubkey.eml'), + True) + ]) + def test_is_keys(self, message, is_keys): + self.is_keys(message, is_keys) + @parameterized.expand([ (load_message('inline_privkey.eml'), [load_key('rsa_1024.priv.asc')]), diff --git a/src/mailman_pgp/pgp/tests/test_mime.py b/src/mailman_pgp/pgp/tests/test_mime.py index 1415be5..78c9e71 100644 --- a/src/mailman_pgp/pgp/tests/test_mime.py +++ b/src/mailman_pgp/pgp/tests/test_mime.py @@ -156,6 +156,15 @@ class TestKeys(MIMEWrapperTestCase): def test_has_keys(self, message, has_keys): self.has_keys(message, has_keys) + @parameterized.expand([ + (load_message('mime_privkey.eml'), + False), + (load_message('mime_pubkey.eml'), + False) + ]) + def test_is_keys(self, message, is_keys): + self.is_keys(message, is_keys) + @parameterized.expand([ (load_message('mime_privkey.eml'), [load_key('rsa_1024.priv.asc')]), diff --git a/src/mailman_pgp/pgp/tests/test_wrapper.py b/src/mailman_pgp/pgp/tests/test_wrapper.py index 13657ac..f1f7621 100644 --- a/src/mailman_pgp/pgp/tests/test_wrapper.py +++ b/src/mailman_pgp/pgp/tests/test_wrapper.py @@ -18,6 +18,9 @@ """Tests for the combined wrapper.""" from parameterized import parameterized +from mailman_pgp.pgp.inline import InlineWrapper +from mailman_pgp.pgp.mime import MIMEWrapper +from mailman_pgp.pgp.mime_multisig import MIMEMultiSigWrapper from mailman_pgp.pgp.wrapper import PGPWrapper from mailman_pgp.testing.pgp import load_key, load_message, WrapperTestCase @@ -194,3 +197,14 @@ class TestCombined(PGPWrapperTestCase): def test_sign_then_encrypt_decrypt_verify(self, message, sign_key, encrypt_key): self.sign_then_encrypt_decrypt_verify(message, sign_key, encrypt_key) + + +class TestPGPWrapper(PGPWrapperTestCase): + def setUp(self): + self.msg = load_message('clear.eml') + + def test_defaults(self): + PGPWrapper(self.msg) + for wrap_class in (InlineWrapper, MIMEWrapper, MIMEMultiSigWrapper): + PGPWrapper(self.msg, wrap_class) + self.assertRaises(ValueError, PGPWrapper, self.msg, 'Not a class') diff --git a/src/mailman_pgp/pgp/wrapper.py b/src/mailman_pgp/pgp/wrapper.py index f506c2e..6193b57 100644 --- a/src/mailman_pgp/pgp/wrapper.py +++ b/src/mailman_pgp/pgp/wrapper.py @@ -37,7 +37,7 @@ class PGPWrapper(): :param msg: The message to wrap. :type msg: mailman.email.message.Message :param default: - :type default: MIMEWrapper|MIMEMultiSigWrapper|InlineWrapper + :type default: Type[MIMEWrapper|MIMEMultiSigWrapper|InlineWrapper] """ self.msg = msg self.mime = MIMEWrapper(msg) diff --git a/src/mailman_pgp/testing/pgp.py b/src/mailman_pgp/testing/pgp.py index 6b2bc48..844b708 100644 --- a/src/mailman_pgp/testing/pgp.py +++ b/src/mailman_pgp/testing/pgp.py @@ -126,6 +126,10 @@ class WrapperTestCase(TestCase): wrapped = self.wrap(message) self.assertEqual(wrapped.has_keys(), has_keys) + def is_keys(self, message, is_keys): + wrapped = self.wrap(message) + self.assertEqual(wrapped.is_keys(), is_keys) + def keys(self, message, keys): wrapped = self.wrap(message) loaded = list(wrapped.keys()) -- cgit v1.3.1