def p(self, *args): parser = MockParser() cmdline.common_options(parser) args = parser.parse_args(args=args) opts = cmdline.get_common_options(args) pconf = config.ProxyConfig(options.Options(**opts)) return parser, pconf
def setup_proxy(self, args): parser = cmdline.mitmdump() args = parser.parse_args(args) if args.quiet: args.flow_detail = 0 dump_options = options.Options() dump_options.load_paths(args.conf) dump_options.merge(cmdline.get_common_options(args)) dump_options.merge( dict( flow_detail = args.flow_detail, keepserving = args.keepserving, filtstr = " ".join(args.filter) if args.filter else None, ) ) dump_options.listen_host = self.proxy_host dump_options.listen_port = self.proxy_port pconf = config.ProxyConfig(dump_options) proxy_server = server.ProxyServer(pconf) master = dump.DumpMaster(dump_options, proxy_server) self.proxy_master = master
def test_load_scripts(): example_dir = utils.Data(__name__).path("../../examples") scripts = glob.glob("%s/*.py" % example_dir) tmaster = tservers.TestMaster(config.ProxyConfig()) for f in scripts: if "har_extractor" in f: continue if "flowwriter" in f: f += " -" if "iframe_injector" in f: f += " foo" # one argument required if "filt" in f: f += " ~a" if "modify_response_body" in f: f += " foo bar" # two arguments required try: s = script.Script( f, script.ScriptContext(tmaster)) # Loads the script file. except Exception as v: if "ImportError" not in str(v): raise else: s.unload()
def test_replay(self): opts = options.Options() conf = config.ProxyConfig(opts) fm = master.Master(opts, DummyServer(conf)) f = tflow.tflow(resp=True) f.request.content = None with pytest.raises(ReplayException, match="missing"): fm.replay_request(f) f.request = None with pytest.raises(ReplayException, match="request"): fm.replay_request(f) f.intercepted = True with pytest.raises(ReplayException, match="intercepted"): fm.replay_request(f) f.live = True with pytest.raises(ReplayException, match="live"): fm.replay_request(f) req = tutils.treq(headers=net_http.Headers(((b":authority", b"foo"), (b"header", b"qvalue"), (b"content-length", b"7")))) f = tflow.tflow(req=req) f.request.http_version = "HTTP/2.0" with mock.patch( 'mitmproxy.proxy.protocol.http_replay.RequestReplayThread.run' ): rt = fm.replay_request(f) assert rt.f.request.http_version == "HTTP/1.1" assert ":authority" not in rt.f.request.headers
def process_options(parser, opts, args): if args.version: print(debug.dump_system_info()) sys.exit(0) if args.options: print(optmanager.dump(opts)) sys.exit(0) if args.quiet: args.flow_detail = 0 for i in args.setoptions: opts.set(i) adict = {} for n in dir(args): if n in opts: adict[n] = getattr(args, n) opts.merge(adict) pconf = config.ProxyConfig(opts) if opts.server: try: return server.ProxyServer(pconf) except exceptions.ServerException as v: print(str(v), file=sys.stderr) sys.exit(1) else: return server.DummyServer(pconf)
def p(self, *args): parser = MockParser() opts = options.Options() cmdline.common_options(parser, opts) args = parser.parse_args(args=args) main.process_options(parser, opts, args) pconf = config.ProxyConfig(opts) return parser, pconf
def test_load_flow_reverse(self): s = tservers.TestState() opts = options.Options(mode="reverse:https://use-this-domain") conf = config.ProxyConfig(opts) fm = master.Master(opts, DummyServer(conf)) fm.addons.add(s) f = tflow.tflow(resp=True) fm.load_flow(f) assert s.flows[0].request.host == "use-this-domain"
def __init__(self, option, obj): self.opts = options.Options() for i in option: self.__addOption(i) self.cf = config.ProxyConfig(self.opts) self.server = ProxyServer(config=self.cf) self.master = Master(opts=self.opts) self.master.server = self.server self.master.addons.add(obj)
def process_options(options): #debug.register_info_dumpers() pconf = config.ProxyConfig(options) if options.no_server: return server.DummyServer(pconf) else: try: return server.ProxyServer(pconf) except exceptions.ServerException as v: print(str(v)) sys.exit(1)
def process_options(parser, options, args): if args.sysinfo: print(debug.sysinfo()) sys.exit(0) debug.register_info_dumpers() pconf = config.ProxyConfig(options) if options.no_server: return server.DummyServer(pconf) else: try: return server.ProxyServer(pconf) except exceptions.ServerException as v: print(str(v), file=sys.stderr) sys.exit(1)
def process_options(parser, options, args): if args.version: print("args.version") sys.exit(0) pconf = config.ProxyConfig(options) if options.no_server: return server.DummyServer(pconf) else: try: return server.ProxyServer(pconf) except exceptions.ServerException as v: print(str(v), file=sys.stderr) sys.exit(1)
def test_fatal_error(self, capsys): opts = options.Options() pconf = config.ProxyConfig(opts) channel = mock.Mock() def ask(_, x): raise RuntimeError channel.ask = ask c = ConnectionHandler(mock.MagicMock(), ("127.0.0.1", 8080), pconf, channel) c.handle() _, err = capsys.readouterr() assert "mitmproxy has crashed" in err
def process_options(_, _options, _args): from mitmproxy.proxy import server # noqa if _args.version: print(debug.dump_system_info()) sys.exit(0) # debug.register_info_dumpers() pconf = config.ProxyConfig(_options) if _options.no_server: return server.DummyServer(pconf) else: try: return server.ProxyServer(pconf) except exceptions.ServerException as v: print(str(v), file=sys.stderr) sys.exit(1)
def process_options(parser, options, args): from mitmproxy.proxy import server if args.sysinfo: print(debug.sysinfo()) try: debug.register_info_dumpers() except Exception as e: print(str(e)) pconf = config.ProxyConfig(options) if options.no_server: return server.DummyServer(pconf) else: try: return server.ProxyServer(pconf) except exceptions.ServerException as v: print(str(v)) return