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