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 <[email protected]>
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

tests/test_replay_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_slow_retrieval_attack.py

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

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

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

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

tests/test_updater.py

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

168168
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
169169
repository_basepath = self.repository_directory[len(os.getcwd()):]
170-
url_prefix = 'http://localhost:' \
170+
url_prefix = 'http://127.0.0.1:' \
171171
+ str(self.server_process_handler.port) + repository_basepath
172172

173173
# Setting 'tuf.settings.repository_directory' with the temporary client
@@ -1110,7 +1110,7 @@ def test_6_get_one_valid_targetinfo(self):
11101110

11111111
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
11121112
repository_basepath = self.repository_directory[len(os.getcwd()):]
1113-
url_prefix = 'http://localhost:' \
1113+
url_prefix = 'http://127.0.0.1:' \
11141114
+ str(self.server_process_handler.port) + repository_basepath
11151115

11161116
self.repository_mirrors = {'mirror1': {'url_prefix': url_prefix,
@@ -1406,7 +1406,7 @@ def test_7_updated_targets(self):
14061406

14071407
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
14081408
repository_basepath = self.repository_directory[len(os.getcwd()):]
1409-
url_prefix = 'http://localhost:' \
1409+
url_prefix = 'http://127.0.0.1:' \
14101410
+ str(self.server_process_handler.port) + repository_basepath
14111411

14121412
# Setting 'tuf.settings.repository_directory' with the temporary client
@@ -1533,7 +1533,7 @@ def test_8_remove_obsolete_targets(self):
15331533

15341534
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
15351535
repository_basepath = self.repository_directory[len(os.getcwd()):]
1536-
url_prefix = 'http://localhost:' \
1536+
url_prefix = 'http://127.0.0.1:' \
15371537
+ str(self.server_process_handler.port) + repository_basepath
15381538

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

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

1864-
url_prefix = 'http://localhost:' + str(self.server_process_handler.port)
1865-
url_prefix2 = 'http://localhost:' + str(self.server_process_handler2.port)
1864+
url_prefix = 'http://127.0.0.1:' + str(self.server_process_handler.port)
1865+
url_prefix2 = 'http://127.0.0.1:' + str(self.server_process_handler2.port)
18661866

18671867
# We have all of the necessary information for two repository mirrors
18681868
# in map.json, except for url prefixes.

tests/test_updater_root_rotation_integration.py

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

141141
# 'path/to/tmp/repository' -> 'localhost:8001/tmp/repository'.
142142
repository_basepath = self.repository_directory[len(os.getcwd()):]
143-
url_prefix = 'http://localhost:' \
143+
url_prefix = 'http://127.0.0.1:' \
144144
+ str(self.server_process_handler.port) + repository_basepath
145145

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

0 commit comments

Comments
 (0)