aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat/bindings/test_openssl.py
diff options
context:
space:
mode:
authorAlex Stapleton <alexs@prol.etari.at>2014-01-22 15:07:38 +0000
committerAlex Stapleton <alexs@prol.etari.at>2014-01-24 08:11:45 +0000
commit06649cf8bcd764c51c9ee819f43a5a0a29290a38 (patch)
tree71acf273f2c1617f281c154149bf4642546f5a95 /tests/hazmat/bindings/test_openssl.py
parent17ed58daa9573458157b02f822f5dc471d954298 (diff)
downloadcryptography-06649cf8bcd764c51c9ee819f43a5a0a29290a38.tar.gz
cryptography-06649cf8bcd764c51c9ee819f43a5a0a29290a38.tar.bz2
cryptography-06649cf8bcd764c51c9ee819f43a5a0a29290a38.zip
Also test the locking cb directly
Diffstat (limited to 'tests/hazmat/bindings/test_openssl.py')
-rw-r--r--tests/hazmat/bindings/test_openssl.py39
1 files changed, 20 insertions, 19 deletions
diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py
index b2264fb5..e5094133 100644
--- a/tests/hazmat/bindings/test_openssl.py
+++ b/tests/hazmat/bindings/test_openssl.py
@@ -47,43 +47,46 @@ class TestOpenSSL(object):
# check that the lock state changes appropriately
lock = b._locks[b.lib.CRYPTO_LOCK_SSL]
+ # starts out unlocked
assert lock.acquire(False)
-
lock.release()
b.lib.CRYPTO_lock(
b.lib.CRYPTO_LOCK | b.lib.CRYPTO_READ,
- b.lib.CRYPTO_LOCK_SSL,
- b.ffi.NULL,
- 0
+ b.lib.CRYPTO_LOCK_SSL, b.ffi.NULL, 0
)
+ # becomes locked
assert not lock.acquire(False)
b.lib.CRYPTO_lock(
b.lib.CRYPTO_UNLOCK | b.lib.CRYPTO_READ,
- b.lib.CRYPTO_LOCK_SSL,
- b.ffi.NULL,
- 0
+ b.lib.CRYPTO_LOCK_SSL, b.ffi.NULL, 0
)
+ # then unlocked
assert lock.acquire(False)
lock.release()
- # force the error path to run.
+ # then test directly
- b.lib.CRYPTO_lock(
- 0,
- b.lib.CRYPTO_LOCK_SSL,
- b.ffi.NULL,
- 0
- )
+ with pytest.raises(RuntimeError):
+ b._lock_cb(0, b.lib.CRYPTO_LOCK_SSL, "<test>", 1)
- lock.acquire(False)
+ # errors shouldnt cause locking
+ assert lock.acquire(False)
lock.release()
- out, err = capfd.readouterr()
- assert "RuntimeError: Unknown lock mode" in err
+ b._lock_cb(b.lib.CRYPTO_LOCK | b.lib.CRYPTO_READ,
+ b.lib.CRYPTO_LOCK_SSL, "<test>", 1)
+ # locked
+ assert not lock.acquire(False)
+
+ b._lock_cb(b.lib.CRYPTO_UNLOCK | b.lib.CRYPTO_READ,
+ b.lib.CRYPTO_LOCK_SSL, "<test>", 1)
+ # unlocked
+ assert lock.acquire(False)
+ lock.release()
def test_crypto_lock_mutex(self):
b = Binding()
@@ -119,9 +122,7 @@ class TestOpenSSL(object):
threads = []
for x in range(10):
t = threading.Thread(target=critical_loop)
- t.daemon = True
t.start()
-
threads.append(t)
while threads: