diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2015-07-03 03:52:39 -0400 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2015-07-03 03:52:39 -0400 |
commit | 53a36a1f8cd7c6bf243d5a5ad5522b0a592bba3d (patch) | |
tree | 6e8ec078cf59bd7d7ea2f94747aba82175298688 /tests/hazmat/bindings/test_openssl.py | |
parent | f5a4519f7ead73cbca826f3d7c815dd8963efb0a (diff) | |
parent | 23cafe861f4da2d7261a41bc57801b226e6b8c1b (diff) | |
download | cryptography-53a36a1f8cd7c6bf243d5a5ad5522b0a592bba3d.tar.gz cryptography-53a36a1f8cd7c6bf243d5a5ad5522b0a592bba3d.tar.bz2 cryptography-53a36a1f8cd7c6bf243d5a5ad5522b0a592bba3d.zip |
Merge branch 'master' into encode-san
Diffstat (limited to 'tests/hazmat/bindings/test_openssl.py')
-rw-r--r-- | tests/hazmat/bindings/test_openssl.py | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py index e6d6fc45..f3f2eaf4 100644 --- a/tests/hazmat/bindings/test_openssl.py +++ b/tests/hazmat/bindings/test_openssl.py @@ -4,11 +4,27 @@ from __future__ import absolute_import, division, print_function +import os + import pytest from cryptography.hazmat.bindings.openssl.binding import Binding +def skip_if_libre_ssl(openssl_version): + if b'LibreSSL' in openssl_version: + pytest.skip("LibreSSL hard-codes RAND_bytes to use arc4random.") + + +class TestLibreSkip(object): + def test_skip_no(self): + assert skip_if_libre_ssl(b"OpenSSL 0.9.8zf 19 Mar 2015") is None + + def test_skip_yes(self): + with pytest.raises(pytest.skip.Exception): + skip_if_libre_ssl(b"LibreSSL 2.1.6") + + class TestOpenSSL(object): def test_binding_loads(self): binding = Binding() @@ -89,8 +105,22 @@ class TestOpenSSL(object): def test_add_engine_more_than_once(self): b = Binding() - res = b.lib.Cryptography_add_osrandom_engine() - assert res == 2 + with pytest.raises(RuntimeError): + b._register_osrandom_engine() + + def test_actual_osrandom_bytes(self, monkeypatch): + b = Binding() + skip_if_libre_ssl(b.ffi.string(b.lib.OPENSSL_VERSION_TEXT)) + sample_data = (b"\x01\x02\x03\x04" * 4) + length = len(sample_data) + + def notrandom(size): + assert size == length + return sample_data + monkeypatch.setattr(os, "urandom", notrandom) + buf = b.ffi.new("char[]", length) + b.lib.RAND_bytes(buf, length) + assert b.ffi.buffer(buf)[0:length] == sample_data def test_ssl_ctx_options(self): # Test that we're properly handling 32-bit unsigned on all platforms. |