mirror of
https://github.com/theupdateframework/python-tuf
synced 2026-05-24 10:08:28 +00:00
Catch SlowRetrievalError for download requests that expect a greater download length that the actual file
A slow retrieval error is eventually raised for the request that cannot be satisfied
This commit is contained in:
parent
c4a89dcf18
commit
e58c01a96c
1 changed files with 7 additions and 13 deletions
|
|
@ -116,22 +116,16 @@ def test_download_url_to_tempfileobj_and_lengths(self):
|
|||
download.safe_download(self.url, self.target_data_length - 4)
|
||||
download.unsafe_download(self.url, self.target_data_length - 4)
|
||||
|
||||
# We catch 'tuf.SlowRetrievalError' here because safe_download()
|
||||
# will not download more bytes than requested and the connection eventually
|
||||
# hits a slow retrieval error when the server can't satisfy the request (
|
||||
# in this case, a length greater than the size of the target file).
|
||||
# We catch 'tuf.SlowRetrievalError' for both safe_download() and
|
||||
# unsafe_download() because they will not download more bytes than
|
||||
# requested and the connection eventually hits a slow retrieval error when
|
||||
# the server can't satisfy the request (in this case, a length greater
|
||||
# than the size of the target file).
|
||||
self.assertRaises(tuf.SlowRetrievalError, download.safe_download,
|
||||
self.url, self.target_data_length + 1)
|
||||
|
||||
# However, we do *not* catch 'tuf.DownloadLengthMismatchError' in the next
|
||||
# test condition because unsafe_download() does not enforce the required
|
||||
# length argument. The length reported and the length downloaded are still
|
||||
# logged.
|
||||
temp_fileobj = \
|
||||
download.unsafe_download(self.url, self.target_data_length + 1)
|
||||
self.assertEqual(self.target_data, temp_fileobj.read().decode('utf-8'))
|
||||
self.assertEqual(self.target_data_length, len(temp_fileobj.read()))
|
||||
temp_fileobj.close_temp_file()
|
||||
self.assertRaises(tuf.SlowRetrievalError, download.unsafe_download,
|
||||
self.url, self.target_data_length + 1)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue