coverage++

This commit is contained in:
Maximilian Hils 2014-09-04 14:46:25 +02:00
parent 1d45c54a04
commit f4d4332472
3 changed files with 35 additions and 2 deletions

View File

@ -59,11 +59,11 @@ class TCPHandler(ProtocolHandler):
# 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.
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)
else:
# 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])
except socket.error as e:
self.c.log("TCP connection closed unexpectedly.", "debug")

View File

@ -37,6 +37,19 @@ class TestHTTPRequest:
def test_origin_form(self):
s = StringIO("GET /foo\xff HTTP/1.1")
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):
s = StringIO("CONNECT oops-no-port.com HTTP/1.1")
@ -45,6 +58,7 @@ class TestHTTPRequest:
r = HTTPRequest.from_stream(s)
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.pretty_url(False) == "address:22"
def test_absolute_form(self):
s = StringIO("GET oops-no-protocol.com HTTP/1.1")
@ -65,6 +79,10 @@ class TestHTTPRequest:
assert r.port == 42
assert r.path == "/ORLY"
def test_repr(self):
r = tutils.treq()
assert repr(r)
class TestHTTPResponse:
def test_read_from_stringio(self):
@ -86,6 +104,19 @@ class TestHTTPResponse:
assert r.content == ""
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):
ssl = True

View File

@ -0,0 +1,2 @@
class TestTcp:
pass