blob: 425f4e655210f4c456a4196f338e7ea2de1cfb70 [file] [log] [blame]
Jean-Paul Calderone65627a22014-03-25 20:58:30 -04001
2"""
3Unit tests for :py:obj:`OpenSSL.tsafe`.
4"""
5
6from OpenSSL import tsafe
7from OpenSSL.SSL import SSLv2_METHOD, SSLv3_METHOD, SSLv23_METHOD, TLSv1_METHOD
8from OpenSSL.SSL import Context
9from OpenSSL.test.util import TestCase, bytes, b
10from OpenSSL.test.test_ssl import _create_certificate_chain
11
12
13class ConnectionTest(TestCase):
14 """
15 Unit tests for :py:obj:`OpenSSL.tsafe.Connection`.
16 """
17
18 def test_instantiating_works_under_all_supported_Python_versions(self):
19 """
20 At least one library (namely `Werkzeug`_) is instantiating
21 :py:obj:`Connection` directly which previously did not work under
22 Python 3 (Bug #1211834: Python 3 Code Uses "apply" function).
23
24 .. _Werkzeug: http://werkzeug.pocoo.org
25 """
26 chain = _create_certificate_chain()
27 [(_, _), (ikey, icert), (skey, scert)] = chain
28
29 # Create the server context
30 ctx = Context(TLSv1_METHOD)
31 ctx.use_privatekey(skey)
32 ctx.use_certificate(scert)
33
34 # The following line should not throw an error
35 socket = tsafe.Connection(ctx, None)