Example #1
0
 def validate_sha256(filename, sha256sum):
     if sha256sum is not None:
         return sha256(filename) == sha256sum
     else:
         logger.warning("sha256sum unavailable, skipping verification.\nMake "
                        "sure that the server you're downloading from is trusted")
         return True
def test_urlretrieve(httpd, partial_download, testfile_stats):
    port = httpd.server_port
    complete_downloader = partial(urlretrieve, 'http://localhost:%s/test/trust.pdf' % port, partial_download.name)
    headers = complete_downloader()
    assert int(headers['Content-Length']) < testfile_stats.size
    assert testfile_stats.sha256sum == sha256(partial_download.name)
    last_touched = os.stat(partial_download.name).st_mtime
    complete_downloader()
    assert last_touched == os.stat(partial_download.name).st_mtime
    with patch('socket.socket.__new__', side_effect=Exception):
        complete_downloader(sha256sum=testfile_stats.sha256sum)
        assert last_touched == os.stat(partial_download.name).st_mtime
        complete_downloader(filesize=testfile_stats.size)
        assert last_touched == os.stat(partial_download.name).st_mtime
Example #3
0
 def validate_sha256(filename, sha256sum):
     if sha256sum is not None:
         return sha256(filename) == sha256sum
     else:
         return True
def test_norange(simple_httpd, partial_download, testfile_stats):
    urlretrieve('http://localhost:%s/test/trust.pdf' % simple_httpd.server_port, partial_download.name)
    assert testfile_stats.sha256sum == sha256(partial_download.name)
def testfile_stats():
    fname = 'test/trust.pdf'
    return FileStats(sha256(fname), os.stat(fname).st_size)