@@ -183,3 +183,41 @@ def test_calculate_sha256(
183
183
calculated_hash
184
184
== "sha256:e216b70f013c47b82a72540d34347632c5bfe59fd54f5fe5d51f6a68b19aaf84"
185
185
)
186
+
187
+
188
+ def test_calculate_sha256_defaults_to_sha256_on_md5_errors (
189
+ mocker : MockerFixture ,
190
+ ) -> None :
191
+ suppressed_value_error = False
192
+
193
+ def mock_hashlib_md5_error () -> None :
194
+ nonlocal suppressed_value_error
195
+ suppressed_value_error = True
196
+ raise ValueError (
197
+ "[digital envelope routines: EVP_DigestInit_ex] disabled for FIPS"
198
+ )
199
+
200
+ filename = "poetry_core-1.5.0-py3-none-any.whl"
201
+ filepath = MockRepository .DIST_FIXTURES / filename
202
+ mock_download = mocker .patch (
203
+ "poetry.repositories.http_repository.download_file" ,
204
+ side_effect = lambda _ , dest , * args , ** kwargs : shutil .copy (filepath , dest ),
205
+ )
206
+ mock_hashlib = mocker .patch ("hashlib.md5" , side_effect = mock_hashlib_md5_error )
207
+
208
+ domain = "foo.com"
209
+ link = Link (
210
+ f"https://{ domain } /{ filename } " ,
211
+ hashes = {"md5" : "be7589b4902793e66d7d979bd8581591" },
212
+ )
213
+ repo = MockRepository ()
214
+
215
+ calculated_hash = repo .calculate_sha256 (link )
216
+
217
+ assert suppressed_value_error
218
+ assert mock_download .call_count == 1
219
+ assert mock_hashlib .call_count == 1
220
+ assert (
221
+ calculated_hash
222
+ == "sha256:e216b70f013c47b82a72540d34347632c5bfe59fd54f5fe5d51f6a68b19aaf84"
223
+ )
0 commit comments