Skip to content

Commit a749a0d

Browse files
committed
Avoid 'localhost' lookup in tests
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 <tsechkova@vmware.com>
1 parent e8923a0 commit a749a0d

14 files changed

+23
-23
lines changed

tests/test_arbitrary_package_attack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def setUp(self):
124124
# Set the url prefix required by the 'tuf/client/updater.py' updater.
125125
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
126126
repository_basepath = self.repository_directory[len(os.getcwd()):]
127-
url_prefix = 'http://localhost:' \
127+
url_prefix = 'http://127.0.0.1:' \
128128
+ str(self.server_process_handler.port) + repository_basepath
129129

130130
# Setting 'tuf.settings.repository_directory' with the temporary client

tests/test_download.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def setUp(self):
7777
self.server_process_handler = utils.TestServerProcess(log=logger)
7878

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

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

175-
url = 'http://localhost:' \
175+
url = 'http://127.0.0.1:' \
176176
+ str(self.server_process_handler.port) + '/' + self.random_string()
177177
self.assertRaises(requests.exceptions.HTTPError,
178178
download_file,
179179
url,
180180
self.target_data_length,
181181
self.fetcher)
182-
url1 = 'http://localhost:' \
182+
url1 = 'http://127.0.0.1:' \
183183
+ str(self.server_process_handler.port + 1) + '/' + self.random_string()
184184
self.assertRaises(requests.exceptions.ConnectionError,
185185
download_file,

tests/test_endless_data_attack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def setUp(self):
126126
# Set the url prefix required by the 'tuf/client/updater.py' updater.
127127
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
128128
repository_basepath = self.repository_directory[len(os.getcwd()):]
129-
url_prefix = 'http://localhost:' \
129+
url_prefix = 'http://127.0.0.1:' \
130130
+ str(self.server_process_handler.port) + repository_basepath
131131

132132
# Setting 'tuf.settings.repository_directory' with the temporary client

tests/test_extraneous_dependencies_attack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def setUp(self):
133133
# Set the url prefix required by the 'tuf/client/updater.py' updater.
134134
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
135135
repository_basepath = self.repository_directory[len(os.getcwd()):]
136-
url_prefix = 'http://localhost:' \
136+
url_prefix = 'http://127.0.0.1:' \
137137
+ str(self.server_process_handler.port) + repository_basepath
138138

139139
# Setting 'tuf.settings.repository_directory' with the temporary client

tests/test_fetcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def setUp(self):
5555
self.server_process_handler = utils.TestServerProcess(log=logger)
5656

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

6161
# Create a temporary file where the target file chunks are written

tests/test_indefinite_freeze_attack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def setUp(self):
146146
# Set the url prefix required by the 'tuf/client/updater.py' updater.
147147
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
148148
repository_basepath = self.repository_directory[len(os.getcwd()):]
149-
url_prefix = 'http://localhost:' \
149+
url_prefix = 'http://127.0.0.1:' \
150150
+ str(self.server_process_handler.port) + repository_basepath
151151

152152
# Setting 'tuf.settings.repository_directory' with the temporary client

tests/test_key_revocation_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def setUp(self):
132132

133133
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
134134
repository_basepath = self.repository_directory[len(os.getcwd()):]
135-
url_prefix = 'http://localhost:' \
135+
url_prefix = 'http://127.0.0.1:' \
136136
+ str(self.server_process_handler.port) + repository_basepath
137137

138138
# Setting 'tuf.settings.repository_directory' with the temporary client

tests/test_mix_and_match_attack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def setUp(self):
132132
# Set the url prefix required by the 'tuf/client/updater.py' updater.
133133
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
134134
repository_basepath = self.repository_directory[len(os.getcwd()):]
135-
url_prefix = 'http://localhost:' \
135+
url_prefix = 'http://127.0.0.1:' \
136136
+ str(self.server_process_handler.port) + repository_basepath
137137

138138
# Setting 'tuf.settings.repository_directory' with the temporary client

tests/test_multiple_repositories_integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ def setUp(self):
136136

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

139-
url_prefix = 'http://localhost:' + str(self.server_process_handler.port)
140-
url_prefix2 = 'http://localhost:' + str(self.server_process_handler2.port)
139+
url_prefix = 'http://127.0.0.1:' + str(self.server_process_handler.port)
140+
url_prefix2 = 'http://127.0.0.1:' + str(self.server_process_handler2.port)
141141

142142
self.repository_mirrors = {'mirror1': {'url_prefix': url_prefix,
143143
'metadata_path': 'metadata',

tests/test_proxy_use.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ def setUp(self):
167167

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

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

175175

176176

0 commit comments

Comments
 (0)