Skip to content

Commit

Permalink
Merge pull request #227 from vladimir-v-diaz/develop
Browse files Browse the repository at this point in the history
Update test_download.py comments and test case.
  • Loading branch information
vladimir-v-diaz committed Jun 17, 2014
2 parents 5487a5b + a57c977 commit 2ff1702
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
34 changes: 17 additions & 17 deletions tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,31 +105,31 @@ def test_download_url_to_tempfileobj(self):

# Test: Incorrect lengths.
def test_download_url_to_tempfileobj_and_lengths(self):

# NOTE: We catch tuf.BadHashError here because the file, shorter by a byte,
# would not match the expected hashes. We log a warning when we find that
# the server-reported length of the file does not match our
# required_length. We also see that STRICT_REQUIRED_LENGTH does not change
# the outcome of the previous test.
download.safe_download(self.url, self.target_data_length - 1)
download.unsafe_download(self.url, self.target_data_length - 1)

# NOTE: We catch tuf.DownloadLengthMismatchError here because the
# STRICT_REQUIRED_LENGTH, which is True by default, mandates that we must
# download exactly what is required.
# We do *not* catch 'tuf.DownloadLengthMismatchError' in the following two
# calls because the file at 'self.url' contains enough bytes to satisfy the
# smaller number of required bytes requested. safe_download() and
# unsafe_download() will only log a warning when the the server-reported
# length of the file does not match the required_length. 'updater.py'
# *does* verify the hashes of downloaded content.
download.safe_download(self.url, self.target_data_length - 4)
download.unsafe_download(self.url, self.target_data_length - 4)

# We catch 'tuf.DownloadLengthMismatchError' here because safe_download()
# will not download more bytes than requested.
self.assertRaises(tuf.DownloadLengthMismatchError, download.safe_download,
self.url, self.target_data_length + 1)

# NOTE: However, we do not catch a tuf.DownloadLengthMismatchError here for
# the same test as the previous one because we have disabled
# STRICT_REQUIRED_LENGTH.
# However, we do *not* catch 'tuf.DownloadLengthMismatchError' next because
# unsafe_download() does the enforce the upper limit. 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()



def test_download_url_to_tempfileobj_and_performance(self):

"""
Expand Down Expand Up @@ -223,8 +223,8 @@ def test_https_connection(self):
message = 'Downloading target file from https server: ' + https_url
logger.info(message)
try:
download.safe_download(https_url, target_data_length - 1)
download.unsafe_download(https_url, target_data_length - 1)
download.safe_download(https_url, target_data_length)
download.unsafe_download(https_url, target_data_length)

finally:
https_server_process
Expand Down
2 changes: 1 addition & 1 deletion tests/test_slow_retrieval_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _start_slow_server(self, mode):

# NOTE: Following error is raised if a delay is not applied:
# <urlopen error [Errno 111] Connection refused>
time.sleep(.5)
time.sleep(1)

return server_process

Expand Down

0 comments on commit 2ff1702

Please sign in to comment.