aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_protocol_http.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-09-05 00:18:17 +0200
committerMaximilian Hils <git@maximilianhils.com>2014-09-05 00:18:17 +0200
commita7a3b5703adff7de12fb479a90ea2628465a4486 (patch)
tree63ef97386f3861885945ec5f5f135720435b6914 /test/test_protocol_http.py
parentb23a1aa4a4dd9f09fc199d03f546a8fafc8b27b8 (diff)
downloadmitmproxy-a7a3b5703adff7de12fb479a90ea2628465a4486.tar.gz
mitmproxy-a7a3b5703adff7de12fb479a90ea2628465a4486.tar.bz2
mitmproxy-a7a3b5703adff7de12fb479a90ea2628465a4486.zip
change replay_request behaviour, refs #346; test upstream proxy mode
Diffstat (limited to 'test/test_protocol_http.py')
-rw-r--r--test/test_protocol_http.py119
1 files changed, 1 insertions, 118 deletions
diff --git a/test/test_protocol_http.py b/test/test_protocol_http.py
index 3ca590f1..41019672 100644
--- a/test/test_protocol_http.py
+++ b/test/test_protocol_http.py
@@ -1,5 +1,4 @@
from libmproxy.protocol.http import *
-from libmproxy.protocol import KILL
from cStringIO import StringIO
import tutils, tservers
@@ -134,120 +133,4 @@ class TestInvalidRequests(tservers.HTTPProxTest):
p.connect()
r = p.request("get:/p/200")
assert r.status_code == 400
- assert "Invalid HTTP request form" in r.content
-
-
-class TestProxyChaining(tservers.HTTPChainProxyTest):
- def test_all(self):
- self.chain[1].tmaster.replacehooks.add("~q", "foo", "bar") # replace in request
- self.chain[0].tmaster.replacehooks.add("~q", "foo", "oh noes!")
- self.proxy.tmaster.replacehooks.add("~q", "bar", "baz")
- self.chain[0].tmaster.replacehooks.add("~s", "baz", "ORLY") # replace in response
-
- p = self.pathoc()
- req = p.request("get:'%s/p/418:b\"foo\"'" % self.server.urlbase)
- assert req.content == "ORLY"
- assert req.status_code == 418
-
-class TestProxyChainingSSL(tservers.HTTPChainProxyTest):
- ssl = True
- def test_simple(self):
- p = self.pathoc()
- req = p.request("get:'/p/418:b\"content\"'")
- assert req.content == "content"
- assert req.status_code == 418
-
- assert self.chain[1].tmaster.state.flow_count() == 2 # CONNECT from pathoc to chain[0],
- # request from pathoc to chain[0]
- assert self.chain[0].tmaster.state.flow_count() == 2 # CONNECT from chain[1] to proxy,
- # request from chain[1] to proxy
- assert self.proxy.tmaster.state.flow_count() == 1 # request from chain[0] (regular proxy doesn't store CONNECTs)
-
- def test_closing_connect_response(self):
- """
- https://github.com/mitmproxy/mitmproxy/issues/313
- """
- def handle_request(f):
- f.request.httpversion = (1, 0)
- del f.request.headers["Content-Length"]
- f.reply()
- _handle_request = self.chain[0].tmaster.handle_request
- self.chain[0].tmaster.handle_request = handle_request
- try:
- assert self.pathoc().request("get:/p/418").status_code == 418
- finally:
- self.chain[0].tmaster.handle_request = _handle_request
-
- def test_sni(self):
- p = self.pathoc(sni="foo.com")
- req = p.request("get:'/p/418:b\"content\"'")
- assert req.content == "content"
- assert req.status_code == 418
-
-class TestProxyChainingSSLReconnect(tservers.HTTPChainProxyTest):
- ssl = True
-
- def test_reconnect(self):
- """
- Tests proper functionality of ConnectionHandler.server_reconnect mock.
- If we have a disconnect on a secure connection that's transparently proxified to
- an upstream http proxy, we need to send the CONNECT request again.
- """
- def kill_requests(master, attr, exclude):
- k = [0] # variable scope workaround: put into array
- _func = getattr(master, attr)
- def handler(f):
- k[0] += 1
- if not (k[0] in exclude):
- f.client_conn.finish()
- f.error = Error("terminated")
- f.reply(KILL)
- return _func(f)
- setattr(master, attr, handler)
-
- kill_requests(self.proxy.tmaster, "handle_request",
- exclude=[
- # fail first request
- 2, # allow second request
- ])
-
- kill_requests(self.chain[0].tmaster, "handle_request",
- exclude=[
- 1, # CONNECT
- # fail first request
- 3, # reCONNECT
- 4, # request
- ])
-
- p = self.pathoc()
- req = p.request("get:'/p/418:b\"content\"'")
- assert self.chain[1].tmaster.state.flow_count() == 2 # CONNECT and request
- assert self.chain[0].tmaster.state.flow_count() == 4 # CONNECT, failing request,
- # reCONNECT, request
- assert self.proxy.tmaster.state.flow_count() == 2 # failing request, request
- # (doesn't store (repeated) CONNECTs from chain[0]
- # as it is a regular proxy)
- assert req.content == "content"
- assert req.status_code == 418
-
- assert not self.proxy.tmaster.state._flow_list[0].response # killed
- assert self.proxy.tmaster.state._flow_list[1].response
-
- assert self.chain[1].tmaster.state._flow_list[0].request.form_in == "authority"
- assert self.chain[1].tmaster.state._flow_list[1].request.form_in == "relative"
-
- assert self.chain[0].tmaster.state._flow_list[0].request.form_in == "authority"
- assert self.chain[0].tmaster.state._flow_list[1].request.form_in == "relative"
- assert self.chain[0].tmaster.state._flow_list[2].request.form_in == "authority"
- assert self.chain[0].tmaster.state._flow_list[3].request.form_in == "relative"
-
- assert self.proxy.tmaster.state._flow_list[0].request.form_in == "relative"
- assert self.proxy.tmaster.state._flow_list[1].request.form_in == "relative"
-
- req = p.request("get:'/p/418:b\"content2\"'")
-
- assert req.status_code == 502
- assert self.chain[1].tmaster.state.flow_count() == 3 # + new request
- assert self.chain[0].tmaster.state.flow_count() == 6 # + new request, repeated CONNECT from chain[1]
- # (both terminated)
- assert self.proxy.tmaster.state.flow_count() == 2 # nothing happened here
+ assert "Invalid HTTP request form" in r.content \ No newline at end of file