mirror of
https://github.com/theupdateframework/python-tuf
synced 2026-05-24 10:08:28 +00:00
Add host address as a test level constant
Use a common test level constant for defining the host address forming the download URL on the client side. Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
This commit is contained in:
parent
1677ce0bf8
commit
2af63cfd8d
15 changed files with 38 additions and 24 deletions
|
|
@ -124,7 +124,7 @@ def setUp(self):
|
|||
# Set the url prefix required by the 'tuf/client/updater.py' updater.
|
||||
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
|
||||
repository_basepath = self.repository_directory[len(os.getcwd()):]
|
||||
url_prefix = 'http://127.0.0.1:' \
|
||||
url_prefix = 'http://' + utils.TEST_HOST_ADDRESS + ':' \
|
||||
+ str(self.server_process_handler.port) + repository_basepath
|
||||
|
||||
# Setting 'tuf.settings.repository_directory' with the temporary client
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ def setUp(self):
|
|||
self.server_process_handler = utils.TestServerProcess(log=logger)
|
||||
|
||||
rel_target_filepath = os.path.basename(target_filepath)
|
||||
self.url = 'http://127.0.0.1:' \
|
||||
self.url = 'http://' + utils.TEST_HOST_ADDRESS + ':' \
|
||||
+ str(self.server_process_handler.port) + '/' + rel_target_filepath
|
||||
|
||||
# Computing hash of target file data.
|
||||
|
|
@ -195,13 +195,13 @@ def test_download_url_to_tempfileobj_and_urls(self):
|
|||
with self.assertRaises(securesystemslib.exceptions.FormatError):
|
||||
download_file(None, self.target_data_length, self.fetcher)
|
||||
|
||||
url = 'http://127.0.0.1:' \
|
||||
url = 'http://' + utils.TEST_HOST_ADDRESS + ':' \
|
||||
+ str(self.server_process_handler.port) + '/' + self.random_string()
|
||||
with self.assertRaises(tuf.exceptions.FetcherHTTPError) as cm:
|
||||
download_file(url, self.target_data_length, self.fetcher)
|
||||
self.assertEqual(cm.exception.status_code, 404)
|
||||
|
||||
url1 = 'http://127.0.0.1:' \
|
||||
url1 = 'http://' + utils.TEST_HOST_ADDRESS + ':' \
|
||||
+ str(self.server_process_handler.port + 1) + '/' + self.random_string()
|
||||
with self.assertRaises(requests.exceptions.ConnectionError):
|
||||
download_file(url1, self.target_data_length, self.fetcher)
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ def setUp(self):
|
|||
# Set the url prefix required by the 'tuf/client/updater.py' updater.
|
||||
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
|
||||
repository_basepath = self.repository_directory[len(os.getcwd()):]
|
||||
url_prefix = 'http://127.0.0.1:' \
|
||||
url_prefix = 'http://' + utils.TEST_HOST_ADDRESS + ':' \
|
||||
+ str(self.server_process_handler.port) + repository_basepath
|
||||
|
||||
# Setting 'tuf.settings.repository_directory' with the temporary client
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ def setUp(self):
|
|||
# Set the url prefix required by the 'tuf/client/updater.py' updater.
|
||||
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
|
||||
repository_basepath = self.repository_directory[len(os.getcwd()):]
|
||||
url_prefix = 'http://127.0.0.1:' \
|
||||
url_prefix = 'http://' + utils.TEST_HOST_ADDRESS + ':' \
|
||||
+ str(self.server_process_handler.port) + repository_basepath
|
||||
|
||||
# Setting 'tuf.settings.repository_directory' with the temporary client
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ def setUp(self):
|
|||
self.server_process_handler = utils.TestServerProcess(log=logger)
|
||||
|
||||
rel_target_filepath = os.path.basename(target_filepath)
|
||||
self.url = 'http://127.0.0.1:' \
|
||||
self.url = 'http://' + utils.TEST_HOST_ADDRESS + ':' \
|
||||
+ str(self.server_process_handler.port) + '/' + rel_target_filepath
|
||||
|
||||
# Create a temporary file where the target file chunks are written
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ def setUp(self):
|
|||
# Set the url prefix required by the 'tuf/client/updater.py' updater.
|
||||
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
|
||||
repository_basepath = self.repository_directory[len(os.getcwd()):]
|
||||
url_prefix = 'http://127.0.0.1:' \
|
||||
url_prefix = 'http://' + utils.TEST_HOST_ADDRESS + ':' \
|
||||
+ str(self.server_process_handler.port) + repository_basepath
|
||||
|
||||
# Setting 'tuf.settings.repository_directory' with the temporary client
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ def setUp(self):
|
|||
|
||||
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
|
||||
repository_basepath = self.repository_directory[len(os.getcwd()):]
|
||||
url_prefix = 'http://127.0.0.1:' \
|
||||
url_prefix = 'http://' + utils.TEST_HOST_ADDRESS + ':' \
|
||||
+ str(self.server_process_handler.port) + repository_basepath
|
||||
|
||||
# Setting 'tuf.settings.repository_directory' with the temporary client
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ def setUp(self):
|
|||
# Set the url prefix required by the 'tuf/client/updater.py' updater.
|
||||
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
|
||||
repository_basepath = self.repository_directory[len(os.getcwd()):]
|
||||
url_prefix = 'http://127.0.0.1:' \
|
||||
url_prefix = 'http://' + utils.TEST_HOST_ADDRESS + ':' \
|
||||
+ str(self.server_process_handler.port) + repository_basepath
|
||||
|
||||
# Setting 'tuf.settings.repository_directory' with the temporary client
|
||||
|
|
|
|||
|
|
@ -136,8 +136,12 @@ def setUp(self):
|
|||
|
||||
logger.debug('Server process 2 started.')
|
||||
|
||||
url_prefix = 'http://127.0.0.1:' + str(self.server_process_handler.port)
|
||||
url_prefix2 = 'http://127.0.0.1:' + str(self.server_process_handler2.port)
|
||||
url_prefix = \
|
||||
'http://' + utils.TEST_HOST_ADDRESS + ':' + \
|
||||
str(self.server_process_handler.port)
|
||||
url_prefix2 = \
|
||||
'http://' + utils.TEST_HOST_ADDRESS + ':' + \
|
||||
str(self.server_process_handler2.port)
|
||||
|
||||
self.repository_mirrors = {'mirror1': {'url_prefix': url_prefix,
|
||||
'metadata_path': 'metadata',
|
||||
|
|
|
|||
|
|
@ -97,7 +97,8 @@ def setUpClass(cls):
|
|||
|
||||
# Note that the HTTP proxy server's address uses http://, regardless of the
|
||||
# type of connection used with the target server.
|
||||
cls.http_proxy_addr = 'http://127.0.0.1:' + str(cls.http_proxy_handler.port)
|
||||
cls.http_proxy_addr = 'http://' + utils.TEST_HOST_ADDRESS + ':' + \
|
||||
str(cls.http_proxy_handler.port)
|
||||
|
||||
|
||||
# Launch an HTTPS proxy server, also derived from inaz2/proxy2.
|
||||
|
|
@ -167,10 +168,12 @@ def setUp(self):
|
|||
|
||||
suffix = '/' + os.path.basename(target_filepath)
|
||||
self.url = \
|
||||
'http://127.0.0.1:' + str(self.http_server_handler.port) + suffix
|
||||
'http://' + utils.TEST_HOST_ADDRESS + ':' + \
|
||||
str(self.http_server_handler.port) + suffix
|
||||
|
||||
self.url_https = \
|
||||
'https://127.0.0.1:' + str(self.https_server_handler.port) + suffix
|
||||
'https://' + utils.TEST_HOST_ADDRESS + ':' + \
|
||||
str(self.https_server_handler.port) + suffix
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ def setUp(self):
|
|||
# Set the url prefix required by the 'tuf/client/updater.py' updater.
|
||||
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
|
||||
repository_basepath = self.repository_directory[len(os.getcwd()):]
|
||||
url_prefix = 'http://127.0.0.1:' \
|
||||
url_prefix = 'http://' + utils.TEST_HOST_ADDRESS + ':' \
|
||||
+ str(self.server_process_handler.port) + repository_basepath
|
||||
|
||||
# Setting 'tuf.settings.repository_directory' with the temporary client
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ def setUp(self):
|
|||
|
||||
logger.info('Slow Retrieval Server process started.')
|
||||
|
||||
url_prefix = 'http://127.0.0.1:' \
|
||||
url_prefix = 'http://' + utils.TEST_HOST_ADDRESS + ':' \
|
||||
+ str(self.server_process_handler.port) + repository_basepath
|
||||
|
||||
# Setting 'tuf.settings.repository_directory' with the temporary client
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ def setUp(self):
|
|||
|
||||
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
|
||||
repository_basepath = self.repository_directory[len(os.getcwd()):]
|
||||
url_prefix = 'http://127.0.0.1:' \
|
||||
url_prefix = 'http://' + utils.TEST_HOST_ADDRESS + ':' \
|
||||
+ str(self.server_process_handler.port) + repository_basepath
|
||||
|
||||
# Setting 'tuf.settings.repository_directory' with the temporary client
|
||||
|
|
@ -1110,7 +1110,7 @@ def test_6_get_one_valid_targetinfo(self):
|
|||
|
||||
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
|
||||
repository_basepath = self.repository_directory[len(os.getcwd()):]
|
||||
url_prefix = 'http://127.0.0.1:' \
|
||||
url_prefix = 'http://' + utils.TEST_HOST_ADDRESS + ':' \
|
||||
+ str(self.server_process_handler.port) + repository_basepath
|
||||
|
||||
self.repository_mirrors = {'mirror1': {'url_prefix': url_prefix,
|
||||
|
|
@ -1406,7 +1406,7 @@ def test_7_updated_targets(self):
|
|||
|
||||
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
|
||||
repository_basepath = self.repository_directory[len(os.getcwd()):]
|
||||
url_prefix = 'http://127.0.0.1:' \
|
||||
url_prefix = 'http://' + utils.TEST_HOST_ADDRESS + ':' \
|
||||
+ str(self.server_process_handler.port) + repository_basepath
|
||||
|
||||
# Setting 'tuf.settings.repository_directory' with the temporary client
|
||||
|
|
@ -1533,7 +1533,7 @@ def test_8_remove_obsolete_targets(self):
|
|||
|
||||
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
|
||||
repository_basepath = self.repository_directory[len(os.getcwd()):]
|
||||
url_prefix = 'http://127.0.0.1:' \
|
||||
url_prefix = 'http://' + utils.TEST_HOST_ADDRESS + ':' \
|
||||
+ str(self.server_process_handler.port) + repository_basepath
|
||||
|
||||
# Setting 'tuf.settings.repository_directory' with the temporary client
|
||||
|
|
@ -1861,8 +1861,12 @@ def setUp(self):
|
|||
|
||||
logger.debug('Server process 2 started.')
|
||||
|
||||
url_prefix = 'http://127.0.0.1:' + str(self.server_process_handler.port)
|
||||
url_prefix2 = 'http://127.0.0.1:' + str(self.server_process_handler2.port)
|
||||
url_prefix = \
|
||||
'http://' + utils.TEST_HOST_ADDRESS + ':' + \
|
||||
str(self.server_process_handler.port)
|
||||
url_prefix2 = \
|
||||
'http://' + utils.TEST_HOST_ADDRESS + ':' + \
|
||||
str(self.server_process_handler2.port)
|
||||
|
||||
# We have all of the necessary information for two repository mirrors
|
||||
# in map.json, except for url prefixes.
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ def setUp(self):
|
|||
|
||||
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
|
||||
repository_basepath = self.repository_directory[len(os.getcwd()):]
|
||||
url_prefix = 'http://127.0.0.1:' \
|
||||
url_prefix = 'http://' + utils.TEST_HOST_ADDRESS + ':' \
|
||||
+ str(self.server_process_handler.port) + repository_basepath
|
||||
|
||||
# Setting 'tuf.settings.repository_directory' with the temporary client
|
||||
|
|
|
|||
|
|
@ -39,6 +39,9 @@
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Used when forming URLs on the client side
|
||||
TEST_HOST_ADDRESS = '127.0.0.1'
|
||||
|
||||
try:
|
||||
# is defined in Python 3
|
||||
TimeoutError
|
||||
|
|
|
|||
Loading…
Reference in a new issue