예제 #1
0
    def test_replay(self):
        o = dump.Options(server_replay=["nonexistent"], replay_kill_extra=True)
        tutils.raises(exceptions.OptionsError, dump.DumpMaster, None, o)

        with tutils.tmpdir() as t:
            p = os.path.join(t, "rep")
            self.flowfile(p)

            o = dump.Options(server_replay=[p], replay_kill_extra=True)
            o.verbosity = 0
            o.flow_detail = 0
            m = dump.DumpMaster(None, o)

            self.cycle(m, b"content")
            self.cycle(m, b"content")

            o = dump.Options(server_replay=[p], replay_kill_extra=False)
            o.verbosity = 0
            o.flow_detail = 0
            m = dump.DumpMaster(None, o)
            self.cycle(m, b"nonexistent")

            o = dump.Options(client_replay=[p], replay_kill_extra=False)
            o.verbosity = 0
            o.flow_detail = 0
            m = dump.DumpMaster(None, o)
예제 #2
0
 def test_error(self):
     o = dump.Options(tfile=StringIO(), flow_detail=1)
     m = dump.DumpMaster(None, o)
     f = tutils.tflow(err=True)
     m.error(f)
     assert m.error(f)
     assert "error" in o.tfile.getvalue()
예제 #3
0
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()
예제 #4
0
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(options=moptions.Options(app_port=8080, app_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()
예제 #5
0
 def mkmaster(self, flt, **options):
     if "verbosity" not in options:
         options["verbosity"] = 0
     if "flow_detail" not in options:
         options["flow_detail"] = 0
     o = dump.Options(filtstr=flt, tfile=io.StringIO(), **options)
     return dump.DumpMaster(None, o)
예제 #6
0
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=None)
    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)
예제 #7
0
 def test_setheader(self):
     o = dump.Options(setheaders=[(".*", "one", "two")], tfile=StringIO())
     o.verbosity = 0
     o.flow_detail = 0
     m = dump.DumpMaster(None, o)
     f = self.cycle(m, b"content")
     assert f.request.headers["one"] == "two"
예제 #8
0
 def _dummy_cycle(self, n, filt, content, **options):
     cs = StringIO()
     o = dump.Options(filtstr=filt, **options)
     m = dump.DumpMaster(None, o, outfile=cs)
     for i in range(n):
         self._cycle(m, content)
     m.shutdown()
     return cs.getvalue()
예제 #9
0
 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.request(f)
     assert m.error(f)
     assert "error" in cs.getvalue()
예제 #10
0
 def test_replacements(self):
     o = dump.Options(
         replacements=[(".*", "content", "foo")],
         tfile=io.StringIO(),
     )
     o.verbosity = 0
     o.flow_detail = 0
     m = dump.DumpMaster(None, o)
     f = self.cycle(m, b"content")
     assert f.request.content == b"foo"
예제 #11
0
 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 = None
     m.request(f)
     f.response = models.HTTPResponse.wrap(netlib.tutils.tresp())
     f.response.content = None
     m.response(f)
     assert "content missing" in cs.getvalue()
예제 #12
0
    def test_replay(self):
        cs = StringIO()

        o = dump.Options(server_replay=["nonexistent"], kill=True)
        tutils.raises(dump.DumpError, dump.DumpMaster, None, o, 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, outfile=cs)

            self.cycle(m, "content")
            self.cycle(m, "content")

            o = dump.Options(server_replay=[p], kill=False)
            m = dump.DumpMaster(None, o, outfile=cs)
            self.cycle(m, "nonexistent")

            o = dump.Options(client_replay=[p], kill=False)
            m = dump.DumpMaster(None, o, outfile=cs)
예제 #13
0
def _run(port, outfile, mode, cadir):
    opts = options.Options(listen_port=port, mode=mode, cadir=cadir)
    config = proxy.ProxyConfig(opts)
    server = ProxyServer(config)
    m = dump.DumpMaster(server, dump.Options(outfile=[outfile,'wb'], verbosity=0))

    # Define a handler for the shutdown signal so the parent process knows how to stop me
    def cleankill(*args, **kwargs):
        m.shutdown()
    signal.signal(signal.SIGTERM, cleankill)

    # Now start the server. This operation will block.
    m.run()
예제 #14
0
 def test_error(self):
     o = dump.Options(tfile=io.StringIO(), flow_detail=1)
     m = dump.DumpMaster(o, proxy.DummyServer())
     f = tutils.tflow(err=True)
     m.error(f)
     assert "error" in o.tfile.getvalue()
예제 #15
0
 def test_app(self):
     o = dump.Options(app=True)
     m = dump.DumpMaster(None, o)
     assert len(m.apps.apps) == 1
예제 #16
0
 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"
예제 #17
0
 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"
예제 #18
0
 def test_app(self):
     o = dump.Options(app=True)
     s = mock.MagicMock()
     m = dump.DumpMaster(s, o)
     assert len(m.apps.apps) == 1
예제 #19
0
 def mkmaster(self, filt, **options):
     cs = StringIO()
     o = dump.Options(filtstr=filt, **options)
     return dump.DumpMaster(None, o, outfile=cs)