diff options
author | Peter Wu <peter@lekensteyn.nl> | 2019-01-24 19:25:29 +0100 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2019-01-24 22:20:13 +0000 |
commit | e85c8bed87821e75965fca093294c23d12ac4b21 (patch) | |
tree | adf0690a902928b79e18229c8dc1d920d5ce06da /test | |
parent | d3f1e2fa19d0aa049658dac244fb78a1dc892743 (diff) |
tshark: fix crash with -Tjson and -e field
Fix the assertion to check for the actual requirements. Add tests for -T
combined with -e.
Bug: 15444
Change-Id: I83e7663572db0c60194f6d6128b9e1ae7396b3f6
Fixes: v2.9.1rc0-226-g30c90fa745 ("epan: use json_dumper for json outputs.")
Reviewed-on: https://code.wireshark.org/review/31724
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/suite_outputformats.py | 60 |
1 files changed, 46 insertions, 14 deletions
diff --git a/test/suite_outputformats.py b/test/suite_outputformats.py index 2ce15def49..8ec47769f5 100644 --- a/test/suite_outputformats.py +++ b/test/suite_outputformats.py @@ -14,41 +14,73 @@ import subprocesstest import fixtures from matchers import * + @fixtures.fixture -def check_outputformat(cmd_tshark, dirs, capture_file): +def check_outputformat(cmd_tshark, request, dirs, capture_file): ''' Check a capture file against a sample, in json format. ''' - def check_outputformat_real(self, pcap_file, format_option, format_file, multiline=False): - self.maxDiff = 1000000 - tshark_proc = self.assertRun((cmd_tshark, '-r', capture_file(pcap_file), '-T', format_option,)) + def check_outputformat_real(format_option, pcap_file='dhcp.pcap', + extra_args=[], expected=None, multiline=False): + self = request.instance + tshark_proc = self.assertRun([cmd_tshark, '-r', capture_file(pcap_file), + '-T', format_option] + extra_args) - expected = open(os.path.join(dirs.baseline_dir, format_file)).read() + # If a filename is given, load the expected values from those. + if isinstance(expected, str): + testdata = open(os.path.join(dirs.baseline_dir, expected)).read() + if multiline: + expected = [json.loads(line) for line in testdata.splitlines()] + else: + expected = json.loads(testdata) actual = tshark_proc.stdout_str if multiline: - expected = expected.splitlines() actual = actual.splitlines() self.assertEqual(len(expected), len(actual)) - for line1, line2 in zip(expected, actual): - json.loads(line1) - json.loads(line2) - self.assertEqual(json.loads(line1), json.loads(line2)) + for expectedObj, actualStr in zip(expected, actual): + self.assertEqual(expectedObj, json.loads(actualStr)) else: - expected = json.loads(expected) actual = json.loads(actual) self.assertEqual(expected, actual) return check_outputformat_real + @fixtures.mark_usefixtures('base_env') @fixtures.uses_fixtures class case_outputformats(subprocesstest.SubprocessTestCase): + maxDiff = 1000000 + def test_outputformat_json(self, check_outputformat): '''Decode some captures into json''' - check_outputformat(self, "dhcp.pcap", "json", "dhcp.json") + check_outputformat("json", expected="dhcp.json") def test_outputformat_jsonraw(self, check_outputformat): '''Decode some captures into jsonraw''' - check_outputformat(self, "dhcp.pcap", "jsonraw", "dhcp.jsonraw") + check_outputformat("jsonraw", expected="dhcp.jsonraw") def test_outputformat_ek(self, check_outputformat): '''Decode some captures into ek''' - check_outputformat(self, "dhcp.pcap", "ek", "dhcp.ek", True) + check_outputformat("ek", expected="dhcp.ek", multiline=True) + + def test_outputformat_json_select_field(self, check_outputformat): + '''Checks that the -e option works with -Tjson.''' + check_outputformat("json", extra_args=['-eframe.number', '-c1'], expected=[ + { + "_index": "packets-2004-12-05", + "_type": "pcap_file", + "_score": None, + "_source": { + "layers": { + "frame.number": [ + "1" + ] + } + } + } + ]) + + def test_outputformat_ek_select_field(self, check_outputformat): + '''Checks that the -e option works with -Tek.''' + check_outputformat("ek", extra_args=['-eframe.number', '-c1'], expected=[ + {"index": {"_index": "packets-2004-12-05", "_type": "pcap_file"}}, + {"timestamp": "1102274184317", "layers": {"frame_number": ["1"]}} + ], multiline=True) |