aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ08nY2017-06-21 18:29:02 +0200
committerJ08nY2017-06-21 18:29:02 +0200
commit16ef2af65c160872d7cc1243199ed2dc4646ccba (patch)
treeb7d03eaee32d597be1d7d351e8ce16db98b0799a
parent89b07e34b41838ab09209879eed1ae29370f319e (diff)
downloadmailman-pgp-16ef2af65c160872d7cc1243199ed2dc4646ccba.tar.gz
mailman-pgp-16ef2af65c160872d7cc1243199ed2dc4646ccba.tar.zst
mailman-pgp-16ef2af65c160872d7cc1243199ed2dc4646ccba.zip
Add InlineWrapper tests.
-rw-r--r--src/mailman_pgp/pgp/inline.py2
-rw-r--r--src/mailman_pgp/pgp/tests/base.py37
-rw-r--r--src/mailman_pgp/pgp/tests/data/inline_signed.eml24
-rw-r--r--src/mailman_pgp/pgp/tests/data/inline_signed_invalid.eml24
-rw-r--r--src/mailman_pgp/pgp/tests/test_inline.py65
-rw-r--r--src/mailman_pgp/pgp/tests/test_mime.py51
6 files changed, 176 insertions, 27 deletions
diff --git a/src/mailman_pgp/pgp/inline.py b/src/mailman_pgp/pgp/inline.py
index 92a7fdb..da4ea36 100644
--- a/src/mailman_pgp/pgp/inline.py
+++ b/src/mailman_pgp/pgp/inline.py
@@ -18,7 +18,7 @@
"""Strict inline PGP message wrapper."""
from email.message import Message
-from pgpy import PGPKey, PGPMessage
+from pgpy import PGPKey, PGPMessage, PGPSignature
from pgpy.types import Armorable
diff --git a/src/mailman_pgp/pgp/tests/base.py b/src/mailman_pgp/pgp/tests/base.py
new file mode 100644
index 0000000..7bbec50
--- /dev/null
+++ b/src/mailman_pgp/pgp/tests/base.py
@@ -0,0 +1,37 @@
+# Copyright (C) 2017 Jan Jancar
+#
+# This file is a part of the Mailman PGP plugin.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>.
+
+""""""
+from email import message_from_file
+
+from pgpy import PGPKey
+from pkg_resources import resource_filename
+
+
+def load_message(path):
+ with open(resource_filename('mailman_pgp.pgp.tests', path)) as f:
+ return message_from_file(f)
+
+
+def load_key(path):
+ key, _ = PGPKey.from_file(
+ resource_filename('mailman_pgp.pgp.tests', path))
+ return key
+
+
+class PGPTestCase():
+ pass \ No newline at end of file
diff --git a/src/mailman_pgp/pgp/tests/data/inline_signed.eml b/src/mailman_pgp/pgp/tests/data/inline_signed.eml
new file mode 100644
index 0000000..cb6d40c
--- /dev/null
+++ b/src/mailman_pgp/pgp/tests/data/inline_signed.eml
@@ -0,0 +1,24 @@
+To: nobody@example.org
+From: RSA 1024b example <RSA-1024b@example.org>
+Subject: Some subject.
+Message-ID: <76a591ed-bfc4-d08b-73d3-fc2489148fd7@example.org>
+Date: Wed, 21 Jun 2017 13:50:59 +0200
+User-Agent: Mutt/1.7.2 (2016-11-26)
+MIME-Version: 1.0
+Content-Type: text/plain; charset=utf-8
+Content-Transfer-Encoding: 8bit
+
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA256
+
+Some signed text.
+
+-----BEGIN PGP SIGNATURE-----
+
+iMoEAQEIADQWIQTUqUiGscoglqZFjlxH8QwIeIS3WAUCWUqdqRYccnNhLTEwMjRi
+QGV4YW1wbGUub3JnAAoJEEfxDAh4hLdYyRsEANGjr5E3Th1n6EUQEye4YBjlOFq6
+aiiSu+4K4O08yHQ5h1vqBkT2gCmcPpQOThNBRazdSYRvIPNLTyMy6ChhaeWzsmR0
+CIN/YYUC9mAh5XOF+tjaJTSlmBBhuJmayW1D8qysZVg3TmD+fXw+JImrhZW/g0Fi
+4B1oU+uBh6VAZZjJ
+=QecT
+-----END PGP SIGNATURE-----
diff --git a/src/mailman_pgp/pgp/tests/data/inline_signed_invalid.eml b/src/mailman_pgp/pgp/tests/data/inline_signed_invalid.eml
new file mode 100644
index 0000000..c7d9b03
--- /dev/null
+++ b/src/mailman_pgp/pgp/tests/data/inline_signed_invalid.eml
@@ -0,0 +1,24 @@
+To: nobody@example.org
+From: RSA 1024b example <RSA-1024b@example.org>
+Subject: Some subject.
+Message-ID: <76a591ed-bfc4-d08b-73d3-fc2489148fd7@example.org>
+Date: Wed, 21 Jun 2017 13:50:59 +0200
+User-Agent: Mutt/1.7.2 (2016-11-26)
+MIME-Version: 1.0
+Content-Type: text/plain; charset=utf-8
+Content-Transfer-Encoding: 8bit
+
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA256
+
+Some signed text. With some INVALID text added!!
+
+-----BEGIN PGP SIGNATURE-----
+
+iMoEAQEIADQWIQTUqUiGscoglqZFjlxH8QwIeIS3WAUCWUqdqRYccnNhLTEwMjRi
+QGV4YW1wbGUub3JnAAoJEEfxDAh4hLdYyRsEANGjr5E3Th1n6EUQEye4YBjlOFq6
+aiiSu+4K4O08yHQ5h1vqBkT2gCmcPpQOThNBRazdSYRvIPNLTyMy6ChhaeWzsmR0
+CIN/YYUC9mAh5XOF+tjaJTSlmBBhuJmayW1D8qysZVg3TmD+fXw+JImrhZW/g0Fi
+4B1oU+uBh6VAZZjJ
+=QecT
+-----END PGP SIGNATURE-----
diff --git a/src/mailman_pgp/pgp/tests/test_inline.py b/src/mailman_pgp/pgp/tests/test_inline.py
new file mode 100644
index 0000000..c6d1d89
--- /dev/null
+++ b/src/mailman_pgp/pgp/tests/test_inline.py
@@ -0,0 +1,65 @@
+# Copyright (C) 2017 Jan Jancar
+#
+# This file is a part of the Mailman PGP plugin.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>.
+
+""""""
+import unittest
+
+from parameterized import parameterized
+
+from mailman_pgp.pgp.inline import InlineWrapper
+from mailman_pgp.pgp.tests.base import PGPTestCase, load_message, load_key
+
+
+class TestSigning(PGPTestCase, unittest.TestCase):
+ def setUp(self):
+ self.wrapper = InlineWrapper
+
+ @parameterized.expand([
+ (load_message('data/inline_signed.eml'),
+ True),
+ (load_message('data/inline_signed_invalid.eml'),
+ True)
+ ])
+ def test_is_signed(self, message, signed):
+ wrapped = self.wrapper(message)
+ self.assertEqual(wrapped.is_signed(), signed)
+
+ def test_sign(self):
+ pass
+
+ @parameterized.expand([
+ (load_message('data/inline_signed.eml'),
+ load_key('data/rsa_1024.pub.asc'),
+ True),
+ (load_message('data/inline_signed_invalid.eml'),
+ load_key('data/rsa_1024.pub.asc'),
+ False)
+ ])
+ def test_verify(self, message, key, valid):
+ wrapped = self.wrapper(message)
+ self.assertEqual(bool(wrapped.verify(key)), valid)
+
+
+class TestEncryption(PGPTestCase, unittest.TestCase):
+ def test_is_encrypted(self):
+ pass
+
+ def test_encrypt(self):
+ pass
+
+ def test_decrypt(self):
+ pass
diff --git a/src/mailman_pgp/pgp/tests/test_mime.py b/src/mailman_pgp/pgp/tests/test_mime.py
index 981259c..6b30344 100644
--- a/src/mailman_pgp/pgp/tests/test_mime.py
+++ b/src/mailman_pgp/pgp/tests/test_mime.py
@@ -17,45 +17,44 @@
""""""
import unittest
-from email import message_from_file
-from pgpy import PGPKey
-from pkg_resources import resource_filename
+from parameterized import parameterized
from mailman_pgp.pgp.mime import MIMEWrapper
+from mailman_pgp.pgp.tests.base import PGPTestCase, load_message, load_key
-class TestSigning(unittest.TestCase):
+class TestSigning(PGPTestCase, unittest.TestCase):
def setUp(self):
- with open(resource_filename('mailman_pgp.pgp.tests',
- 'data/mime_signed.eml')) as f:
- self.signed = message_from_file(f)
- with open(resource_filename('mailman_pgp.pgp.tests',
- 'data/mime_signed_invalid.eml')) as f:
- self.signed_invalid = message_from_file(f)
+ self.wrapper = MIMEWrapper
- self.pub, _ = PGPKey.from_file(
- resource_filename('mailman_pgp.pgp.tests',
- 'data/rsa_1024.pub.asc'))
- self.priv, _ = PGPKey.from_file(
- resource_filename('mailman_pgp.pgp.tests',
- 'data/rsa_1024.priv.asc'))
- self.wrapped = MIMEWrapper(self.signed)
- self.wrapped_invalid = MIMEWrapper(self.signed_invalid)
-
- def test_is_signed(self):
- self.assertTrue(self.wrapped.is_signed())
- self.assertTrue(self.wrapped_invalid.is_signed())
+ @parameterized.expand([
+ (load_message('data/mime_signed.eml'),
+ True),
+ (load_message('data/mime_signed_invalid.eml'),
+ True)
+ ])
+ def test_is_signed(self, message, signed):
+ wrapped = self.wrapper(message)
+ self.assertEqual(wrapped.is_signed(), signed)
def test_sign(self):
pass
- def test_verify(self):
- self.assertTrue(self.wrapped.verify(self.pub))
- self.assertFalse(self.wrapped_invalid.verify(self.pub))
+ @parameterized.expand([
+ (load_message('data/mime_signed.eml'),
+ load_key('data/rsa_1024.pub.asc'),
+ True),
+ (load_message('data/mime_signed_invalid.eml'),
+ load_key('data/rsa_1024.pub.asc'),
+ False)
+ ])
+ def test_verify(self, message, key, valid):
+ wrapped = self.wrapper(message)
+ self.assertEqual(bool(wrapped.verify(key)), valid)
-class TestEncryption(unittest.TestCase):
+class TestEncryption(PGPTestCase, unittest.TestCase):
def test_is_encrypted(self):
pass