diff options
Diffstat (limited to 'tests/test_ssl.py')
-rw-r--r-- | tests/test_ssl.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_ssl.py b/tests/test_ssl.py index d2a56b7..44a042b 100644 --- a/tests/test_ssl.py +++ b/tests/test_ssl.py @@ -6,6 +6,7 @@ Unit tests for :mod:`OpenSSL.SSL`. """ import datetime +import sys import uuid from gc import collect, get_referrers @@ -2662,6 +2663,14 @@ class TestConnectionGetCipherList(object): assert isinstance(cipher, str) +class VeryLarge(bytes): + """ + Mock object so that we don't have to allocate 2**31 bytes + """ + def __len__(self): + return 2**31 + + class TestConnectionSend(object): """ Tests for `Connection.send`. @@ -2725,6 +2734,21 @@ class TestConnectionSend(object): assert count == 2 assert client.recv(2) == b'xy' + @pytest.mark.skipif( + sys.maxsize < 2**31, + reason="sys.maxsize < 2**31 - test requires 64 bit" + ) + def test_buf_too_large(self): + """ + When passed a buffer containing >= 2**31 bytes, + `Connection.send` bails out as SSL_write only + accepts an int for the buffer length. + """ + connection = Connection(Context(TLSv1_METHOD), None) + with pytest.raises(ValueError) as exc_info: + connection.send(VeryLarge()) + exc_info.match(r"Cannot send more than .+ bytes at once") + def _make_memoryview(size): """ |