def test_normal(self, load_flow, tmpdir, data):
     rf = readfile.ReadFileStdin()
     with taddons.context():
         tfile = tmpdir.join("tfile")
         tfile.write(data.getvalue())
         rf.load_flows_from_path(str(tfile))
         assert load_flow.called
Exemple #2
0
 async def test_normal(self, tmpdir, data):
     rf = readfile.ReadFileStdin()
     with taddons.context(rf) as tctx:
         tf = tmpdir.join("tfile")
         with mock.patch('mitmproxy.master.Master.load_flow') as mck:
             tf.write(data.getvalue())
             tctx.configure(rf, rfile=str(tf))
             mck.assert_not_awaited()
             rf.running()
             await asyncio.sleep(0)
             mck.assert_awaited()
Exemple #3
0
    async def test_stdin(self, stdin, data, corrupt_data):
        rf = readfile.ReadFileStdin()
        with taddons.context(rf):
            with mock.patch('mitmproxy.master.Master.load_flow') as mck:
                stdin.buffer = data
                mck.assert_not_awaited()
                await rf.load_flows(stdin.buffer)
                mck.assert_awaited()

                stdin.buffer = corrupt_data
                with pytest.raises(exceptions.FlowReadException):
                    await rf.load_flows(stdin.buffer)
Exemple #4
0
    def __init__(self, proxy_events, listen_port, include_path):
        self.opts = options.Options()
        self.opts.listen_port = listen_port
        self.opts.confdir = include_path
        self.master = master.Master(self.opts)
        proxy_events.set_proxy(self)
        self.master.addons.add(proxy_events)

        self.master.addons.add(termlog.TermLog())
        self.master.addons.add(*addons.default_addons())
        self.master.addons.add(keepserving.KeepServing(),
                               readfile.ReadFileStdin())
    def test_stdin(self, stdin, load_flow, data, corrupt_data):
        rf = readfile.ReadFileStdin()
        with taddons.context() as tctx:
            stdin.buffer = data
            tctx.configure(rf, rfile="-")
            assert not load_flow.called
            rf.running()
            assert load_flow.called

            stdin.buffer = corrupt_data
            tctx.configure(rf, rfile="-")
            with pytest.raises(exceptions.OptionsError):
                rf.running()
Exemple #6
0
 def __init__(
     self,
     options: options.Options,
     with_termlog=True,
     with_dumper=True,
 ) -> None:
     super().__init__(options)
     self.errorcheck = ErrorCheck()
     if with_termlog:
         self.addons.add(termlog.TermLog())
     self.addons.add(*addons.default_addons())
     if with_dumper:
         self.addons.add(dumper.Dumper())
     self.addons.add(keepserving.KeepServing(), readfile.ReadFileStdin(),
                     self.errorcheck)