def test_replay(self): cs = StringIO() o = dump.Options(server_replay="nonexistent", kill=True) libpry.raises(dump.DumpError, dump.DumpMaster, None, o, None, outfile=cs) with tutils.tmpdir() as t: p = os.path.join(t, "rep") self._flowfile(p) o = dump.Options(server_replay=p, kill=True) m = dump.DumpMaster(None, o, None, outfile=cs) self._cycle(m, "content") self._cycle(m, "content") o = dump.Options(server_replay=p, kill=False) m = dump.DumpMaster(None, o, None, outfile=cs) self._cycle(m, "nonexistent") o = dump.Options(client_replay=p, kill=False) m = dump.DumpMaster(None, o, None, outfile=cs)
def test_replay(self): cs = StringIO() o = dump.Options(server_replay="nonexistent", kill=True) libpry.raises(dump.DumpError, dump.DumpMaster, None, o, None, outfile=cs) t = self.tmpdir() p = os.path.join(t, "rep") f = open(p, "w") fw = flow.FlowWriter(f) t = tutils.tflow_full() t.response = tutils.tresp(t.request) fw.add(t) f.close() o = dump.Options(server_replay=p, kill=True) m = dump.DumpMaster(None, o, None, outfile=cs) self._cycle(m, "content") self._cycle(m, "content") o = dump.Options(server_replay=p, kill=False) m = dump.DumpMaster(None, o, None, outfile=cs) self._cycle(m, "nonexistent") o = dump.Options(client_replay=p, kill=False) m = dump.DumpMaster(None, o, None, outfile=cs)
def test_strfuncs(): o = dump.Options() m = dump.DumpMaster(None, o) m.outfile = StringIO() m.o.flow_detail = 0 m.echo_flow(tutils.tflow()) assert not m.outfile.getvalue() m.o.flow_detail = 4 m.echo_flow(tutils.tflow()) assert m.outfile.getvalue() m.outfile = StringIO() m.echo_flow(tutils.tflow(resp=True)) assert "<<" in m.outfile.getvalue() m.outfile = StringIO() m.echo_flow(tutils.tflow(err=True)) assert "<<" in m.outfile.getvalue() flow = tutils.tflow() flow.request = netlib.tutils.treq() flow.request.stickycookie = True flow.client_conn = mock.MagicMock() flow.client_conn.address.host = "foo" flow.response = netlib.tutils.tresp(content=CONTENT_MISSING) flow.response.is_replay = True flow.response.status_code = 300 m.echo_flow(flow) flow = tutils.tflow(resp=netlib.tutils.tresp(content="{")) flow.response.headers["content-type"] = "application/json" flow.response.status_code = 400 m.echo_flow(flow)
def _dummy_cycle(self, n, filt, content, **options): cs = StringIO() o = dump.Options(**options) m = dump.DumpMaster(None, o, filt, outfile=cs) for i in range(n): self._cycle(m, content) return cs.getvalue()
def test_contentview(get_content_view): get_content_view.side_effect = ContentViewException(""), ("x", iter([])) o = dump.Options(flow_detail=4, verbosity=3) m = dump.DumpMaster(None, o, StringIO()) m.echo_flow(tutils.tflow()) assert "Content viewer failed" in m.outfile.getvalue()
def main(): app = wx.App(False) if len(sys.argv) >= 2 and sys.argv[1] == '-test': config = wx.Config("padherder_proxy_test") print "In test mode" else: config = wx.Config("padherder_proxy") wx.ConfigBase.Set(config) frame = MainWindow(None, "Padherder Proxy v%s" % PH_PROXY_VERSION) host = config.Read("host") or socket.gethostbyname(socket.gethostname()) logger = dnsproxy.MyDNSLogger(frame.dns_tab) thread.start_new_thread(dnsproxy.serveDNS, (logger, frame.main_tab, frame)) try: app_config = proxy.ProxyConfig(port=8080, host=host) app_server = ProxyServer(app_config) app_master = dump.DumpMaster( app_server, dump.Options(app_host='mitm.it', app_port=80, app=True)) frame.app_master = app_master thread.start_new_thread(app_master.run, ()) except: evt = custom_events.wxStatusEvent( message='Error initalizing mitm proxy:\n' + traceback.format_exc() + '\n\nYou probably put in an incorrect IP address in Settings') wx.PostEvent(frame.main_tab, evt) app.MainLoop()
def test_error(self): cs = StringIO() o = dump.Options(flow_detail=1) m = dump.DumpMaster(None, o, outfile=cs) f = tutils.tflow(err=True) m.handle_request(f) assert m.handle_error(f) assert "error" in cs.getvalue()
def test_error(self): cs = StringIO() o = dump.Options(verbosity=1) m = dump.DumpMaster(None, o, None, outfile=cs) f = tutils.tflow_err() m.handle_request(f.request) assert m.handle_error(f.error) assert "error" in cs.getvalue()
def test_missing_content(self): cs = StringIO() o = dump.Options(flow_detail=3) m = dump.DumpMaster(None, o, outfile=cs) f = tutils.tflow() f.request.content = CONTENT_MISSING m.handle_request(f) f.response = HTTPResponse.wrap(netlib.tutils.tresp()) f.response.content = CONTENT_MISSING m.handle_response(f) assert "content missing" in cs.getvalue()
def main(): #config stuff if(len(sys.argv) == 2): if(os.path.isfile(sys.argv[1])): sys.argv[1] = "@" + sys.argv[1] os.chdir(os.path.split(inspect.getfile( inspect.currentframe() ))[0]) defaultConfig = (len(sys.argv) == 1) if defaultConfig and os.path.exists('default.conf'): sys.argv.insert(1,'@default.conf') parser = ArgumentParser( usage = "%(prog)s [options]", fromfile_prefix_chars="@" ) ArgumentParser.convert_arg_line_to_args = hcmdline.convert_arg_line_to_args parser.add_argument('--version', action='version', version=version.NAMEVERSION) mcmdline.common_options(parser) hcmdline.fix_options(parser) #remove some mitmproxy stuff options = parser.parse_args() dumpoptions = dump.Options(dumpdir=options.dumpdir,**mcmdline.get_common_options(options)) #set up proxy server proxyconfig = mproxy.process_proxy_options(parser, options) if options.no_server: server = mproxy.DummyServer(proxyconfig) else: try: server = mproxy.ProxyServer(proxyconfig, options.port, options.addr) except mproxy.ProxyServerError, v: print >> sys.stderr, "%(name)s: %(args)s" % {"name": version.NAME, "args": v.args[0]} sys.exit(1)
def test_setheader(self): o = dump.Options(setheaders=[(".*", "one", "two")]) m = dump.DumpMaster(None, o, None) f = self._cycle(m, "content") assert f.request.headers["one"] == ["two"]
def test_replacements(self): o = dump.Options(replacements=[(".*", "content", "foo")]) m = dump.DumpMaster(None, o, None) f = self._cycle(m, "content") assert f.request.content == "foo"
def test_options(self): o = dump.Options(verbosity=2) assert o.verbosity == 2 libpry.raises(AttributeError, dump.Options, nonexistent=2)
def test_app(self): o = dump.Options(app=True) s = mock.MagicMock() m = dump.DumpMaster(s, o, None) assert s.apps.add.call_count == 1
def test_options(self): o = dump.Options(verbosity=2) assert o.verbosity == 2
def test_setheader(self): cs = StringIO() o = dump.Options(setheaders=[(".*", "one", "two")]) m = dump.DumpMaster(None, o, outfile=cs) f = self._cycle(m, "content") assert f.request.headers["one"] == "two"
def test_replacements(self): cs = StringIO() o = dump.Options(replacements=[(".*", "content", "foo")]) m = dump.DumpMaster(None, o, outfile=cs) f = self._cycle(m, "content") assert f.request.content == "foo"
def test_app(self): o = dump.Options(app=True) s = mock.MagicMock() m = dump.DumpMaster(s, o) assert len(m.apps.apps) == 1