From b13acd7956f2e09bf5f9001f8f55d018a381f6c2 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sat, 26 Sep 2015 01:23:59 +0200 Subject: adjust to netlib request changes + docs --- test/test_dump.py | 2 +- test/test_flow.py | 10 +++++----- test/test_server.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/test_dump.py b/test/test_dump.py index 56d3edd2..9586a304 100644 --- a/test/test_dump.py +++ b/test/test_dump.py @@ -62,7 +62,7 @@ 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) diff --git a/test/test_flow.py b/test/test_flow.py index b54b7508..0cd45576 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -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() @@ -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,7 +1043,7 @@ 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 = HTTPRequest.wrap(netlib.tutils.treq(content=netlib.utils.urlencode(d.lst))) r.headers["content-type"] = HDR_FORM_URLENCODED assert r.get_form_urlencoded() == d diff --git a/test/test_server.py b/test/test_server.py index 5f644c96..2a09d2e5 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 -- cgit v1.2.3 From 1b6ea5caf3ab7c30cc4a822b81ad8288efbae70d Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sat, 26 Sep 2015 17:41:14 +0200 Subject: adjust to netlib response changes + docs --- test/test_dump.py | 6 +++--- test/test_flow.py | 10 +++++----- test/test_protocol_http.py | 4 ++-- test/test_server.py | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/test_dump.py b/test/test_dump.py index 9586a304..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) @@ -69,7 +69,7 @@ class TestDumpMaster: 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 0cd45576..ca862bda 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 @@ -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 @@ -1044,7 +1044,7 @@ class TestRequest: def test_getset_form_urlencoded(self): d = odict.ODict([("one", "two"), ("three", "four")]) r = HTTPRequest.wrap(netlib.tutils.treq(content=netlib.utils.urlencode(d.lst))) - r.headers["content-type"] = HDR_FORM_URLENCODED + r.headers["content-type"] = "application/x-www-form-urlencoded" assert r.get_form_urlencoded() == d d = odict.ODict([("x", "y")]) diff --git a/test/test_protocol_http.py b/test/test_protocol_http.py index 5ddb5b5b..4158adda 100644 --- a/test/test_protocol_http.py +++ b/test/test_protocol_http.py @@ -46,11 +46,11 @@ 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 diff --git a/test/test_server.py b/test/test_server.py index 2a09d2e5..9488595f 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -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) -- cgit v1.2.3 From 6075957a9730c6ca5c4c7361bd774345f83d6f59 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 27 Sep 2015 00:50:14 +0200 Subject: move tests to netlib --- test/test_flow.py | 79 ------------------------------------------------------- 1 file changed, 79 deletions(-) (limited to 'test') diff --git a/test/test_flow.py b/test/test_flow.py index ca862bda..1d5cc354 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -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") -- cgit v1.2.3