diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-06-14 08:28:34 -0500 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-06-14 08:28:34 -0500 |
commit | 12a4e0fd70476a3b54193a12aa760b100baaa019 (patch) | |
tree | ef3422f0946ed33b07f3d0726c070acf4e35f923 /tests/hazmat/backends | |
parent | c6d202ed4becfcad6c1aacc3e274e00f83352a40 (diff) | |
parent | fea104bc505baf2a648d37f7da9ab48d1a5212a0 (diff) | |
download | cryptography-12a4e0fd70476a3b54193a12aa760b100baaa019.tar.gz cryptography-12a4e0fd70476a3b54193a12aa760b100baaa019.tar.bz2 cryptography-12a4e0fd70476a3b54193a12aa760b100baaa019.zip |
Merge pull request #1130 from dreid/isolate-openssl-urandom-default
Attempt to better isolate this test by getting the backend name from a subprocess.
Diffstat (limited to 'tests/hazmat/backends')
-rw-r--r-- | tests/hazmat/backends/test_openssl.py | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index aa2122fb..75369efc 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -13,6 +13,10 @@ from __future__ import absolute_import, division, print_function +import subprocess +import sys +import textwrap + import pretend import pytest @@ -212,14 +216,32 @@ class TestOpenSSLRandomEngine(object): name = backend._lib.ENGINE_get_name(current_default) assert name == backend._lib.Cryptography_osrandom_engine_name - # This must be the first test in the class so that the teardown method - # has not (potentially) altered the default engine. - def test_osrandom_engine_is_default(self): - e = backend._lib.ENGINE_get_default_RAND() - name = backend._lib.ENGINE_get_name(e) - assert name == backend._lib.Cryptography_osrandom_engine_name - res = backend._lib.ENGINE_free(e) - assert res == 1 + def test_osrandom_engine_is_default(self, tmpdir): + engine_printer = textwrap.dedent( + """ + import sys + from cryptography.hazmat.backends.openssl.backend import backend + + e = backend._lib.ENGINE_get_default_RAND() + name = backend._lib.ENGINE_get_name(e) + sys.stdout.write(backend._ffi.string(name).decode('ascii')) + res = backend._lib.ENGINE_free(e) + assert res == 1 + """ + ) + engine_name = tmpdir.join('engine_name') + + with engine_name.open('w') as out: + subprocess.check_call( + [sys.executable, "-c", engine_printer], + stdout=out + ) + + osrandom_engine_name = backend._ffi.string( + backend._lib.Cryptography_osrandom_engine_name + ) + + assert engine_name.read().encode('ascii') == osrandom_engine_name def test_osrandom_sanity_check(self): # This test serves as a check against catastrophic failure. |