Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
In the tests, always initialize GnuPG object in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
micahflee committed Mar 16, 2017
1 parent 8bc2af3 commit 0d5a878
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions test/gnupg_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,48 @@
from .test_helpers import *

def test_gpg_is_available():
gpg = GnuPG()
gpg = GnuPG(debug=True)
assert gpg.is_gpg_available()

def test_gpg_recv_key():
def test_gpg_recv_key(debug=True):
gpg = GnuPG()
gpg.recv_key(b'hkp://keys.gnupg.net', test_key_fp, False, None, None)
assert gpg.get_uid(test_key_fp) == 'GPG Sync Unit Test Key (not secure in any way)'

@raises(InvalidKeyserver)
def test_gpg_recv_key_invalid_keyserver():
gpg = GnuPG()
gpg = GnuPG(debug=True)
gpg.recv_key(b'hkp://fakekeyserver', test_key_fp, False, None, None)

@raises(NotFoundOnKeyserver)
def test_gpg_recv_key_not_found_on_keyserver():
gpg = GnuPG()
gpg = GnuPG(debug=True)
gpg.recv_key(b'hkp://keys.gnupg.net', b'0000000000000000000000000000000000000000', False, None, None)

@raises(InvalidFingerprint)
def test_gpg_test_key_invalid_fingerprint():
gpg = GnuPG()
gpg = GnuPG(debug=True)
gpg.test_key(b'deadbeef')

@raises(NotFoundInKeyring)
def test_gpg_test_key_not_found_in_keyring():
gpg = GnuPG()
gpg = GnuPG(debug=True)
gpg.test_key(b'0000000000000000000000000000000000000000')

@raises(RevokedKey)
def test_gpg_test_key_revoked():
gpg = GnuPG()
gpg = GnuPG(debug=True)
import_key('revoked_pubkey.asc', gpg.homedir)
gpg.test_key(b'79358BDE97F831D6027B8FFBDB2F866200EBDDE9')

@raises(ExpiredKey)
def test_gpg_test_key_expired():
gpg = GnuPG()
gpg = GnuPG(debug=True)
import_key('expired_pubkey.asc', gpg.homedir)
gpg.test_key(b'30996DFF545AD6A02462639624C6564F385E35F8')

def test_gpg_get_uid():
gpg = GnuPG()
gpg = GnuPG(debug=True)
import_key('pgpsync_multiple_uids.asc', gpg.homedir)
import_key('gpgsync_test_pubkey.asc', gpg.homedir)

Expand All @@ -59,7 +59,7 @@ def test_gpg_get_uid():

def test_gpg_verify():
# test a message that works to verify
gpg = GnuPG()
gpg = GnuPG(debug=True)
import_key('gpgsync_test_pubkey.asc', gpg.homedir)
msg = open(get_gpg_file('signed_message-valid.txt'), 'rb').read()
msg_sig = open(get_gpg_file('signed_message-valid.txt.sig'), 'rb').read()
Expand All @@ -68,39 +68,39 @@ def test_gpg_verify():
@raises(BadSignature)
def test_gpg_verify_invalid_sig():
# test a message with an invalid sig
gpg = GnuPG()
gpg = GnuPG(debug=True)
import_key('gpgsync_test_pubkey.asc', gpg.homedir)
msg = open(get_gpg_file('signed_message-invalid.txt'), 'rb').read()
msg_sig = open(get_gpg_file('signed_message-invalid.txt.sig'), 'rb').read()
gpg.verify(msg_sig, msg, b'3B72C32B49CBB5BBDD57440E1D07D43448FB8382')

@raises(RevokedKey)
def test_gpg_verify_revoked():
gpg = GnuPG()
gpg = GnuPG(debug=True)
import_key('revoked_pubkey.asc', gpg.homedir)
msg = open(get_gpg_file('signed_message-revoked.txt'), 'rb').read()
msg_sig = open(get_gpg_file('signed_message-revoked.txt.sig'), 'rb').read()
gpg.verify(msg_sig, msg, b'79358BDE97F831D6027B8FFBDB2F866200EBDDE9')

@raises(ExpiredKey)
def test_gpg_verify_expired():
gpg = GnuPG()
gpg = GnuPG(debug=True)
import_key('expired_pubkey.asc', gpg.homedir)
msg = open(get_gpg_file('signed_message-expired.txt'), 'rb').read()
msg_sig = open(get_gpg_file('signed_message-expired.txt.sig'), 'rb').read()
gpg.verify(msg_sig, msg, b'30996DFF545AD6A02462639624C6564F385E35F8')

@raises(SignedWithWrongKey)
def test_gpg_verify_wrong_key():
gpg = GnuPG()
gpg = GnuPG(debug=True)
import_key('gpgsync_test_pubkey.asc', gpg.homedir)
import_key('pgpsync_multiple_uids.asc', gpg.homedir)
msg = open(get_gpg_file('signed_message-valid.txt'), 'rb').read()
msg_sig = open(get_gpg_file('signed_message-valid.txt.sig'), 'rb').read()
gpg.verify(msg_sig, msg, b'D86B4D4BB5DFDD378B58D4D3F121AC6230396C33')

def test_gpg_list_all_keyids():
gpg = GnuPG()
gpg = GnuPG(debug=True)

import_key('gpgsync_test_pubkey.asc', gpg.homedir)
key1_fp = common.clean_fp(b'3B72C32B49CBB5BBDD57440E1D07D43448FB8382')
Expand All @@ -113,7 +113,7 @@ def test_gpg_list_all_keyids():

def test_gpg_export_pubkey_to_disk():
appdata = tempfile.TemporaryDirectory()
gpg = GnuPG(appdata_path=appdata.name)
gpg = GnuPG(appdata_path=appdata.name, debug=True)

fp = b'3B72C32B49CBB5BBDD57440E1D07D43448FB8382'
filename = gpg.get_pubkey_filename_on_disk(fp)
Expand All @@ -133,7 +133,7 @@ def test_gpg_export_pubkey_to_disk():

def test_gpg_import_pubkey_from_disk():
appdata = tempfile.TemporaryDirectory()
gpg = GnuPG(appdata_path=appdata.name)
gpg = GnuPG(appdata_path=appdata.name, debug=True)

fp = b'3B72C32B49CBB5BBDD57440E1D07D43448FB8382'
filename = gpg.get_pubkey_filename_on_disk(fp)
Expand All @@ -153,7 +153,7 @@ def test_gpg_import_pubkey_from_disk():

def test_gpg_delete_pubkey_from_disk():
appdata = tempfile.TemporaryDirectory()
gpg = GnuPG(appdata_path=appdata.name)
gpg = GnuPG(appdata_path=appdata.name, debug=True)

fp = b'3B72C32B49CBB5BBDD57440E1D07D43448FB8382'
filename = gpg.get_pubkey_filename_on_disk(fp)
Expand Down

0 comments on commit 0d5a878

Please sign in to comment.