coverage++
This commit is contained in:
parent
f4d4332472
commit
795e19f6b7
|
@ -168,7 +168,7 @@ class LiveConnection(object):
|
||||||
persistent_change
|
persistent_change
|
||||||
), "debug")
|
), "debug")
|
||||||
|
|
||||||
if self._backup_server_conn:
|
if not self._backup_server_conn:
|
||||||
self._backup_server_conn = self.c.server_conn
|
self._backup_server_conn = self.c.server_conn
|
||||||
self.c.server_conn = None
|
self.c.server_conn = None
|
||||||
else: # This is at least the second temporary change. We can kill the current connection.
|
else: # This is at least the second temporary change. We can kill the current connection.
|
||||||
|
|
|
@ -76,8 +76,6 @@ class ServerConnection(tcp.TCPClient, stateobject.SimpleStateObject):
|
||||||
tcp.TCPClient.__init__(self, address)
|
tcp.TCPClient.__init__(self, address)
|
||||||
|
|
||||||
self.state = [] # a list containing (conntype, state) tuples
|
self.state = [] # a list containing (conntype, state) tuples
|
||||||
self.peername = None
|
|
||||||
self.sockname = None
|
|
||||||
self.timestamp_start = None
|
self.timestamp_start = None
|
||||||
self.timestamp_end = None
|
self.timestamp_end = None
|
||||||
self.timestamp_tcp_setup = None
|
self.timestamp_tcp_setup = None
|
||||||
|
@ -98,8 +96,6 @@ class ServerConnection(tcp.TCPClient, stateobject.SimpleStateObject):
|
||||||
|
|
||||||
_stateobject_attributes = dict(
|
_stateobject_attributes = dict(
|
||||||
state=list,
|
state=list,
|
||||||
peername=tuple,
|
|
||||||
sockname=tuple,
|
|
||||||
timestamp_start=float,
|
timestamp_start=float,
|
||||||
timestamp_end=float,
|
timestamp_end=float,
|
||||||
timestamp_tcp_setup=float,
|
timestamp_tcp_setup=float,
|
||||||
|
@ -114,9 +110,10 @@ class ServerConnection(tcp.TCPClient, stateobject.SimpleStateObject):
|
||||||
def _get_state(self):
|
def _get_state(self):
|
||||||
d = super(ServerConnection, self)._get_state()
|
d = super(ServerConnection, self)._get_state()
|
||||||
d.update(
|
d.update(
|
||||||
address={"address": self.address(), "use_ipv6": self.address.use_ipv6},
|
address={"address": self.address(),
|
||||||
source_address= {"address": self.source_address(),
|
"use_ipv6": self.address.use_ipv6},
|
||||||
"use_ipv6": self.source_address.use_ipv6} if self.source_address else None,
|
source_address= ({"address": self.source_address(),
|
||||||
|
"use_ipv6": self.source_address.use_ipv6} if self.source_address else None),
|
||||||
cert=self.cert.to_pem() if self.cert else None
|
cert=self.cert.to_pem() if self.cert else None
|
||||||
)
|
)
|
||||||
return d
|
return d
|
||||||
|
@ -140,8 +137,6 @@ class ServerConnection(tcp.TCPClient, stateobject.SimpleStateObject):
|
||||||
def connect(self):
|
def connect(self):
|
||||||
self.timestamp_start = utils.timestamp()
|
self.timestamp_start = utils.timestamp()
|
||||||
tcp.TCPClient.connect(self)
|
tcp.TCPClient.connect(self)
|
||||||
self.peername = self.connection.getpeername()
|
|
||||||
self.sockname = self.connection.getsockname()
|
|
||||||
self.timestamp_tcp_setup = utils.timestamp()
|
self.timestamp_tcp_setup = utils.timestamp()
|
||||||
|
|
||||||
def send(self, message):
|
def send(self, message):
|
||||||
|
|
|
@ -1,2 +1,21 @@
|
||||||
class TestTcp:
|
import tservers
|
||||||
pass
|
from netlib.certutils import SSLCert
|
||||||
|
|
||||||
|
class TestTcp(tservers.IgnoreProxTest):
|
||||||
|
ignore = []
|
||||||
|
|
||||||
|
def test_simple(self):
|
||||||
|
# i = ignore (tcp passthrough), n = normal
|
||||||
|
pi, pn = self.pathocs()
|
||||||
|
i = pi.request("get:'/p/304'")
|
||||||
|
i2 = pi.request("get:'/p/304'")
|
||||||
|
n = pn.request("get:'/p/304'")
|
||||||
|
|
||||||
|
assert i.status_code == i2.status_code == n.status_code == 304
|
||||||
|
|
||||||
|
i_cert = SSLCert(i.sslinfo.certchain[0])
|
||||||
|
i2_cert = SSLCert(i2.sslinfo.certchain[0])
|
||||||
|
n_cert = SSLCert(n.sslinfo.certchain[0])
|
||||||
|
|
||||||
|
assert i_cert == i2_cert
|
||||||
|
assert not i_cert == n_cert
|
|
@ -100,7 +100,7 @@ class TestProcessProxyOptions:
|
||||||
|
|
||||||
|
|
||||||
class TestProxyServer:
|
class TestProxyServer:
|
||||||
@tutils.SkipWindows # binding to 0.0.0.0:1 works without special permissions on Windows
|
@tutils.SkipWindows # binding to 0.0.0.0:1 works without special permissions on Windows
|
||||||
def test_err(self):
|
def test_err(self):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
cmdline.common_options(parser)
|
cmdline.common_options(parser)
|
||||||
|
|
|
@ -312,7 +312,7 @@ class TestProxy(tservers.HTTPProxTest):
|
||||||
f = self.pathod("200:b@100")
|
f = self.pathod("200:b@100")
|
||||||
assert f.status_code == 200
|
assert f.status_code == 200
|
||||||
f = self.master.state.view[0]
|
f = self.master.state.view[0]
|
||||||
assert f.server_conn.peername == ("127.0.0.1", self.server.port)
|
assert f.server_conn.address == ("127.0.0.1", self.server.port)
|
||||||
|
|
||||||
class TestProxySSL(tservers.HTTPProxTest):
|
class TestProxySSL(tservers.HTTPProxTest):
|
||||||
ssl=True
|
ssl=True
|
||||||
|
@ -342,6 +342,7 @@ class MasterRedirectRequest(tservers.TestMaster):
|
||||||
|
|
||||||
def handle_response(self, f):
|
def handle_response(self, f):
|
||||||
f.response.content = 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)]
|
||||||
tservers.TestMaster.handle_response(self, f)
|
tservers.TestMaster.handle_response(self, f)
|
||||||
|
|
||||||
|
|
||||||
|
@ -374,7 +375,8 @@ class TestRedirectRequest(tservers.HTTPProxTest):
|
||||||
assert self.server.last_log()
|
assert self.server.last_log()
|
||||||
assert not self.server2.last_log()
|
assert not self.server2.last_log()
|
||||||
|
|
||||||
assert r3.content == r2.content == r1.content
|
assert r1.content == r2.content == r3.content
|
||||||
|
assert r1.headers.get_first("server-conn-id") == r3.headers.get_first("server-conn-id")
|
||||||
# Make sure that we actually use the same connection in this test case
|
# Make sure that we actually use the same connection in this test case
|
||||||
|
|
||||||
class MasterStreamRequest(tservers.TestMaster):
|
class MasterStreamRequest(tservers.TestMaster):
|
||||||
|
|
|
@ -263,6 +263,29 @@ class ReverseProxTest(ProxTestBase):
|
||||||
return p.request(q)
|
return p.request(q)
|
||||||
|
|
||||||
|
|
||||||
|
class IgnoreProxTest(ProxTestBase):
|
||||||
|
ssl = True
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_proxy_config(cls):
|
||||||
|
d = super(IgnoreProxTest, cls).get_proxy_config()
|
||||||
|
d["ignore"] = [".+:%s" % cls.server.port] # ignore by port
|
||||||
|
return d
|
||||||
|
|
||||||
|
def pathoc_raw(self):
|
||||||
|
return libpathod.pathoc.Pathoc(("127.0.0.1", self.proxy.port), ssl=self.ssl)
|
||||||
|
|
||||||
|
def pathocs(self):
|
||||||
|
"""
|
||||||
|
Returns a (pathod_ignore, pathoc_normal) tuple.
|
||||||
|
"""
|
||||||
|
p_ignore = self.pathoc_raw()
|
||||||
|
p_ignore.connect(("127.0.0.1", self.server.port))
|
||||||
|
p_normal = self.pathoc_raw()
|
||||||
|
p_normal.connect(("127.0.0.1", self.server2.port))
|
||||||
|
return p_ignore, p_normal
|
||||||
|
|
||||||
|
|
||||||
class ChainProxTest(ProxTestBase):
|
class ChainProxTest(ProxTestBase):
|
||||||
"""
|
"""
|
||||||
Chain n instances of mitmproxy in a row - because we can.
|
Chain n instances of mitmproxy in a row - because we can.
|
||||||
|
|
Loading…
Reference in New Issue