From 2e799314de37303cfa60570b43779eda5da8d788 Mon Sep 17 00:00:00 2001 From: drebs Date: Mon, 25 Nov 2013 10:49:07 -0200 Subject: Fix smtp tests to accept deferred and new param encoding. --- mail/src/leap/mail/smtp/tests/__init__.py | 4 ++-- mail/src/leap/mail/smtp/tests/test_gateway.py | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/mail/src/leap/mail/smtp/tests/__init__.py b/mail/src/leap/mail/smtp/tests/__init__.py index 62b015f..1459cea 100644 --- a/mail/src/leap/mail/smtp/tests/__init__.py +++ b/mail/src/leap/mail/smtp/tests/__init__.py @@ -115,8 +115,8 @@ class TestCaseWithKeyManager(BaseLeapTest): 'username': address, 'password': '', 'encrypted_only': True, - 'cert': 'src/leap/mail/smtp/tests/cert/server.crt', - 'key': 'src/leap/mail/smtp/tests/cert/server.key', + 'cert': u'src/leap/mail/smtp/tests/cert/server.crt', + 'key': u'src/leap/mail/smtp/tests/cert/server.key', } class Response(object): diff --git a/mail/src/leap/mail/smtp/tests/test_gateway.py b/mail/src/leap/mail/smtp/tests/test_gateway.py index f9ea027..4c2f04f 100644 --- a/mail/src/leap/mail/smtp/tests/test_gateway.py +++ b/mail/src/leap/mail/smtp/tests/test_gateway.py @@ -22,7 +22,6 @@ SMTP gateway tests. import re - from datetime import datetime from gnupg._util import _make_binary_stream from twisted.test import proto_helpers @@ -131,6 +130,9 @@ class TestSmtpGateway(TestCaseWithKeyManager): for line in self.EMAIL_DATA[4:12]: m.lineReceived(line) m.eomReceived() + # we need to call the following explicitelly because it was deferred + # inside the previous method + m._maybe_encrypt_and_sign() # assert structure of encrypted message self.assertTrue('Content-Type' in m._msg) self.assertEqual('multipart/encrypted', m._msg.get_content_type()) @@ -146,7 +148,8 @@ class TestSmtpGateway(TestCaseWithKeyManager): decrypted = self._km.decrypt( m._msg.get_payload(1).get_payload(), privkey) self.assertEqual( - '\n' + '\r\n'.join(self.EMAIL_DATA[9:12]) + '\r\n', + '\n' + '\r\n'.join(self.EMAIL_DATA[9:12]) + '\r\n\r\n--\r\n' + + 'I prefer encrypted email - https://leap.se/key/anotheruser.\r\n', decrypted, 'Decrypted text differs from plaintext.') @@ -168,6 +171,9 @@ class TestSmtpGateway(TestCaseWithKeyManager): m.lineReceived(line) # trigger encryption and signing m.eomReceived() + # we need to call the following explicitelly because it was deferred + # inside the previous method + m._maybe_encrypt_and_sign() # assert structure of encrypted message self.assertTrue('Content-Type' in m._msg) self.assertEqual('multipart/encrypted', m._msg.get_content_type()) @@ -185,7 +191,8 @@ class TestSmtpGateway(TestCaseWithKeyManager): decrypted = self._km.decrypt( m._msg.get_payload(1).get_payload(), privkey, verify=pubkey) self.assertEqual( - '\n' + '\r\n'.join(self.EMAIL_DATA[9:12]) + '\r\n', + '\n' + '\r\n'.join(self.EMAIL_DATA[9:12]) + '\r\n\r\n--\r\n' + + 'I prefer encrypted email - https://leap.se/key/anotheruser.\r\n', decrypted, 'Decrypted text differs from plaintext.') @@ -208,6 +215,9 @@ class TestSmtpGateway(TestCaseWithKeyManager): m.lineReceived(line) # trigger signing m.eomReceived() + # we need to call the following explicitelly because it was deferred + # inside the previous method + m._maybe_encrypt_and_sign() # assert structure of signed message self.assertTrue('Content-Type' in m._msg) self.assertEqual('multipart/signed', m._msg.get_content_type()) @@ -216,8 +226,9 @@ class TestSmtpGateway(TestCaseWithKeyManager): self.assertEqual('pgp-sha512', m._msg.get_param('micalg')) # assert content of message self.assertEqual( - m._msg.get_payload(0).get_payload(decode=True), - '\r\n'.join(self.EMAIL_DATA[9:13])) + '\r\n'.join(self.EMAIL_DATA[9:13])+'\r\n--\r\n' + + 'I prefer encrypted email - https://leap.se/key/anotheruser.\r\n', + m._msg.get_payload(0).get_payload(decode=True)) # assert content of signature self.assertTrue( m._msg.get_payload(1).get_payload().startswith( -- cgit v1.2.3