diff options
-rw-r--r-- | bcrypt/__init__.py | 11 | ||||
-rw-r--r-- | tests/test_bcrypt.py | 5 |
2 files changed, 16 insertions, 0 deletions
diff --git a/bcrypt/__init__.py b/bcrypt/__init__.py index bae9c35..8e871f8 100644 --- a/bcrypt/__init__.py +++ b/bcrypt/__init__.py @@ -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) diff --git a/tests/test_bcrypt.py b/tests/test_bcrypt.py index 8e6ff19..bb32299 100644 --- a/tests/test_bcrypt.py +++ b/tests/test_bcrypt.py @@ -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) |