-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Moving towards 1.1.0 #15
Closed
Closed
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
48866fb
There's no problem with encrypt being public
acatton 86a80b4
Make load_configuration() return config
acatton 44ee5d6
Define the gpg context as a property
acatton 6644b1e
Remove unused import
acatton 9701489
Fix #2
acatton abf5ab4
This is testing python, not zeyple
acatton b2669d5
Always use os.path.join instead of concatenation
acatton 70fba59
Fix style: the PEP-0008 requires two space before an inline comment
acatton db7c9ad
Make the tests use a temporary directory and temporary gpg homedir
acatton f202c68
Use test keys (for decoding later)
acatton d3793df
Octal literals needs to be lead by 0o in Python 3
acatton f378afa
Propose a better alternative to #10
acatton 398cde0
Merge branch 'include-10' into moving-towards-1.1.0
acatton 35cd5fd
Fix bad abreviation fname -> filename
acatton ce71bff
Remove wrongfully committed test keys
acatton a019007
Force all data to be binary and get rid of is_encrypted()
acatton 1720c02
Behave according to the RFCs
acatton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
-----BEGIN PGP PRIVATE KEY BLOCK----- | ||
Comment: THESE PRIVATE KEYS ARE FOR TESTING, DO NOT IMPORT THEM!! | ||
|
||
lQHYBFW5puEBBACb4DlfxmTUNMNwNf/36yY53+fKQsjmi1Vq2xmCMs88TRBiFmol | ||
5tJHhVPIBJQfkGw9JnRO93aZQj7f9xHexVtQqrKcl/r38OkMEDCHS4zUoRfuWMTx | ||
++X25I9sPNY2H1p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s/hXwvIDy92xxiL1yEQIA95G9th/DO+e/hxGOFTis | ||
1xuipKxn915MAKeeFjAIEu/cC/SXrNVpu1GQylN0Fj61Ud1aEWLXZ4igfqOHiafe | ||
swH/SVDhXiGB9kppo4fkfh3XhastBDmasyo8TUTuk34MlGMkvjU6D05iJRzRBGZw | ||
fR3d5rhJGUnpoSApZvJbezuUA5bhiJ8EGAECAAkFAlW5pvwCGwwACgkQBCLxxZf7 | ||
FoeJkQP/RuIUMAG772pfvdYH0L5s97U8On52lu6XyU7BIDnO3GU864DlX8K0KILU | ||
5MF4G+SulNv8Kci6gK2tszgruOFI8NGAkBZrDgDCLcEH1k7o0S/jYKxvkAfHz91O | ||
UjI8Ynl8Yri1XVdG3OP6Bm2x90j/v0D15vgxvYGXAHLBYO84rto= | ||
=+1Yx | ||
-----END PGP PRIVATE KEY BLOCK----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
-----BEGIN PGP PRIVATE KEY BLOCK----- | ||
Comment: NEVER USE THIS KEY, THIS KEY IS FOR TESTING | ||
|
||
lQHYBFW5pC8BBADJRSpFia07qiS5lEOyBjAQzn16b4WR1iHktGAXV/LD4D3NE2Hc | ||
i0HHs9CxJ1xqbAcblltxCb6kFq+kHA1gzeNYbUBmfu0XciU850s8JCtbWilKLKRD | ||
cYX20Tgof5APqINEswfTytyVFSiK6bMlGMZjj9R2McoPPb20lbnwJ1npxwARAQAB | ||
AAP8Cmg0tuwN9KGxKCf035E7xQT85WrN9SLup7hRFM0QYpniuC95GF1IJVE0f22o | ||
mYVEvxqTDmyIbN7JJMZ8175toVEqT4TO/eND79PW+7MVINlmbz712xfPu2oVYGEe | ||
Avx/jTcOpmKPHnY+F9z0InRnWAGzuxbHCXQs8ECREOW3NqkCAM5UULZ0LrXlvgOu | ||
o8NHx17SW+t6kw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HU | ||
dn9eVNnEaerng6EMkIkV9xCTuNtWb89OdQIAlRfXV/23R+krjbCzDkNNVag6l8d2 | ||
E0nG4k4uS6iazFcghnutTzcoKG1uMOMSlLJ11Q5m3g9ebEz8uUXeaT81bKIMiJ8E | ||
GAECAAkFAlW5pC8CGwwACgkQnAqeRfWkB0rBhgP+LtZy+NiQGNSUZ2LxlYgwsbYT | ||
jSOAOYwVODpaIAyTQzvCKxPhZM7RMUlWPpamZQrUofZTNmsu7Cnj5ThE9WgcsXPg | ||
VIoxy7jXGU5g0TZuJXEsHV4jGYvIBfcY/R4LjTskLL20CX8EWIv9U59PY4lSV+mZ | ||
nHv89db50/2kNSibsZU= | ||
=VY60 | ||
-----END PGP PRIVATE KEY BLOCK----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
-----BEGIN PGP PRIVATE KEY BLOCK----- | ||
Comment: NEVER USE THIS KEY, THIS KEY IS FOR TESTING | ||
|
||
lQHYBFW5pF4BBADfRJzouz2MH3YZ7qTBSzfxzIHYrtfZoetG0rFp4B5FPNggXz0P | ||
tDIVSqwpkb3Yp5PDWR0u/1RyEeSHh9YL2EMezpi8ZGQFn9Cjmkc48sluaSWLj5Cc | ||
hedaCV/t5/IfvvsQdD8PyZGC4Os+nuwryUVM9Hc2UwShMEPNaBmhdFDXXwARAQAB | ||
AAP8DeAsxEYGwDOgWmI7eQvcsTldhILxRURL4/3qKsNT/keWwwRIPjabujkG1BqL | ||
qvBXPZfHOYmCzQgRpN6rTdcl7KF0pGCaksgY3KakiOp3/wNIe1RuN+bLj7fHCttT | ||
PT9FNQKkqKdTGCXn3ViYTqDBuXmXSteel8IcIRjh8TyGBBECAOHeDNVzmEpn+6Ei | ||
Womq7LWUQLKLaJkgEuhwJIJOQMTFbCBgyoWfdJVSke422V2TpYGPMbLCGx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geECH5ZyppAf4pXfFUzfMx | ||
NySYStM9CCIY6r+QnK3/UX5rlnbJu98h2w1wF0GtdIG3D0y2nPDUdCK9ejnClTam | ||
GMG2cYTZnMzVn1mInwQYAQIACQUCVbmkXgIbDAAKCRAf9YefAE74fZ4oBACYkp4O | ||
gsy+aMUejadahvm9+bfzqU1tQ9iWlG/9Xz9pjj5sJbOrHD7z0qRpLMYAZru2llgw | ||
T7vdp9JzmUeTdGY7/4Ce8+rw6ZxRpGRBagdWFChgDbb0f+uT8xu3Ef+Fk4aOZ/IR | ||
XCVN6qkCuKUdfQB6xMxKEQnL2wRruHuCFgk1Xw== | ||
=gOA4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,52 +4,87 @@ | |
import unittest | ||
from mock import Mock | ||
import os | ||
import subprocess | ||
import shutil | ||
import six | ||
from six.moves.configparser import ConfigParser | ||
import tempfile | ||
from textwrap import dedent | ||
from zeyple import zeyple | ||
|
||
LINUS_ID = '79BE3E4300411886' | ||
KEYS_FNAME = os.path.join(os.path.dirname(__file__), 'keys.gpg') | ||
TEST1_ID = 'D6513C04E24C1F83' | ||
TEST1_EMAIL = '[email protected]' | ||
TEST2_ID = '0422F1C597FB1687' | ||
TEST2_EMAIL = '[email protected]' | ||
|
||
def is_encrypted(string): | ||
return string.startswith(six.b('-----BEGIN PGP MESSAGE-----')) | ||
|
||
class ZeypleTest(unittest.TestCase): | ||
def setUp(self): | ||
shutil.copyfile('tests/zeyple.conf', 'zeyple.conf') | ||
os.system("gpg --recv-keys %s 2> /dev/null" % LINUS_ID) | ||
self.zeyple = zeyple.Zeyple() | ||
self.zeyple._send_message = Mock() # don't try to send emails | ||
self.tmpdir = tempfile.mkdtemp() | ||
|
||
def tearDown(self): | ||
os.remove('zeyple.conf') | ||
self.conffile = os.path.join(self.tmpdir, 'zeyple.conf') | ||
self.homedir = os.path.join(self.tmpdir, 'gpg') | ||
self.logfile = os.path.join(self.tmpdir, 'zeyple.log') | ||
|
||
config = ConfigParser() | ||
|
||
config.add_section('zeyple') | ||
config.set('zeyple', 'log_file', self.logfile) | ||
config.set('zeyple', 'add_header', 'true') | ||
|
||
config.add_section('gpg') | ||
config.set('gpg', 'home', self.homedir) | ||
|
||
config.add_section('relay') | ||
config.set('relay', 'host', 'example.net') | ||
config.set('relay', 'port', '2525') | ||
|
||
with open(self.conffile, 'w') as fp: | ||
config.write(fp) | ||
|
||
def test_config(self): | ||
"""Parses the configuration file properly""" | ||
os.mkdir(self.homedir, 0o700) | ||
subprocess.check_call( | ||
['gpg', '--homedir', self.homedir, '--import', KEYS_FNAME], | ||
stderr=open('/dev/null'), | ||
) | ||
|
||
self.zeyple = zeyple.Zeyple(self.conffile) | ||
self.zeyple._send_message = Mock() # don't try to send emails | ||
|
||
def tearDown(self): | ||
shutil.rmtree(self.tmpdir) | ||
|
||
log_file = self.zeyple._config.get('zeyple', 'log_file') | ||
assert log_file == '/tmp/zeyple.log' | ||
def decrypt(self, data): | ||
gpg = subprocess.Popen( | ||
['gpg', '--homedir', self.homedir, '--decrypt'], | ||
stdin=subprocess.PIPE, | ||
stdout=subprocess.PIPE, | ||
) | ||
return gpg.communicate(data.encode('ascii'))[0] | ||
|
||
def test_user_key(self): | ||
"""Returns the right ID for the given email address""" | ||
|
||
assert self.zeyple._user_key('[email protected]') is None | ||
|
||
user_key = self.zeyple._user_key('[email protected]') | ||
assert user_key == LINUS_ID | ||
user_key = self.zeyple._user_key(TEST1_EMAIL) | ||
assert user_key == TEST1_ID | ||
|
||
def test_encrypt_with_plain_text(self): | ||
"""Encrypts plain text""" | ||
|
||
encrypted = self.zeyple._encrypt( | ||
'The key is under the carpet.', [LINUS_ID] | ||
encrypted = self.zeyple.encrypt( | ||
'The key is under the carpet.', [TEST1_ID] | ||
) | ||
assert is_encrypted(encrypted) | ||
|
||
def test_encrypt_with_unicode(self): | ||
"""Encrypts Unicode text""" | ||
|
||
encrypted = self.zeyple._encrypt('héhé', [LINUS_ID]) | ||
encrypted = self.zeyple.encrypt('héhé', [TEST1_ID]) | ||
assert is_encrypted(encrypted) | ||
|
||
def test_process_message_with_simple_message(self): | ||
|
@@ -58,14 +93,14 @@ def test_process_message_with_simple_message(self): | |
emails = self.zeyple.process_message(dedent("""\ | ||
Received: by example.org (Postfix, from userid 0) | ||
id DD3B67981178; Thu, 6 Sep 2012 23:35:37 +0000 (UTC) | ||
To: [email protected] | ||
To: """ + TEST1_EMAIL + """ | ||
Subject: Hello with Unicode héüøœ©ßð®å¥¹²æ¿áßö«ç | ||
Message-Id: <[email protected]> | ||
Date: Thu, 6 Sep 2012 23:35:37 +0000 (UTC) | ||
From: [email protected] (root) | ||
|
||
test ðßïð | ||
"""), ["[email protected]"]) | ||
"""), [TEST1_EMAIL]) | ||
|
||
assert emails[0]['X-Zeyple'] is not None | ||
assert is_encrypted(emails[0].get_payload().encode('utf-8')) | ||
|
@@ -78,7 +113,7 @@ def test_process_message_with_multipart_message(self): | |
Received: by example.org (Postfix, from userid 0) | ||
id CE9876C78258; Sat, 8 Sep 2012 13:00:18 +0000 (UTC) | ||
Date: Sat, 08 Sep 2012 13:00:18 +0000 | ||
To: [email protected] | ||
To: """ + TEST1_EMAIL + """ | ||
Subject: test | ||
User-Agent: Heirloom mailx 12.4 7/29/08 | ||
MIME-Version: 1.0 | ||
|
@@ -106,10 +141,32 @@ def test_process_message_with_multipart_message(self): | |
Yy90ZXN0JyB3d3ctZGF0YQo= | ||
|
||
--=_504b4162.Gyt30puFsMOHWjpCATT1XRbWoYI1iR/sT4UX78zEEMJbxu+h-- | ||
"""), ["[email protected]"]) | ||
"""), [TEST1_EMAIL]) | ||
|
||
assert emails[0]['X-Zeyple'] is not None | ||
assert emails[0].is_multipart() | ||
for part in emails[0].walk(): | ||
assert not is_encrypted(part.as_string().encode('utf-8')) | ||
assert not emails[0].is_multipart() # GPG encrypt the multipart | ||
assert is_encrypted(emails[0].get_payload().encode('utf-8')) | ||
|
||
def test_process_message_with_multiple_recipients(self): | ||
"""Encrypt a message with multiple recipients""" | ||
|
||
content = "Content" | ||
|
||
emails = self.zeyple.process_message(dedent("""\ | ||
Received: by example.org (Postfix, from userid 0) | ||
id DD3B67981178; Thu, 6 Sep 2012 23:35:37 +0000 (UTC) | ||
To: """ + ', '.join([TEST1_EMAIL, TEST2_EMAIL]) + """ | ||
Subject: もしもし with Unicode | ||
Message-Id: <[email protected]> | ||
Date: Thu, 6 Sep 2012 23:35:37 +0000 (UTC) | ||
From: [email protected] (root) | ||
|
||
""" + content + """ | ||
"""), [TEST1_EMAIL, TEST2_EMAIL]) | ||
|
||
assert len(emails) == 2 # It had two recipients | ||
|
||
for m in emails: | ||
assert m['X-Zeyple'] is not None | ||
payload = self.decrypt(m.get_payload()).strip() | ||
assert payload == six.b(content) | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be great to replace
assert is_encrypted(...)
withassert self.decrypt(...) == plain_text_content
for all tests now that we have a way to decrypt messages.is_encrypted()
was to make sure the email was actually encrypted but if we could both check that it is encrypted and properly decryptable, it's even better. Thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right know,
self.decrypt
doesn't play well with non-ascii characters, and I haven't tried to figure it out yet. This is why the test I wrote use ascii characters for now. But yeah, that sounds like the right way to go. I added it to the todolist of this pull request.