Merge pull request #26 from dstufft/disable-implicit-compile
Disable the ability to implicitly compile the CFFI module
This commit is contained in:
commit
2085c39004
@ -53,6 +53,13 @@ def _create_modulename(cdef_sources, source, sys_version):
|
||||
return '_bcrypt_cffi_{0}{1}'.format(k1, k2)
|
||||
|
||||
|
||||
def _compile_module(*args, **kwargs):
|
||||
raise RuntimeError(
|
||||
"Attempted implicit compile of a cffi module. All cffi modules should "
|
||||
"be pre-compiled at installation time."
|
||||
)
|
||||
|
||||
|
||||
class LazyLibrary(object):
|
||||
def __init__(self, ffi):
|
||||
self._ffi = ffi
|
||||
@ -106,6 +113,10 @@ _ffi.verifier = Verifier(
|
||||
modulename=_create_modulename(CDEF, SOURCE, sys.version),
|
||||
)
|
||||
|
||||
# Patch the Verifier() instance to prevent CFFI from compiling the module
|
||||
_ffi.verifier.compile_module = _compile_module
|
||||
_ffi.verifier._compile_module = _compile_module
|
||||
|
||||
|
||||
_bcrypt_lib = LazyLibrary(_ffi)
|
||||
|
||||
|
||||
@ -9,6 +9,11 @@ import six
|
||||
import bcrypt
|
||||
|
||||
|
||||
def test_raise_implicit_compile():
|
||||
with pytest.raises(RuntimeError):
|
||||
bcrypt._compile_module()
|
||||
|
||||
|
||||
def test_gensalt_basic(monkeypatch):
|
||||
urandom = mock.Mock(return_value=b"0000000000000000")
|
||||
monkeypatch.setattr(os, "urandom", urandom)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user