From 4bd15a28b73f521fc08ea77512198faffeaaa247 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 10 Mar 2014 17:43:39 +0100 Subject: [PATCH] fix #28 --- netlib/tcp.py | 4 +++- requirements.txt | 2 +- test/test_tcp.py | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/netlib/tcp.py b/netlib/tcp.py index 078ac4970..c5f97f948 100644 --- a/netlib/tcp.py +++ b/netlib/tcp.py @@ -143,7 +143,9 @@ class Reader(_FileLike): raise NetLibTimeout except socket.error: raise NetLibDisconnect - except SSL.SysCallError: + except SSL.SysCallError as e: + if e.args == (-1, 'Unexpected EOF'): + break raise NetLibDisconnect except SSL.Error, v: raise NetLibSSLError(v.message) diff --git a/requirements.txt b/requirements.txt index 460a60e45..7b45f7c3f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ pyasn1>=0.1.7 -pyOpenSSL>=0.13 \ No newline at end of file +pyOpenSSL>=0.14 \ No newline at end of file diff --git a/test/test_tcp.py b/test/test_tcp.py index ec995702e..771468296 100644 --- a/test/test_tcp.py +++ b/test/test_tcp.py @@ -106,6 +106,11 @@ class TestDisconnect(test.ServerTestBase): assert c.rfile.readline() == testval +class HardDisconnectHandler(tcp.BaseHandler): + def handle(self): + self.connection.close() + + class TestServerSSL(test.ServerTestBase): handler = EchoHandler ssl = dict( @@ -293,6 +298,24 @@ class TestSSLDisconnect(test.ServerTestBase): tutils.raises(Queue.Empty, self.q.get_nowait) +class TestSSLHardDisconnect(test.ServerTestBase): + handler = HardDisconnectHandler + ssl = dict( + cert = tutils.test_data.path("data/server.crt"), + key = tutils.test_data.path("data/server.key"), + request_client_cert = False, + v3_only = False + ) + def test_echo(self): + c = tcp.TCPClient(("127.0.0.1", self.port)) + c.connect() + c.convert_to_ssl() + # Exercise SSL.SysCallError + c.rfile.read(10) + c.close() + tutils.raises(tcp.NetLibDisconnect, c.wfile.write, "foo") + + class TestDisconnect(test.ServerTestBase): def test_echo(self): c = tcp.TCPClient(("127.0.0.1", self.port))