aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorThomas Kriechbaumer <thomas@kriechbaumer.name>2017-05-24 13:21:58 +0200
committerThomas Kriechbaumer <thomas@kriechbaumer.name>2017-05-24 13:21:58 +0200
commit2faaa0b2a23089b9ffccf2d46dc42328edb76ddd (patch)
tree2b999eff66468bd2d3896181f2e7bb1197f8e461 /test
parent928085c597e900aa76fe0b05eb74dfa3380e787d (diff)
downloadmitmproxy-2faaa0b2a23089b9ffccf2d46dc42328edb76ddd.tar.gz
mitmproxy-2faaa0b2a23089b9ffccf2d46dc42328edb76ddd.tar.bz2
mitmproxy-2faaa0b2a23089b9ffccf2d46dc42328edb76ddd.zip
connections tests: fix leaking sockets
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/net/tservers.py5
-rw-r--r--test/mitmproxy/test_connections.py12
2 files changed, 9 insertions, 8 deletions
diff --git a/test/mitmproxy/net/tservers.py b/test/mitmproxy/net/tservers.py
index 7f75b62f..44701aa5 100644
--- a/test/mitmproxy/net/tservers.py
+++ b/test/mitmproxy/net/tservers.py
@@ -16,9 +16,6 @@ class _ServerThread(threading.Thread):
def run(self):
self.server.serve_forever()
- def shutdown(self):
- self.server.shutdown()
-
class _TServer(tcp.TCPServer):
@@ -104,7 +101,7 @@ class ServerTestBase:
@classmethod
def teardown_class(cls):
- cls.server.shutdown()
+ cls.server.server.shutdown()
def teardown(self):
self.server.server.wait_for_silence()
diff --git a/test/mitmproxy/test_connections.py b/test/mitmproxy/test_connections.py
index e320885d..daf4c79e 100644
--- a/test/mitmproxy/test_connections.py
+++ b/test/mitmproxy/test_connections.py
@@ -140,16 +140,17 @@ class TestServerConnection:
assert d.last_log()
c.finish()
+ c.close()
d.shutdown()
def test_terminate_error(self):
d = test.Daemon()
c = connections.ServerConnection((d.IFACE, d.port))
c.connect()
+ c.close()
c.connection = mock.Mock()
c.connection.recv = mock.Mock(return_value=False)
c.connection.flush = mock.Mock(side_effect=exceptions.TcpDisconnect)
- c.finish()
d.shutdown()
def test_sni(self):
@@ -194,22 +195,25 @@ class TestClientConnectionTLS:
s = socket.create_connection(address)
s = ctx.wrap_socket(s, server_hostname=sni)
s.send(b'foobar')
- s.shutdown(socket.SHUT_RDWR)
+ s.close()
threading.Thread(target=client_run).start()
connection, client_address = sock.accept()
c = connections.ClientConnection(connection, client_address, None)
cert = tutils.test_data.path("mitmproxy/net/data/server.crt")
+ with open(tutils.test_data.path("mitmproxy/net/data/server.key")) as f:
+ raw_key = f.read()
key = OpenSSL.crypto.load_privatekey(
OpenSSL.crypto.FILETYPE_PEM,
- open(tutils.test_data.path("mitmproxy/net/data/server.key"), "rb").read())
+ raw_key)
c.convert_to_ssl(cert, key)
assert c.connected()
assert c.sni == sni
assert c.tls_established
assert c.rfile.read(6) == b'foobar'
c.finish()
+ sock.close()
class TestServerConnectionTLS(tservers.ServerTestBase):
@@ -222,7 +226,7 @@ class TestServerConnectionTLS(tservers.ServerTestBase):
@pytest.mark.parametrize("clientcert", [
None,
tutils.test_data.path("mitmproxy/data/clientcert"),
- os.path.join(tutils.test_data.path("mitmproxy/data/clientcert"), "client.pem"),
+ tutils.test_data.path("mitmproxy/data/clientcert/client.pem"),
])
def test_tls(self, clientcert):
c = connections.ServerConnection(("127.0.0.1", self.port))