Skip to content

Commit b3ada5b

Browse files
committed
updater: remove unused _soft_check_file_length
This internal method isn't used by any code other than tests. Signed-off-by: Joshua Lock <[email protected]>
1 parent 201e07d commit b3ada5b

2 files changed

Lines changed: 0 additions & 66 deletions

File tree

tests/test_updater.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,25 +1629,6 @@ def test_10__hard_check_file_length(self):
16291629

16301630

16311631

1632-
def test_10__soft_check_file_length(self):
1633-
# Test for exception if file object is not equal to trusted file length.
1634-
with tempfile.TemporaryFile() as temp_file_object:
1635-
temp_file_object.write(b'XXX')
1636-
temp_file_object.seek(0)
1637-
self.assertRaises(tuf.exceptions.DownloadLengthMismatchError,
1638-
self.repository_updater._soft_check_file_length,
1639-
temp_file_object, 1)
1640-
1641-
# Verify that an exception is not raised if the file length <= the observed
1642-
# file length.
1643-
temp_file_object.seek(0)
1644-
self.repository_updater._soft_check_file_length(temp_file_object, 3)
1645-
temp_file_object.seek(0)
1646-
self.repository_updater._soft_check_file_length(temp_file_object, 4)
1647-
1648-
1649-
1650-
16511632
def test_10__targets_of_role(self):
16521633
# Test for non-existent role.
16531634
self.assertRaises(tuf.exceptions.UnknownRoleError,

tuf/client/updater.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,53 +1263,6 @@ def _hard_check_file_length(self, file_object, trusted_file_length):
12631263

12641264

12651265

1266-
def _soft_check_file_length(self, file_object, trusted_file_length):
1267-
"""
1268-
<Purpose>
1269-
Non-public method that checks the trusted file length of a file object.
1270-
The length of the file must be less than or equal to the expected
1271-
length. This is a deliberately redundant implementation designed to
1272-
complement tuf.download._check_downloaded_length().
1273-
1274-
<Arguments>
1275-
file_object:
1276-
A file object.
1277-
1278-
trusted_file_length:
1279-
A non-negative integer that is the trusted length of the file.
1280-
1281-
<Exceptions>
1282-
tuf.exceptions.DownloadLengthMismatchError, if the lengths do
1283-
not match.
1284-
1285-
<Side Effects>
1286-
Reads the contents of 'file_object' and logs a message if 'file_object'
1287-
is less than or equal to the trusted length.
1288-
Position within file_object is changed.
1289-
1290-
<Returns>
1291-
None.
1292-
"""
1293-
1294-
# Read the entire contents of 'file_object', a
1295-
file_object.seek(0)
1296-
observed_length = len(file_object.read())
1297-
1298-
# Return and log a message if 'file_object' is less than or equal to
1299-
# 'trusted_file_length', otherwise raise an exception. A soft check
1300-
# ensures that an upper bound restricts how large a file is downloaded.
1301-
if observed_length > trusted_file_length:
1302-
raise tuf.exceptions.DownloadLengthMismatchError(trusted_file_length,
1303-
observed_length)
1304-
1305-
else:
1306-
logger.debug('Observed length (' + str(observed_length) +\
1307-
') <= trusted length (' + str(trusted_file_length) + ')')
1308-
1309-
1310-
1311-
1312-
13131266
def _get_target_file(self, target_filepath, file_length, file_hashes,
13141267
prefix_filename_with_hash):
13151268
"""

0 commit comments

Comments
 (0)