aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2015-09-28 13:54:53 +0200
committerMaximilian Hils <git@maximilianhils.com>2015-09-28 13:54:53 +0200
commitc11ab3676dee2a490994665e867bcfcb26945777 (patch)
treef898c23973b10079fa4479238d5f8f5a8e61d46e /test
parent6661770d4eee3eab3305793613586f3684c24ae9 (diff)
parent6075957a9730c6ca5c4c7361bd774345f83d6f59 (diff)
downloadmitmproxy-c11ab3676dee2a490994665e867bcfcb26945777.tar.gz
mitmproxy-c11ab3676dee2a490994665e867bcfcb26945777.tar.bz2
mitmproxy-c11ab3676dee2a490994665e867bcfcb26945777.zip
Merge branch 'http-models'
Diffstat (limited to 'test')
-rw-r--r--test/test_dump.py8
-rw-r--r--test/test_flow.py99
-rw-r--r--test/test_protocol_http.py6
-rw-r--r--test/test_server.py6
4 files changed, 20 insertions, 99 deletions
diff --git a/test/test_dump.py b/test/test_dump.py
index 56d3edd2..a903a651 100644
--- a/test/test_dump.py
+++ b/test/test_dump.py
@@ -38,13 +38,13 @@ def test_strfuncs():
flow.request.stickycookie = True
flow.client_conn = mock.MagicMock()
flow.client_conn.address.host = "foo"
- flow.response = netlib.tutils.tresp(body=CONTENT_MISSING)
+ flow.response = netlib.tutils.tresp(content=CONTENT_MISSING)
flow.response.is_replay = True
flow.response.status_code = 300
m.echo_flow(flow)
- flow = tutils.tflow(resp=netlib.tutils.tresp(body="{"))
+ flow = tutils.tflow(resp=netlib.tutils.tresp(content="{"))
flow.response.headers["content-type"] = "application/json"
flow.response.status_code = 400
m.echo_flow(flow)
@@ -62,14 +62,14 @@ def test_contentview(get_content_view):
class TestDumpMaster:
def _cycle(self, m, content):
- f = tutils.tflow(req=netlib.tutils.treq(body=content))
+ f = tutils.tflow(req=netlib.tutils.treq(content=content))
l = Log("connect")
l.reply = mock.MagicMock()
m.handle_log(l)
m.handle_clientconnect(f.client_conn)
m.handle_serverconnect(f.server_conn)
m.handle_request(f)
- f.response = HTTPResponse.wrap(netlib.tutils.tresp(body=content))
+ f.response = HTTPResponse.wrap(netlib.tutils.tresp(content=content))
f = m.handle_response(f)
m.handle_clientdisconnect(f.client_conn)
return f
diff --git a/test/test_flow.py b/test/test_flow.py
index b54b7508..1d5cc354 100644
--- a/test/test_flow.py
+++ b/test/test_flow.py
@@ -8,8 +8,8 @@ import mock
import netlib.utils
from netlib import odict
-from netlib.http import CONTENT_MISSING, HDR_FORM_URLENCODED, Headers
-from libmproxy import filt, protocol, controller, tnetstring, flow
+from netlib.http import CONTENT_MISSING, Headers
+from libmproxy import filt, controller, tnetstring, flow
from libmproxy.models import Error, Flow, HTTPRequest, HTTPResponse, HTTPFlow, decoded
from libmproxy.proxy.config import HostMatcher
from libmproxy.proxy import ProxyConfig
@@ -338,7 +338,7 @@ class TestServerPlaybackState:
assert s._hash(r) == s._hash(r2)
-class TestFlow:
+class TestFlow(object):
def test_copy(self):
f = tutils.tflow(resp=True)
a0 = f.get_state()
@@ -849,7 +849,7 @@ class TestFlowMaster:
s = flow.State()
f = tutils.tflow()
- f.response = HTTPResponse.wrap(netlib.tutils.tresp(body=f.request))
+ f.response = HTTPResponse.wrap(netlib.tutils.tresp(content=f.request))
pb = [f]
fm = flow.FlowMaster(None, s)
@@ -903,7 +903,7 @@ class TestFlowMaster:
def test_server_playback_kill(self):
s = flow.State()
f = tutils.tflow()
- f.response = HTTPResponse.wrap(netlib.tutils.tresp(body=f.request))
+ f.response = HTTPResponse.wrap(netlib.tutils.tresp(content=f.request))
pb = [f]
fm = flow.FlowMaster(None, s)
fm.refresh_server_playback = True
@@ -1017,10 +1017,10 @@ class TestRequest:
r.port = 22
assert r.url == "https://address:22/path"
- assert r.pretty_url(True) == "https://address:22/path"
+ assert r.pretty_url == "https://address:22/path"
r.headers["Host"] = "foo.com"
- assert r.pretty_url(False) == "https://address:22/path"
- assert r.pretty_url(True) == "https://foo.com:22/path"
+ assert r.url == "https://address:22/path"
+ assert r.pretty_url == "https://foo.com:22/path"
def test_path_components(self):
r = HTTPRequest.wrap(netlib.tutils.treq())
@@ -1043,8 +1043,8 @@ class TestRequest:
def test_getset_form_urlencoded(self):
d = odict.ODict([("one", "two"), ("three", "four")])
- r = HTTPRequest.wrap(netlib.tutils.treq(body=netlib.utils.urlencode(d.lst)))
- r.headers["content-type"] = HDR_FORM_URLENCODED
+ r = HTTPRequest.wrap(netlib.tutils.treq(content=netlib.utils.urlencode(d.lst)))
+ r.headers["content-type"] = "application/x-www-form-urlencoded"
assert r.get_form_urlencoded() == d
d = odict.ODict([("x", "y")])
@@ -1105,35 +1105,6 @@ class TestRequest:
r.constrain_encoding()
assert "oink" not in r.headers["accept-encoding"]
- def test_decodeencode(self):
- r = HTTPRequest.wrap(netlib.tutils.treq())
- r.headers["content-encoding"] = "identity"
- r.content = "falafel"
- r.decode()
- assert "content-encoding" not in r.headers
- assert r.content == "falafel"
-
- r = HTTPRequest.wrap(netlib.tutils.treq())
- r.content = "falafel"
- assert not r.decode()
-
- r = HTTPRequest.wrap(netlib.tutils.treq())
- r.headers["content-encoding"] = "identity"
- r.content = "falafel"
- r.encode("identity")
- assert r.headers["content-encoding"] == "identity"
- assert r.content == "falafel"
-
- r = HTTPRequest.wrap(netlib.tutils.treq())
- r.headers["content-encoding"] = "identity"
- r.content = "falafel"
- r.encode("gzip")
- assert r.headers["content-encoding"] == "gzip"
- assert r.content != "falafel"
- r.decode()
- assert "content-encoding" not in r.headers
- assert r.content == "falafel"
-
def test_get_decoded_content(self):
r = HTTPRequest.wrap(netlib.tutils.treq())
r.content = None
@@ -1192,35 +1163,6 @@ class TestResponse:
assert not "foo" in r.content
assert r.headers["boo"] == "boo"
- def test_decodeencode(self):
- r = HTTPResponse.wrap(netlib.tutils.tresp())
- r.headers["content-encoding"] = "identity"
- r.content = "falafel"
- assert r.decode()
- assert "content-encoding" not in r.headers
- assert r.content == "falafel"
-
- r = HTTPResponse.wrap(netlib.tutils.tresp())
- r.headers["content-encoding"] = "identity"
- r.content = "falafel"
- r.encode("identity")
- assert r.headers["content-encoding"] == "identity"
- assert r.content == "falafel"
-
- r = HTTPResponse.wrap(netlib.tutils.tresp())
- r.headers["content-encoding"] = "identity"
- r.content = "falafel"
- r.encode("gzip")
- assert r.headers["content-encoding"] == "gzip"
- assert r.content != "falafel"
- assert r.decode()
- assert "content-encoding" not in r.headers
- assert r.content == "falafel"
-
- r.headers["content-encoding"] = "gzip"
- assert not r.decode()
- assert r.content == "falafel"
-
def test_get_content_type(self):
resp = HTTPResponse.wrap(netlib.tutils.tresp())
resp.headers = Headers(content_type="text/plain")
@@ -1265,27 +1207,6 @@ class TestClientConnection:
assert str(c)
-def test_decoded():
- r = HTTPRequest.wrap(netlib.tutils.treq())
- assert r.content == "content"
- assert "content-encoding" not in r.headers
- r.encode("gzip")
- assert r.headers["content-encoding"]
- assert r.content != "content"
- with decoded(r):
- assert "content-encoding" not in r.headers
- assert r.content == "content"
- assert r.headers["content-encoding"]
- assert r.content != "content"
-
- with decoded(r):
- r.content = "foo"
-
- assert r.content != "foo"
- r.decode()
- assert r.content == "foo"
-
-
def test_replacehooks():
h = flow.ReplaceHooks()
h.add("~q", "foo", "bar")
diff --git a/test/test_protocol_http.py b/test/test_protocol_http.py
index 5943b57f..8c843d73 100644
--- a/test/test_protocol_http.py
+++ b/test/test_protocol_http.py
@@ -48,14 +48,14 @@ class TestInvalidRequests(tservers.HTTPProxTest):
p = self.pathoc()
r = p.request("connect:'%s:%s'" % ("127.0.0.1", self.server2.port))
assert r.status_code == 400
- assert "Invalid HTTP request form" in r.body
+ assert "Invalid HTTP request form" in r.content
def test_relative_request(self):
p = self.pathoc_raw()
p.connect()
r = p.request("get:/p/200")
assert r.status_code == 400
- assert "Invalid HTTP request form" in r.body
+ assert "Invalid HTTP request form" in r.content
class TestExpectHeader(tservers.HTTPProxTest):
@@ -81,4 +81,4 @@ class TestExpectHeader(tservers.HTTPProxTest):
resp = http1.read_response(client.rfile, treq())
assert resp.status_code == 200
- client.finish() \ No newline at end of file
+ client.finish()
diff --git a/test/test_server.py b/test/test_server.py
index 5f644c96..9488595f 100644
--- a/test/test_server.py
+++ b/test/test_server.py
@@ -235,7 +235,8 @@ class TestHTTP(tservers.HTTPProxTest, CommonMixin, AppMixin):
# There's a race here, which means we can get any of a number of errors.
# Rather than introduce yet another sleep into the test suite, we just
# relax the Exception specification.
- tutils.raises(Exception, p.request, "get:'%s'" % response)
+ with raises(Exception):
+ p.request("get:'%s'" % response)
def test_reconnect(self):
req = "get:'%s/p/200:b@1:da'" % self.server.urlbase
@@ -573,7 +574,6 @@ class TestProxy(tservers.HTTPProxTest):
recvd += len(connection.recv(5000))
connection.close()
- print(self.master.state.view._list)
first_flow = self.master.state.view[0]
second_flow = self.master.state.view[1]
assert first_flow.server_conn.timestamp_tcp_setup
@@ -616,7 +616,7 @@ class MasterRedirectRequest(tservers.TestMaster):
super(MasterRedirectRequest, self).handle_request(f)
def handle_response(self, f):
- f.response.body = str(f.client_conn.address.port)
+ f.response.content = str(f.client_conn.address.port)
f.response.headers["server-conn-id"] = str(f.server_conn.source_address.port)
super(MasterRedirectRequest, self).handle_response(f)