Mercurial > p > roundup > code
comparison test/test_mailgw.py @ 5494:b7fa56ced601
use gpg module instead of pyme module for PGP encryption
| author | Christof Meerwald <cmeerw@cmeerw.org> |
|---|---|
| date | Sun, 12 Aug 2018 16:17:14 +0100 |
| parents | 725266c03eab |
| children | 497ab896397d |
comparison
equal
deleted
inserted
replaced
| 5493:725266c03eab | 5494:b7fa56ced601 |
|---|---|
| 16 import unittest, tempfile, os, shutil, errno, imp, sys, difflib, time | 16 import unittest, tempfile, os, shutil, errno, imp, sys, difflib, time |
| 17 | 17 |
| 18 import pytest | 18 import pytest |
| 19 | 19 |
| 20 try: | 20 try: |
| 21 import pyme, pyme.core | 21 import gpg, gpg.core |
| 22 skip_pgp = lambda func, *args, **kwargs: func | 22 skip_pgp = lambda func, *args, **kwargs: func |
| 23 except ImportError: | 23 except ImportError: |
| 24 # FIX: workaround for a bug in pytest.mark.skip(): | 24 # FIX: workaround for a bug in pytest.mark.skip(): |
| 25 # https://github.com/pytest-dev/pytest/issues/568 | 25 # https://github.com/pytest-dev/pytest/issues/568 |
| 26 from .pytest_patcher import mark_class | 26 from .pytest_patcher import mark_class |
| 27 skip_pgp = mark_class(pytest.mark.skip( | 27 skip_pgp = mark_class(pytest.mark.skip( |
| 28 reason="Skipping PGP tests: 'pyme' not installed")) | 28 reason="Skipping PGP tests: 'gpg' not installed")) |
| 29 | 29 |
| 30 | 30 |
| 31 from roundup.anypy.email_ import message_from_bytes | |
| 31 from roundup.anypy.strings import StringIO, b2s, u2s | 32 from roundup.anypy.strings import StringIO, b2s, u2s |
| 32 | 33 |
| 33 if 'SENDMAILDEBUG' not in os.environ: | 34 if 'SENDMAILDEBUG' not in os.environ: |
| 34 os.environ['SENDMAILDEBUG'] = 'mail-test.log' | 35 os.environ['SENDMAILDEBUG'] = 'mail-test.log' |
| 35 SENDMAILDEBUG = os.environ['SENDMAILDEBUG'] | 36 SENDMAILDEBUG = os.environ['SENDMAILDEBUG'] |
| 4383 self.db.security.addPermissionToRole('pgp', 'Email Access') | 4384 self.db.security.addPermissionToRole('pgp', 'Email Access') |
| 4384 self.db.security.addPermissionToRole('pgp', 'Create', 'issue') | 4385 self.db.security.addPermissionToRole('pgp', 'Create', 'issue') |
| 4385 # trap_exc=1: we want a bounce message: | 4386 # trap_exc=1: we want a bounce message: |
| 4386 self._handle_mail(self.encrypted_msg, trap_exc=1) | 4387 self._handle_mail(self.encrypted_msg, trap_exc=1) |
| 4387 m = self._get_mail() | 4388 m = self._get_mail() |
| 4388 fp = email.parser.FeedParser() | 4389 parts = email.message_from_string(m).get_payload() |
| 4389 fp.feed(m) | |
| 4390 parts = fp.close().get_payload() | |
| 4391 self.assertEqual(len(parts),2) | 4390 self.assertEqual(len(parts),2) |
| 4392 self.assertEqual(parts[0].get_payload().strip(), 'Version: 1') | 4391 self.assertEqual(parts[0].get_payload().strip(), 'Version: 1') |
| 4393 crypt = pyme.core.Data(parts[1].get_payload()) | 4392 crypt = gpg.core.Data(parts[1].get_payload()) |
| 4394 plain = pyme.core.Data() | 4393 plain = gpg.core.Data() |
| 4395 ctx = pyme.core.Context() | 4394 ctx = gpg.core.Context() |
| 4396 res = ctx.op_decrypt(crypt, plain) | 4395 res = ctx.op_decrypt(crypt, plain) |
| 4397 self.assertEqual(res, None) | 4396 self.assertEqual(res, None) |
| 4398 plain.seek(0,0) | 4397 plain.seek(0,0) |
| 4399 fp = email.parser.FeedParser() | 4398 parts = message_from_bytes(plain.read()).get_payload() |
| 4400 fp.feed(plain.read()) | |
| 4401 parts = fp.close().get_payload() | |
| 4402 self.assertEqual(len(parts),2) | 4399 self.assertEqual(len(parts),2) |
| 4403 self.assertEqual(parts[0].get_payload().strip(), | 4400 self.assertEqual(parts[0].get_payload().strip(), |
| 4404 'You are not permitted to create messages.') | 4401 'You are not permitted to create messages.') |
| 4405 self.assertEqual(parts[1].get_payload().strip(), | 4402 self.assertEqual(parts[1].get_payload().strip(), |
| 4406 '''Content-Type: text/plain; charset=us-ascii | 4403 '''Content-Type: text/plain; charset=us-ascii |
