Kill flow.master - create master.Master

Also extract events into .events
This commit is contained in:
Aldo Cortesi 2016-10-19 13:22:50 +13:00
parent 264a09e778
commit bce387a5a0
31 changed files with 239 additions and 230 deletions

View File

@ -12,10 +12,10 @@ from mitmproxy import flow, controller, options
from mitmproxy.proxy import ProxyServer, ProxyConfig
class MyMaster(flow.FlowMaster):
class MyMaster(master.Master):
def run(self):
try:
flow.FlowMaster.run(self)
master.Master.run(self)
except KeyboardInterrupt:
self.shutdown()

View File

@ -10,14 +10,14 @@ from mitmproxy import controller, proxy
from mitmproxy.proxy.server import ProxyServer
class StickyMaster(controller.Master):
class StickyMaster(master.Master):
def __init__(self, server):
controller.Master.__init__(self, server)
master.Master.__init__(self, server)
self.stickyhosts = {}
def run(self):
try:
return controller.Master.run(self)
return master.Master.run(self)
except KeyboardInterrupt:
self.shutdown()

View File

@ -6,9 +6,8 @@ import threading
import traceback
from mitmproxy import exceptions
from mitmproxy import controller
from mitmproxy import ctx
from mitmproxy.flow import master as flowmaster
from mitmproxy import events
import watchdog.events
@ -154,7 +153,7 @@ class Script:
self.last_options = None
self.should_reload = threading.Event()
for i in controller.Events:
for i in events.Events:
if not hasattr(self, i):
def mkprox():
evt = i
@ -221,7 +220,7 @@ class ScriptLoader:
sc = Script(command)
sc.load_script()
for f in flows:
for evt, o in flowmaster.event_sequence(f):
for evt, o in events.event_sequence(f):
sc.run(evt, o)
sc.done()
return sc

View File

@ -18,6 +18,7 @@ from mitmproxy import builtins
from mitmproxy import contentviews
from mitmproxy import controller
from mitmproxy import exceptions
from mitmproxy import master
from mitmproxy import flow
from mitmproxy import flowfilter
from mitmproxy import utils
@ -218,11 +219,11 @@ class Options(mitmproxy.options.Options):
super().__init__(**kwargs)
class ConsoleMaster(flow.FlowMaster):
class ConsoleMaster(master.Master):
palette = []
def __init__(self, options, server):
flow.FlowMaster.__init__(self, options, server)
master.Master.__init__(self, options, server)
self.state = ConsoleState()
self.stream_path = None
# This line is just for type hinting
@ -600,7 +601,7 @@ class ConsoleMaster(flow.FlowMaster):
def load_flows_path(self, path):
reterr = None
try:
flow.FlowMaster.load_flows_file(self, path)
master.Master.load_flows_file(self, path)
except exceptions.FlowReadException as e:
reterr = str(e)
signals.flowlist_change.send(self)
@ -631,7 +632,7 @@ class ConsoleMaster(flow.FlowMaster):
def shutdown(self):
self.state.killall(self)
flow.FlowMaster.shutdown(self)
master.Master.shutdown(self)
def clear_flows(self):
self.state.clear()

View File

