diff options
author | Gerald Combs <gerald@wireshark.org> | 2018-04-27 16:03:24 -0700 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2018-04-30 18:50:10 +0000 |
commit | d32ccb5c879c84d8ecf13010ca2dfb67ddfe512d (patch) | |
tree | e8aed163d7fb0ebab0413b7e619b9ece5268eeae /test | |
parent | 295abe2e83ba8428e84e7ff9b2f6f94ae948fa76 (diff) |
Test: Add name resolution.
Change-Id: I7b289de5c807b61e1825b30c7f98bfc50caa9625
Reviewed-on: https://code.wireshark.org/review/27228
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/config.py | 32 | ||||
-rw-r--r-- | test/subprocesstest.py | 7 | ||||
-rw-r--r-- | test/suite_decryption.py | 2 | ||||
-rw-r--r-- | test/suite_nameres.py | 85 | ||||
-rwxr-xr-x | test/test.py | 4 |
5 files changed, 127 insertions, 3 deletions
diff --git a/test/config.py b/test/config.py index 203869c643..53fbeff995 100644 --- a/test/config.py +++ b/test/config.py @@ -12,6 +12,7 @@ import os import os.path import re +import shutil import subprocess import sys import tempfile @@ -45,8 +46,12 @@ have_kerberos = False have_libgcrypt17 = False test_env = None +program_path = None home_path = None conf_path = None +custom_profile_path = None +custom_profile_name = 'Custom Profile' + this_dir = os.path.dirname(__file__) baseline_dir = os.path.join(this_dir, 'baseline') capture_dir = os.path.join(this_dir, 'captures') @@ -143,10 +148,12 @@ def setProgramPath(path): cmd_path = os.path.join(path, cmd + dotexe) if not os.path.exists(cmd_path) or not os.access(cmd_path, os.X_OK): cmd_path = None + program_path = None retval = False globals()[cmd_var] = cmd_path getTsharkInfo() getDefaultCaptureInterface() + setUpHostFiles() return retval def testEnvironment(): @@ -155,6 +162,7 @@ def testEnvironment(): def setUpTestEnvironment(): global home_path global conf_path + global custom_profile_path global test_env test_confdir = tempfile.mkdtemp(prefix='wireshark-tests.') home_path = os.path.join(test_confdir, 'home') @@ -165,10 +173,14 @@ def setUpTestEnvironment(): home_env = 'HOME' conf_path = os.path.join(home_path, '.config', 'wireshark') os.makedirs(conf_path) + # Test spaces while we're here. + custom_profile_path = os.path.join(conf_path, 'profiles', custom_profile_name) + os.makedirs(custom_profile_path) test_env = os.environ.copy() + test_env['WIRESHARK_RUN_FROM_BUILD_DIRECTORY'] = '1' test_env[home_env] = home_path -def setUpConfigFile(conf_file): +def setUpUatFile(conf_file): global home_path global conf_path if home_path is None or conf_path is None: @@ -186,6 +198,24 @@ def setUpConfigFile(conf_file): cf_fd.write(cf_contents) cf_fd.close() +def setUpHostFiles(): + if program_path is None: + return + global program_path + global conf_path + global custom_profile_path + if conf_path is None or custom_profile_path is None: + setUpTestEnvironment() + bundle_path = os.path.join(program_path, 'Wireshark.app', 'Contents', 'MacOS') + if os.path.isdir(bundle_path): + global_path = bundle_path + else: + global_path = program_path + hosts_path_pfx = os.path.join(this_dir, 'hosts.') + shutil.copyfile(hosts_path_pfx + 'global', os.path.join(global_path, 'hosts')) + shutil.copyfile(hosts_path_pfx + 'personal', os.path.join(conf_path, 'hosts')) + shutil.copyfile(hosts_path_pfx + 'custom', os.path.join(custom_profile_path, 'hosts')) + if sys.platform.startswith('win32') or sys.platform.startswith('darwin'): can_capture = True diff --git a/test/subprocesstest.py b/test/subprocesstest.py index dd231b6722..e7b3fa8a20 100644 --- a/test/subprocesstest.py +++ b/test/subprocesstest.py @@ -249,7 +249,12 @@ class SubprocessTestCase(unittest.TestCase): return True def startProcess(self, proc_args, env=None, shell=False): - '''Start a process in the background. Returns a subprocess.Popen object. You typically wait for it using waitProcess() or assertWaitProcess().''' + '''Start a process in the background. Returns a subprocess.Popen object. + + You typically wait for it using waitProcess() or assertWaitProcess().''' + if env is None: + # Avoid using the test user's real environment by default. + env = config.test_env proc = LoggingPopen(proc_args, env=env, shell=shell, log_fd=self.log_fd) self.processes.append(proc) return proc diff --git a/test/suite_decryption.py b/test/suite_decryption.py index e5092a19c5..5813456e5f 100644 --- a/test/suite_decryption.py +++ b/test/suite_decryption.py @@ -24,7 +24,7 @@ uat_files = [ 'ikev2_decryption_table', ] for uat in uat_files: - config.setUpConfigFile(uat) + config.setUpUatFile(uat) class case_decrypt_80211(subprocesstest.SubprocessTestCase): diff --git a/test/suite_nameres.py b/test/suite_nameres.py new file mode 100644 index 0000000000..6552703372 --- /dev/null +++ b/test/suite_nameres.py @@ -0,0 +1,85 @@ +# +# -*- coding: utf-8 -*- +# 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 +# +'''Name resolution tests''' + +import config +import os.path +import subprocesstest +import unittest + +dns_icmp_pcapng = os.path.join(config.capture_dir, 'dns+icmp.pcapng.gz') + +tf_str = { True: 'TRUE', False: 'FALSE' } + +def check_name_resolution(self, o_net_name, o_external_name_res, o_hosts_file, custom_profile, grep_str, fail_on_match=False): + tshark_cmd = (config.cmd_tshark, + '-r', dns_icmp_pcapng, + '-o', 'nameres.network_name: ' + tf_str[o_net_name], + '-o', 'nameres.use_external_name_resolver: ' + tf_str[o_external_name_res], + '-o', 'nameres.hosts_file_handling: ' + tf_str[o_hosts_file], + ) + if custom_profile: + tshark_cmd += ('-C', config.custom_profile_name) + self.assertRun(tshark_cmd, env=config.test_env) + if fail_on_match: + self.assertFalse(self.grepOutput(grep_str)) + else: + self.assertTrue(self.grepOutput(grep_str)) + + +class case_name_resolution(subprocesstest.SubprocessTestCase): + + def test_name_resolution_net_t_ext_f_hosts_f_global(self): + '''Name resolution, no external, no profile hosts, global profile.''' + # nameres.network_name: True + # nameres.use_external_name_resolver: False + # nameres.hosts_file_handling: False + # Profile: Default + check_name_resolution(self, True, False, False, False, 'global-8-8-8-8') + + def test_name_resolution_net_t_ext_f_hosts_f_personal(self): + '''Name resolution, no external, no profile hosts, personal profile.''' + # nameres.network_name: True + # nameres.use_external_name_resolver: False + # nameres.hosts_file_handling: False + # Profile: Default + check_name_resolution(self, True, False, False, False, 'personal-8-8-4-4') + + def test_name_resolution_net_t_ext_f_hosts_f_custom(self): + '''Name resolution, no external, no profile hosts, custom profile.''' + # nameres.network_name: True + # nameres_use_external_name_resolver: False + # nameres.hosts_file_handling: False + # Profile: Custom + check_name_resolution(self, True, False, False, True, 'custom-4-2-2-2') + + def test_name_resolution_net_t_ext_f_hosts_t_global(self): + '''Name resolution, no external, profile hosts, global profile.''' + # nameres.network_name: True + # nameres.use_external_name_resolver: False + # nameres.hosts_file_handling: True + # Profile: Default + check_name_resolution(self, True, False, True, False, 'global-8-8-8-8', True) + + def test_name_resolution_net_t_ext_f_hosts_t_personal(self): + '''Name resolution, no external, profile hosts, personal profile.''' + # nameres.network_name: True + # nameres.use_external_name_resolver: False + # nameres.hosts_file_handling: True + # Profile: Default + check_name_resolution(self, True, False, True, False, 'personal-8-8-4-4') + + def test_name_resolution_net_t_ext_f_hosts_t_custom(self): + '''Name resolution, no external, profile hosts, custom profile.''' + # nameres.network_name: True + # nameres_use_external_name_resolver: False + # nameres.hosts_file_handling: True + # Profile: Custom + check_name_resolution(self, True, False, True, True, 'custom-4-2-2-2') diff --git a/test/test.py b/test/test.py index 26e1a75239..156da53a90 100755 --- a/test/test.py +++ b/test/test.py @@ -13,6 +13,10 @@ # To do: # - Avoid printing Python tracebacks when we assert? It looks like we'd need # to override unittest.TextTestResult.addFailure(). +# - Switch to Python 3 only? [Windows, Linux, macOS] x [Python 2, Python 3] +# is painful. +# - Remove BIN_PATH/hosts via config.tearDownHostFiles + case_name_resolution.tearDownClass? + import argparse import config |