diff options
author | Ruben Pollan <meskio@sindominio.net> | 2016-04-28 00:12:23 -0300 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2016-04-28 00:12:23 -0300 |
commit | 7396398e81fda41d4cb2ea7ffbdfa8f02746cad8 (patch) | |
tree | ddd01d38a15399e516c31bdd2e7814ee9e21dc34 /tests | |
parent | 04e5136c3d2fbcfd30a374f95d8b7c5f819e0d27 (diff) |
[feat] simple pgp/mime creation
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_protection.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test_protection.py b/tests/test_protection.py new file mode 100644 index 0000000..f83d3f7 --- /dev/null +++ b/tests/test_protection.py @@ -0,0 +1,48 @@ +import base64 +import unittest +from email.parser import Parser +from zope.interface import implementer + +from memoryhole import protect, OpenPGP + + +FROM = "me@domain.com" +TO = "you@other.com" +SUBJECT = "some subject" +BODY = "body text" +EMAIL = """From: %(from)s +To: %(to)s +Subject: %(subject)s + +%(body)s +""" % { + "from": FROM, + "to": TO, + "subject": SUBJECT, + "body": BODY +} + + +class ProtectTest(unittest.TestCase): + def test_pgp_mime(self): + p = Parser() + msg = p.parsestr(EMAIL) + encrypter = Encrypter() + encmsg = protect(msg, encrypter) + + self.assertEqual(encmsg.get_payload(1).get_payload(), encrypter.encstr) + self.assertEqual(BODY, encrypter.data[1:-1]) # remove '\n' + self.assertEqual(encmsg.get_content_type(), "multipart/encrypted") + + +@implementer(OpenPGP) +class Encrypter(object): + encstr = "this is encrypted" + + def encrypt(self, data, encraddr, singaddr): + self.data = data + return self.encstr + + +if __name__ == "__main__": + unittest.main() |