示例#1
0
    def test_binaryops(self):
        a = filt.parse("~u foobar | ~h voing")
        isinstance(a, filt.FOr)
        self._dump(a)

        a = filt.parse("~u foobar & ~h voing")
        isinstance(a, filt.FAnd)
        self._dump(a)
示例#2
0
    def test_match(self):
        f = tutils.tflow()
        f.response = tutils.tresp()
        f.request = f.response.request
        assert not f.match(filt.parse("~b test"))
        assert f.match(None)
        assert not f.match(filt.parse("~b test"))

        f = tutils.tflow_err()
        assert f.match(filt.parse("~e"))
示例#3
0
    def test_quoting(self):
        a = filt.parse("~u 'foo ~u bar' ~u voing")
        assert a.lst[0].expr == "foo ~u bar"
        assert a.lst[1].expr == "voing"
        self._dump(a)

        a = filt.parse("~u foobar")
        assert a.expr == "foobar"

        a = filt.parse(r"~u 'foobar\"\''")
        assert a.expr == "foobar\"'"

        a = filt.parse(r'~u "foo \'bar"')
        assert a.expr == "foo 'bar"
示例#4
0
 def _response(self, cookie, host):
     s = flow.StickyCookieState(filt.parse(".*"))
     f = tutils.tflow_full()
     f.server_conn.address = tcp.Address((host, 80))
     f.response.headers["Set-Cookie"] = [cookie]
     s.handle_response(f)
     return s, f
示例#5
0
 def _response(self, cookie, host):
     s = flow.StickyCookieState(filt.parse(".*"))
     f = tutils.tflow_full()
     f.request.host = host
     f.response.headers["Set-Cookie"] = [cookie]
     s.handle_response(f)
     return s, f
示例#6
0
    def test_naked_url(self):
        #a = filt.parse("foobar")
        #assert a.lst[0].expr == "foobar"

        a = filt.parse("foobar ~h rex")
        assert a.lst[0].expr == "foobar"
        assert a.lst[1].expr == "rex"
        self._dump(a)
示例#7
0
    def test_handle_response(self):
        s = flow.StickyAuthState(filt.parse(".*"))
        f = tutils.tflow(resp=True)
        f.request.headers["authorization"] = "foo"
        s.handle_request(f)
        assert "address" in s.hosts

        f = tutils.tflow(resp=True)
        s.handle_request(f)
        assert f.request.headers["authorization"] == "foo"
示例#8
0
    def test_handle_response(self):
        s = flow.StickyAuthState(filt.parse(".*"))
        f = tutils.tflow_full()
        f.request.headers["authorization"] = ["foo"]
        s.handle_request(f)
        assert "host" in s.hosts

        f = tutils.tflow_full()
        s.handle_request(f)
        assert f.request.headers["authorization"] == ["foo"]
示例#9
0
    def test_view(self):
        c = console.State()

        f = tflow()
        c.add_browserconnect(f)
        assert len(c.view) == 1
        c.set_limit(filt.parse("~q"))
        assert len(c.view) == 0
        c.set_limit(None)

        
        f = tflow()
        req = treq(f.connection)
        c.add_browserconnect(f)
        c.add_request(req)
        assert len(c.view) == 2
        c.set_limit(filt.parse("~q"))
        assert len(c.view) == 1
        c.set_limit(filt.parse("~s"))
        assert len(c.view) == 0
示例#10
0
 def test_focus_view(self):
     c = console.State()
     self._add_request(c)
     self._add_response(c)
     self._add_request(c)
     self._add_response(c)
     self._add_request(c)
     self._add_response(c)
     c.set_limit(filt.parse("~q"))
     assert len(c.view) == 3
     assert c.focus == 2
示例#11
0
 def test_simple(self):
     assert not filt.parse("~b")
     assert filt.parse("~q")
     assert filt.parse("~c 10")
     assert filt.parse("~m foobar")
     assert filt.parse("~u foobar")
     assert filt.parse("~q ~c 10")
     p = filt.parse("~q ~c 10")
     self._dump(p)
     assert len(p.lst) == 2
