aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorThomas Kriechbaumer <thomas@kriechbaumer.name>2017-02-21 00:20:44 +0100
committerThomas Kriechbaumer <thomas@kriechbaumer.name>2017-02-24 13:39:02 +0100
commit3e9125a3c13084f4abb0e5b74554909f24df9454 (patch)
tree924b6d81e14c24535aef662e3696c291d7370bc5 /test
parentd0d11cec7b479932668eb4e7c99d7824018d0460 (diff)
downloadmitmproxy-3e9125a3c13084f4abb0e5b74554909f24df9454.tar.gz
mitmproxy-3e9125a3c13084f4abb0e5b74554909f24df9454.tar.bz2
mitmproxy-3e9125a3c13084f4abb0e5b74554909f24df9454.zip
nuke tcp.Address and add proper IPv6 support
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/addons/test_dumper.py2
-rw-r--r--test/mitmproxy/net/test_socks.py5
-rw-r--r--test/mitmproxy/net/test_tcp.py18
-rw-r--r--test/mitmproxy/net/tservers.py4
-rw-r--r--test/mitmproxy/proxy/protocol/test_http2.py26
-rw-r--r--test/mitmproxy/proxy/protocol/test_websocket.py8
-rw-r--r--test/mitmproxy/proxy/test_server.py9
-rw-r--r--test/mitmproxy/test_flow.py2
-rw-r--r--test/mitmproxy/test_flowfilter.py10
-rw-r--r--test/mitmproxy/test_proxy.py2
-rw-r--r--test/mitmproxy/tservers.py5
11 files changed, 44 insertions, 47 deletions
diff --git a/test/mitmproxy/addons/test_dumper.py b/test/mitmproxy/addons/test_dumper.py
index 6a66d0c9..75b994fa 100644
--- a/test/mitmproxy/addons/test_dumper.py
+++ b/test/mitmproxy/addons/test_dumper.py
@@ -70,7 +70,7 @@ def test_simple():
flow.request = tutils.treq()
flow.request.stickycookie = True
flow.client_conn = mock.MagicMock()
- flow.client_conn.address.host = "foo"
+ flow.client_conn.address[0] = "foo"
flow.response = tutils.tresp(content=None)
flow.response.is_replay = True
flow.response.status_code = 300
diff --git a/test/mitmproxy/net/test_socks.py b/test/mitmproxy/net/test_socks.py
index e00dd410..fbd31ef4 100644
--- a/test/mitmproxy/net/test_socks.py
+++ b/test/mitmproxy/net/test_socks.py
@@ -3,7 +3,6 @@ from io import BytesIO
import pytest
from mitmproxy.net import socks
-from mitmproxy.net import tcp
from mitmproxy.test import tutils
@@ -176,7 +175,7 @@ def test_message_ipv6():
msg.to_file(out)
assert out.getvalue() == raw.getvalue()[:-2]
- assert msg.addr.host == ipv6_addr
+ assert msg.addr[0] == ipv6_addr
def test_message_invalid_host():
@@ -196,6 +195,6 @@ def test_message_unknown_atyp():
with pytest.raises(socks.SocksError):
socks.Message.from_file(raw)
- m = socks.Message(5, 1, 0x02, tcp.Address(("example.com", 5050)))
+ m = socks.Message(5, 1, 0x02, ("example.com", 5050))
with pytest.raises(socks.SocksError):
m.to_file(BytesIO())
diff --git a/test/mitmproxy/net/test_tcp.py b/test/mitmproxy/net/test_tcp.py
index ff6362c8..252d896c 100644
--- a/test/mitmproxy/net/test_tcp.py
+++ b/test/mitmproxy/net/test_tcp.py
@@ -116,11 +116,11 @@ class TestServerBind(tservers.ServerTestBase):
class TestServerIPv6(tservers.ServerTestBase):
handler = EchoHandler
- addr = tcp.Address(("localhost", 0), use_ipv6=True)
+ addr = ("::1", 0)
def test_echo(self):
testval = b"echo!\n"
- c = tcp.TCPClient(tcp.Address(("::1", self.port), use_ipv6=True))
+ c = tcp.TCPClient(("::1", self.port))
with c.connect():
c.wfile.write(testval)
c.wfile.flush()
@@ -132,7 +132,7 @@ class TestEcho(tservers.ServerTestBase):
def test_echo(self):
testval = b"echo!\n"
- c = tcp.TCPClient(("127.0.0.1", self.port))
+ c = tcp.TCPClient(("localhost", self.port))
with c.connect():
c.wfile.write(testval)
c.wfile.flush()
@@ -783,18 +783,6 @@ class TestPeekSSL(TestPeek):
return conn.pop()
-class TestAddress:
- def test_simple(self):
- a = tcp.Address(("localhost", 80), True)
- assert a.use_ipv6
- b = tcp.Address(("foo.com", 80), True)
- assert not a == b
- c = tcp.Address(("localhost", 80), True)
- assert a == c
- assert not a != c
- assert repr(a) == "localhost:80"
-
-
class TestSSLKeyLogger(tservers.ServerTestBase):
handler = EchoHandler
ssl = dict(
diff --git a/test/mitmproxy/net/tservers.py b/test/mitmproxy/net/tservers.py
index 68a2caa0..ebe6d3eb 100644
--- a/test/mitmproxy/net/tservers.py
+++ b/test/mitmproxy/net/tservers.py
@@ -86,13 +86,13 @@ class _TServer(tcp.TCPServer):
class ServerTestBase:
ssl = None
handler = None
- addr = ("localhost", 0)
+ addr = ("127.0.0.1", 0)
@classmethod
def setup_class(cls, **kwargs):
cls.q = queue.Queue()
s = cls.makeserver(**kwargs)
- cls.port = s.address.port
+ cls.port = s.address[1]
cls.server = _ServerThread(s)
cls.server.start()
diff --git a/test/mitmproxy/proxy/protocol/test_http2.py b/test/mitmproxy/proxy/protocol/test_http2.py
index cb9c0474..19c2d2ef 100644
--- a/test/mitmproxy/proxy/protocol/test_http2.py
+++ b/test/mitmproxy/proxy/protocol/test_http2.py
@@ -124,10 +124,10 @@ class _Http2TestBase:
b'CONNECT',
b'',
b'localhost',
- self.server.server.address.port,
+ self.server.server.address[1],
b'/',
b'HTTP/1.1',
- [(b'host', b'localhost:%d' % self.server.server.address.port)],
+ [(b'host', b'localhost:%d' % self.server.server.address[1])],
b'',
)))
client.wfile.flush()
@@ -231,7 +231,7 @@ class TestSimple(_Http2Test):
client.wfile,
h2_conn,
headers=[
- (':authority', "127.0.0.1:{}".format(self.server.server.address.port)),
+ (':authority', "127.0.0.1:{}".format(self.server.server.address[1])),
(':method', 'GET'),
(':scheme', 'https'),
(':path', '/'),
@@ -307,7 +307,7 @@ class TestForbiddenHeaders(_Http2Test):
client.wfile,
h2_conn,
headers=[
- (':authority', "127.0.0.1:{}".format(self.server.server.address.port)),
+ (':authority', "127.0.0.1:{}".format(self.server.server.address[1])),
(':method', 'GET'),
(':scheme', 'https'),
(':path', '/'),
@@ -384,7 +384,7 @@ class TestRequestWithPriority(_Http2Test):
client.wfile,
h2_conn,
headers=[
- (':authority', "127.0.0.1:{}".format(self.server.server.address.port)),
+ (':authority', "127.0.0.1:{}".format(self.server.server.address[1])),
(':method', 'GET'),
(':scheme', 'https'),
(':path', '/'),
@@ -469,7 +469,7 @@ class TestPriority(_Http2Test):
client.wfile,
h2_conn,
headers=[
- (':authority', "127.0.0.1:{}".format(self.server.server.address.port)),
+ (':authority', "127.0.0.1:{}".format(self.server.server.address[1])),
(':method', 'GET'),
(':scheme', 'https'),
(':path', '/'),
@@ -527,7 +527,7 @@ class TestStreamResetFromServer(_Http2Test):
client.wfile,
h2_conn,
headers=[
- (':authority', "127.0.0.1:{}".format(self.server.server.address.port)),
+ (':authority', "127.0.0.1:{}".format(self.server.server.address[1])),
(':method', 'GET'),
(':scheme', 'https'),
(':path', '/'),
@@ -576,7 +576,7 @@ class TestBodySizeLimit(_Http2Test):
client.wfile,
h2_conn,
headers=[
- (':authority', "127.0.0.1:{}".format(self.server.server.address.port)),
+ (':authority', "127.0.0.1:{}".format(self.server.server.address[1])),
(':method', 'GET'),
(':scheme', 'https'),
(':path', '/'),
@@ -672,7 +672,7 @@ class TestPushPromise(_Http2Test):
client, h2_conn = self._setup_connection()
self._send_request(client.wfile, h2_conn, stream_id=1, headers=[
- (':authority', "127.0.0.1:{}".format(self.server.server.address.port)),
+ (':authority', "127.0.0.1:{}".format(self.server.server.address[1])),
(':method', 'GET'),
(':scheme', 'https'),
(':path', '/'),
@@ -728,7 +728,7 @@ class TestPushPromise(_Http2Test):
client, h2_conn = self._setup_connection()
self._send_request(client.wfile, h2_conn, stream_id=1, headers=[
- (':authority', "127.0.0.1:{}".format(self.server.server.address.port)),
+ (':authority', "127.0.0.1:{}".format(self.server.server.address[1])),
(':method', 'GET'),
(':scheme', 'https'),
(':path', '/'),
@@ -791,7 +791,7 @@ class TestConnectionLost(_Http2Test):
client, h2_conn = self._setup_connection()
self._send_request(client.wfile, h2_conn, stream_id=1, headers=[
- (':authority', "127.0.0.1:{}".format(self.server.server.address.port)),
+ (':authority', "127.0.0.1:{}".format(self.server.server.address[1])),
(':method', 'GET'),
(':scheme', 'https'),
(':path', '/'),
@@ -848,7 +848,7 @@ class TestMaxConcurrentStreams(_Http2Test):
# this will exceed MAX_CONCURRENT_STREAMS on the server connection
# and cause mitmproxy to throttle stream creation to the server
self._send_request(client.wfile, h2_conn, stream_id=stream_id, headers=[
- (':authority', "127.0.0.1:{}".format(self.server.server.address.port)),
+ (':authority', "127.0.0.1:{}".format(self.server.server.address[1])),
(':method', 'GET'),
(':scheme', 'https'),
(':path', '/'),
@@ -894,7 +894,7 @@ class TestConnectionTerminated(_Http2Test):
client, h2_conn = self._setup_connection()
self._send_request(client.wfile, h2_conn, headers=[
- (':authority', "127.0.0.1:{}".format(self.server.server.address.port)),
+ (':authority', "127.0.0.1:{}".format(self.server.server.address[1])),
(':method', 'GET'),
(':scheme', 'https'),
(':path', '/'),
diff --git a/test/mitmproxy/proxy/protocol/test_websocket.py b/test/mitmproxy/proxy/protocol/test_websocket.py
index 4ea01d34..bac0e527 100644
--- a/test/mitmproxy/proxy/protocol/test_websocket.py
+++ b/test/mitmproxy/proxy/protocol/test_websocket.py
@@ -87,8 +87,8 @@ class _WebSocketTestBase:
"authority",
"CONNECT",
"",
- "localhost",
- self.server.server.address.port,
+ "127.0.0.1",
+ self.server.server.address[1],
"",
"HTTP/1.1",
content=b'')
@@ -105,8 +105,8 @@ class _WebSocketTestBase:
"relative",
"GET",
"http",
- "localhost",
- self.server.server.address.port,
+ "127.0.0.1",
+ self.server.server.address[1],
"/ws",
"HTTP/1.1",
headers=http.Headers(
diff --git a/test/mitmproxy/proxy/test_server.py b/test/mitmproxy/proxy/test_server.py
index 0be772a4..8b133085 100644
--- a/test/mitmproxy/proxy/test_server.py
+++ b/test/mitmproxy/proxy/test_server.py
@@ -17,7 +17,6 @@ from mitmproxy.net import socks
from mitmproxy import certs
from mitmproxy import exceptions
from mitmproxy.net.http import http1
-from mitmproxy.net.tcp import Address
from pathod import pathoc
from pathod import pathod
@@ -561,7 +560,7 @@ class TestHttps2Http(tservers.ReverseProxyTest):
def get_options(cls):
opts = super().get_options()
s = parse_server_spec(opts.upstream_server)
- opts.upstream_server = "http://%s" % s.address
+ opts.upstream_server = "http://{}:{}".format(s.address[0], s.address[1])
return opts
def pathoc(self, ssl, sni=None):
@@ -720,7 +719,7 @@ class MasterRedirectRequest(tservers.TestMaster):
# This part should have no impact, but it should also not cause any exceptions.
addr = f.live.server_conn.address
- addr2 = Address(("127.0.0.1", self.redirect_port))
+ addr2 = ("127.0.0.1", self.redirect_port)
f.live.set_server(addr2)
f.live.set_server(addr)
@@ -730,8 +729,8 @@ class MasterRedirectRequest(tservers.TestMaster):
@controller.handler
def response(self, f):
- f.response.content = bytes(f.client_conn.address.port)
- f.response.headers["server-conn-id"] = str(f.server_conn.source_address.port)
+ f.response.content = bytes(f.client_conn.address[1])
+ f.response.headers["server-conn-id"] = str(f.server_conn.source_address[1])
super().response(f)
diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py
index a78e5f80..f289afa8 100644
--- a/test/mitmproxy/test_flow.py
+++ b/test/mitmproxy/test_flow.py
@@ -418,7 +418,7 @@ class TestClientConnection:
c.get_state()
c2 = tflow.tclient_conn()
- c2.address.address = (c2.address.host, 4242)
+ c2.address = (c2.address[0], 4242)
assert not c == c2
c2.timestamp_start = 42
diff --git a/test/mitmproxy/test_flowfilter.py b/test/mitmproxy/test_flowfilter.py
index bfce265e..646c210f 100644
--- a/test/mitmproxy/test_flowfilter.py
+++ b/test/mitmproxy/test_flowfilter.py
@@ -221,6 +221,11 @@ class TestMatchingHTTPFlow:
assert not self.q("~src :99", q)
assert self.q("~src address:22", q)
+ q.client_conn.address = None
+ assert not self.q('~src address:22', q)
+ q.client_conn = None
+ assert not self.q('~src address:22', q)
+
def test_dst(self):
q = self.req()
q.server_conn = tflow.tserver_conn()
@@ -230,6 +235,11 @@ class TestMatchingHTTPFlow:
assert not self.q("~dst :99", q)
assert self.q("~dst address:22", q)
+ q.server_conn.address = None
+ assert not self.q('~dst address:22', q)
+ q.server_conn = None
+ assert not self.q('~dst address:22', q)
+
def test_and(self):
s = self.resp()
assert self.q("~c 200 & ~h head", s)
diff --git a/test/mitmproxy/test_proxy.py b/test/mitmproxy/test_proxy.py
index a14c851e..d2615840 100644
--- a/test/mitmproxy/test_proxy.py
+++ b/test/mitmproxy/test_proxy.py
@@ -160,7 +160,7 @@ class TestProxyServer:
ProxyServer(conf)
def test_err_2(self):
- conf = ProxyConfig(options.Options(listen_host="invalidhost"))
+ conf = ProxyConfig(options.Options(listen_host="256.256.256.256"))
with pytest.raises(Exception, match="Error starting proxy server"):
ProxyServer(conf)
diff --git a/test/mitmproxy/tservers.py b/test/mitmproxy/tservers.py
index 298fddcb..9a289ae5 100644
--- a/test/mitmproxy/tservers.py
+++ b/test/mitmproxy/tservers.py
@@ -98,13 +98,14 @@ class ProxyThread(threading.Thread):
threading.Thread.__init__(self)
self.tmaster = tmaster
self.name = "ProxyThread (%s:%s)" % (
- tmaster.server.address.host, tmaster.server.address.port
+ tmaster.server.address[0],
+ tmaster.server.address[1],
)
controller.should_exit = False
@property
def port(self):
- return self.tmaster.server.address.port
+ return self.tmaster.server.address[1]
@property
def tlog(self):