diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_protocol_tcp.py | 23 | ||||
-rw-r--r-- | test/test_proxy.py | 2 | ||||
-rw-r--r-- | test/test_server.py | 6 | ||||
-rw-r--r-- | test/tservers.py | 23 |
4 files changed, 49 insertions, 5 deletions
diff --git a/test/test_protocol_tcp.py b/test/test_protocol_tcp.py index 7236ee67..8b6bb68d 100644 --- a/test/test_protocol_tcp.py +++ b/test/test_protocol_tcp.py @@ -1,2 +1,21 @@ -class TestTcp: - pass
\ No newline at end of file +import tservers +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
\ No newline at end of file diff --git a/test/test_proxy.py b/test/test_proxy.py index ad2bb2d7..f762e610 100644 --- a/test/test_proxy.py +++ b/test/test_proxy.py @@ -100,7 +100,7 @@ class TestProcessProxyOptions: 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): parser = argparse.ArgumentParser() cmdline.common_options(parser) diff --git a/test/test_server.py b/test/test_server.py index 21d01f5a..ed5133cb 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -312,7 +312,7 @@ class TestProxy(tservers.HTTPProxTest): f = self.pathod("200:b@100") assert f.status_code == 200 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): ssl=True @@ -342,6 +342,7 @@ class MasterRedirectRequest(tservers.TestMaster): def handle_response(self, f): 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) @@ -374,7 +375,8 @@ class TestRedirectRequest(tservers.HTTPProxTest): assert self.server.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 class MasterStreamRequest(tservers.TestMaster): diff --git a/test/tservers.py b/test/tservers.py index 9f2abbe1..91743903 100644 --- a/test/tservers.py +++ b/test/tservers.py @@ -263,6 +263,29 @@ class ReverseProxTest(ProxTestBase): 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): """ Chain n instances of mitmproxy in a row - because we can. |