diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/builtins/test_anticache.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/builtins/test_anticomp.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/builtins/test_filestreamer.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/builtins/test_replace.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/builtins/test_script.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/builtins/test_setheaders.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/builtins/test_stickyauth.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/builtins/test_stickycookie.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/test_flow.py | 7 | ||||
-rw-r--r-- | test/mitmproxy/test_optmanager.py (renamed from test/mitmproxy/test_options.py) | 8 | ||||
-rw-r--r-- | test/mitmproxy/test_protocol_http2.py | 14 | ||||
-rw-r--r-- | test/mitmproxy/test_proxy.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/test_server.py | 45 | ||||
-rw-r--r-- | test/mitmproxy/tservers.py | 54 |
14 files changed, 79 insertions, 67 deletions
diff --git a/test/mitmproxy/builtins/test_anticache.py b/test/mitmproxy/builtins/test_anticache.py index 127e1c1a..5a00af03 100644 --- a/test/mitmproxy/builtins/test_anticache.py +++ b/test/mitmproxy/builtins/test_anticache.py @@ -2,7 +2,7 @@ from .. import tutils, mastertest from mitmproxy.builtins import anticache from mitmproxy.flow import master from mitmproxy.flow import state -from mitmproxy.flow import options +from mitmproxy import options class TestAntiCache(mastertest.MasterTest): diff --git a/test/mitmproxy/builtins/test_anticomp.py b/test/mitmproxy/builtins/test_anticomp.py index 601e56c8..6bfd54bb 100644 --- a/test/mitmproxy/builtins/test_anticomp.py +++ b/test/mitmproxy/builtins/test_anticomp.py @@ -2,7 +2,7 @@ from .. import tutils, mastertest from mitmproxy.builtins import anticomp from mitmproxy.flow import master from mitmproxy.flow import state -from mitmproxy.flow import options +from mitmproxy import options class TestAntiComp(mastertest.MasterTest): diff --git a/test/mitmproxy/builtins/test_filestreamer.py b/test/mitmproxy/builtins/test_filestreamer.py index 002006b7..c1d5947f 100644 --- a/test/mitmproxy/builtins/test_filestreamer.py +++ b/test/mitmproxy/builtins/test_filestreamer.py @@ -7,7 +7,7 @@ import os.path from mitmproxy.builtins import filestreamer from mitmproxy.flow import master, FlowReader from mitmproxy.flow import state -from mitmproxy.flow import options +from mitmproxy import options class TestStream(mastertest.MasterTest): diff --git a/test/mitmproxy/builtins/test_replace.py b/test/mitmproxy/builtins/test_replace.py index f8010bec..a0b4b722 100644 --- a/test/mitmproxy/builtins/test_replace.py +++ b/test/mitmproxy/builtins/test_replace.py @@ -2,7 +2,7 @@ from .. import tutils, mastertest from mitmproxy.builtins import replace from mitmproxy.flow import master from mitmproxy.flow import state -from mitmproxy.flow import options +from mitmproxy import options class TestReplace(mastertest.MasterTest): diff --git a/test/mitmproxy/builtins/test_script.py b/test/mitmproxy/builtins/test_script.py index c9616249..f37c7f94 100644 --- a/test/mitmproxy/builtins/test_script.py +++ b/test/mitmproxy/builtins/test_script.py @@ -4,7 +4,7 @@ from mitmproxy.builtins import script from mitmproxy import exceptions from mitmproxy.flow import master from mitmproxy.flow import state -from mitmproxy.flow import options +from mitmproxy import options from .. import tutils, mastertest diff --git a/test/mitmproxy/builtins/test_setheaders.py b/test/mitmproxy/builtins/test_setheaders.py index 1a8d048c..4465719d 100644 --- a/test/mitmproxy/builtins/test_setheaders.py +++ b/test/mitmproxy/builtins/test_setheaders.py @@ -2,7 +2,7 @@ from .. import tutils, mastertest from mitmproxy.builtins import setheaders from mitmproxy.flow import state -from mitmproxy.flow import options +from mitmproxy import options class TestSetHeaders(mastertest.MasterTest): diff --git a/test/mitmproxy/builtins/test_stickyauth.py b/test/mitmproxy/builtins/test_stickyauth.py index 1e617402..9233f435 100644 --- a/test/mitmproxy/builtins/test_stickyauth.py +++ b/test/mitmproxy/builtins/test_stickyauth.py @@ -2,7 +2,7 @@ from .. import tutils, mastertest from mitmproxy.builtins import stickyauth from mitmproxy.flow import master from mitmproxy.flow import state -from mitmproxy.flow import options +from mitmproxy import options class TestStickyAuth(mastertest.MasterTest): diff --git a/test/mitmproxy/builtins/test_stickycookie.py b/test/mitmproxy/builtins/test_stickycookie.py index b8d703bd..81b540db 100644 --- a/test/mitmproxy/builtins/test_stickycookie.py +++ b/test/mitmproxy/builtins/test_stickycookie.py @@ -2,7 +2,7 @@ from .. import tutils, mastertest from mitmproxy.builtins import stickycookie from mitmproxy.flow import master from mitmproxy.flow import state -from mitmproxy.flow import options +from mitmproxy import options from netlib import tutils as ntutils diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index e17a125c..36b212a7 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -3,8 +3,7 @@ import io import netlib.utils from netlib.http import Headers -from mitmproxy import filt, controller, flow -from mitmproxy.flow import options +from mitmproxy import filt, controller, flow, options from mitmproxy.contrib import tnetstring from mitmproxy.exceptions import FlowReadException from mitmproxy.models import Error @@ -745,7 +744,7 @@ class TestFlowMaster: f = tutils.tflow(resp=True) pb = [tutils.tflow(resp=True), f] fm = flow.FlowMaster( - flow.options.Options(), + options.Options(), DummyServer(ProxyConfig(options.Options())), s ) @@ -776,7 +775,7 @@ class TestFlowMaster: f.response = HTTPResponse.wrap(netlib.tutils.tresp(content=f.request)) pb = [f] - fm = flow.FlowMaster(flow.options.Options(), None, s) + fm = flow.FlowMaster(options.Options(), None, s) fm.refresh_server_playback = True assert not fm.do_server_playback(tutils.tflow()) diff --git a/test/mitmproxy/test_options.py b/test/mitmproxy/test_optmanager.py index af619b27..67f76ecd 100644 --- a/test/mitmproxy/test_options.py +++ b/test/mitmproxy/test_optmanager.py @@ -1,12 +1,12 @@ from __future__ import absolute_import, print_function, division import copy -from mitmproxy import options +from mitmproxy import optmanager from mitmproxy import exceptions from netlib import tutils -class TO(options.Options): +class TO(optmanager.OptManager): def __init__(self, one=None, two=None): self.one = one self.two = two @@ -93,8 +93,8 @@ def test_rollback(): def test_repr(): - assert repr(TO()) == "test.mitmproxy.test_options.TO({'one': None, 'two': None})" - assert repr(TO(one='x' * 60)) == """test.mitmproxy.test_options.TO({ + assert repr(TO()) == "test.mitmproxy.test_optmanager.TO({'one': None, 'two': None})" + assert repr(TO(one='x' * 60)) == """test.mitmproxy.test_optmanager.TO({ 'one': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'two': None })""" diff --git a/test/mitmproxy/test_protocol_http2.py b/test/mitmproxy/test_protocol_http2.py index a7a3ba3f..afbffb67 100644 --- a/test/mitmproxy/test_protocol_http2.py +++ b/test/mitmproxy/test_protocol_http2.py @@ -9,9 +9,8 @@ import traceback import h2 -from mitmproxy.flow import options +from mitmproxy import options from mitmproxy.proxy.config import ProxyConfig -from mitmproxy.cmdline import APP_HOST, APP_PORT import netlib from ..netlib import tservers as netlib_tservers @@ -90,11 +89,11 @@ class _Http2TestBase(object): @classmethod def setup_class(cls): cls.masteroptions = options.Options() - cnf, opts = cls.get_proxy_config() - cls.config = ProxyConfig(opts, **cnf) + opts = cls.get_options() + cls.config = ProxyConfig(opts) tmaster = tservers.TestMaster(opts, cls.config) - tmaster.start_app(APP_HOST, APP_PORT) + tmaster.start_app(options.APP_HOST, options.APP_PORT) cls.proxy = tservers.ProxyThread(tmaster) cls.proxy.start() @@ -103,11 +102,10 @@ class _Http2TestBase(object): cls.proxy.shutdown() @classmethod - def get_proxy_config(cls): + def get_options(cls): opts = options.Options(listen_port=0, no_upstream_cert=False) opts.cadir = os.path.join(tempfile.gettempdir(), "mitmproxy") - d = dict() - return d, opts + return opts @property def master(self): diff --git a/test/mitmproxy/test_proxy.py b/test/mitmproxy/test_proxy.py index 7095d9d2..6e790e28 100644 --- a/test/mitmproxy/test_proxy.py +++ b/test/mitmproxy/test_proxy.py @@ -3,10 +3,10 @@ import mock from OpenSSL import SSL from mitmproxy import cmdline +from mitmproxy import options from mitmproxy.proxy import ProxyConfig from mitmproxy.models.connections import ServerConnection from mitmproxy.proxy.server import DummyServer, ProxyServer, ConnectionHandler -from mitmproxy.flow import options from mitmproxy.proxy import config from netlib.exceptions import TcpDisconnect from pathod import test diff --git a/test/mitmproxy/test_server.py b/test/mitmproxy/test_server.py index b8b057fd..233af597 100644 --- a/test/mitmproxy/test_server.py +++ b/test/mitmproxy/test_server.py @@ -486,11 +486,11 @@ class TestSocks5(tservers.SocksModeTest): class TestHttps2Http(tservers.ReverseProxyTest): @classmethod - def get_proxy_config(cls): - d, opts = super(TestHttps2Http, cls).get_proxy_config() + def get_options(cls): + opts = super(TestHttps2Http, cls).get_options() s = parse_server_spec(opts.upstream_server) opts.upstream_server = "http://%s" % s.address - return d, opts + return opts def pathoc(self, ssl, sni=None): """ @@ -766,9 +766,14 @@ class TestFakeResponse(tservers.HTTPProxyTest): class TestServerConnect(tservers.HTTPProxyTest): masterclass = MasterFakeResponse - no_upstream_cert = True ssl = True + @classmethod + def get_options(cls): + opts = tservers.HTTPProxyTest.get_options() + opts.no_upstream_cert = True + return opts + def test_unnecessary_serverconnect(self): """A replayed/fake response with no_upstream_cert should not connect to an upstream server""" assert self.pathod("200").status_code == 200 @@ -1034,20 +1039,34 @@ class AddUpstreamCertsToClientChainMixin: if receivedCert.digest('sha256') == upstreamCert.digest('sha256'): upstream_cert_found_in_client_chain = True break - assert(upstream_cert_found_in_client_chain == self.add_upstream_certs_to_client_chain) - + assert(upstream_cert_found_in_client_chain == self.master.options.add_upstream_certs_to_client_chain) -class TestHTTPSAddUpstreamCertsToClientChainTrue(AddUpstreamCertsToClientChainMixin, tservers.HTTPProxyTest): +class TestHTTPSAddUpstreamCertsToClientChainTrue( + AddUpstreamCertsToClientChainMixin, + tservers.HTTPProxyTest +): """ - If --add-server-certs-to-client-chain is True, then the client should receive the upstream server's certificates + If --add-server-certs-to-client-chain is True, then the client should + receive the upstream server's certificates """ - add_upstream_certs_to_client_chain = True - + @classmethod + def get_options(cls): + opts = super(tservers.HTTPProxyTest, cls).get_options() + opts.add_upstream_certs_to_client_chain = True + return opts -class TestHTTPSAddUpstreamCertsToClientChainFalse(AddUpstreamCertsToClientChainMixin, tservers.HTTPProxyTest): +class TestHTTPSAddUpstreamCertsToClientChainFalse( + AddUpstreamCertsToClientChainMixin, + tservers.HTTPProxyTest +): """ - If --add-server-certs-to-client-chain is False, then the client should not receive the upstream server's certificates + If --add-server-certs-to-client-chain is False, then the client should not + receive the upstream server's certificates """ - add_upstream_certs_to_client_chain = False + @classmethod + def get_options(cls): + opts = super(tservers.HTTPProxyTest, cls).get_options() + opts.add_upstream_certs_to_client_chain = False + return opts diff --git a/test/mitmproxy/tservers.py b/test/mitmproxy/tservers.py index 495765da..f5119166 100644 --- a/test/mitmproxy/tservers.py +++ b/test/mitmproxy/tservers.py @@ -8,9 +8,7 @@ from mitmproxy.proxy.config import ProxyConfig from mitmproxy.proxy.server import ProxyServer import pathod.test import pathod.pathoc -from mitmproxy import flow, controller -from mitmproxy.flow import options -from mitmproxy.cmdline import APP_HOST, APP_PORT +from mitmproxy import flow, controller, options from mitmproxy import builtins testapp = flask.Flask(__name__) @@ -77,8 +75,8 @@ class ProxyTestBase(object): # Test Configuration ssl = None ssloptions = False - no_upstream_cert = False masterclass = TestMaster + add_upstream_certs_to_client_chain = False @classmethod @@ -90,10 +88,10 @@ class ProxyTestBase(object): ssl=cls.ssl, ssloptions=cls.ssloptions) - cnf, opts = cls.get_proxy_config() - cls.config = ProxyConfig(opts, **cnf) + opts = cls.get_options() + cls.config = ProxyConfig(opts) tmaster = cls.masterclass(opts, cls.config) - tmaster.start_app(APP_HOST, APP_PORT) + tmaster.start_app(options.APP_HOST, options.APP_PORT) cls.proxy = ProxyThread(tmaster) cls.proxy.start() @@ -117,13 +115,11 @@ class ProxyTestBase(object): return self.proxy.tmaster @classmethod - def get_proxy_config(cls): + def get_options(cls): cls.cadir = os.path.join(tempfile.gettempdir(), "mitmproxy") - cnf = dict() - return cnf, options.Options( + return options.Options( listen_port=0, cadir=cls.cadir, - no_upstream_cert = cls.no_upstream_cert, add_upstream_certs_to_client_chain=cls.add_upstream_certs_to_client_chain ) @@ -162,11 +158,11 @@ class HTTPProxyTest(ProxyTestBase): p = pathod.pathoc.Pathoc( ("127.0.0.1", self.proxy.port), True, fp=None ) - p.connect((APP_HOST, APP_PORT)) + p.connect((options.APP_HOST, options.APP_PORT)) return p.request("get:'%s'" % page) else: p = self.pathoc() - return p.request("get:'http://%s%s'" % (APP_HOST, page)) + return p.request("get:'http://%s%s'" % (options.APP_HOST, page)) class TResolver: @@ -198,10 +194,10 @@ class TransparentProxyTest(ProxyTestBase): super(TransparentProxyTest, cls).teardown_class() @classmethod - def get_proxy_config(cls): - d, opts = ProxyTestBase.get_proxy_config() + def get_options(cls): + opts = ProxyTestBase.get_options() opts.mode = "transparent" - return d, opts + return opts def pathod(self, spec, sni=None): """ @@ -230,8 +226,8 @@ class ReverseProxyTest(ProxyTestBase): ssl = None @classmethod - def get_proxy_config(cls): - d, opts = ProxyTestBase.get_proxy_config() + def get_options(cls): + opts = ProxyTestBase.get_options() opts.upstream_server = "".join( [ "https" if cls.ssl else "http", @@ -241,7 +237,7 @@ class ReverseProxyTest(ProxyTestBase): ] ) opts.mode = "reverse" - return d, opts + return opts def pathoc(self, sni=None): """ @@ -269,10 +265,10 @@ class ReverseProxyTest(ProxyTestBase): class SocksModeTest(HTTPProxyTest): @classmethod - def get_proxy_config(cls): - d, opts = ProxyTestBase.get_proxy_config() + def get_options(cls): + opts = ProxyTestBase.get_options() opts.mode = "socks5" - return d, opts + return opts class ChainProxyTest(ProxyTestBase): @@ -291,16 +287,16 @@ class ChainProxyTest(ProxyTestBase): cls.chain = [] super(ChainProxyTest, cls).setup_class() for _ in range(cls.n): - cnf, opts = cls.get_proxy_config() - config = ProxyConfig(opts, **cnf) + opts = cls.get_options() + config = ProxyConfig(opts) tmaster = cls.masterclass(opts, config) proxy = ProxyThread(tmaster) proxy.start() cls.chain.insert(0, proxy) # Patch the orginal proxy to upstream mode - cnf, opts = cls.get_proxy_config() - cls.config = cls.proxy.tmaster.config = cls.proxy.tmaster.server.config = ProxyConfig(opts, **cnf) + opts = cls.get_options() + cls.config = cls.proxy.tmaster.config = cls.proxy.tmaster.server.config = ProxyConfig(opts) @classmethod def teardown_class(cls): @@ -315,14 +311,14 @@ class ChainProxyTest(ProxyTestBase): proxy.tmaster.state.clear() @classmethod - def get_proxy_config(cls): - d, opts = super(ChainProxyTest, cls).get_proxy_config() + def get_options(cls): + opts = super(ChainProxyTest, cls).get_options() if cls.chain: # First proxy is in normal mode. opts.update( mode="upstream", upstream_server="http://127.0.0.1:%s" % cls.chain[0].port ) - return d, opts + return opts class HTTPUpstreamProxyTest(ChainProxyTest, HTTPProxyTest): |