aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2018-11-20 02:47:36 +0100
committerAnders Broman <a.broman58@gmail.com>2018-11-20 05:03:56 +0000
commit656cc19fc7de25c3ac7f9d847c37745ccc272247 (patch)
tree79de668a68c25fd5bfe8ac2ee36d5b18824fa653 /test
parentfb9c6905eff10f6f49a433ead8bd78e232fa068d (diff)
Replace JSON-GLib by custom JSON dumper library
The (optional) JSON-GLib library adds dependencies on GObject, GIO. For statically linked oss-fuzz builds it also adds libffi and more. To avoid these dependencies, replace JSON-GLib by some custom code. This allows `tshark -G elastic-mapping` to be enabled by default without extra deps. API design goals of the new JSON dumper library: - Small interface without a lot of abstraction. - Avoid memory allocations if possible (currently none, but maybe json_puts_string will be replaced to improve UTF-8 support). - Do not implement parsing, this is currently handled by jsmn. Methods to open/close array/objects and to set members are inspired by the JsonGlib interface. The interfaces to write values is inspired by the sharkd code (json_puts_string is also borrowed from that). The only observed differences in the tshark output: - JSON-GLib ignores duplicates, json_dumper does not and may produce duplicates and currently print two "ip.opt.sec_prot_auth_unassigned". - JSON-GLib adds a space before a colon (unimportant formatting detail). - (Not observed, but UTF-8 strings will be wrong like bug 14948.) A test was added to catch changes in the tshark output. I also fuzzed json_dumper with libFuzzer + UBSAN/ASAN and fixed an off-by-one error. Change-Id: I0c85b18777b04d1e0f613a3d59935ec59be87ff4 Link: https://www.wireshark.org/lists/wireshark-dev/201811/msg00052.html Reviewed-on: https://code.wireshark.org/review/30732 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/baseline/elastic-mapping-ip-subset.json45
-rw-r--r--test/suite_clopts.py17
2 files changed, 62 insertions, 0 deletions
diff --git a/test/baseline/elastic-mapping-ip-subset.json b/test/baseline/elastic-mapping-ip-subset.json
new file mode 100644
index 0000000000..49333ffc01
--- /dev/null
+++ b/test/baseline/elastic-mapping-ip-subset.json
@@ -0,0 +1,45 @@
+{
+ "template" : "packets-*",
+ "settings" : {
+ "index.mapping.total_fields.limit" : 1000000
+ },
+ "mappings" : {
+ "pcap_file" : {
+ "dynamic" : false,
+ "properties" : {
+ "timestamp" : {
+ "type" : "date"
+ },
+ "layers" : {
+ "properties" : {
+ "ip" : {
+ "properties" : {
+ "ip_version" : {
+ "type" : "short"
+ },
+ "ip_tos_delay" : {
+ "type" : "boolean"
+ },
+ "ip_len" : {
+ "type" : "integer"
+ },
+ "ip_dst" : {
+ "type" : "ip"
+ },
+ "ip_dst_host" : {
+ "type" : "string"
+ },
+ "ip_geoip_lat" : {
+ "type" : "float"
+ },
+ "ip_opt_padding" : {
+ "type" : "byte"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/test/suite_clopts.py b/test/suite_clopts.py
index 722769b08d..4a0d7b10ce 100644
--- a/test/suite_clopts.py
+++ b/test/suite_clopts.py
@@ -9,6 +9,8 @@
#
'''Command line option tests'''
+import json
+import os.path
import subprocess
import subprocesstest
import fixtures
@@ -181,6 +183,21 @@ class case_tshark_dump_glossaries(subprocesstest.SubprocessTestCase):
self.runProcess((cmd_tshark, '-G', 'plugins'), env=base_env)
self.assertGreaterEqual(self.countOutput('dissector'), 10, 'Fewer than 10 dissector plugins found')
+ def test_tshark_elastic_mapping(self, cmd_tshark, dirs, base_env):
+ def get_ip_props(obj):
+ return obj['mappings']['pcap_file']['properties']['layers']['properties']['ip']['properties']
+ baseline_file = os.path.join(dirs.baseline_dir, 'elastic-mapping-ip-subset.json')
+ with open(baseline_file) as f:
+ expected_obj = json.load(f)
+ keys_to_check = get_ip_props(expected_obj).keys()
+ proc = self.assertRun((cmd_tshark, '-G', 'elastic-mapping', '--elastic-mapping-filter', 'ip'))
+ actual_obj = json.loads(proc.stdout_str)
+ ip_props = get_ip_props(actual_obj)
+ for key in list(ip_props.keys()):
+ if key not in keys_to_check:
+ del ip_props[key]
+ self.assertEqual(actual_obj, expected_obj)
+
@fixtures.mark_usefixtures('test_env')
@fixtures.uses_fixtures