diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-10-19 13:22:50 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-10-19 13:22:50 +1300 |
commit | bce387a5a0d52f682f479b11cb40ae0918e070c0 (patch) | |
tree | 4b96065dc5f7c7e904a731002a184ae890de4802 /test | |
parent | 264a09e7789500673282075b2f5b9956268f0cea (diff) | |
download | mitmproxy-bce387a5a0d52f682f479b11cb40ae0918e070c0.tar.gz mitmproxy-bce387a5a0d52f682f479b11cb40ae0918e070c0.tar.bz2 mitmproxy-bce387a5a0d52f682f479b11cb40ae0918e070c0.zip |
Kill flow.master - create master.Master
Also extract events into .events
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/builtins/test_anticache.py | 4 | ||||
-rw-r--r-- | test/mitmproxy/builtins/test_anticomp.py | 4 | ||||
-rw-r--r-- | test/mitmproxy/builtins/test_clientplayback.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/builtins/test_filestreamer.py | 7 | ||||
-rw-r--r-- | test/mitmproxy/builtins/test_replace.py | 4 | ||||
-rw-r--r-- | test/mitmproxy/builtins/test_script.py | 12 | ||||
-rw-r--r-- | test/mitmproxy/builtins/test_stickyauth.py | 4 | ||||
-rw-r--r-- | test/mitmproxy/builtins/test_stickycookie.py | 4 | ||||
-rw-r--r-- | test/mitmproxy/builtins/test_streambodies.py | 4 | ||||
-rw-r--r-- | test/mitmproxy/data/addonscripts/recorder.py | 3 | ||||
-rw-r--r-- | test/mitmproxy/mastertest.py | 6 | ||||
-rw-r--r-- | test/mitmproxy/script/test_concurrent.py | 4 | ||||
-rw-r--r-- | test/mitmproxy/test_addons.py | 4 | ||||
-rw-r--r-- | test/mitmproxy/test_controller.py | 7 | ||||
-rw-r--r-- | test/mitmproxy/test_examples.py | 4 | ||||
-rw-r--r-- | test/mitmproxy/test_flow.py | 13 | ||||
-rw-r--r-- | test/mitmproxy/test_flow_state.py | 3 | ||||
-rw-r--r-- | test/mitmproxy/test_web_app.py | 7 | ||||
-rw-r--r-- | test/mitmproxy/tservers.py | 7 |
19 files changed, 55 insertions, 48 deletions
diff --git a/test/mitmproxy/builtins/test_anticache.py b/test/mitmproxy/builtins/test_anticache.py index df73bb1b..790ae97d 100644 --- a/test/mitmproxy/builtins/test_anticache.py +++ b/test/mitmproxy/builtins/test_anticache.py @@ -1,6 +1,6 @@ from .. import tutils, mastertest from mitmproxy.builtins import anticache -from mitmproxy.flow import master +from mitmproxy import master from mitmproxy import options from mitmproxy import proxy @@ -8,7 +8,7 @@ from mitmproxy import proxy class TestAntiCache(mastertest.MasterTest): def test_simple(self): o = options.Options(anticache = True) - m = master.FlowMaster(o, proxy.DummyServer()) + m = master.Master(o, proxy.DummyServer()) sa = anticache.AntiCache() m.addons.add(sa) diff --git a/test/mitmproxy/builtins/test_anticomp.py b/test/mitmproxy/builtins/test_anticomp.py index 84618ba6..d5a0d6eb 100644 --- a/test/mitmproxy/builtins/test_anticomp.py +++ b/test/mitmproxy/builtins/test_anticomp.py @@ -1,6 +1,6 @@ from .. import tutils, mastertest from mitmproxy.builtins import anticomp -from mitmproxy.flow import master +from mitmproxy import master from mitmproxy import options from mitmproxy import proxy @@ -8,7 +8,7 @@ from mitmproxy import proxy class TestAntiComp(mastertest.MasterTest): def test_simple(self): o = options.Options(anticomp = True) - m = master.FlowMaster(o, proxy.DummyServer()) + m = master.Master(o, proxy.DummyServer()) sa = anticomp.AntiComp() m.addons.add(sa) diff --git a/test/mitmproxy/builtins/test_clientplayback.py b/test/mitmproxy/builtins/test_clientplayback.py index 15702340..e2c5be7e 100644 --- a/test/mitmproxy/builtins/test_clientplayback.py +++ b/test/mitmproxy/builtins/test_clientplayback.py @@ -25,7 +25,7 @@ class TestClientPlayback: cp.keepserving = False cp.flows = None cp.current = None - with mock.patch("mitmproxy.controller.Master.shutdown") as sd: + with mock.patch("mitmproxy.master.Master.shutdown") as sd: with mastertest.mockctx(): cp.tick() sd.assert_called() diff --git a/test/mitmproxy/builtins/test_filestreamer.py b/test/mitmproxy/builtins/test_filestreamer.py index 31e607b5..35fe1ca2 100644 --- a/test/mitmproxy/builtins/test_filestreamer.py +++ b/test/mitmproxy/builtins/test_filestreamer.py @@ -3,7 +3,8 @@ from .. import tutils, mastertest import os.path from mitmproxy.builtins import filestreamer -from mitmproxy.flow import master, FlowReader +from mitmproxy import master +from mitmproxy.flow import io from mitmproxy import options from mitmproxy import proxy @@ -14,13 +15,13 @@ class TestStream(mastertest.MasterTest): p = os.path.join(tdir, "foo") def r(): - r = FlowReader(open(p, "rb")) + r = io.FlowReader(open(p, "rb")) return list(r.stream()) o = options.Options( outfile = (p, "wb") ) - m = master.FlowMaster(o, proxy.DummyServer()) + m = master.Master(o, proxy.DummyServer()) sa = filestreamer.FileStreamer() m.addons.add(sa) diff --git a/test/mitmproxy/builtins/test_replace.py b/test/mitmproxy/builtins/test_replace.py index 98e2e169..35f3d430 100644 --- a/test/mitmproxy/builtins/test_replace.py +++ b/test/mitmproxy/builtins/test_replace.py @@ -1,6 +1,6 @@ from .. import tutils, mastertest, tservers from mitmproxy.builtins import replace -from mitmproxy.flow import master +from mitmproxy import master from mitmproxy import options from mitmproxy import proxy @@ -36,7 +36,7 @@ class TestReplace(mastertest.MasterTest): ("~s", "foo", "bar"), ] ) - m = master.FlowMaster(o, proxy.DummyServer()) + m = master.Master(o, proxy.DummyServer()) sa = replace.Replace() m.addons.add(sa) diff --git a/test/mitmproxy/builtins/test_script.py b/test/mitmproxy/builtins/test_script.py index 331a7fa2..ab4343b5 100644 --- a/test/mitmproxy/builtins/test_script.py +++ b/test/mitmproxy/builtins/test_script.py @@ -8,7 +8,7 @@ from mitmproxy import exceptions from mitmproxy import options from mitmproxy import proxy from mitmproxy.builtins import script -from mitmproxy.flow import master +from mitmproxy import master from .. import tutils, mastertest @@ -58,7 +58,7 @@ def test_load_script(): class TestScript(mastertest.MasterTest): def test_simple(self): o = options.Options() - m = master.FlowMaster(o, proxy.DummyServer()) + m = master.Master(o, proxy.DummyServer()) sc = script.Script( tutils.test_data.path( "data/addonscripts/recorder.py" @@ -112,7 +112,7 @@ class TestScript(mastertest.MasterTest): def test_addon(self): o = options.Options() - m = master.FlowMaster(o, proxy.DummyServer()) + m = master.Master(o, proxy.DummyServer()) sc = script.Script( tutils.test_data.path( "data/addonscripts/addon.py" @@ -145,7 +145,7 @@ class TestCutTraceback: class TestScriptLoader(mastertest.MasterTest): def test_run_once(self): o = options.Options(scripts=[]) - m = master.FlowMaster(o, proxy.DummyServer()) + m = master.Master(o, proxy.DummyServer()) sl = script.ScriptLoader() m.addons.add(sl) @@ -169,7 +169,7 @@ class TestScriptLoader(mastertest.MasterTest): def test_simple(self): o = options.Options(scripts=[]) - m = master.FlowMaster(o, proxy.DummyServer()) + m = master.Master(o, proxy.DummyServer()) sc = script.ScriptLoader() m.addons.add(sc) assert len(m.addons) == 1 @@ -184,7 +184,7 @@ class TestScriptLoader(mastertest.MasterTest): def test_dupes(self): o = options.Options(scripts=["one", "one"]) - m = master.FlowMaster(o, proxy.DummyServer()) + m = master.Master(o, proxy.DummyServer()) sc = script.ScriptLoader() tutils.raises(exceptions.OptionsError, m.addons.add, o, sc) diff --git a/test/mitmproxy/builtins/test_stickyauth.py b/test/mitmproxy/builtins/test_stickyauth.py index 3331a82e..22523548 100644 --- a/test/mitmproxy/builtins/test_stickyauth.py +++ b/test/mitmproxy/builtins/test_stickyauth.py @@ -1,6 +1,6 @@ from .. import tutils, mastertest from mitmproxy.builtins import stickyauth -from mitmproxy.flow import master +from mitmproxy import master from mitmproxy import options from mitmproxy import proxy @@ -8,7 +8,7 @@ from mitmproxy import proxy class TestStickyAuth(mastertest.MasterTest): def test_simple(self): o = options.Options(stickyauth = ".*") - m = master.FlowMaster(o, proxy.DummyServer()) + m = master.Master(o, proxy.DummyServer()) sa = stickyauth.StickyAuth() m.addons.add(sa) diff --git a/test/mitmproxy/builtins/test_stickycookie.py b/test/mitmproxy/builtins/test_stickycookie.py index d1a535cf..c70b03d8 100644 --- a/test/mitmproxy/builtins/test_stickycookie.py +++ b/test/mitmproxy/builtins/test_stickycookie.py @@ -1,6 +1,6 @@ from .. import tutils, mastertest from mitmproxy.builtins import stickycookie -from mitmproxy.flow import master +from mitmproxy import master from mitmproxy import options from mitmproxy import proxy from netlib import tutils as ntutils @@ -14,7 +14,7 @@ def test_domain_match(): class TestStickyCookie(mastertest.MasterTest): def mk(self): o = options.Options(stickycookie = ".*") - m = master.FlowMaster(o, proxy.DummyServer()) + m = master.Master(o, proxy.DummyServer()) sc = stickycookie.StickyCookie() m.addons.add(sc) return m, sc diff --git a/test/mitmproxy/builtins/test_streambodies.py b/test/mitmproxy/builtins/test_streambodies.py index 6ff86048..4a8c2474 100644 --- a/test/mitmproxy/builtins/test_streambodies.py +++ b/test/mitmproxy/builtins/test_streambodies.py @@ -1,5 +1,5 @@ from .. import tutils, mastertest -from mitmproxy.flow import master +from mitmproxy import master from mitmproxy import options from mitmproxy import proxy @@ -9,7 +9,7 @@ from mitmproxy.builtins import streambodies class TestStreamBodies(mastertest.MasterTest): def test_simple(self): o = options.Options(stream_large_bodies = 10) - m = master.FlowMaster(o, proxy.DummyServer()) + m = master.Master(o, proxy.DummyServer()) sa = streambodies.StreamBodies() m.addons.add(sa) diff --git a/test/mitmproxy/data/addonscripts/recorder.py b/test/mitmproxy/data/addonscripts/recorder.py index 3d7a51bf..5be88e5c 100644 --- a/test/mitmproxy/data/addonscripts/recorder.py +++ b/test/mitmproxy/data/addonscripts/recorder.py @@ -1,4 +1,5 @@ from mitmproxy import controller +from mitmproxy import events from mitmproxy import ctx import sys @@ -10,7 +11,7 @@ class CallLogger: self.name = name def __getattr__(self, attr): - if attr in controller.Events: + if attr in events.Events: def prox(*args, **kwargs): lg = (self.name, attr, args, kwargs) if attr != "log": diff --git a/test/mitmproxy/mastertest.py b/test/mitmproxy/mastertest.py index ae11e577..915f9501 100644 --- a/test/mitmproxy/mastertest.py +++ b/test/mitmproxy/mastertest.py @@ -3,7 +3,7 @@ import contextlib from . import tutils import netlib.tutils -from mitmproxy.flow import master +from mitmproxy import master from mitmproxy import flow, proxy, models, options @@ -39,9 +39,9 @@ class MasterTest: f.close() -class RecordingMaster(master.FlowMaster): +class RecordingMaster(master.Master): def __init__(self, *args, **kwargs): - master.FlowMaster.__init__(self, *args, **kwargs) + master.Master.__init__(self, *args, **kwargs) self.event_log = [] def add_log(self, e, level): diff --git a/test/mitmproxy/script/test_concurrent.py b/test/mitmproxy/script/test_concurrent.py index 6b1d4a12..bebd8dea 100644 --- a/test/mitmproxy/script/test_concurrent.py +++ b/test/mitmproxy/script/test_concurrent.py @@ -3,7 +3,7 @@ from mitmproxy import controller from mitmproxy.builtins import script from mitmproxy import options from mitmproxy import proxy -from mitmproxy.flow import master +from mitmproxy import master import time @@ -16,7 +16,7 @@ class Thing: class TestConcurrent(mastertest.MasterTest): @tutils.skip_appveyor def test_concurrent(self): - m = master.FlowMaster(options.Options(), proxy.DummyServer()) + m = master.Master(options.Options(), proxy.DummyServer()) sc = script.Script( tutils.test_data.path( "data/addonscripts/concurrent_decorator.py" diff --git a/test/mitmproxy/test_addons.py b/test/mitmproxy/test_addons.py index 22d22c85..dcf14398 100644 --- a/test/mitmproxy/test_addons.py +++ b/test/mitmproxy/test_addons.py @@ -1,6 +1,6 @@ from mitmproxy import addons -from mitmproxy import controller from mitmproxy import options +from mitmproxy import master from mitmproxy import proxy @@ -14,7 +14,7 @@ class TAddon: def test_simple(): o = options.Options() - m = controller.Master(o, proxy.DummyServer(o)) + m = master.Master(o, proxy.DummyServer(o)) a = addons.Addons(m) a.add(TAddon("one")) assert a.get("one") diff --git a/test/mitmproxy/test_controller.py b/test/mitmproxy/test_controller.py index b7a8a17f..071638a9 100644 --- a/test/mitmproxy/test_controller.py +++ b/test/mitmproxy/test_controller.py @@ -8,6 +8,7 @@ import queue from mitmproxy.exceptions import Kill, ControlException from mitmproxy import proxy +from mitmproxy import master from netlib.tutils import raises @@ -17,7 +18,7 @@ class TMsg: class TestMaster: def test_simple(self): - class DummyMaster(controller.Master): + class DummyMaster(master.Master): @controller.handler def log(self, _): m.should_exit.set() @@ -35,7 +36,7 @@ class TestMaster: assert m.should_exit.is_set() def test_server_simple(self): - m = controller.Master(None, proxy.DummyServer(None)) + m = master.Master(None, proxy.DummyServer(None)) m.start() m.shutdown() m.start() @@ -45,7 +46,7 @@ class TestMaster: class TestServerThread: def test_simple(self): m = Mock() - t = controller.ServerThread(m) + t = master.ServerThread(m) t.run() assert m.serve_forever.called diff --git a/test/mitmproxy/test_examples.py b/test/mitmproxy/test_examples.py index 5950fb60..ee5080e8 100644 --- a/test/mitmproxy/test_examples.py +++ b/test/mitmproxy/test_examples.py @@ -6,7 +6,7 @@ from mitmproxy import options from mitmproxy import contentviews from mitmproxy import proxy from mitmproxy.builtins import script -from mitmproxy.flow import master +from mitmproxy import master import netlib.utils @@ -23,7 +23,7 @@ class ScriptError(Exception): pass -class RaiseMaster(master.FlowMaster): +class RaiseMaster(master.Master): def add_log(self, e, level): if level in ("warn", "error"): raise ScriptError(e) diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index ab181357..2b387f5c 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -14,6 +14,7 @@ from mitmproxy.models import HTTPResponse from mitmproxy.proxy import ProxyConfig from mitmproxy.proxy.server import DummyServer from mitmproxy.models.connections import ClientConnection +from mitmproxy import master from . import tutils @@ -110,7 +111,7 @@ class TestHTTPFlow: def test_killall(self): srv = DummyServer(None) s = flow.State() - fm = flow.FlowMaster(None, srv) + fm = master.Master(None, srv) fm.addons.add(s) f = tutils.tflow() @@ -363,7 +364,7 @@ class TestSerialize: def test_load_flows(self): r = self._treader() s = flow.State() - fm = flow.FlowMaster(None, DummyServer()) + fm = master.Master(None, DummyServer()) fm.addons.add(s) fm.load_flows(r) assert len(s.flows) == 6 @@ -376,7 +377,7 @@ class TestSerialize: upstream_server="https://use-this-domain" ) conf = ProxyConfig(opts) - fm = flow.FlowMaster(opts, DummyServer(conf)) + fm = master.Master(opts, DummyServer(conf)) fm.addons.add(s) fm.load_flows(r) assert s.flows[0].request.host == "use-this-domain" @@ -423,7 +424,7 @@ class TestSerialize: class TestFlowMaster: def test_replay(self): - fm = flow.FlowMaster(None, DummyServer()) + fm = master.Master(None, DummyServer()) f = tutils.tflow(resp=True) f.request.content = None tutils.raises("missing", fm.replay_request, f) @@ -435,12 +436,12 @@ class TestFlowMaster: tutils.raises("live", fm.replay_request, f) def test_create_flow(self): - fm = flow.FlowMaster(None, DummyServer()) + fm = master.Master(None, DummyServer()) assert fm.create_request("GET", "http", "example.com", 80, "/") def test_all(self): s = flow.State() - fm = flow.FlowMaster(None, DummyServer()) + fm = master.Master(None, DummyServer()) fm.addons.add(s) f = tutils.tflow(req=None) fm.clientconnect(f.client_conn) diff --git a/test/mitmproxy/test_flow_state.py b/test/mitmproxy/test_flow_state.py index 02582f50..05f4cbb4 100644 --- a/test/mitmproxy/test_flow_state.py +++ b/test/mitmproxy/test_flow_state.py @@ -1,12 +1,13 @@ from mitmproxy import flow from mitmproxy import proxy +from mitmproxy import master from . import tutils class TestState: def test_duplicate_flow(self): s = flow.State() - fm = flow.FlowMaster(None, proxy.DummyServer()) + fm = master.Master(None, proxy.DummyServer()) fm.addons.add(s) f = tutils.tflow(resp=True) fm.load_flow(f) diff --git a/test/mitmproxy/test_web_app.py b/test/mitmproxy/test_web_app.py index 21cd1ab2..89354960 100644 --- a/test/mitmproxy/test_web_app.py +++ b/test/mitmproxy/test_web_app.py @@ -1,13 +1,14 @@ import tornado.testing from mitmproxy import proxy -from mitmproxy.web import app, master +from mitmproxy.web import app +from mitmproxy.web import master as webmaster class TestApp(tornado.testing.AsyncHTTPTestCase): def get_app(self): - o = master.Options() - m = master.WebMaster(o, proxy.DummyServer()) + o = webmaster.Options() + m = webmaster.WebMaster(o, proxy.DummyServer()) return app.Application(m, None, None) def test_index(self): diff --git a/test/mitmproxy/tservers.py b/test/mitmproxy/tservers.py index b09a6cf9..254af2f0 100644 --- a/test/mitmproxy/tservers.py +++ b/test/mitmproxy/tservers.py @@ -6,18 +6,19 @@ import sys from mitmproxy.proxy.config import ProxyConfig from mitmproxy.proxy.server import ProxyServer +from mitmproxy import master from mitmproxy.flow import state import pathod.test import pathod.pathoc -from mitmproxy import flow, controller, options +from mitmproxy import controller, options import netlib.exceptions -class TestMaster(flow.FlowMaster): +class TestMaster(master.Master): def __init__(self, opts, config): s = ProxyServer(config) - flow.FlowMaster.__init__(self, opts, s) + master.Master.__init__(self, opts, s) def clear_addons(self, addons): self.addons.clear() |