Exemplo n.º 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)
Exemplo n.º 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"))
Exemplo n.º 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"
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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"
Exemplo n.º 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"]
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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()))
Exemplo n.º 13
0
 def test_nesting(self):
     a = filt.parse("(~u foobar & ~h voing)")
     assert a.lst[0].expr == "foobar"
     self._dump(a)
Exemplo n.º 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")
Exemplo n.º 15
0
 def test_parse_err(self):
     assert filt.parse("~h [") is None
Exemplo n.º 16
0
 def test_nesting(self):
     a = filt.parse("(~u foobar & ~h voing)")
     assert a.lst[0].expr == "foobar"
     self._dump(a)
Exemplo n.º 17
0
def start(context, argv):
	if len(argv) != 2:
		raise ValueError("Usage: -s 'filt.py FILTER'")
	context.filter = filt.parse(argv[1])
Exemplo n.º 18
0
 def test_wideops(self):
     a = filt.parse("~hq 'header: qvalue'")
     assert isinstance(a, filt.FHeadRequest)
     self._dump(a)
Exemplo n.º 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
Exemplo n.º 20
0
 def test_parse_err(self):
     assert filt.parse("~h [") is None
Exemplo n.º 21
0
 def test_match(self):
     f = tflow()
     f.response = tresp()
     f.request = f.response.request
     assert not f.match(filt.parse("~b test"))
Exemplo n.º 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)
Exemplo n.º 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]
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 26
0
 def q(self, q, o):
     return filt.parse(q)(o)
Exemplo n.º 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")
Exemplo n.º 28
0
 def q(self, q, o):
     return filt.parse(q)(o)
Exemplo n.º 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)
Exemplo n.º 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