2018-04-03 00:12:23 +00:00
|
|
|
#
|
|
|
|
# Wireshark tests
|
|
|
|
# By Gerald Combs <gerald@wireshark.org>
|
|
|
|
#
|
|
|
|
# Ported from a set of Bash scripts which were copyright 2005 Ulf Lamping
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#
|
|
|
|
'''Command line option tests'''
|
|
|
|
|
2018-11-20 01:47:36 +00:00
|
|
|
import json
|
2019-04-05 22:29:51 +00:00
|
|
|
import sys
|
2018-11-20 01:47:36 +00:00
|
|
|
import os.path
|
2018-04-03 00:12:23 +00:00
|
|
|
import subprocess
|
|
|
|
import subprocesstest
|
2018-11-13 01:17:33 +00:00
|
|
|
import fixtures
|
2019-04-05 22:29:51 +00:00
|
|
|
import shutil
|
2018-04-03 00:12:23 +00:00
|
|
|
|
|
|
|
#glossaries = ('fields', 'protocols', 'values', 'decodes', 'defaultprefs', 'currentprefs')
|
|
|
|
|
|
|
|
glossaries = ('decodes', 'values')
|
2018-04-27 17:35:17 +00:00
|
|
|
testout_pcap = 'testout.pcap'
|
2018-04-03 00:12:23 +00:00
|
|
|
|
2018-11-13 01:17:33 +00:00
|
|
|
|
|
|
|
@fixtures.uses_fixtures
|
|
|
|
class case_dumpcap_options(subprocesstest.SubprocessTestCase):
|
2018-04-03 00:12:23 +00:00
|
|
|
# XXX Should we generate individual test functions instead of looping?
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_dumpcap_invalid_chars(self, cmd_dumpcap, base_env):
|
2018-04-03 00:12:23 +00:00
|
|
|
'''Invalid dumpcap parameters'''
|
|
|
|
for char_arg in 'CEFGHJKNOQRTUVWXYejloxz':
|
2018-11-13 01:17:33 +00:00
|
|
|
self.assertRun((cmd_dumpcap, '-' + char_arg), env=base_env,
|
2018-04-03 00:12:23 +00:00
|
|
|
expected_return=self.exit_command_line)
|
|
|
|
|
|
|
|
# XXX Should we generate individual test functions instead of looping?
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_dumpcap_valid_chars(self, cmd_dumpcap, base_env):
|
2018-04-03 00:12:23 +00:00
|
|
|
for char_arg in 'hv':
|
2018-11-13 01:17:33 +00:00
|
|
|
self.assertRun((cmd_dumpcap, '-' + char_arg), env=base_env)
|
2018-04-03 00:12:23 +00:00
|
|
|
|
|
|
|
# XXX Should we generate individual test functions instead of looping?
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_dumpcap_interface_chars(self, cmd_dumpcap, base_env):
|
2018-04-03 00:12:23 +00:00
|
|
|
'''Valid dumpcap parameters requiring capture permissions'''
|
|
|
|
valid_returns = [self.exit_ok, self.exit_error]
|
|
|
|
for char_arg in 'DL':
|
2018-11-13 01:17:33 +00:00
|
|
|
process = self.runProcess((cmd_dumpcap, '-' + char_arg), env=base_env)
|
2018-04-03 00:12:23 +00:00
|
|
|
self.assertIn(process.returncode, valid_returns)
|
|
|
|
|
|
|
|
|
2018-11-15 17:44:59 +00:00
|
|
|
@fixtures.mark_usefixtures('base_env')
|
2018-11-13 01:17:33 +00:00
|
|
|
@fixtures.uses_fixtures
|
2018-04-03 00:12:23 +00:00
|
|
|
class case_dumpcap_capture_clopts(subprocesstest.SubprocessTestCase):
|
2018-11-15 17:44:59 +00:00
|
|
|
def test_dumpcap_invalid_capfilter(self, cmd_dumpcap, capture_interface):
|
2018-04-03 00:12:23 +00:00
|
|
|
'''Invalid capture filter'''
|
|
|
|
invalid_filter = '__invalid_protocol'
|
|
|
|
# $DUMPCAP -f 'jkghg' -w './testout.pcap' > ./testout.txt 2>&1
|
2018-04-27 17:35:17 +00:00
|
|
|
testout_file = self.filename_from_id(testout_pcap)
|
2018-11-15 17:44:59 +00:00
|
|
|
self.runProcess((cmd_dumpcap, '-f', invalid_filter, '-w', testout_file))
|
2018-04-03 00:12:23 +00:00
|
|
|
self.assertTrue(self.grepOutput('Invalid capture filter "' + invalid_filter + '" for interface'))
|
|
|
|
|
2018-11-15 17:44:59 +00:00
|
|
|
def test_dumpcap_invalid_interface_name(self, cmd_dumpcap, capture_interface):
|
2018-04-03 00:12:23 +00:00
|
|
|
'''Invalid capture interface name'''
|
|
|
|
invalid_interface = '__invalid_interface'
|
|
|
|
# $DUMPCAP -i invalid_interface -w './testout.pcap' > ./testout.txt 2>&1
|
2018-04-27 17:35:17 +00:00
|
|
|
testout_file = self.filename_from_id(testout_pcap)
|
2018-11-15 17:44:59 +00:00
|
|
|
self.runProcess((cmd_dumpcap, '-i', invalid_interface, '-w', testout_file))
|
2018-04-03 00:12:23 +00:00
|
|
|
self.assertTrue(self.grepOutput('The capture session could not be initiated'))
|
|
|
|
|
2018-11-15 17:44:59 +00:00
|
|
|
def test_dumpcap_invalid_interface_index(self, cmd_dumpcap, capture_interface):
|
2018-04-03 00:12:23 +00:00
|
|
|
'''Invalid capture interface index'''
|
|
|
|
invalid_index = '0'
|
|
|
|
# $DUMPCAP -i 0 -w './testout.pcap' > ./testout.txt 2>&1
|
2018-04-27 17:35:17 +00:00
|
|
|
testout_file = self.filename_from_id(testout_pcap)
|
2018-11-15 17:44:59 +00:00
|
|
|
self.runProcess((cmd_dumpcap, '-i', invalid_index, '-w', testout_file))
|
2018-04-03 00:12:23 +00:00
|
|
|
self.assertTrue(self.grepOutput('There is no interface with that adapter index'))
|
|
|
|
|
|
|
|
|
2018-11-13 01:17:33 +00:00
|
|
|
@fixtures.mark_usefixtures('test_env')
|
|
|
|
@fixtures.uses_fixtures
|
2018-04-03 00:12:23 +00:00
|
|
|
class case_basic_clopts(subprocesstest.SubprocessTestCase):
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_existing_file(self, cmd_tshark, capture_file):
|
2018-04-03 00:12:23 +00:00
|
|
|
# $TSHARK -r "${CAPTURE_DIR}dhcp.pcap" > ./testout.txt 2>&1
|
2018-11-13 01:17:33 +00:00
|
|
|
self.assertRun((cmd_tshark, '-r', capture_file('dhcp.pcap')))
|
2018-04-03 00:12:23 +00:00
|
|
|
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_nonexistent_file(self, cmd_tshark, capture_file):
|
2018-04-03 00:12:23 +00:00
|
|
|
# $TSHARK - r ThisFileDontExist.pcap > ./testout.txt 2 > &1
|
2018-11-13 01:17:33 +00:00
|
|
|
self.assertRun((cmd_tshark, '-r', capture_file('__ceci_nest_pas_une.pcap')),
|
2018-04-03 00:12:23 +00:00
|
|
|
expected_return=self.exit_error)
|
|
|
|
|
|
|
|
|
2018-11-13 01:17:33 +00:00
|
|
|
@fixtures.mark_usefixtures('test_env')
|
|
|
|
@fixtures.uses_fixtures
|
|
|
|
class case_tshark_options(subprocesstest.SubprocessTestCase):
|
2018-04-03 00:12:23 +00:00
|
|
|
# XXX Should we generate individual test functions instead of looping?
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_tshark_invalid_chars(self, cmd_tshark):
|
2018-04-03 00:12:23 +00:00
|
|
|
'''Invalid tshark parameters'''
|
|
|
|
for char_arg in 'ABCEFHJKMNORTUWXYZabcdefijkmorstuwyz':
|
2018-11-13 01:17:33 +00:00
|
|
|
self.assertRun((cmd_tshark, '-' + char_arg),
|
2018-04-03 00:12:23 +00:00
|
|
|
expected_return=self.exit_command_line)
|
|
|
|
|
|
|
|
# XXX Should we generate individual test functions instead of looping?
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_tshark_valid_chars(self, cmd_tshark):
|
2018-04-03 00:12:23 +00:00
|
|
|
for char_arg in 'Ghv':
|
2018-11-13 01:17:33 +00:00
|
|
|
self.assertRun((cmd_tshark, '-' + char_arg))
|
2018-04-03 00:12:23 +00:00
|
|
|
|
|
|
|
# XXX Should we generate individual test functions instead of looping?
|
2018-11-15 17:44:59 +00:00
|
|
|
def test_tshark_interface_chars(self, cmd_tshark, cmd_dumpcap):
|
2018-04-03 00:12:23 +00:00
|
|
|
'''Valid tshark parameters requiring capture permissions'''
|
2018-11-15 17:44:59 +00:00
|
|
|
# These options require dumpcap
|
2018-04-03 00:12:23 +00:00
|
|
|
valid_returns = [self.exit_ok, self.exit_error]
|
|
|
|
for char_arg in 'DL':
|
2018-11-13 01:17:33 +00:00
|
|
|
process = self.runProcess((cmd_tshark, '-' + char_arg))
|
2018-04-03 00:12:23 +00:00
|
|
|
self.assertIn(process.returncode, valid_returns)
|
|
|
|
|
|
|
|
|
2018-11-13 01:17:33 +00:00
|
|
|
@fixtures.mark_usefixtures('test_env')
|
|
|
|
@fixtures.uses_fixtures
|
2018-04-03 00:12:23 +00:00
|
|
|
class case_tshark_capture_clopts(subprocesstest.SubprocessTestCase):
|
2018-11-15 17:44:59 +00:00
|
|
|
def test_tshark_invalid_capfilter(self, cmd_tshark, capture_interface):
|
2018-04-03 00:12:23 +00:00
|
|
|
'''Invalid capture filter'''
|
|
|
|
invalid_filter = '__invalid_protocol'
|
|
|
|
# $TSHARK -f 'jkghg' -w './testout.pcap' > ./testout.txt 2>&1
|
2018-04-27 17:35:17 +00:00
|
|
|
testout_file = self.filename_from_id(testout_pcap)
|
2018-11-13 01:17:33 +00:00
|
|
|
self.runProcess((cmd_tshark, '-f', invalid_filter, '-w', testout_file ))
|
2018-04-03 00:12:23 +00:00
|
|
|
self.assertTrue(self.grepOutput('Invalid capture filter "' + invalid_filter + '" for interface'))
|
|
|
|
|
2018-11-15 17:44:59 +00:00
|
|
|
def test_tshark_invalid_interface_name(self, cmd_tshark, capture_interface):
|
2018-04-03 00:12:23 +00:00
|
|
|
'''Invalid capture interface name'''
|
|
|
|
invalid_interface = '__invalid_interface'
|
|
|
|
# $TSHARK -i invalid_interface -w './testout.pcap' > ./testout.txt 2>&1
|
2018-04-27 17:35:17 +00:00
|
|
|
testout_file = self.filename_from_id(testout_pcap)
|
2018-11-13 01:17:33 +00:00
|
|
|
self.runProcess((cmd_tshark, '-i', invalid_interface, '-w', testout_file))
|
2018-04-03 00:12:23 +00:00
|
|
|
self.assertTrue(self.grepOutput('The capture session could not be initiated'))
|
|
|
|
|
2018-11-15 17:44:59 +00:00
|
|
|
def test_tshark_invalid_interface_index(self, cmd_tshark, capture_interface):
|
2018-04-03 00:12:23 +00:00
|
|
|
'''Invalid capture interface index'''
|
|
|
|
invalid_index = '0'
|
|
|
|
# $TSHARK -i 0 -w './testout.pcap' > ./testout.txt 2>&1
|
2018-04-27 17:35:17 +00:00
|
|
|
testout_file = self.filename_from_id(testout_pcap)
|
2018-11-13 01:17:33 +00:00
|
|
|
self.runProcess((cmd_tshark, '-i', invalid_index, '-w', testout_file))
|
2018-04-03 00:12:23 +00:00
|
|
|
self.assertTrue(self.grepOutput('There is no interface with that adapter index'))
|
|
|
|
|
|
|
|
|
2018-11-13 01:17:33 +00:00
|
|
|
@fixtures.mark_usefixtures('test_env')
|
|
|
|
@fixtures.uses_fixtures
|
2018-04-03 00:12:23 +00:00
|
|
|
class case_tshark_name_resolution_clopts(subprocesstest.SubprocessTestCase):
|
2018-11-15 17:44:59 +00:00
|
|
|
def test_tshark_valid_name_resolution(self, cmd_tshark, capture_interface):
|
2018-10-05 06:54:55 +00:00
|
|
|
# $TSHARK -N mnNtdv -a duration:1 > ./testout.txt 2>&1
|
2018-11-13 01:17:33 +00:00
|
|
|
self.assertRun((cmd_tshark, '-N', 'mnNtdv', '-a', 'duration: 1'))
|
2018-04-03 00:12:23 +00:00
|
|
|
|
|
|
|
# XXX Add invalid name resolution.
|
|
|
|
|
2018-11-13 01:17:33 +00:00
|
|
|
@fixtures.mark_usefixtures('test_env')
|
|
|
|
@fixtures.uses_fixtures
|
2018-05-30 20:32:20 +00:00
|
|
|
class case_tshark_unicode_clopts(subprocesstest.SubprocessTestCase):
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_tshark_unicode_display_filter(self, cmd_tshark, capture_file):
|
2018-05-30 20:32:20 +00:00
|
|
|
'''Unicode (UTF-8) display filter'''
|
2018-11-30 00:31:32 +00:00
|
|
|
self.assertRun((cmd_tshark, '-r', capture_file('http.pcap'), '-Y', 'tcp.flags.str == "·······AP···"'))
|
2018-05-30 20:32:20 +00:00
|
|
|
self.assertTrue(self.grepOutput('HEAD.*/v4/iuident.cab'))
|
|
|
|
|
|
|
|
|
2018-11-13 01:17:33 +00:00
|
|
|
@fixtures.uses_fixtures
|
2018-04-03 00:12:23 +00:00
|
|
|
class case_tshark_dump_glossaries(subprocesstest.SubprocessTestCase):
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_tshark_dump_glossary(self, cmd_tshark, base_env):
|
2018-04-03 00:12:23 +00:00
|
|
|
for glossary in glossaries:
|
|
|
|
try:
|
|
|
|
self.log_fd.truncate()
|
Fix issues discovered by common python linters
Fix some issues discovered by common python linters including:
* switch `None` comparisons to use `is` rather than `==`. Identity !=
equality, and I've spent 40+ hours before tracking down a subtle bug
caused by exactly this issue. Note that this may introduce a problem if
one of the scripts is depending on this behavior, in which case the
comparison should be changed to `True`/`False` rather than `None`.
* Use `except Exception:` as bare `except:` statements have been
discouraged for years. Ideally for some of these we'd examine if there
were specific exceptions that should be caught, but for now I simply
caught all. Again, this could introduce very subtle behavioral changes
under Python 2, but IIUC, that was all fixed in Python 3, so safe to
move to `except Exception:`.
* Use more idiomatic `if not x in y`--> `if x not in y`
* Use more idiomatic 2 blank lines. I only did this at the beginning,
until I realized how overwhelming this was going to be to apply, then I
stopped.
* Add a TODO where an undefined function name is called, so will fail
whenever that code is run.
* Add more idiomatic spacing around `:`. This is also only partially
cleaned up, as I gave up when I saw how `asn2wrs.py` was clearly
infatuated with the construct.
* Various other small cleanups, removed some trailing whitespace and
improper indentation that wasn't a multiple of 4, etc.
There is still _much_ to do, but I haven't been heavily involved with
this project before, so thought this was a sufficient amount to put up
and see what the feedback is.
Linters that I have enabled which highlighted some of these issues
include:
* `pylint`
* `flake8`
* `pycodestyle`
2020-09-21 05:44:41 +00:00
|
|
|
except Exception:
|
2018-04-03 00:12:23 +00:00
|
|
|
pass
|
2021-02-04 03:01:17 +00:00
|
|
|
self.assertRun((cmd_tshark, '-G', glossary), env=base_env, max_lines=20)
|
2018-05-03 19:05:12 +00:00
|
|
|
self.assertEqual(self.countOutput(count_stdout=False, count_stderr=True), 0, 'Found error output while printing glossary ' + glossary)
|
2018-04-03 00:12:23 +00:00
|
|
|
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_tshark_glossary_valid_utf8(self, cmd_tshark, base_env):
|
2018-04-03 00:12:23 +00:00
|
|
|
for glossary in glossaries:
|
2018-11-13 01:17:33 +00:00
|
|
|
env = base_env
|
2018-04-03 00:12:23 +00:00
|
|
|
env['LANG'] = 'en_US.UTF-8'
|
2018-11-13 01:17:33 +00:00
|
|
|
g_contents = subprocess.check_output((cmd_tshark, '-G', glossary), env=env, stderr=subprocess.PIPE)
|
2018-04-03 00:12:23 +00:00
|
|
|
decoded = True
|
|
|
|
try:
|
|
|
|
g_contents.decode('UTF-8')
|
|
|
|
except UnicodeDecodeError:
|
|
|
|
decoded = False
|
|
|
|
self.assertTrue(decoded, '{} is not valid UTF-8'.format(glossary))
|
|
|
|
|
2021-02-26 15:21:30 +00:00
|
|
|
def test_tshark_glossary_plugin_count(self, cmd_tshark, base_env, features):
|
|
|
|
if not features.have_plugins:
|
|
|
|
self.skipTest('Test requires binary plugin support.')
|
2018-11-30 00:31:32 +00:00
|
|
|
self.assertRun((cmd_tshark, '-G', 'plugins'), env=base_env)
|
2018-04-03 00:12:23 +00:00
|
|
|
self.assertGreaterEqual(self.countOutput('dissector'), 10, 'Fewer than 10 dissector plugins found')
|
|
|
|
|
2018-11-20 01:47:36 +00:00
|
|
|
def test_tshark_elastic_mapping(self, cmd_tshark, dirs, base_env):
|
|
|
|
def get_ip_props(obj):
|
2019-05-08 08:42:39 +00:00
|
|
|
return obj['mappings']['doc']['properties']['layers']['properties']['ip']['properties']
|
2019-05-07 07:42:38 +00:00
|
|
|
self.maxDiff = None
|
2018-11-20 01:47:36 +00:00
|
|
|
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)
|
|
|
|
|
2019-01-28 19:09:46 +00:00
|
|
|
def test_tshark_unicode_folders(self, cmd_tshark, unicode_env, features):
|
2018-12-20 22:25:23 +00:00
|
|
|
'''Folders output with unicode'''
|
2019-01-28 19:09:46 +00:00
|
|
|
if not features.have_lua:
|
|
|
|
self.skipTest('Test requires Lua scripting support.')
|
2018-12-20 22:25:23 +00:00
|
|
|
proc = self.assertRun((cmd_tshark, '-G', 'folders'), env=unicode_env.env)
|
|
|
|
out = proc.stdout_str
|
|
|
|
pluginsdir = [x.split('\t', 1)[1] for x in out.splitlines() if x.startswith('Personal Lua Plugins:')]
|
|
|
|
self.assertEqual([unicode_env.pluginsdir], pluginsdir)
|
|
|
|
|
2018-11-13 01:17:33 +00:00
|
|
|
|
|
|
|
@fixtures.mark_usefixtures('test_env')
|
|
|
|
@fixtures.uses_fixtures
|
2018-11-07 19:33:41 +00:00
|
|
|
class case_tshark_z_expert(subprocesstest.SubprocessTestCase):
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_tshark_z_expert_all(self, cmd_tshark, capture_file):
|
|
|
|
self.assertRun((cmd_tshark, '-q', '-z', 'expert',
|
|
|
|
'-r', capture_file('http-ooo.pcap')))
|
2018-11-07 19:33:41 +00:00
|
|
|
self.assertTrue(self.grepOutput('Errors'))
|
|
|
|
self.assertTrue(self.grepOutput('Warns'))
|
|
|
|
self.assertTrue(self.grepOutput('Chats'))
|
|
|
|
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_tshark_z_expert_error(self, cmd_tshark, capture_file):
|
|
|
|
self.assertRun((cmd_tshark, '-q', '-z', 'expert,error',
|
|
|
|
'-r', capture_file('http-ooo.pcap')))
|
2018-11-07 19:33:41 +00:00
|
|
|
self.assertTrue(self.grepOutput('Errors'))
|
|
|
|
self.assertFalse(self.grepOutput('Warns'))
|
|
|
|
self.assertFalse(self.grepOutput('Chats'))
|
|
|
|
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_tshark_z_expert_warn(self, cmd_tshark, capture_file):
|
|
|
|
self.assertRun((cmd_tshark, '-q', '-z', 'expert,warn',
|
|
|
|
'-r', capture_file('http-ooo.pcap')))
|
2018-11-07 19:33:41 +00:00
|
|
|
self.assertTrue(self.grepOutput('Errors'))
|
|
|
|
self.assertTrue(self.grepOutput('Warns'))
|
|
|
|
self.assertFalse(self.grepOutput('Chats'))
|
|
|
|
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_tshark_z_expert_note(self, cmd_tshark, capture_file):
|
|
|
|
self.assertRun((cmd_tshark, '-q', '-z', 'expert,note',
|
|
|
|
'-r', capture_file('http2-data-reassembly.pcap')))
|
2018-11-07 19:33:41 +00:00
|
|
|
self.assertTrue(self.grepOutput('Warns'))
|
|
|
|
self.assertTrue(self.grepOutput('Notes'))
|
|
|
|
self.assertFalse(self.grepOutput('Chats'))
|
|
|
|
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_tshark_z_expert_chat(self, cmd_tshark, capture_file):
|
|
|
|
self.assertRun((cmd_tshark, '-q', '-z', 'expert,chat',
|
|
|
|
'-r', capture_file('http-ooo.pcap')))
|
2018-11-07 19:33:41 +00:00
|
|
|
self.assertTrue(self.grepOutput('Errors'))
|
|
|
|
self.assertTrue(self.grepOutput('Warns'))
|
|
|
|
self.assertTrue(self.grepOutput('Chats'))
|
|
|
|
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_tshark_z_expert_comment(self, cmd_tshark, capture_file):
|
|
|
|
self.assertRun((cmd_tshark, '-q', '-z', 'expert,comment',
|
|
|
|
'-r', capture_file('sip.pcapng')))
|
2018-11-07 19:33:41 +00:00
|
|
|
self.assertTrue(self.grepOutput('Notes'))
|
|
|
|
self.assertTrue(self.grepOutput('Comments'))
|
|
|
|
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_tshark_z_expert_invalid_filter(self, cmd_tshark, capture_file):
|
2018-11-07 19:33:41 +00:00
|
|
|
invalid_filter = '__invalid_protocol'
|
2018-11-13 01:17:33 +00:00
|
|
|
self.assertRun((cmd_tshark, '-q', '-z', 'expert,' + invalid_filter,
|
|
|
|
'-r', capture_file('http-ooo.pcap')),
|
2018-11-07 19:33:41 +00:00
|
|
|
expected_return=self.exit_command_line)
|
|
|
|
self.assertTrue(self.grepOutput('Filter "' + invalid_filter + '" is invalid'))
|
|
|
|
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_tshark_z_expert_error_invalid_filter(self, cmd_tshark, capture_file):
|
2018-11-07 19:33:41 +00:00
|
|
|
invalid_filter = '__invalid_protocol'
|
2018-11-13 01:17:33 +00:00
|
|
|
self.assertRun((cmd_tshark, '-q', '-z', 'expert,error,' + invalid_filter,
|
|
|
|
'-r', capture_file('http-ooo.pcap')),
|
2018-11-07 19:33:41 +00:00
|
|
|
expected_return=self.exit_command_line)
|
|
|
|
self.assertTrue(self.grepOutput('Filter "' + invalid_filter + '" is invalid'))
|
|
|
|
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_tshark_z_expert_filter(self, cmd_tshark, capture_file):
|
|
|
|
self.assertRun((cmd_tshark, '-q', '-z', 'expert,udp', # udp is a filter
|
|
|
|
'-r', capture_file('http-ooo.pcap')))
|
2018-11-07 19:33:41 +00:00
|
|
|
self.assertFalse(self.grepOutput('Errors'))
|
|
|
|
self.assertFalse(self.grepOutput('Warns'))
|
|
|
|
self.assertFalse(self.grepOutput('Chats'))
|
|
|
|
|
2018-11-13 01:17:33 +00:00
|
|
|
def test_tshark_z_expert_error_filter(self, cmd_tshark, capture_file):
|
|
|
|
self.assertRun((cmd_tshark, '-q', '-z', 'expert,error,udp', # udp is a filter
|
|
|
|
'-r', capture_file('http-ooo.pcap')))
|
2018-11-07 19:33:41 +00:00
|
|
|
self.assertFalse(self.grepOutput('Errors'))
|
|
|
|
self.assertFalse(self.grepOutput('Warns'))
|
|
|
|
self.assertFalse(self.grepOutput('Chats'))
|
2019-04-05 22:29:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
@fixtures.mark_usefixtures('test_env')
|
|
|
|
@fixtures.uses_fixtures
|
|
|
|
class case_tshark_extcap(subprocesstest.SubprocessTestCase):
|
2019-04-14 18:42:33 +00:00
|
|
|
# dumpcap dependency has been added to run this test only with capture support
|
2019-04-19 00:51:03 +00:00
|
|
|
def test_tshark_extcap_interfaces(self, cmd_tshark, cmd_dumpcap, test_env, home_path):
|
2019-04-05 22:29:51 +00:00
|
|
|
# Script extcaps don't work with the current code on windows.
|
|
|
|
# https://www.wireshark.org/docs/wsdg_html_chunked/ChCaptureExtcap.html
|
|
|
|
# TODO: skip this test until it will get fixed.
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
self.skipTest('FIXME extcap .py scripts needs special treatment on Windows')
|
2019-04-19 00:51:03 +00:00
|
|
|
extcap_dir_path = os.path.join(home_path, 'extcap')
|
|
|
|
os.makedirs(extcap_dir_path)
|
|
|
|
test_env['WIRESHARK_EXTCAP_DIR'] = extcap_dir_path
|
|
|
|
source_file = os.path.join(os.path.dirname(__file__), 'sampleif.py')
|
|
|
|
shutil.copy2(source_file, extcap_dir_path)
|
2019-04-05 22:29:51 +00:00
|
|
|
# Ensure the test extcap_tool is properly loaded
|
2019-04-19 00:51:03 +00:00
|
|
|
self.assertRun((cmd_tshark, '-D'), env=test_env)
|
2019-04-05 22:29:51 +00:00
|
|
|
self.assertEqual(1, self.countOutput('sampleif'))
|
|
|
|
# Ensure tshark lists 2 interfaces in the preferences
|
2019-04-19 00:51:03 +00:00
|
|
|
self.assertRun((cmd_tshark, '-G', 'currentprefs'), env=test_env)
|
2019-04-05 22:29:51 +00:00
|
|
|
self.assertEqual(2, self.countOutput('extcap.sampleif.test'))
|