summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Paul Calderone <exarkun@twistedmatrix.com>2014-01-11 05:29:44 -0800
committerJean-Paul Calderone <exarkun@twistedmatrix.com>2014-01-11 05:29:44 -0800
commit9efd9c6d5819203fbae65e7d5cd2824f5337b865 (patch)
tree37b44f1f71876c4574fca81d5147e229e2027c5b
parent73f93130e3a49a81e500e80749ad61a2f78744cd (diff)
parentd4033eb5b39a7e1cf59a0aaa0cdc380d4b725a99 (diff)
downloadpyopenssl-9efd9c6d5819203fbae65e7d5cd2824f5337b865.tar.gz
Merge pull request #5 from pyca/pypy-fixes
Some changes to make the test suite green on PyPy This adds some missing initialization that is actually necessary to work on PyPy (whereas it is only necessary to work on CPython sometimes). It also adjusts some garbage collector interactions in one test to satisfy PyPy's somewhat different garbage collection requirements.
-rw-r--r--OpenSSL/crypto.py11
-rw-r--r--OpenSSL/test/test_ssl.py16
2 files changed, 25 insertions, 2 deletions
diff --git a/OpenSSL/crypto.py b/OpenSSL/crypto.py
index c2180d0..103deab 100644
--- a/OpenSSL/crypto.py
+++ b/OpenSSL/crypto.py
@@ -2257,3 +2257,14 @@ except ImportError:
else:
_initialize_openssl_threads(get_ident, Lock)
del get_ident, Lock
+
+# There are no direct unit tests for this initialization. It is tested
+# indirectly since it is necessary for functions like dump_privatekey when
+# using encryption.
+#
+# Thus OpenSSL.test.test_crypto.FunctionTests.test_dump_privatekey_passphrase
+# and some other similar tests may fail without this (though they may not if
+# the Python runtime has already done some initialization of the underlying
+# OpenSSL library (and is linked against the same one that cryptography is
+# using)).
+_lib.OpenSSL_add_all_algorithms()
diff --git a/OpenSSL/test/test_ssl.py b/OpenSSL/test/test_ssl.py
index 881d409..ea4fceb 100644
--- a/OpenSSL/test/test_ssl.py
+++ b/OpenSSL/test/test_ssl.py
@@ -5,7 +5,7 @@
Unit tests for :py:obj:`OpenSSL.SSL`.
"""
-from gc import collect
+from gc import collect, get_referrers
from errno import ECONNREFUSED, EINPROGRESS, EWOULDBLOCK, EPIPE
from sys import platform, version_info
from socket import SHUT_RDWR, error, socket
@@ -1139,6 +1139,7 @@ class ServerNameCallbackTests(TestCase, _LoopbackMixin):
self.assertRaises(
TypeError, context.set_tlsext_servername_callback, 1, 2)
+
def test_old_callback_forgotten(self):
"""
If :py:obj:`Context.set_tlsext_servername_callback` is used to specify a new
@@ -1157,8 +1158,19 @@ class ServerNameCallbackTests(TestCase, _LoopbackMixin):
del callback
context.set_tlsext_servername_callback(replacement)
+
+ # One run of the garbage collector happens to work on CPython. PyPy
+ # doesn't collect the underlying object until a second run for whatever
+ # reason. That's fine, it still demonstrates our code has properly
+ # dropped the reference.
collect()
- self.assertIdentical(None, tracker())
+ collect()
+
+ callback = tracker()
+ if callback is not None:
+ referrers = get_referrers(callback)
+ if len(referrers) > 1:
+ self.fail("Some references remain: %r" % (referrers,))
def test_no_servername(self):