From b41d1f448cd44753387f3145a34cc6533e92835b Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Thu, 17 Apr 2014 16:02:04 -0400 Subject: Add a test for the False case of Cryptography_HAS_EC. --- OpenSSL/test/test_ssl.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/OpenSSL/test/test_ssl.py b/OpenSSL/test/test_ssl.py index ca896d9..b4f81b4 100644 --- a/OpenSSL/test/test_ssl.py +++ b/OpenSSL/test/test_ssl.py @@ -21,6 +21,7 @@ from OpenSSL.crypto import PKey, X509, X509Extension, X509Store from OpenSSL.crypto import dump_privatekey, load_privatekey from OpenSSL.crypto import dump_certificate, load_certificate +from OpenSSL.SSL import _lib from OpenSSL.SSL import OPENSSL_VERSION_NUMBER, SSLEAY_VERSION, SSLEAY_CFLAGS from OpenSSL.SSL import SSLEAY_PLATFORM, SSLEAY_DIR, SSLEAY_BUILT_ON from OpenSSL.SSL import SENT_SHUTDOWN, RECEIVED_SHUTDOWN @@ -1185,6 +1186,23 @@ class ContextTests(TestCase, _LoopbackMixin): context.set_tmp_ecdh_curve(curve) # Must not throw. + def test_set_tmp_ecdh_curve_not_available(self): + """ + :py:obj:`Context.set_tmp_ecdh_curve` raises :py:obj:`ECNotAvailable` if + elliptic curve support is not available from the underlying OpenSSL + version at all. + """ + self.addCleanup( + setattr, + _lib, "Cryptography_HAS_EC", _lib.Cryptography_HAS_EC) + _lib.Cryptography_HAS_EC = False + + context = Context(TLSv1_METHOD) + self.assertRaises( + ECNotAvailable, + context.set_tmp_ecdh_curve, next(iter(ELLIPTIC_CURVE_DESCRIPTIONS))) + + def test_set_tmp_ecdh_curve_bad_sn(self): """ :py:obj:`Context.set_tmp_ecdh_curve` raises -- cgit v1.2.1