diff options
author | Dario Lombardo <lomato@gmail.com> | 2019-01-06 10:34:32 +0100 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2019-01-14 16:00:29 +0000 |
commit | c3d198c401d5ec17289159cc88e2f891070e7779 (patch) | |
tree | fee286134f8799ecc84211baf6099ab204876338 /test | |
parent | 252938ed253846671a101f6b3f3e90354be3e4b2 (diff) |
dfilter: add string() function.
This function can convert non-string fields into strings. This allows the
user to apply string functions (like contains and matches) to non-string fields.
Examples:
string(frame.number) matches "[13579]$" => for odd frames
string(eth.dst) matches "aa\.bb\.cc\.dd\.ee\..." => to match a group of stations
string(snmp.name) matches "^1.2.3.4" => for all OIDs under a specific node
Change-Id: I18173f50ba5314ecdcd1e4b66c7e8ba5b44257ee
Reviewed-on: https://code.wireshark.org/review/31427
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'test')
-rw-r--r-- | test/suite_dfilter/group_dfunction_string.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/suite_dfilter/group_dfunction_string.py b/test/suite_dfilter/group_dfunction_string.py new file mode 100644 index 0000000000..c1bd17342c --- /dev/null +++ b/test/suite_dfilter/group_dfunction_string.py @@ -0,0 +1,39 @@ +# Copyright (c) 2019 by Dario Lombardo <lomato@gmail.com> +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import unittest +import fixtures +from suite_dfilter.dfiltertest import * + +@fixtures.uses_fixtures +class case_dfunction_string(unittest.TestCase): + trace_file = "dhcp.pcap" + + def test_matches_1(self, checkDFilterCount): + dfilter = "string(frame.number) matches \"[13579]$\"" + checkDFilterCount(dfilter, 2) + + def test_contains_1(self, checkDFilterCount): + dfilter = "string(eth.src) contains \"00:08:74\"" + checkDFilterCount(dfilter, 2) + + def test_fail_1(self, checkDFilterFail): + # Invalid filter (only non-string fields are supported) + dfilter = "string(dhcp.server) == hostname" + checkDFilterFail(dfilter) + + def test_fail_2(self, checkDFilterFail): + # Invalid field: value + dfilter = "string(123) == \"123\"" + checkDFilterFail(dfilter) + + def test_fail_3(self, checkDFilterFail): + # Invalid field: protocol + dfilter = "string(dhcp) == hostname" + checkDFilterFail(dfilter) + + def test_fail_4(self, checkDFilterFail): + # Invalid field: bytes + dfilter = "string(dhcp.option.value) == \"hostname\"" + checkDFilterFail(dfilter) |