streamfile: add streamfile_filter and use it instead of filtstr

This commit is contained in:
Aldo Cortesi 2017-03-19 13:08:26 +13:00
parent 6f745b90a8
commit 475a4e3eb0
3 changed files with 13 additions and 7 deletions

View File

@ -22,12 +22,12 @@ class StreamFile:
def configure(self, options, updated):
# We're already streaming - stop the previous stream and restart
if "filtstr" in updated:
if options.filtstr:
self.filt = flowfilter.parse(options.filtstr)
if "streamfile_filter" in updated:
if options.streamfile_filter:
self.filt = flowfilter.parse(options.streamfile_filter)
if not self.filt:
raise exceptions.OptionsError(
"Invalid filter specification: %s" % options.filtstr
"Invalid filter specification: %s" % options.streamfile_filter
)
else:
self.filt = None

View File

@ -160,6 +160,10 @@ class Options(optmanager.OptManager):
"streamfile", Optional[str], None,
"Write flows to file. Prefix path with + to append."
)
self.add_option(
"streamfile_filter", Optional[str], None,
"Filter which flows are written to file."
)
self.add_option(
"server_replay_ignore_content", bool, False,
"Ignore request's content while searching for a saved flow to replay."

View File

@ -15,10 +15,12 @@ def test_configure(tmpdir):
with pytest.raises(exceptions.OptionsError):
tctx.configure(sa, streamfile=str(tmpdir))
with pytest.raises(Exception, match="Invalid filter"):
tctx.configure(sa, streamfile=str(tmpdir.join("foo")), filtstr="~~")
tctx.configure(sa, filtstr="foo")
tctx.configure(
sa, streamfile=str(tmpdir.join("foo")), streamfile_filter="~~"
)
tctx.configure(sa, streamfile_filter="foo")
assert sa.filt
tctx.configure(sa, filtstr=None)
tctx.configure(sa, streamfile_filter=None)
assert not sa.filt