Skip to content

Commit

Permalink
Avoid 'localhost' lookup in tests
Browse files Browse the repository at this point in the history
On Windows (Github Actions) the lookup for 'localhost' takes 1 second.
This is because:
- Windows retries connect() with a timeout
- the machine has IPv6 and IPv4 but Testserver only binds the port on IPv4
- the test clients connect to 'localhost'

Since socketserver.TCPServer does not seem to support IPv6 before 3.8,
just replace 'localhost' with '127.0.0.1' in client-side URLs.

See #1257

Signed-off-by: Teodora Sechkova <[email protected]>
  • Loading branch information
sechkova committed Jan 22, 2021
1 parent 77900af commit abac87f
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion tests/test_arbitrary_package_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://localhost:' \
url_prefix = 'http://127.0.0.1:' \
+ str(self.server_process_handler.port) + repository_basepath

# Setting 'tuf.settings.repository_directory' with the temporary client
Expand Down
6 changes: 3 additions & 3 deletions tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://localhost:' \
self.url = 'http://127.0.0.1:' \
+ str(self.server_process_handler.port) + '/' + rel_target_filepath

# Computing hash of target file data.
Expand Down Expand Up @@ -172,14 +172,14 @@ def test_download_url_to_tempfileobj_and_urls(self):
self.assertRaises(securesystemslib.exceptions.FormatError,
download_file, None, self.target_data_length, self.fetcher)

url = 'http://localhost:' \
url = 'http://127.0.0.1:' \
+ str(self.server_process_handler.port) + '/' + self.random_string()
self.assertRaises(requests.exceptions.HTTPError,
download_file,
url,
self.target_data_length,
self.fetcher)
url1 = 'http://localhost:' \
url1 = 'http://127.0.0.1:' \
+ str(self.server_process_handler.port + 1) + '/' + self.random_string()
self.assertRaises(requests.exceptions.ConnectionError,
download_file,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_endless_data_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://localhost:' \
url_prefix = 'http://127.0.0.1:' \
+ str(self.server_process_handler.port) + repository_basepath

# Setting 'tuf.settings.repository_directory' with the temporary client
Expand Down
2 changes: 1 addition & 1 deletion tests/test_extraneous_dependencies_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://localhost:' \
url_prefix = 'http://127.0.0.1:' \
+ str(self.server_process_handler.port) + repository_basepath

# Setting 'tuf.settings.repository_directory' with the temporary client
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def setUp(self):
self.server_process_handler = utils.TestServerProcess(log=logger)

rel_target_filepath = os.path.basename(target_filepath)
self.url = 'http://localhost:' \
self.url = 'http://127.0.0.1:' \
+ str(self.server_process_handler.port) + '/' + rel_target_filepath

# Create a temporary file where the target file chunks are written
Expand Down
2 changes: 1 addition & 1 deletion tests/test_indefinite_freeze_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://localhost:' \
url_prefix = 'http://127.0.0.1:' \
+ str(self.server_process_handler.port) + repository_basepath

# Setting 'tuf.settings.repository_directory' with the temporary client
Expand Down
2 changes: 1 addition & 1 deletion tests/test_key_revocation_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://localhost:' \
url_prefix = 'http://127.0.0.1:' \
+ str(self.server_process_handler.port) + repository_basepath

# Setting 'tuf.settings.repository_directory' with the temporary client
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mix_and_match_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://localhost:' \
url_prefix = 'http://127.0.0.1:' \
+ str(self.server_process_handler.port) + repository_basepath

# Setting 'tuf.settings.repository_directory' with the temporary client
Expand Down
4 changes: 2 additions & 2 deletions tests/test_multiple_repositories_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def setUp(self):

logger.debug('Server process 2 started.')

url_prefix = 'http://localhost:' + str(self.server_process_handler.port)
url_prefix2 = 'http://localhost:' + str(self.server_process_handler2.port)
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)

self.repository_mirrors = {'mirror1': {'url_prefix': url_prefix,
'metadata_path': 'metadata',
Expand Down
4 changes: 2 additions & 2 deletions tests/test_proxy_use.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ def setUp(self):

suffix = '/' + os.path.basename(target_filepath)
self.url = \
'http://localhost:' + str(self.http_server_handler.port) + suffix
'http://127.0.0.1:' + str(self.http_server_handler.port) + suffix

self.url_https = \
'https://localhost:' + str(self.https_server_handler.port) + suffix
'https://127.0.0.1:' + str(self.https_server_handler.port) + suffix



Expand Down
2 changes: 1 addition & 1 deletion tests/test_replay_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://localhost:' \
url_prefix = 'http://127.0.0.1:' \
+ str(self.server_process_handler.port) + repository_basepath

# Setting 'tuf.settings.repository_directory' with the temporary client
Expand Down
2 changes: 1 addition & 1 deletion tests/test_slow_retrieval_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def setUp(self):

logger.info('Slow Retrieval Server process started.')

url_prefix = 'http://localhost:' \
url_prefix = 'http://127.0.0.1:' \
+ str(self.server_process_handler.port) + repository_basepath

# Setting 'tuf.settings.repository_directory' with the temporary client
Expand Down
12 changes: 6 additions & 6 deletions tests/test_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://localhost:' \
url_prefix = 'http://127.0.0.1:' \
+ str(self.server_process_handler.port) + repository_basepath

# Setting 'tuf.settings.repository_directory' with the temporary client
Expand Down Expand Up @@ -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://localhost:' \
url_prefix = 'http://127.0.0.1:' \
+ str(self.server_process_handler.port) + repository_basepath

self.repository_mirrors = {'mirror1': {'url_prefix': url_prefix,
Expand Down Expand Up @@ -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://localhost:' \
url_prefix = 'http://127.0.0.1:' \
+ str(self.server_process_handler.port) + repository_basepath

# Setting 'tuf.settings.repository_directory' with the temporary client
Expand Down Expand Up @@ -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://localhost:' \
url_prefix = 'http://127.0.0.1:' \
+ str(self.server_process_handler.port) + repository_basepath

# Setting 'tuf.settings.repository_directory' with the temporary client
Expand Down Expand Up @@ -1861,8 +1861,8 @@ def setUp(self):

logger.debug('Server process 2 started.')

url_prefix = 'http://localhost:' + str(self.server_process_handler.port)
url_prefix2 = 'http://localhost:' + str(self.server_process_handler2.port)
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)

# We have all of the necessary information for two repository mirrors
# in map.json, except for url prefixes.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_updater_root_rotation_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://localhost:' \
url_prefix = 'http://127.0.0.1:' \
+ str(self.server_process_handler.port) + repository_basepath

# Setting 'tuf.settings.repository_directory' with the temporary client
Expand Down

0 comments on commit abac87f

Please sign in to comment.