def test_verify_file_s3etag_algorithm_double_md5(self, mock_calc_sum): checksum = 'ceb8853ddc5086cc4ab9e149f8f09c88-2' checksums = {'s3etag': checksum} mock_calc_sum.return_value = checksum assert wc.verify_file(checksums, 'dummy/path') # Verify s3etag value containing a '-' uses S3DoubleMD5 and custom read_limit. mock_calc_sum.assert_called_once_with(wc.S3DoubleMD5, 'dummy/path', 1024*1024*8)
def test_verify_file_s3etag_algorithm_regular_md5(self, mock_calc_sum): checksum = '72b484a2610cb54ec22e48c8104ba3bd' checksums = {'s3etag': checksum} mock_calc_sum.return_value = checksum assert wc.verify_file(checksums, 'dummy/path') # Verify the hash_function used was md5. mock_calc_sum.assert_called_once_with(hashlib.md5, 'dummy/path', wc.READ_LIMIT)
def test_verify_file_one_supported_algorithm(self, mock_calc_sum): """Test one unsupported/one supported algorithm returns True.""" checksum = '33304d104f95d826da40079bad2400dc4d005403' checksums = OrderedDict([('abc', 'algorithm_unsupported'), ('sha1', checksum)]) mock_calc_sum.return_value = checksum with patch('wasapi_client.LOGGER', autospec=True) as mock_logger: assert wc.verify_file(checksums, 'dummy/path') # Check that unsupported algorithm was tried. mock_logger.debug.assert_called_once_with('abc is unsupported') mock_logger.info.assert_called_once_with('Checksum success at: dummy/path')
def test_verify_file_checksum_mismatch(self, mock_calc_sum): """Test calculated checksum does not match the expected.""" checksum = '33304d104f95d826da40079bad2400dc4d005403' algorithm = 'sha1' path = 'dummy/path' checksums = {algorithm: checksum} mock_calc_sum.return_value = checksum + 'notmatching' with patch('wasapi_client.LOGGER', autospec=True) as mock_logger: assert not wc.verify_file(checksums, path) msg = 'Checksum {} mismatch for {}: expected {}, got {}notmatching'.format( algorithm, path, checksum, checksum) mock_logger.error.assert_called_once_with(msg)
def test_verify_file_unsupported_algorithm(self): """Test all algorithms being unsupported returns False.""" checksums = {'shaq1': 'shaq1algorithmdoesnotexist'} assert not wc.verify_file(checksums, 'dummy/path')
def test_verify_file(self, mock_calc_sum): """Test a matching checksum returns True.""" checksum = '33304d104f95d826da40079bad2400dc4d005403' checksums = {'sha1': checksum} mock_calc_sum.return_value = checksum assert wc.verify_file(checksums, 'dummy/path')