-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed missed & inaccurate tests, add tests for some legacy keys
- Loading branch information
Showing
1 changed file
with
90 additions
and
15 deletions.
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 |
---|---|---|
|
@@ -35,9 +35,63 @@ | |
|
||
from tiny_gnupg import GnuPG, run | ||
|
||
|
||
def pop(dictionary): | ||
return next(iter(dictionary)) | ||
legacy_key = """-----BEGIN PGP PUBLIC KEY BLOCK----- | ||
Version: OpenPGP.js v4.3.0 | ||
Comment: https://openpgpjs.org | ||
xsFNBFgXnNwBEADDvpflLPNrbYvxcNuCcGdTAjGmRLgZRhANvOuAqMd/vTID | ||
frdnzDx+fGBxiZvK97hkRxRZh5+E5fAXgDjkb+bepVbFhzGKa5yXAJgSkAMR | ||
3EPozkFnWlFhd1+TrNkGkS4k1IvB60TBnm0ppDo7oIINREFrYDg5orubngzW | ||
LPy67KZa9kRElZteLukrkdrZJZl/zAp/wxWzdklafgKJ8W3VbINiyaj8Pvsk | ||
utX3+s2VrMsDg5YRFkb1xpSP8q/ed7qZrhaENC26+SxE/9b40G+Y/Jn9dOzg | ||
9QI/xGp5OfCWd2FZ5MYimjmp9cyz+Yam+mlxHFOCE4RnnKP/xB5n/IdsWH46 | ||
E/DsC6Uec9rQM0MDtHQZGmS2EHo/JuDelhkgpOy6ZICL2BOgJW57vw3lQ6OO | ||
PuANpipHlpHRKa4B+iLpWbJdgr3B4S0oX0saARZkE61M48uRQM44ja7yDCza | ||
wQ3HmwC3xLDFKip9E+mn4dufooF4G7DWCs4HnLBMQsal5RKMo4bPd1mezh2l | ||
bdej/EXdBYF5lioqSTcHR4UTQzmje9fzJYTTW2z8o5wRrM8GqqcKOSnGF60k | ||
q1LjRVg1XL/BnR5j00OZhG23Qdl13W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Smoku3G | ||
jw7BklRbPnH6ZBuVXHNaq0PglDVILIyWYv66NYyZvSN0BbIYN+POVYaAZm/R | ||
AQ/U+KaSLIJkOjAgxc6PQDvxgIDl/jaeZE7UjOi+83MDsoks5hZgGO99lBoz | ||
9pXlthFPXDbOGfwCYspKeJseTT+QD6cASu63BI0mDHv6/toF3qxgmH0vw5sA | ||
0t9R3ZaSlr/fCSp/Ykj7pZPzhNNnzgh1apTi8qr/G2dMgqV+wbmYrb/Ulzyw | ||
+gbKqyFRxmxIfyxUVc9gOF50JV8ALjFmjAvUsrChmnTQxiXWCKPlc6ecvJKn | ||
VCcIf3clIQfiCfs76qEz9pW8LBANtuoBA8gxkRxNe1ia3Ljw | ||
=IoDL | ||
-----END PGP PUBLIC KEY BLOCK----- | ||
""" | ||
|
||
|
||
dev_signed_encrypted_message = """-----BEGIN PGP MESSAGE----- | ||
|
@@ -100,6 +154,10 @@ def gpg(): | |
print("teardown".center(18, "-")) | ||
|
||
|
||
def pop(dictionary): | ||
return next(iter(dictionary)) | ||
|
||
|
||
async def async_method_runner(gpg): | ||
assert gpg.Connector.__class__ == SocksConnector | ||
async with gpg.Session as session: | ||
|
@@ -384,13 +442,14 @@ def test_packet_parsing(gpg): | |
### | ||
assert key == key_from_signature | ||
assert key == key_from_signed_encrypted_message | ||
assert key != key_from_encrypted_message # anonymous message sender | ||
assert key == key_from_encrypted_message # better parsing finds fingerprint? | ||
assert key == key_from_gpg_key | ||
|
||
|
||
def test_auto_fetch_methods(gpg): | ||
message = "testing" | ||
keyserver_email = "[email protected]" | ||
test_fingerprint = "864C145731DD963466CC7571A2604867523C7ED8" | ||
dev_email = "[email protected]" | ||
dev_fingerprint = "31FDCC4F9961AFAC522A9D41AE2B47FA1EF44F0A" | ||
gpg.delete(dev_fingerprint) | ||
|
@@ -399,7 +458,12 @@ def test_auto_fetch_methods(gpg): | |
msg = run(gpg.auto_decrypt(dev_signed_message)) | ||
except Exception as exception: | ||
if exception.value == dev_fingerprint: | ||
"""Rate limited on the server""" | ||
""" | ||
Everything is OK. | ||
Our queries are just being blocked and rate limited on the | ||
server. If this exception doesn't proc, then everything is | ||
still OK, and we haven't been rate limited. | ||
""" | ||
pass | ||
else: | ||
raise LookupError( | ||
|
@@ -411,30 +475,41 @@ def test_auto_fetch_methods(gpg): | |
packets_0 = gpg.list_packets(dev_signed_encrypted_message) | ||
packets_1 = gpg.list_packets(dev_encrypted_message) | ||
packets_2 = gpg.list_packets(dev_signed_message) | ||
packets_3 = gpg.list_packets(legacy_key) | ||
packets_4 = gpg.list_packets(dev_key) | ||
assert type(packets_0) == list | ||
assert type(packets_1) == list | ||
assert type(packets_2) == list | ||
assert len(packets_0) >= 4 | ||
assert len(packets_1) >= 4 | ||
assert len(packets_2) >= 11 | ||
assert type(packets_3) == list | ||
assert type(packets_4) == list | ||
assert len(packets_0) == 4 | ||
assert len(packets_1) == 4 | ||
assert len(packets_2) == 11 | ||
assert len(packets_3) == 28 | ||
assert len(packets_4) == 31 | ||
try: | ||
gpg.list_packets(20*"Non-OpenPGP data") | ||
gpg.list_packets(20 * "Non-OpenPGP data") | ||
except: | ||
"""Successfully failed when invalid data sent for parsing""" | ||
### | ||
fingerprint_0 = gpg.packet_fingerprint(dev_signed_message) | ||
fingerprint_1 = gpg.packet_fingerprint(dev_signed_message) | ||
fingerprint_0 = gpg.packet_fingerprint(dev_signed_encrypted_message) | ||
fingerprint_1 = gpg.packet_fingerprint(dev_encrypted_message) | ||
fingerprint_2 = gpg.packet_fingerprint(dev_signed_message) | ||
fingerprint_3 = gpg.packet_fingerprint(dev_signed_message) | ||
fingerprint_3 = gpg.packet_fingerprint(legacy_key) | ||
fingerprint_4 = gpg.packet_fingerprint(dev_key) | ||
fingerprint_0_key = gpg.list_keys(fingerprint_0) | ||
fingerprint_1_key = gpg.list_keys(fingerprint_1) | ||
fingerprint_2_key = gpg.list_keys(fingerprint_2) | ||
fingerprint_3_key = gpg.list_keys(fingerprint_3) | ||
fingerprint_4_key = gpg.list_keys(fingerprint_4) | ||
key_from_fingerprint = gpg.list_keys(dev_fingerprint) | ||
assert fingerprint_0_key == key_from_fingerprint | ||
assert fingerprint_1_key == key_from_fingerprint | ||
key_from_test_fingerprint = gpg.list_keys(test_fingerprint) | ||
assert fingerprint_0_key == key_from_test_fingerprint | ||
assert fingerprint_1_key == key_from_test_fingerprint | ||
assert fingerprint_2_key == key_from_fingerprint | ||
assert fingerprint_3_key == key_from_fingerprint | ||
assert fingerprint_3_key != key_from_fingerprint | ||
assert fingerprint_3_key != key_from_test_fingerprint | ||
assert fingerprint_4_key == key_from_fingerprint | ||
### | ||
try: | ||
failed = False | ||
|