From 07de62c1ecf9c202a45a5c49b280c1df4eb3f685 Mon Sep 17 00:00:00 2001 From: David Reid Date: Fri, 13 Jun 2014 10:23:33 -0700 Subject: Attempt to better isolate this test by getting the backend name from a subprocess. --- tests/hazmat/backends/test_openssl.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'tests/hazmat/backends') diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index aa2122fb..09a7f0a5 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 sys +import subprocess +import textwrap + import pretend import pytest @@ -215,11 +219,29 @@ class TestOpenSSLRandomEngine(object): # 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 + engine_name = subprocess.check_output( + [sys.executable, + "-c", + 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)) + res = backend._lib.ENGINE_free(e) + assert res == 1 + """ + ) + ] + ) + + osrandom_engine_name = backend._ffi.string( + backend._lib.Cryptography_osrandom_engine_name + ) + + assert engine_name == osrandom_engine_name def test_osrandom_sanity_check(self): # This test serves as a check against catastrophic failure. -- cgit v1.2.3 From 3ad768f7af9aa5cecbfec210f7fde5578672a5a3 Mon Sep 17 00:00:00 2001 From: David Reid Date: Fri, 13 Jun 2014 10:33:32 -0700 Subject: Fix flake8. --- tests/hazmat/backends/test_openssl.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'tests/hazmat/backends') diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index 09a7f0a5..420baf6b 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -13,8 +13,8 @@ from __future__ import absolute_import, division, print_function -import sys import subprocess +import sys import textwrap import pretend @@ -219,22 +219,21 @@ class TestOpenSSLRandomEngine(object): # 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): + 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)) + res = backend._lib.ENGINE_free(e) + assert res == 1 + """ + ) + engine_name = subprocess.check_output( - [sys.executable, - "-c", - 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)) - res = backend._lib.ENGINE_free(e) - assert res == 1 - """ - ) - ] + [sys.executable, "-c", engine_printer] ) osrandom_engine_name = backend._ffi.string( -- cgit v1.2.3 From 1d20fc0cc77ae4e5da6bca1b8ac5396cb4c011ea Mon Sep 17 00:00:00 2001 From: David Reid Date: Fri, 13 Jun 2014 10:33:48 -0700 Subject: Remove outdated comment. --- tests/hazmat/backends/test_openssl.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests/hazmat/backends') diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index 420baf6b..2d953597 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -216,8 +216,6 @@ 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): engine_printer = textwrap.dedent( """ -- cgit v1.2.3 From fea104bc505baf2a648d37f7da9ab48d1a5212a0 Mon Sep 17 00:00:00 2001 From: David Reid Date: Fri, 13 Jun 2014 11:18:02 -0700 Subject: Portable usage of subprocess w/ python3 and python2.6 fixes. --- tests/hazmat/backends/test_openssl.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'tests/hazmat/backends') diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index 2d953597..75369efc 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -216,7 +216,7 @@ class TestOpenSSLRandomEngine(object): name = backend._lib.ENGINE_get_name(current_default) assert name == backend._lib.Cryptography_osrandom_engine_name - def test_osrandom_engine_is_default(self): + def test_osrandom_engine_is_default(self, tmpdir): engine_printer = textwrap.dedent( """ import sys @@ -224,21 +224,24 @@ class TestOpenSSLRandomEngine(object): e = backend._lib.ENGINE_get_default_RAND() name = backend._lib.ENGINE_get_name(e) - sys.stdout.write(backend._ffi.string(name)) + sys.stdout.write(backend._ffi.string(name).decode('ascii')) res = backend._lib.ENGINE_free(e) assert res == 1 """ ) + engine_name = tmpdir.join('engine_name') - engine_name = subprocess.check_output( - [sys.executable, "-c", engine_printer] - ) + 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 == 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. -- cgit v1.2.3