mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-30 03:14:22 +00:00
coverage++
This commit is contained in:
parent
1d45c54a04
commit
f4d4332472
@ -59,11 +59,11 @@ class TCPHandler(ProtocolHandler):
|
|||||||
# if one of the peers is over SSL, we need to send bytes/strings
|
# if one of the peers is over SSL, we need to send bytes/strings
|
||||||
if not src.ssl_established: # only ssl to dst, i.e. we revc'd into buf but need bytes/string now.
|
if not src.ssl_established: # only ssl to dst, i.e. we revc'd into buf but need bytes/string now.
|
||||||
contents = buf[:size].tobytes()
|
contents = buf[:size].tobytes()
|
||||||
# self.c.log("%s %s\r\n%s" % (direction, dst_str, cleanBin(contents)), "debug")
|
self.c.log("%s %s\r\n%s" % (direction, dst_str, cleanBin(contents)), "debug")
|
||||||
dst.connection.send(contents)
|
dst.connection.send(contents)
|
||||||
else:
|
else:
|
||||||
# socket.socket.send supports raw bytearrays/memoryviews
|
# socket.socket.send supports raw bytearrays/memoryviews
|
||||||
# self.c.log("%s %s\r\n%s" % (direction, dst_str, cleanBin(buf.tobytes())), "debug")
|
self.c.log("%s %s\r\n%s" % (direction, dst_str, cleanBin(buf.tobytes())), "debug")
|
||||||
dst.connection.send(buf[:size])
|
dst.connection.send(buf[:size])
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
self.c.log("TCP connection closed unexpectedly.", "debug")
|
self.c.log("TCP connection closed unexpectedly.", "debug")
|
||||||
|
@ -37,6 +37,19 @@ class TestHTTPRequest:
|
|||||||
def test_origin_form(self):
|
def test_origin_form(self):
|
||||||
s = StringIO("GET /foo\xff HTTP/1.1")
|
s = StringIO("GET /foo\xff HTTP/1.1")
|
||||||
tutils.raises("Bad HTTP request line", HTTPRequest.from_stream, s)
|
tutils.raises("Bad HTTP request line", HTTPRequest.from_stream, s)
|
||||||
|
s = StringIO("GET /foo HTTP/1.1\r\nConnection: Upgrade\r\nUpgrade: h2c")
|
||||||
|
r = HTTPRequest.from_stream(s)
|
||||||
|
assert r.headers["Upgrade"] == ["h2c"]
|
||||||
|
|
||||||
|
raw = r._assemble_headers()
|
||||||
|
assert "Upgrade" not in raw
|
||||||
|
assert "Host" not in raw
|
||||||
|
|
||||||
|
r.url = "http://example.com/foo"
|
||||||
|
|
||||||
|
raw = r._assemble_headers()
|
||||||
|
assert "Host" in raw
|
||||||
|
|
||||||
|
|
||||||
def test_authority_form(self):
|
def test_authority_form(self):
|
||||||
s = StringIO("CONNECT oops-no-port.com HTTP/1.1")
|
s = StringIO("CONNECT oops-no-port.com HTTP/1.1")
|
||||||
@ -45,6 +58,7 @@ class TestHTTPRequest:
|
|||||||
r = HTTPRequest.from_stream(s)
|
r = HTTPRequest.from_stream(s)
|
||||||
r.scheme, r.host, r.port = "http", "address", 22
|
r.scheme, r.host, r.port = "http", "address", 22
|
||||||
assert r._assemble() == "CONNECT address:22 HTTP/1.1\r\nHost: address:22\r\n\r\n"
|
assert r._assemble() == "CONNECT address:22 HTTP/1.1\r\nHost: address:22\r\n\r\n"
|
||||||
|
assert r.pretty_url(False) == "address:22"
|
||||||
|
|
||||||
def test_absolute_form(self):
|
def test_absolute_form(self):
|
||||||
s = StringIO("GET oops-no-protocol.com HTTP/1.1")
|
s = StringIO("GET oops-no-protocol.com HTTP/1.1")
|
||||||
@ -65,6 +79,10 @@ class TestHTTPRequest:
|
|||||||
assert r.port == 42
|
assert r.port == 42
|
||||||
assert r.path == "/ORLY"
|
assert r.path == "/ORLY"
|
||||||
|
|
||||||
|
def test_repr(self):
|
||||||
|
r = tutils.treq()
|
||||||
|
assert repr(r)
|
||||||
|
|
||||||
|
|
||||||
class TestHTTPResponse:
|
class TestHTTPResponse:
|
||||||
def test_read_from_stringio(self):
|
def test_read_from_stringio(self):
|
||||||
@ -86,6 +104,19 @@ class TestHTTPResponse:
|
|||||||
assert r.content == ""
|
assert r.content == ""
|
||||||
tutils.raises("Invalid server response: 'content", HTTPResponse.from_stream, s, "GET")
|
tutils.raises("Invalid server response: 'content", HTTPResponse.from_stream, s, "GET")
|
||||||
|
|
||||||
|
def test_repr(self):
|
||||||
|
r = tutils.tresp()
|
||||||
|
assert "unknown content type" in repr(r)
|
||||||
|
r.headers["content-type"] = ["foo"]
|
||||||
|
assert "foo" in repr(r)
|
||||||
|
assert repr(tutils.tresp(content=CONTENT_MISSING))
|
||||||
|
|
||||||
|
|
||||||
|
class TestHTTPFlow(object):
|
||||||
|
def test_repr(self):
|
||||||
|
f = tutils.tflow(resp=True, err=True)
|
||||||
|
assert repr(f)
|
||||||
|
|
||||||
|
|
||||||
class TestInvalidRequests(tservers.HTTPProxTest):
|
class TestInvalidRequests(tservers.HTTPProxTest):
|
||||||
ssl = True
|
ssl = True
|
||||||
|
2
test/test_protocol_tcp.py
Normal file
2
test/test_protocol_tcp.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
class TestTcp:
|
||||||
|
pass
|
Loading…
Reference in New Issue
Block a user