Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
 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()
Ejemplo n.º 4
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()
Ejemplo n.º 5
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=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)
Ejemplo n.º 6
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(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()
Ejemplo n.º 7
0
 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()
Ejemplo n.º 8
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.handle_request(f)
     assert m.handle_error(f)
     assert "error" in cs.getvalue()
Ejemplo n.º 9
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 = 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()
Ejemplo n.º 10
0
 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"]
Ejemplo n.º 11
0
 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"
Ejemplo n.º 12
0
 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
Ejemplo n.º 13
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"
Ejemplo n.º 14
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"
Ejemplo n.º 15
0
 def test_app(self):
     o = dump.Options(app=True)
     s = mock.MagicMock()
     m = dump.DumpMaster(s, o)
     assert len(m.apps.apps) == 1