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/src/transport/TSSLSocket.py b/lib/py/src/transport/TSSLSocket.py
index 066d8da..5b3ae59 100644
--- a/lib/py/src/transport/TSSLSocket.py
+++ b/lib/py/src/transport/TSSLSocket.py
@@ -291,11 +291,11 @@
plain_sock = socket.socket(family, socktype)
try:
return self._wrap_socket(plain_sock)
- except Exception:
+ except Exception as ex:
plain_sock.close()
msg = 'failed to initialize SSL'
logger.exception(msg)
- raise TTransportException(TTransportException.NOT_OPEN, msg)
+ raise TTransportException(type=TTransportException.NOT_OPEN, message=msg, inner=ex)
def open(self):
super(TSSLSocket, self).open()
@@ -307,7 +307,7 @@
except TTransportException:
raise
except Exception as ex:
- raise TTransportException(TTransportException.UNKNOWN, str(ex))
+ raise TTransportException(message=str(ex), inner=ex)
class TSSLServerSocket(TSocket.TServerSocket, TSSLBase):