diff options
author | Donald Stufft <donald@stufft.io> | 2014-12-05 23:14:42 -0500 |
---|---|---|
committer | Donald Stufft <donald@stufft.io> | 2014-12-05 23:14:42 -0500 |
commit | 595b2f501411947f96606714645d2bf4f849704a (patch) | |
tree | e8086256ab9b93166d1b1d8652009116547dfd9a | |
parent | 8604f11bb82bb9b7632d16e42614c4bbc290b773 (diff) | |
download | py-bcrypt-git-595b2f501411947f96606714645d2bf4f849704a.tar.gz |
Disable the ability to implicitly compile the CFFI module
-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) |