diff options
| author | Alex Gaynor <alex.gaynor@gmail.com> | 2015-09-05 15:34:33 -0400 |
|---|---|---|
| committer | Alex Gaynor <alex.gaynor@gmail.com> | 2015-09-05 15:34:33 -0400 |
| commit | 8a217590682985ab485b95259d7fc54ca12bb6e9 (patch) | |
| tree | d08285b1dcc5692c32a1e266a470b1273aad2274 /OpenSSL | |
| parent | 92ebd87d70d6c4c30271b7e76d26b08eb668defa (diff) | |
| parent | 8e94f1b853223380b93a16d25fbb030d3a121bf9 (diff) | |
| download | pyopenssl-8a217590682985ab485b95259d7fc54ca12bb6e9.tar.gz | |
Merge pull request #347 from hynek/more-test_ssl
More test ssl
Diffstat (limited to 'OpenSSL')
| -rw-r--r-- | OpenSSL/test/test_ssl.py | 168 |
1 files changed, 72 insertions, 96 deletions
diff --git a/OpenSSL/test/test_ssl.py b/OpenSSL/test/test_ssl.py index cb92020..b4c42af 100644 --- a/OpenSSL/test/test_ssl.py +++ b/OpenSSL/test/test_ssl.py @@ -7,7 +7,7 @@ Unit tests for :py:obj:`OpenSSL.SSL`. from gc import collect, get_referrers from errno import ECONNREFUSED, EINPROGRESS, EWOULDBLOCK, EPIPE, ESHUTDOWN -from sys import platform, getfilesystemencoding +from sys import platform, getfilesystemencoding, version_info from socket import MSG_PEEK, SHUT_RDWR, error, socket from os import makedirs from os.path import join @@ -100,6 +100,10 @@ MBYCEQCobsg29c9WZP/54oAPcwiDAgEC skip_if_py3 = pytest.mark.skipif(PY3, reason="Python 2 only") +skip_if_py26 = pytest.mark.skipif( + version_info[0:2] == (2, 6), + reason="Python 2.7 and later only" +) def join_bytes_or_unicode(prefix, suffix): @@ -2461,9 +2465,9 @@ class ConnectionTests(TestCase, _LoopbackMixin): def test_set_session_wrong_args(self): """ - If called with an object that is not an instance of :py:class:`Session`, - or with other than one argument, :py:obj:`Connection.set_session` raises - :py:obj:`TypeError`. + If called with an object that is not an instance of + :py:class:`Session`, or with other than one argument, + :py:obj:`Connection.set_session` raises :py:obj:`TypeError`. """ ctx = Context(TLSv1_METHOD) connection = Connection(ctx, None) @@ -2624,11 +2628,11 @@ class ConnectionTests(TestCase, _LoopbackMixin): def test_tls_finished_message_symmetry(self): """ - The TLS Finished message send by server must be the TLS Finished message - received by client. + The TLS Finished message send by server must be the TLS Finished + message received by client. - The TLS Finished message send by client must be the TLS Finished message - received by server. + The TLS Finished message send by client must be the TLS Finished + message received by server. """ server, client = self._loopback() @@ -2741,13 +2745,12 @@ class ConnectionGetCipherListTests(TestCase): """ def test_wrong_args(self): """ - :py:obj:`Connection.get_cipher_list` raises :py:obj:`TypeError` if called with any - arguments. + :py:obj:`Connection.get_cipher_list` raises :py:obj:`TypeError` if + called with any arguments. """ connection = Connection(Context(TLSv1_METHOD), None) self.assertRaises(TypeError, connection.get_cipher_list, None) - def test_result(self): """ :py:obj:`Connection.get_cipher_list` returns a :py:obj:`list` of @@ -2760,7 +2763,6 @@ class ConnectionGetCipherListTests(TestCase): self.assertTrue(isinstance(cipher, str)) - class ConnectionSendTests(TestCase, _LoopbackMixin): """ Tests for :py:obj:`Connection.send` @@ -2776,18 +2778,16 @@ class ConnectionSendTests(TestCase, _LoopbackMixin): self.assertRaises(TypeError, connection.send, object()) self.assertRaises(TypeError, connection.send, "foo", object(), "bar") - def test_short_bytes(self): """ - When passed a short byte string, :py:obj:`Connection.send` transmits all of it - and returns the number of bytes sent. + When passed a short byte string, :py:obj:`Connection.send` transmits + all of it and returns the number of bytes sent. """ server, client = self._loopback() count = server.send(b('xy')) self.assertEquals(count, 2) self.assertEquals(client.recv(2), b('xy')) - def test_text(self): """ When passed a text, :py:obj:`Connection.send` transmits all of it and @@ -2807,39 +2807,29 @@ class ConnectionSendTests(TestCase, _LoopbackMixin): self.assertEquals(count, 2) self.assertEquals(client.recv(2), b"xy") - try: - memoryview - except NameError: - "cannot test sending memoryview without memoryview" - else: - def test_short_memoryview(self): - """ - When passed a memoryview onto a small number of bytes, - :py:obj:`Connection.send` transmits all of them and returns the number of - bytes sent. - """ - server, client = self._loopback() - count = server.send(memoryview(b('xy'))) - self.assertEquals(count, 2) - self.assertEquals(client.recv(2), b('xy')) - - - try: - buffer - except NameError: - "cannot test sending buffer without buffer" - else: - def test_short_buffer(self): - """ - When passed a buffer containing a small number of bytes, - :py:obj:`Connection.send` transmits all of them and returns the number of - bytes sent. - """ - server, client = self._loopback() - count = server.send(buffer(b('xy'))) - self.assertEquals(count, 2) - self.assertEquals(client.recv(2), b('xy')) + @skip_if_py26 + def test_short_memoryview(self): + """ + When passed a memoryview onto a small number of bytes, + :py:obj:`Connection.send` transmits all of them and returns the number + of bytes sent. + """ + server, client = self._loopback() + count = server.send(memoryview(b('xy'))) + self.assertEquals(count, 2) + self.assertEquals(client.recv(2), b('xy')) + @skip_if_py3 + def test_short_buffer(self): + """ + When passed a buffer containing a small number of bytes, + :py:obj:`Connection.send` transmits all of them and returns the number + of bytes sent. + """ + server, client = self._loopback() + count = server.send(buffer(b('xy'))) + self.assertEquals(count, 2) + self.assertEquals(client.recv(2), b('xy')) def _make_memoryview(size): @@ -2850,7 +2840,6 @@ def _make_memoryview(size): return memoryview(bytearray(size)) - class ConnectionRecvIntoTests(TestCase, _LoopbackMixin): """ Tests for :py:obj:`Connection.recv_into` @@ -2869,7 +2858,6 @@ class ConnectionRecvIntoTests(TestCase, _LoopbackMixin): self.assertEqual(client.recv_into(output_buffer), 2) self.assertEqual(output_buffer, bytearray(b('xy\x00\x00\x00'))) - def test_bytearray_no_length(self): """ :py:obj:`Connection.recv_into` can be passed a ``bytearray`` instance @@ -2877,7 +2865,6 @@ class ConnectionRecvIntoTests(TestCase, _LoopbackMixin): """ self._no_length_test(bytearray) - def _respects_length_test(self, factory): """ Assert that when the given buffer is passed to ``Connection.recv_into`` @@ -2894,7 +2881,6 @@ class ConnectionRecvIntoTests(TestCase, _LoopbackMixin): output_buffer, bytearray(b('abcde\x00\x00\x00\x00\x00')) ) - def test_bytearray_respects_length(self): """ When called with a ``bytearray`` instance, @@ -2903,7 +2889,6 @@ class ConnectionRecvIntoTests(TestCase, _LoopbackMixin): """ self._respects_length_test(bytearray) - def _doesnt_overfill_test(self, factory): """ Assert that if there are more bytes available to be read from the @@ -2921,7 +2906,6 @@ class ConnectionRecvIntoTests(TestCase, _LoopbackMixin): rest = client.recv(5) self.assertEqual(b('fghij'), rest) - def test_bytearray_doesnt_overfill(self): """ When called with a ``bytearray`` instance, @@ -2930,7 +2914,6 @@ class ConnectionRecvIntoTests(TestCase, _LoopbackMixin): """ self._doesnt_overfill_test(bytearray) - def _really_doesnt_overfill_test(self, factory): """ Assert that if the value given by ``nbytes`` is greater than the actual @@ -2947,7 +2930,6 @@ class ConnectionRecvIntoTests(TestCase, _LoopbackMixin): rest = client.recv(5) self.assertEqual(b('fghij'), rest) - def test_bytearray_really_doesnt_overfill(self): """ When called with a ``bytearray`` instance and an ``nbytes`` value that @@ -2957,7 +2939,6 @@ class ConnectionRecvIntoTests(TestCase, _LoopbackMixin): """ self._doesnt_overfill_test(bytearray) - def test_peek(self): server, client = self._loopback() @@ -2965,50 +2946,45 @@ class ConnectionRecvIntoTests(TestCase, _LoopbackMixin): for _ in range(2): output_buffer = bytearray(5) - self.assertEqual(client.recv_into(output_buffer, flags=MSG_PEEK), 2) + self.assertEqual( + client.recv_into(output_buffer, flags=MSG_PEEK), 2) self.assertEqual(output_buffer, bytearray(b('xy\x00\x00\x00'))) + @skip_if_py26 + def test_memoryview_no_length(self): + """ + :py:obj:`Connection.recv_into` can be passed a ``memoryview`` + instance and data in the receive buffer is written to it. + """ + self._no_length_test(_make_memoryview) - try: - memoryview - except NameError: - "cannot test recv_into memoryview without memoryview" - else: - def test_memoryview_no_length(self): - """ - :py:obj:`Connection.recv_into` can be passed a ``memoryview`` - instance and data in the receive buffer is written to it. - """ - self._no_length_test(_make_memoryview) - - - def test_memoryview_respects_length(self): - """ - When called with a ``memoryview`` instance, - :py:obj:`Connection.recv_into` respects the ``nbytes`` parameter - and doesn't copy more than that number of bytes in. - """ - self._respects_length_test(_make_memoryview) - - - def test_memoryview_doesnt_overfill(self): - """ - When called with a ``memoryview`` instance, - :py:obj:`Connection.recv_into` respects the size of the array and - doesn't write more bytes into it than will fit. - """ - self._doesnt_overfill_test(_make_memoryview) - + @skip_if_py26 + def test_memoryview_respects_length(self): + """ + When called with a ``memoryview`` instance, + :py:obj:`Connection.recv_into` respects the ``nbytes`` parameter + and doesn't copy more than that number of bytes in. + """ + self._respects_length_test(_make_memoryview) - def test_memoryview_really_doesnt_overfill(self): - """ - When called with a ``memoryview`` instance and an ``nbytes`` value - that is too large, :py:obj:`Connection.recv_into` respects the size - of the array and not the ``nbytes`` value and doesn't write more - bytes into the buffer than will fit. - """ - self._doesnt_overfill_test(_make_memoryview) + @skip_if_py26 + def test_memoryview_doesnt_overfill(self): + """ + When called with a ``memoryview`` instance, + :py:obj:`Connection.recv_into` respects the size of the array and + doesn't write more bytes into it than will fit. + """ + self._doesnt_overfill_test(_make_memoryview) + @skip_if_py26 + def test_memoryview_really_doesnt_overfill(self): + """ + When called with a ``memoryview`` instance and an ``nbytes`` value + that is too large, :py:obj:`Connection.recv_into` respects the size + of the array and not the ``nbytes`` value and doesn't write more + bytes into the buffer than will fit. + """ + self._doesnt_overfill_test(_make_memoryview) class ConnectionSendallTests(TestCase, _LoopbackMixin): |
