From abe681fcbe17394c9fa6c777f1f2acc5c7ddc071 Mon Sep 17 00:00:00 2001 From: Arnon Yaari Date: Wed, 10 Sep 2014 17:16:19 +0300 Subject: [PATCH 1/2] use tunnel.sock instead of resp.fp in SSLTunnelConnection resp.fp is a socket._fileobject instead of a socket.socket object, so it is incompatible with gevent. Fix issue #163 --- pyVmomi/SoapAdapter.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyVmomi/SoapAdapter.py b/pyVmomi/SoapAdapter.py index bca8f02..cbe67f0 100644 --- a/pyVmomi/SoapAdapter.py +++ b/pyVmomi/SoapAdapter.py @@ -1035,11 +1035,10 @@ class SSLTunnelConnection(object): tunnel = http_client.HTTPConnection(path, **kwargs) tunnel.request('CONNECT', self.proxyPath) resp = tunnel.getresponse() - tunnelSocket = resp.fp if resp.status != 200: raise httplib.HTTPException("{0} {1}".format(resp.status, resp.reason)) retval = http_client.HTTPSConnection(path) - retval.sock = _SocketWrapper(tunnelSocket, + retval.sock = _SocketWrapper(tunnel.sock, keyfile=key_file, certfile=cert_file) return retval From 97b5fcf0da646e5e948162fe849d0acad41278d2 Mon Sep 17 00:00:00 2001 From: Arnon Yaari Date: Thu, 11 Sep 2014 13:05:07 +0300 Subject: [PATCH 2/2] add test for SSLTunnelConnection --- tests/__init__.py | 3 ++- tests/fixtures/ssl_tunnel.yaml | 14 ++++++++++++++ tests/test_connect.py | 6 ++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/ssl_tunnel.yaml diff --git a/tests/__init__.py b/tests/__init__.py index 8b1c9b7..f7cef1e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -16,6 +16,7 @@ import logging import os import unittest import vcr +import socket def tests_resource_path(local_path=''): @@ -29,7 +30,7 @@ fixtures_path = tests_resource_path('fixtures') def monkey_patch_vcrpy(): # TODO (hartsock): This should be unnecessary. Remove after vcrpy updates. vcr.stubs.VCRHTTPSConnection.is_verified = True - + vcr.stubs.VCRFakeSocket = socket.socket class VCRTestBase(unittest.TestCase): diff --git a/tests/fixtures/ssl_tunnel.yaml b/tests/fixtures/ssl_tunnel.yaml new file mode 100644 index 0000000..4a0f260 --- /dev/null +++ b/tests/fixtures/ssl_tunnel.yaml @@ -0,0 +1,14 @@ +interactions: +- request: + body: null + headers: {} + method: CONNECT + uri: http://vcsasdkTunnel:8089 + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + content-type: [text/html] + date: ['Thu, 11 Sep 2014 08:23:36 GMT'] + status: {code: 200, message: OK} +version: 1 diff --git a/tests/test_connect.py b/tests/test_connect.py index 9ad982f..9f937ff 100644 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -68,5 +68,11 @@ class ConnectionTests(tests.VCRTestBase): def test_disconnect_on_no_connection(self): connect.Disconnect(None) + @vcr.use_cassette('ssl_tunnel.yaml', + cassette_library_dir=tests.fixtures_path, + record_mode='none') + def test_ssl_tunnel(self): + connect.SoapStubAdapter('sdkTunnel', 8089, httpProxyHost='vcsa').GetConnection() + if __name__ == '__main__': unittest.main() \ No newline at end of file