From ed0f219167be6bc6819d6ec4d24986812ab266cb Mon Sep 17 00:00:00 2001 From: Ujjwal Verma Date: Wed, 26 Jul 2017 01:02:30 +0530 Subject: [PATCH] fixed addon error --- mitmproxy/test/tflow.py | 2 +- test/mitmproxy/addons/test_cut.py | 2 +- test/mitmproxy/test_connections.py | 2 +- test/mitmproxy/test_flowfilter.py | 14 +++++++------- test/mitmproxy/tservers.py | 8 ++++++-- web/src/js/__tests__/ducks/_tflow.js | 2 +- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/mitmproxy/test/tflow.py b/mitmproxy/test/tflow.py index 9004df2fa..e754cb54e 100644 --- a/mitmproxy/test/tflow.py +++ b/mitmproxy/test/tflow.py @@ -148,7 +148,7 @@ def tclient_conn(): """ c = connections.ClientConnection.from_state(dict( id=str(uuid.uuid4()), - address=("address", 22), + address=("127.0.0.1", 22), clientcert=None, mitmcert=None, ssl_established=False, diff --git a/test/mitmproxy/addons/test_cut.py b/test/mitmproxy/addons/test_cut.py index e028331fa..242c6c2f1 100644 --- a/test/mitmproxy/addons/test_cut.py +++ b/test/mitmproxy/addons/test_cut.py @@ -32,7 +32,7 @@ def test_extract(): ["s.header[header-response]", "svalue"], ["cc.address.port", "22"], - ["cc.address.host", "address"], + ["cc.address.host", "127.0.0.1"], ["cc.tls_version", "TLSv1.2"], ["cc.sni", "address"], ["cc.ssl_established", "false"], diff --git a/test/mitmproxy/test_connections.py b/test/mitmproxy/test_connections.py index 99367bb65..83f0bd34b 100644 --- a/test/mitmproxy/test_connections.py +++ b/test/mitmproxy/test_connections.py @@ -29,7 +29,7 @@ class TestClientConnection: def test_repr(self): c = tflow.tclient_conn() - assert 'address:22' in repr(c) + assert '127.0.0.1:22' in repr(c) assert 'ALPN' in repr(c) assert 'TLS' not in repr(c) diff --git a/test/mitmproxy/test_flowfilter.py b/test/mitmproxy/test_flowfilter.py index fe9b2408b..c411258a6 100644 --- a/test/mitmproxy/test_flowfilter.py +++ b/test/mitmproxy/test_flowfilter.py @@ -225,11 +225,11 @@ class TestMatchingHTTPFlow: def test_src(self): q = self.req() - assert self.q("~src address", q) + assert self.q("~src 127.0.0.1", q) assert not self.q("~src foobar", q) assert self.q("~src :22", q) assert not self.q("~src :99", q) - assert self.q("~src address:22", q) + assert self.q("~src 127.0.0.1:22", q) q.client_conn.address = None assert not self.q('~src address:22', q) @@ -315,11 +315,11 @@ class TestMatchingTCPFlow: def test_src(self): f = self.flow() - assert self.q("~src address", f) + assert self.q("~src 127.0.0.1", f) assert not self.q("~src foobar", f) assert self.q("~src :22", f) assert not self.q("~src :99", f) - assert self.q("~src address:22", f) + assert self.q("~src 127.0.0.1:22", f) def test_dst(self): f = self.flow() @@ -440,11 +440,11 @@ class TestMatchingWebSocketFlow: def test_src(self): f = self.flow() - assert self.q("~src address", f) + assert self.q("~src 127.0.0.1", f) assert not self.q("~src foobar", f) assert self.q("~src :22", f) assert not self.q("~src :99", f) - assert self.q("~src address:22", f) + assert self.q("~src 127.0.0.1:22", f) def test_dst(self): f = self.flow() @@ -524,7 +524,7 @@ class TestMatchingDummyFlow: assert not self.q("~s", f) - assert self.q("~src address", f) + assert self.q("~src 127.0.0.1", f) assert not self.q("~src nonexistent", f) assert not self.q("~tcp", f) diff --git a/test/mitmproxy/tservers.py b/test/mitmproxy/tservers.py index 3a2050e10..9faaf20ef 100644 --- a/test/mitmproxy/tservers.py +++ b/test/mitmproxy/tservers.py @@ -2,6 +2,7 @@ import os.path import threading import tempfile import sys +from unittest import mock import mitmproxy.platform from mitmproxy.proxy.config import ProxyConfig @@ -23,10 +24,13 @@ class MasterTest: def cycle(self, master, content): f = tflow.tflow(req=tutils.treq(content=content)) - master.addons.handle_lifecycle("clientconnect", f.client_conn) + layer = mock.Mock("mitmproxy.proxy.protocol.base.Layer") + layer.client_conn = f.client_conn + layer.reply = controller.DummyReply() + master.addons.handle_lifecycle("clientconnect", layer) for i in eventsequence.iterate(f): master.addons.handle_lifecycle(*i) - master.addons.handle_lifecycle("clientdisconnect", f.client_conn) + master.addons.handle_lifecycle("clientdisconnect", layer) return f def dummy_cycle(self, master, n, content): diff --git a/web/src/js/__tests__/ducks/_tflow.js b/web/src/js/__tests__/ducks/_tflow.js index f6a382bdb..44b323427 100644 --- a/web/src/js/__tests__/ducks/_tflow.js +++ b/web/src/js/__tests__/ducks/_tflow.js @@ -2,7 +2,7 @@ export default function(){ return { "client_conn": { "address": [ - "address", + "127.0.0.1", 22 ], "alpn_proto_negotiated": "http/1.1",