2019-01-06 09:34:32 +00:00
|
|
|
# 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"
|
2021-11-08 10:53:56 +00:00
|
|
|
error = 'String conversion for field "dhcp.server" is not supported'
|
2019-01-24 12:44:49 +00:00
|
|
|
checkDFilterFail(dfilter, error)
|
2019-01-06 09:34:32 +00:00
|
|
|
|
|
|
|
def test_fail_2(self, checkDFilterFail):
|
|
|
|
# Invalid field: value
|
|
|
|
dfilter = "string(123) == \"123\""
|
2021-11-08 10:53:56 +00:00
|
|
|
error = 'Only fields can be used as parameter for string()'
|
2019-01-24 12:44:49 +00:00
|
|
|
checkDFilterFail(dfilter, error)
|
2019-01-06 09:34:32 +00:00
|
|
|
|
|
|
|
def test_fail_3(self, checkDFilterFail):
|
|
|
|
# Invalid field: protocol
|
|
|
|
dfilter = "string(dhcp) == hostname"
|
2021-11-08 10:53:56 +00:00
|
|
|
error = 'String conversion for field "dhcp" is not supported'
|
2019-01-24 12:44:49 +00:00
|
|
|
checkDFilterFail(dfilter, error)
|
2019-01-06 09:34:32 +00:00
|
|
|
|
|
|
|
def test_fail_4(self, checkDFilterFail):
|
|
|
|
# Invalid field: bytes
|
|
|
|
dfilter = "string(dhcp.option.value) == \"hostname\""
|
2021-11-08 10:53:56 +00:00
|
|
|
error = 'String conversion for field "dhcp.option.value" is not supported'
|
2019-01-24 12:44:49 +00:00
|
|
|
checkDFilterFail(dfilter, error)
|
2022-04-13 13:07:01 +00:00
|
|
|
|
|
|
|
@fixtures.uses_fixtures
|
|
|
|
class case_dfunction_maxmin(unittest.TestCase):
|
|
|
|
trace_file = "sip.pcapng"
|
|
|
|
|
|
|
|
def test_min_1(self, checkDFilterCount):
|
|
|
|
dfilter = 'min(udp.srcport, udp.dstport) == 5060'
|
|
|
|
checkDFilterCount(dfilter, 5)
|
|
|
|
|
|
|
|
def test_min_2(self, checkDFilterCount):
|
|
|
|
dfilter = 'min(udp.srcport, udp.dstport) == 5070'
|
|
|
|
checkDFilterCount(dfilter, 0)
|
|
|
|
|
|
|
|
def test_max_1(self, checkDFilterCount):
|
|
|
|
dfilter = 'max(udp.srcport, udp.dstport) == 5070'
|
|
|
|
checkDFilterCount(dfilter, 3)
|
|
|
|
|
|
|
|
def test_max_2(self, checkDFilterCount):
|
|
|
|
dfilter = 'max(udp.srcport, udp.dstport) == 5060'
|
|
|
|
checkDFilterCount(dfilter, 2)
|
|
|
|
|
|
|
|
def test_max_3(self, checkDFilterCount):
|
|
|
|
dfilter = 'max(udp.srcport, udp.dstport) < 5060'
|
|
|
|
checkDFilterCount(dfilter, 1)
|
2022-04-13 14:30:36 +00:00
|
|
|
|
2022-12-26 03:42:07 +00:00
|
|
|
def test_max_4(self, checkDFilterCount):
|
|
|
|
dfilter = 'max(5060, udp.dstport) == udp.srcport'
|
|
|
|
checkDFilterCount(dfilter, 2)
|
|
|
|
|
2022-12-28 17:18:59 +00:00
|
|
|
def test_max_5(self, checkDFilterFail):
|
|
|
|
error = 'Constant expression is invalid on the LHS'
|
2022-12-26 03:42:07 +00:00
|
|
|
dfilter = 'max(5060, 5070) == udp.srcport'
|
2022-12-28 17:18:59 +00:00
|
|
|
checkDFilterFail(dfilter, error)
|
2022-12-26 20:37:55 +00:00
|
|
|
|
2022-04-13 14:30:36 +00:00
|
|
|
@fixtures.uses_fixtures
|
|
|
|
class case_dfunction_abs(unittest.TestCase):
|
|
|
|
trace_file = "dhcp.pcapng"
|
|
|
|
|
|
|
|
def test_function_abs_1(self, checkDFilterCount):
|
|
|
|
dfilter = 'udp.dstport == abs(-67)'
|
|
|
|
checkDFilterCount(dfilter, 2)
|