Skip to content

Commit

Permalink
Fixed transactional MD5 check for files
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Friedman committed May 4, 2017
1 parent 9585f95 commit 69759ad
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Changed blob constants to support up to 256 MB on put blob for block blobs. The default value for put blob threshold has also been updated to half of the maximum, or 128 MB currently.
* Fixed a bug that prevented setting content MD5 to true when creating a new file.
* Fixed a bug where access conditions, options, and operation context were not being passed when calling openWriteExisting() on a page blob or a file.
* Fixed a bug where an exception was being thrown on a range get of a blob or file when the options disableContentMD5Validation is set to false and useTransactionalContentMD5 is set to true and there is no overall MD5.
* Fixed a bug where retries were happening immediately if a sock exception was thrown.

2017.01.18 Version 5.0.0
* Prefix support for listing files and directories.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void fileTestMethodSetUp() throws URISyntaxException, StorageException {

@After
public void fileTestMethodTearDown() throws StorageException {
//this.share.deleteIfExists();
this.share.deleteIfExists();
}

/**
Expand Down Expand Up @@ -1124,6 +1124,28 @@ public void testCloudFileUploadRange() throws URISyntaxException, StorageExcepti

inputStream = new ByteArrayInputStream(buffer);
}

@Test
@Category({ DevFabricTests.class, DevStoreTests.class })
public void testVerifyTransactionalMD5ValidationMissingOverallMD5() throws URISyntaxException, StorageException, IOException {
final String fileName = FileTestHelper.generateRandomFileName();
final CloudFile fileRef = this.share.getRootDirectoryReference().getFileReference(fileName);

final int length = 3*1024;
ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length);
FileRequestOptions options = new FileRequestOptions();
options.setDisableContentMD5Validation(true);
options.setStoreFileContentMD5(false);

fileRef.upload(srcStream, length, null, options, null);

options.setDisableContentMD5Validation(false);
options.setStoreFileContentMD5(true);
options.setUseTransactionalContentMD5(true);
final CloudFile fileRef2 = this.share.getRootDirectoryReference().getFileReference(fileName);
fileRef2.downloadRange(1024, (long)1024, new ByteArrayOutputStream(), null, options, null);
assertNull(fileRef2.getProperties().getContentMD5());
}

/**
* Test clearing file ranges.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1379,19 +1379,19 @@ public Integer preProcessResponse(CloudFile file, CloudFileClient client, Operat
final FileAttributes retrievedAttributes = FileResponse.getFileAttributes(this.getConnection(),
file.getStorageUri());

if (!options.getDisableContentMD5Validation() && options.getUseTransactionalContentMD5()
&& Utility.isNullOrEmpty(retrievedAttributes.getProperties().getContentMD5())) {
throw new StorageException(StorageErrorCodeStrings.MISSING_MD5_HEADER, SR.MISSING_MD5,
Constants.HeaderConstants.HTTP_UNUSED_306, null, null);
}

file.properties = retrievedAttributes.getProperties();
file.metadata = retrievedAttributes.getMetadata();

// Need to store the Content MD5 in case we fail part way through.
// We would still need to verify the entire range.
this.setContentMD5(this.getConnection().getHeaderField(Constants.HeaderConstants.CONTENT_MD5));

if (!options.getDisableContentMD5Validation() && options.getUseTransactionalContentMD5()
&& Utility.isNullOrEmpty(this.getContentMD5())) {
throw new StorageException(StorageErrorCodeStrings.MISSING_MD5_HEADER, SR.MISSING_MD5,
Constants.HeaderConstants.HTTP_UNUSED_306, null, null);
}

this.setLockedETag(file.properties.getEtag());
this.setArePropertiesPopulated(true);
}
Expand Down

0 comments on commit 69759ad

Please sign in to comment.