Skip to content

Commit 77ca0af

Browse files
committed
Remove unsafe_download option for target files
Remove the boolean switch to toggle safe or unsafe download in Updater._get_file since the method is private and is always called with the download_safely option enabled. Signed-off-by: Teodora Sechkova <[email protected]>
1 parent baae9bd commit 77ca0af

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

tests/test_updater.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1771,10 +1771,7 @@ def verify_target_file(targets_path):
17711771
self.repository_updater._check_hashes(targets_path, file_hashes)
17721772

17731773
self.repository_updater._get_file('targets.json', verify_target_file,
1774-
file_type, file_size, download_safely=True).close()
1775-
1776-
self.repository_updater._get_file('targets.json', verify_target_file,
1777-
file_type, file_size, download_safely=False).close()
1774+
file_type, file_size).close()
17781775

17791776
def test_13__targets_of_role(self):
17801777
# Test case where a list of targets is given. By default, the 'targets'

tuf/client/updater.py

+5-15
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ def verify_target_file(target_file_object):
13701370
target_filepath = os.path.join(dirname, target_digest + '.' + basename)
13711371

13721372
return self._get_file(target_filepath, verify_target_file,
1373-
'target', file_length, download_safely=True)
1373+
'target', file_length)
13741374

13751375

13761376

@@ -1654,8 +1654,7 @@ def _get_metadata_file(self, metadata_role, remote_filename,
16541654

16551655

16561656

1657-
def _get_file(self, filepath, verify_file_function, file_type, file_length,
1658-
download_safely=True):
1657+
def _get_file(self, filepath, verify_file_function, file_type, file_length):
16591658
"""
16601659
<Purpose>
16611660
Non-public method that tries downloading, up to a certain length, a
@@ -1682,9 +1681,6 @@ def _get_file(self, filepath, verify_file_function, file_type, file_length,
16821681
The expected length, or upper bound, of the target or metadata file to
16831682
be downloaded.
16841683
1685-
download_safely:
1686-
A boolean switch to toggle safe or unsafe download of the file.
1687-
16881684
<Exceptions>
16891685
tuf.exceptions.NoWorkingMirrorError:
16901686
The metadata could not be fetched. This is raised only when all known
@@ -1708,15 +1704,9 @@ def _get_file(self, filepath, verify_file_function, file_type, file_length,
17081704

17091705
for file_mirror in file_mirrors:
17101706
try:
1711-
# TODO: Instead of the more fragile 'download_safely' switch, unroll
1712-
# the function into two separate ones: one for "safe" download, and the
1713-
# other one for "unsafe" download? This should induce safer and more
1714-
# readable code.
1715-
if download_safely:
1716-
file_object = tuf.download.safe_download(file_mirror, file_length)
1717-
1718-
else:
1719-
file_object = tuf.download.unsafe_download(file_mirror, file_length)
1707+
# Eensure the length of the downloaded file matches 'file_length'
1708+
# exactly.
1709+
file_object = tuf.download.safe_download(file_mirror, file_length)
17201710

17211711
# Verify 'file_object' according to the callable function.
17221712
# 'file_object' is also verified if decompressed above (i.e., the

0 commit comments

Comments
 (0)