Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Check for OpenSSL.crypto when detecting OpenSSL. #191

Merged
merged 1 commit into from
May 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions oauth2client/crypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ def _TryOpenSslImport():

"""
try:
_ = imp.find_module('OpenSSL')
_, _package_dir, _ = imp.find_module('OpenSSL')
if not (os.path.isfile(os.path.join(_package_dir, 'crypto.py')) or
os.path.isfile(os.path.join(_package_dir, 'crypto.so')) or
os.path.isdir(os.path.join(_package_dir, 'crypto'))):
raise ImportError('No module named OpenSSL.crypto')

This comment was marked as spam.

This comment was marked as spam.

return
except ImportError:
import OpenSSL
import OpenSSL.crypto


try:
Expand Down
29 changes: 28 additions & 1 deletion tests/test_crypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,34 @@ def find_module(module_name):
finally:
sys.path = orig_sys_path
imp.find_module = imp_find_module
import OpenSSL
import OpenSSL.crypto
reload(crypt)

def test_without_openssl_crypto(self):
import imp
imp_find_module = imp.find_module
orig_sys_path = sys.path
orig_isfile = os.path.isfile
openssl_module = imp.find_module('OpenSSL')
def find_module(module_name):
if module_name == 'OpenSSL':
return openssl_module
raise ImportError('No module named %s' % module_name)
try:
for m in list(sys.modules):
if m.startswith('OpenSSL'):
sys.modules.pop(m)
sys.path = []
imp.find_module = find_module
os.path.isfile = lambda filename: False
reload(crypt)
self.assertRaises(NotImplementedError, crypt.pkcs12_key_as_pem,
'FOO', 'BAR')
finally:
sys.path = orig_sys_path
imp.find_module = imp_find_module
os.path.isfile = orig_isfile
import OpenSSL.crypto
reload(crypt)

def test_with_nonsense_key(self):
Expand Down