示例#12
0
    def test_filter(self):
        sio = StringIO()
        fl = filt.parse("~c 200")
        w = flow.FilteredFlowWriter(sio, fl)

        f = tutils.tflow_full()
        f.response.code = 200
        w.add(f)

        f = tutils.tflow_full()
        f.response.code = 201
        w.add(f)

        sio.seek(0)
        r = flow.FlowReader(sio)
        assert len(list(r.stream()))
示例#13
0
 def test_nesting(self):
     a = filt.parse("(~u foobar & ~h voing)")
     assert a.lst[0].expr == "foobar"
     self._dump(a)
示例#14
0
 def test_domain_match(self):
     s = flow.StickyCookieState(filt.parse(".*"))
     assert s.domain_match("www.google.com", ".google.com")
     assert s.domain_match("google.com", ".google.com")
示例#15
0
 def test_parse_err(self):
     assert filt.parse("~h [") is None
示例#16
0
 def test_nesting(self):
     a = filt.parse("(~u foobar & ~h voing)")
     assert a.lst[0].expr == "foobar"
     self._dump(a)
示例#17
0
文件: filt.py 项目: Nolski/mitmproxy
def start(context, argv):
	if len(argv) != 2:
		raise ValueError("Usage: -s 'filt.py FILTER'")
	context.filter = filt.parse(argv[1])
示例#18
0
 def test_wideops(self):
     a = filt.parse("~hq 'header: qvalue'")
     assert isinstance(a, filt.FHeadRequest)
     self._dump(a)
示例#19
0
 def _response(self, cookie, host):
     s = flow.StickyCookieState(filt.parse(".*"))
     f = tutils.tflow(req=tutils.treq(host=host, port=80), resp=True)
     f.response.headers["Set-Cookie"] = [cookie]
     s.handle_response(f)
     return s, f
示例#20
0
 def test_parse_err(self):
     assert filt.parse("~h [") is None
示例#21
0
 def test_match(self):
     f = tflow()
     f.response = tresp()
     f.request = f.response.request
     assert not f.match(filt.parse("~b test"))
示例#22
0
 def test_naked_url(self):
     a = filt.parse("foobar ~h rex")
     assert a.lst[0].expr == "foobar"
     assert a.lst[1].expr == "rex"
     self._dump(a)
示例#23
0
def start(context, argv):
  if len(argv) != 3:
    raise ValueError("Must give a filter and a jq expression")
  context.filter = filt.parse(argv[1])
  context.expression = argv[2]
示例#24
0
 def test_not(self):
     a = filt.parse("!~h test")
     assert a.itm.expr == "test"
     a = filt.parse("!(~u test & ~h bar)")
     assert a.itm.lst[0].expr == "test"
     self._dump(a)
示例#25
0
 def _response(self, cookie, host):
     s = flow.StickyCookieState(filt.parse(".*"))
     f = tutils.tflow(req=tutils.treq(host=host, port=80), resp=True)
     f.response.headers["Set-Cookie"] = [cookie]
     s.handle_response(f)
     return s, f
示例#26
0
 def q(self, q, o):
     return filt.parse(q)(o)
示例#27
0
 def test_domain_match(self):
     s = flow.StickyCookieState(filt.parse(".*"))
     assert s.domain_match("www.google.com", ".google.com")
     assert s.domain_match("google.com", ".google.com")
示例#28
0
 def q(self, q, o):
     return filt.parse(q)(o)
示例#29
0
 def test_match(self):
     f = tutils.tflow()
     f.response = tutils.tresp()
     f.request = f.response.request
     assert not f.match(filt.parse("~b test"))
     assert not f.match(None)
示例#30
0
def start(context, argv):
    context.filter = filt.parse("~s & ~u .*(\/loq\/all_updates|\/bq\/stories).*")   # only calls to /loq/all_updates or /bq/stories. edit this if you want to save responses from different endpoints