@ -1,45 +1,6 @@
import functools
import threading
import contextlib
import queue
from mitmproxy import addons
from mitmproxy import options
from . import ctx as mitmproxy_ctx
from netlib import basethread
from . import exceptions
Events = frozenset([
"clientconnect",
"clientdisconnect",
"serverconnect",
"serverdisconnect",
"tcp_start",
"tcp_message",
"tcp_error",
"tcp_end",
"request",
"requestheaders",
"response",
"responseheaders",
"error",
"intercept",
"resume",
"websocket_handshake",
"next_layer",
"configure",
"done",
"log",
"start",
"tick",
])
from mitmproxy import exceptions
class LogEntry:
@ -83,101 +44,6 @@ class Log:
self.master.add_log(text, level)
class Master:
"""
The master handles mitmproxy's main event loop.
"""
def __init__(self, opts, server):
self.options = opts or options.Options()
self.addons = addons.Addons(self)
self.event_queue = queue.Queue()
self.should_exit = threading.Event()
self.server = server
channel = Channel(self.event_queue, self.should_exit)
server.set_channel(channel)
@contextlib.contextmanager
def handlecontext(self):
# Handlecontexts also have to nest - leave cleanup to the outermost
if mitmproxy_ctx.master:
yield
return
mitmproxy_ctx.master = self
mitmproxy_ctx.log = Log(self)
try:
yield
finally:
mitmproxy_ctx.master = None
mitmproxy_ctx.log = None
def tell(self, mtype, m):
m.reply = DummyReply()
self.event_queue.put((mtype, m))
def add_log(self, e, level):
"""
level: debug, info, warn, error
"""
with self.handlecontext():
self.addons("log", LogEntry(e, level))
def start(self):
self.should_exit.clear()
ServerThread(self.server).start()
def run(self):
self.start()
try:
while not self.should_exit.is_set():
# Don't choose a very small timeout in Python 2:
# https://github.com/mitmproxy/mitmproxy/issues/443
# TODO: Lower the timeout value if we move to Python 3.
self.tick(0.1)
finally:
self.shutdown()
def tick(self, timeout):
with self.handlecontext():
self.addons("tick")
changed = False
try:
mtype, obj = self.event_queue.get(timeout=timeout)
if mtype not in Events:
raise exceptions.ControlException("Unknown event %s" % repr(mtype))
handle_func = getattr(self, mtype)
if not callable(handle_func):
raise exceptions.ControlException("Handler %s not callable" % mtype)
if not handle_func.__dict__.get("__handler"):
raise exceptions.ControlException(
"Handler function %s is not decorated with controller.handler" % (
handle_func
)
)
handle_func(obj)
self.event_queue.task_done()
changed = True
except queue.Empty:
pass
return changed
def shutdown(self):
self.server.shutdown()
self.should_exit.set()
self.addons.done()
class ServerThread(basethread.BaseThread):
def __init__(self, server):
self.server = server
address = getattr(self.server, "address", None)
super().__init__(
"ServerThread ({})".format(repr(address))
)
def run(self):
self.server.serve_forever()
class Channel:
"""
The only way for the proxy server to communicate with the master

View File

@ -1,2 +1,2 @@
master = None # type: "mitmproxy.flow.FlowMaster"
master = None # type: "mitmproxy.master.Master"
log = None # type: "mitmproxy.controller.Log"

View File

@ -6,6 +6,7 @@ from mitmproxy import exceptions
from mitmproxy import flow
from mitmproxy import builtins
from mitmproxy import options
from mitmproxy import master
from mitmproxy.builtins import dumper, termlog
from netlib import tcp
@ -30,10 +31,10 @@ class Options(options.Options):
super().__init__(**kwargs)
class DumpMaster(flow.FlowMaster):
class DumpMaster(master.Master):
def __init__(self, options, server):
flow.FlowMaster.__init__(self, options, server)
master.Master.__init__(self, options, server)
self.has_errored = False
self.addons.add(termlog.TermLog())
self.addons.add(*builtins.default_addons())

58
mitmproxy/events.py Normal file
View File

@ -0,0 +1,58 @@
from mitmproxy import controller
from mitmproxy import models
Events = frozenset([
"clientconnect",
"clientdisconnect",
"serverconnect",
"serverdisconnect",
"tcp_start",
"tcp_message",
"tcp_error",
"tcp_end",
"request",
"requestheaders",
"response",
"responseheaders",
"error",
"intercept",
"resume",
"websocket_handshake",
"next_layer",
"configure",
"done",
"log",
"start",
"tick",
])
def event_sequence(f):
if isinstance(f, models.HTTPFlow):
if f.request:
yield "requestheaders", f
yield "request", f
if f.response:
yield "responseheaders", f
yield "response", f
if f.error:
yield "error", f
elif isinstance(f, models.TCPFlow):
messages = f.messages
f.messages = []
f.reply = controller.DummyReply()
yield "tcp_start", f
while messages:
f.messages.append(messages.pop(0))
yield "tcp_message", f
if f.error:
yield "tcp_error", f
yield "tcp_end", f
else:
raise NotImplementedError

View File

@ -1,10 +1,9 @@
from mitmproxy.flow import export
from mitmproxy.flow.io import FlowWriter, FilteredFlowWriter, FlowReader, read_flows_from_paths
from mitmproxy.flow.master import FlowMaster
from mitmproxy.flow.state import State, FlowView
__all__ = [
"export",
"FlowWriter", "FilteredFlowWriter", "FlowReader", "read_flows_from_paths",
"FlowMaster", "State", "FlowView",
"State", "FlowView",
]

View File

@ -1,40 +1,117 @@
import os
import threading
import contextlib
import queue
import sys
from netlib import http
from mitmproxy import addons
from mitmproxy import options
from mitmproxy import controller
from mitmproxy import events
from mitmproxy import exceptions
from mitmproxy import models
from mitmproxy.flow import io
from mitmproxy.protocol import http_replay
from netlib import basethread
from netlib import http
from . import ctx as mitmproxy_ctx
def event_sequence(f):
if isinstance(f, models.HTTPFlow):
if f.request:
yield "requestheaders", f
yield "request", f
if f.response:
yield "responseheaders", f
yield "response", f
if f.error:
yield "error", f
elif isinstance(f, models.TCPFlow):
messages = f.messages
f.messages = []
f.reply = controller.DummyReply()
yield "tcp_start", f
while messages:
f.messages.append(messages.pop(0))
yield "tcp_message", f
if f.error:
yield "tcp_error", f
yield "tcp_end", f
else:
raise NotImplementedError
class ServerThread(basethread.BaseThread):
def __init__(self, server):
self.server = server
address = getattr(self.server, "address", None)
super().__init__(
"ServerThread ({})".format(repr(address))
)
def run(self):
self.server.serve_forever()
class FlowMaster(controller.Master):
class Master:
"""
The master handles mitmproxy's main event loop.
"""
def __init__(self, opts, server):
self.options = opts or options.Options()
self.addons = addons.Addons(self)
self.event_queue = queue.Queue()
self.should_exit = threading.Event()
self.server = server
channel = controller.Channel(self.event_queue, self.should_exit)
server.set_channel(channel)
@contextlib.contextmanager
def handlecontext(self):
# Handlecontexts also have to nest - leave cleanup to the outermost
if mitmproxy_ctx.master:
yield
return
mitmproxy_ctx.master = self
mitmproxy_ctx.log = controller.Log(self)
try:
yield
finally:
mitmproxy_ctx.master = None
mitmproxy_ctx.log = None
def tell(self, mtype, m):
m.reply = controller.DummyReply()
self.event_queue.put((mtype, m))
def add_log(self, e, level):
"""
level: debug, info, warn, error
"""
with self.handlecontext():
self.addons("log", controller.LogEntry(e, level))
def start(self):
self.should_exit.clear()
ServerThread(self.server).start()
def run(self):
self.start()
try:
while not self.should_exit.is_set():
# Don't choose a very small timeout in Python 2:
# https://github.com/mitmproxy/mitmproxy/issues/443
# TODO: Lower the timeout value if we move to Python 3.
self.tick(0.1)
finally:
self.shutdown()
def tick(self, timeout):
with self.handlecontext():
self.addons("tick")
changed = False
try:
mtype, obj = self.event_queue.get(timeout=timeout)
if mtype not in events.Events:
raise exceptions.ControlException("Unknown event %s" % repr(mtype))
handle_func = getattr(self, mtype)
if not callable(handle_func):
raise exceptions.ControlException("Handler %s not callable" % mtype)
if not handle_func.__dict__.get("__handler"):
raise exceptions.ControlException(
"Handler function %s is not decorated with controller.handler" % (
handle_func
)
)
handle_func(obj)
self.event_queue.task_done()
changed = True
except queue.Empty:
pass
return changed
def shutdown(self):
self.server.shutdown()
self.should_exit.set()
self.addons.done()
def create_request(self, method, scheme, host, port, path):
"""
this method creates a new artificial and minimalist request also adds it to flowlist
@ -70,7 +147,7 @@ class FlowMaster(controller.Master):
f.request.port = self.server.config.upstream_server.address.port
f.request.scheme = self.server.config.upstream_server.scheme
f.reply = controller.DummyReply()
for e, o in event_sequence(f):
for e, o in events.event_sequence(f):
getattr(self, e)(o)
def load_flows(self, fr):

View File

@ -3,7 +3,7 @@ This module provides a @concurrent decorator primitive to
offload computations from mitmproxy's main master thread.
"""
from mitmproxy import controller
from mitmproxy import events
from netlib import basethread
@ -12,7 +12,7 @@ class ScriptThread(basethread.BaseThread):
def concurrent(fn):
if fn.__name__ not in controller.Events - {"start", "configure", "tick"}:
if fn.__name__ not in events.Events - {"start", "configure", "tick"}:
raise NotImplementedError(
"Concurrent decorator not supported for '%s' method." % fn.__name__
)

View File

@ -11,6 +11,7 @@ from mitmproxy import controller
from mitmproxy import exceptions
from mitmproxy import flow
from mitmproxy import options
from mitmproxy import master
from mitmproxy.web import app
from netlib.http import authentication
@ -130,7 +131,7 @@ class Options(options.Options):
self.wauthenticator = None
class WebMaster(flow.FlowMaster):
class WebMaster(master.Master):
def __init__(self, options, server):
super().__init__(options, server)

View File

@ -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)

View File

@ -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)

View File

@ -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()

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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":

View File

@ -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):

View File

@ -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"

View File

@ -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")

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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):

View File

@ -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()