2020-12-14 19:00:35 +00:00
|
|
|
from unittest import mock
|
|
|
|
|
|
|
|
from mitmproxy import controller
|
|
|
|
from mitmproxy import eventsequence
|
2020-12-19 23:12:21 +00:00
|
|
|
from mitmproxy import io
|
2021-01-01 12:46:57 +00:00
|
|
|
from mitmproxy.proxy import server_hooks
|
2020-12-14 19:00:35 +00:00
|
|
|
from mitmproxy.test import tflow
|
|
|
|
from mitmproxy.test import tutils
|
|
|
|
|
|
|
|
|
|
|
|
class MasterTest:
|
|
|
|
|
|
|
|
async def cycle(self, master, content):
|
|
|
|
f = tflow.tflow(req=tutils.treq(content=content))
|
|
|
|
layer = mock.Mock("mitmproxy.proxy.protocol.base.Layer")
|
|
|
|
layer.client_conn = f.client_conn
|
|
|
|
layer.reply = controller.DummyReply()
|
2021-01-01 12:46:57 +00:00
|
|
|
await master.addons.handle_lifecycle(server_hooks.ClientConnectedHook(layer))
|
|
|
|
for e in eventsequence.iterate(f):
|
|
|
|
await master.addons.handle_lifecycle(e)
|
|
|
|
await master.addons.handle_lifecycle(server_hooks.ClientDisconnectedHook(layer))
|
2020-12-14 19:00:35 +00:00
|
|
|
return f
|
|
|
|
|
|
|
|
async def dummy_cycle(self, master, n, content):
|
|
|
|
for i in range(n):
|
|
|
|
await self.cycle(master, content)
|
|
|
|
await master._shutdown()
|
|
|
|
|
|
|
|
def flowfile(self, path):
|
|
|
|
with open(path, "wb") as f:
|
|
|
|
fw = io.FlowWriter(f)
|
|
|
|
t = tflow.tflow(resp=True)
|
|
|
|
fw.add(t)
|