From 7c3e7a83f06b0ff8f0c27a4486eaa6448ba6485e Mon Sep 17 00:00:00 2001 From: Glyph Date: Mon, 29 Jun 2015 17:21:02 -0700 Subject: the output of RAND_bytes is os.urandom's result --- tests/hazmat/bindings/test_openssl.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py index 75a8e3f1..207fece9 100644 --- a/tests/hazmat/bindings/test_openssl.py +++ b/tests/hazmat/bindings/test_openssl.py @@ -4,6 +4,8 @@ from __future__ import absolute_import, division, print_function +import os + import pytest from cryptography.hazmat.bindings.openssl.binding import Binding @@ -92,6 +94,18 @@ class TestOpenSSL(object): with pytest.raises(RuntimeError): b._register_osrandom_engine() + def test_actual_osrandom_bytes(self, monkeypatch): + 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) + b = Binding() + 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. b = Binding() -- cgit v1.2.3