Jean-Paul Calderone | 65627a2 | 2014-03-25 20:58:30 -0400 | [diff] [blame^] | 1 | |
| 2 | """ |
| 3 | Unit tests for :py:obj:`OpenSSL.tsafe`. |
| 4 | """ |
| 5 | |
| 6 | from OpenSSL import tsafe |
| 7 | from OpenSSL.SSL import SSLv2_METHOD, SSLv3_METHOD, SSLv23_METHOD, TLSv1_METHOD |
| 8 | from OpenSSL.SSL import Context |
| 9 | from OpenSSL.test.util import TestCase, bytes, b |
| 10 | from OpenSSL.test.test_ssl import _create_certificate_chain |
| 11 | |
| 12 | |
| 13 | class 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) |