THRIFT-4904: Fix python unit test errors and exception escapes
Due to the way SSL layers on top of sockets, it was possible
to complete a connection and then have the server close it.
This would happen if the client is not checking certificates
but the server is. The TSSLSocket unit test was enhanced to
do a read and a write as well as just connecting to ensure a
more complete test.
The TSocket read() and write() calls were leaking OSError,
socker.error, and ssl.Error exceptions. These cases are now
wrapped into a TTransportException of the appropriate type,
and the original exception is added as an argument named inner.
diff --git a/lib/py/test/test_sslsocket.py b/lib/py/test/test_sslsocket.py
index 598c174..f4c87f1 100644
--- a/lib/py/test/test_sslsocket.py
+++ b/lib/py/test/test_sslsocket.py
@@ -75,6 +75,9 @@
try:
self._client = self._server.accept()
+ if self._client:
+ self._client.read(5) # hello
+ self._client.write(b"there")
except Exception:
logging.exception('error on server side (%s):' % self.name)
if not self._expect_failure:
@@ -141,7 +144,8 @@
client.setTimeout(20)
with self._assert_raises(TTransportException):
client.open()
- self.assertTrue(acc.client is None)
+ client.write(b"hello")
+ client.read(5) # b"there"
finally:
logging.disable(logging.NOTSET)
@@ -153,8 +157,10 @@
def _assert_connection_success(self, server, path=None, **client_args):
with self._connectable_client(server, path=path, **client_args) as (acc, client):
- client.open()
try:
+ client.open()
+ client.write(b"hello")
+ self.assertEqual(client.read(5), b"there")
self.assertTrue(acc.client is not None)
finally:
client.close()