aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-02-05 20:26:47 +0100
committerMaximilian Hils <git@maximilianhils.com>2014-02-05 20:26:47 +0100
commitf26d91cb814436fa5c1290459f5313e6831bd53c (patch)
treee54d13d395f7746b5b92637dd642645ceb34cd58 /test
parent9a55cd733268ff66c19ff6fead18291ec8342d8c (diff)
downloadmitmproxy-f26d91cb814436fa5c1290459f5313e6831bd53c.tar.gz
mitmproxy-f26d91cb814436fa5c1290459f5313e6831bd53c.tar.bz2
mitmproxy-f26d91cb814436fa5c1290459f5313e6831bd53c.zip
add skeleton to change destinatin server during intercept, fix all testcases on windows
Diffstat (limited to 'test')
-rw-r--r--test/test_dump.py4
-rw-r--r--test/test_flow.py27
-rw-r--r--test/test_proxy.py4
-rw-r--r--test/test_script.py2
4 files changed, 25 insertions, 12 deletions
diff --git a/test/test_dump.py b/test/test_dump.py
index f6688b1a..314356fc 100644
--- a/test/test_dump.py
+++ b/test/test_dump.py
@@ -26,12 +26,12 @@ class TestDumpMaster:
m.handle_log(l)
cc = req.flow.client_conn
cc.reply = mock.MagicMock()
- resp = tutils.tresp(req, content=content)
m.handle_clientconnect(cc)
- sc = proxy.ServerConnection((req.host, req.port))
+ sc = proxy.ServerConnection((req.host, req.port), None)
sc.reply = mock.MagicMock()
m.handle_serverconnection(sc)
m.handle_request(req)
+ resp = tutils.tresp(req, content=content)
f = m.handle_response(resp)
m.handle_clientdisconnect(cc)
return f
diff --git a/test/test_flow.py b/test/test_flow.py
index 5ae6c8d6..f28697c1 100644
--- a/test/test_flow.py
+++ b/test/test_flow.py
@@ -4,6 +4,7 @@ import email.utils
from libmproxy import filt, protocol, controller, utils, tnetstring, proxy, flow
from libmproxy.protocol.primitives import Error, Flow
from libmproxy.protocol.http import decoded
+from netlib import tcp
import tutils
@@ -32,7 +33,7 @@ class TestStickyCookieState:
def _response(self, cookie, host):
s = flow.StickyCookieState(filt.parse(".*"))
f = tutils.tflow_full()
- f.request.host = host
+ f.server_conn.address = tcp.Address((host, 80))
f.response.headers["Set-Cookie"] = [cookie]
s.handle_response(f)
return s, f
@@ -68,7 +69,7 @@ class TestStickyAuthState:
f = tutils.tflow_full()
f.request.headers["authorization"] = ["foo"]
s.handle_request(f)
- assert "host" in s.hosts
+ assert "address" in s.hosts
f = tutils.tflow_full()
s.handle_request(f)
@@ -586,7 +587,7 @@ class TestFlowMaster:
req = tutils.treq()
fm.handle_clientconnect(req.flow.client_conn)
assert fm.scripts[0].ns["log"][-1] == "clientconnect"
- sc = proxy.ServerConnection((req.host, req.port))
+ sc = proxy.ServerConnection((req.host, req.port), None)
sc.reply = controller.DummyReply()
fm.handle_serverconnection(sc)
assert fm.scripts[0].ns["log"][-1] == "serverconnect"
@@ -800,11 +801,23 @@ class TestRequest:
def test_get_url(self):
r = tutils.tflow().request
- assert r.get_url() == "https://host:22/"
- assert r.get_url(hostheader=True) == "https://host:22/"
+
+ assert r.get_url() == "http://address:22/path"
+
+ r.flow.server_conn.ssl_established = True
+ assert r.get_url() == "https://address:22/path"
+
+ r.flow.server_conn.address = tcp.Address(("host", 42))
+ assert r.get_url() == "https://host:42/path"
+
+ r.host = "address"
+ r.port = 22
+ assert r.get_url() == "https://address:22/path"
+
+ assert r.get_url(hostheader=True) == "https://address:22/path"
r.headers["Host"] = ["foo.com"]
- assert r.get_url() == "https://host:22/"
- assert r.get_url(hostheader=True) == "https://foo.com:22/"
+ assert r.get_url() == "https://address:22/path"
+ assert r.get_url(hostheader=True) == "https://foo.com:22/path"
def test_path_components(self):
r = tutils.treq()
diff --git a/test/test_proxy.py b/test/test_proxy.py
index 41d41d0c..c42d66e7 100644
--- a/test/test_proxy.py
+++ b/test/test_proxy.py
@@ -19,7 +19,7 @@ class TestServerConnection:
self.d.shutdown()
def test_simple(self):
- sc = proxy.ServerConnection((self.d.IFACE, self.d.port))
+ sc = proxy.ServerConnection((self.d.IFACE, self.d.port), None)
sc.connect()
r = tutils.treq()
r.flow.server_conn = sc
@@ -31,7 +31,7 @@ class TestServerConnection:
sc.finish()
def test_terminate_error(self):
- sc = proxy.ServerConnection((self.d.IFACE, self.d.port))
+ sc = proxy.ServerConnection((self.d.IFACE, self.d.port), None)
sc.connect()
sc.connection = mock.Mock()
sc.connection.recv = mock.Mock(return_value=False)
diff --git a/test/test_script.py b/test/test_script.py
index 7ee85f2c..2e48081b 100644
--- a/test/test_script.py
+++ b/test/test_script.py
@@ -75,7 +75,7 @@ class TestScript:
# Two instantiations
assert m.call_count == 2
assert (time.time() - t_start) < 0.09
- time.sleep(0.2)
+ time.sleep(0.3 - (time.time() - t_start))
# Plus two invocations
assert m.call_count == 4