Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit d3193c2

Browse files
authored
Merge pull request #144 from jofriedm-msft/dev
Fixed MD5 and OpenWriteExisting bugs.
2 parents 8426507 + 959273d commit d3193c2

File tree

7 files changed

+85
-15
lines changed

7 files changed

+85
-15
lines changed

BreakingChanges.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
Changes in X.X.X
2+
3+
BLOB/FILE
4+
* Fixed a bug which allowed setting content MD5 to true when calling openWriteExisting() on a page blob or file.
5+
16
Changes in 5.0.0
27

38
BLOB
49
* getQualifiedUri() has been deprecated. Please use getSnapshotQualifiedUri() instead. This new function will return the blob including the snapshot (if present) and no SAS token.
510
* getQualifiedStorageUri() has been deprecated. Please use getSnapshotQualifiedStorageUri() instead. This new function will return the blob including the snapshot (if present) and no SAS token.
611
* Fixed a bug where copying from a blob that included a SAS token and a snapshot did not use the SAS token.
7-
12+
813
FILE
914
* Fixed a bug where copying from a blob that included a SAS token and a snapshot did not use the SAS token.
10-
15+
1116
QUEUE
1217
* For addMessage() the CloudQueueMessage message passed in will be populated with the pop receipt, insertion/expiration time, and message ID.
1318

@@ -164,8 +169,8 @@ Changes in 0.5.0
164169

165170
OTHER
166171
* The packaging structure has changed to
167-
1. com.microsoft.windowsazure.storage � RetryPolicies, LocationMode, StorageException, Storage Credentials etc. Basically all public classes that are common across services.
168-
2. com.microsoft.windowsazure.storage.core � These classes are reserved for internal use and users never have to include this namespace in their projects.
172+
1. com.microsoft.windowsazure.storage � RetryPolicies, LocationMode, StorageException, Storage Credentials etc. Basically all public classes that are common across services.
173+
2. com.microsoft.windowsazure.storage.core � These classes are reserved for internal use and users never have to include this namespace in their projects.
169174
3. com.microsoft.windowsazure.storage.blob
170175
4. com.microsoft.windowsazure.storage.queue
171176
5. com.microsoft.windowsazure.storage.table

ChangeLog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
2017.XX.XX Version X.X.X
22
* 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.
3+
* Fixed a bug that prevented setting content MD5 to true when creating a new file.
4+
* Fixed a bug where access conditions, options, and operation context were not being passed when calling openWriteExisting() on a page blob or a file.
35

46
2017.01.18 Version 5.0.0
57
* Prefix support for listing files and directories.

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudPageBlobTests.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,32 @@ public void testPageBlobDownloadRangeValidationTest() throws StorageException, U
211211
assertEquals(100, downloadLength);
212212
}
213213

214+
/**
215+
* Test requesting stored content MD5 with OpenWriteExisting().
216+
*
217+
* @throws URISyntaxException
218+
* @throws StorageException
219+
*/
220+
@Test
221+
public void testPageOpenWriteExistingWithMD5() throws URISyntaxException, StorageException, IOException {
222+
final String pageBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testPageBlob");
223+
final CloudPageBlob pageBlobRef = this.container.getPageBlobReference(pageBlobName);
224+
pageBlobRef.create(512);
225+
226+
BlobRequestOptions options = new BlobRequestOptions();
227+
options.setStoreBlobContentMD5(true);
228+
options.setDisableContentMD5Validation(false);
229+
230+
try
231+
{
232+
pageBlobRef.openWriteExisting(null, options, null);
233+
fail("Expect failure due to requesting MD5 calculation");
234+
}
235+
catch (IllegalArgumentException e)
236+
{
237+
}
238+
}
239+
214240
@Test
215241
public void testPageBlobUploadFromStreamTest() throws URISyntaxException, StorageException, IOException {
216242
final String pageBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testPageBlob");

microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileTests.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,45 @@ public void testFileUploadMD5Validation() throws URISyntaxException, StorageExce
724724
assertEquals(calculatedMD5, fileRef2.getProperties().getContentMD5());
725725
}
726726

727+
@Test
728+
public void testFileContentMD5NewFileTest() throws URISyntaxException, StorageException, IOException {
729+
final String fileName = FileTestHelper.generateRandomFileName();
730+
final CloudFile file = this.share.getRootDirectoryReference().getFileReference(fileName);
731+
732+
FileRequestOptions options = new FileRequestOptions();
733+
options.setStoreFileContentMD5(true);
734+
options.setDisableContentMD5Validation(false);
735+
736+
File tempFile = File.createTempFile("sourceFile", ".tmp");
737+
file.uploadFromFile(tempFile.getAbsolutePath(), null, options, null);
738+
}
739+
740+
/**
741+
* Test requesting stored content MD5 with OpenWriteExisting().
742+
*
743+
* @throws URISyntaxException
744+
* @throws StorageException
745+
*/
746+
@Test
747+
public void testCloudFileOpenWriteExistingWithMD5() throws URISyntaxException, StorageException, IOException {
748+
String fileName = FileTestHelper.generateRandomFileName();
749+
final CloudFile fileRef = this.share.getRootDirectoryReference().getFileReference(fileName);
750+
fileRef.create(512);
751+
752+
FileRequestOptions options = new FileRequestOptions();
753+
options.setStoreFileContentMD5(true);
754+
options.setDisableContentMD5Validation(false);
755+
756+
try
757+
{
758+
fileRef.openWriteExisting(null, options, null);
759+
fail("Expect failure due to requesting MD5 calculation");
760+
}
761+
catch (IllegalArgumentException e)
762+
{
763+
}
764+
}
765+
727766
@Test
728767
public void testFileEmptyHeaderSigningTest() throws URISyntaxException, StorageException, IOException {
729768
final String fileName = FileTestHelper.generateRandomFileName();

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudPageBlob.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,7 @@ public BlobOutputStream openWriteExisting() throws StorageException {
832832
@DoesServiceRequest
833833
public BlobOutputStream openWriteExisting(AccessCondition accessCondition, BlobRequestOptions options,
834834
OperationContext opContext) throws StorageException {
835-
return this
836-
.openOutputStreamInternal(null /* length */, null /* accessCondition */, null /* options */, null /* opContext */);
835+
return this.openOutputStreamInternal(null /* length */, accessCondition, options, opContext);
837836
}
838837

839838
/**

microsoft-azure-storage/src/com/microsoft/azure/storage/core/SR.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public class SR {
9292
public static final String INVALID_DATE_STRING = "Invalid Date String: %s.";
9393
public static final String INVALID_EDMTYPE_VALUE = "Invalid value '%s' for EdmType.";
9494
public static final String INVALID_ENCRYPTION_ALGORITHM = "Invalid Encryption Algorithm found on the resource. This version of the client library does not support the specified encryption algorithm.";
95-
public static final String INVALID_FILE_LENGTH = "File length must be greater than 0 bytes.";
95+
public static final String INVALID_FILE_LENGTH = "File length must be greater than or equal to 0 bytes.";
9696
public static final String INVALID_GEO_REPLICATION_STATUS = "Null or Invalid geo-replication status in response: %s.";
9797
public static final String INVALID_IP_ADDRESS = "Error when parsing IPv4 address: IP address '%s' is invalid.";
9898
public static final String INVALID_KEY = "Storage Key is not a valid base64 encoded string.";

microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFile.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,8 +1855,7 @@ public FileOutputStream openWriteExisting() throws StorageException {
18551855
@DoesServiceRequest
18561856
public FileOutputStream openWriteExisting(AccessCondition accessCondition, FileRequestOptions options,
18571857
OperationContext opContext) throws StorageException {
1858-
return this
1859-
.openOutputStreamInternal(null /* length */, null /* accessCondition */, null /* options */, null /* opContext */);
1858+
return this.openOutputStreamInternal(null /* length */, accessCondition, options, opContext);
18601859
}
18611860

18621861
/**
@@ -1946,13 +1945,13 @@ private FileOutputStream openOutputStreamInternal(Long length, AccessCondition a
19461945
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient, false /* setStartTime */);
19471946

19481947
if (length != null) {
1948+
this.create(length, accessCondition, options, opContext);
1949+
}
1950+
else {
19491951
if (options.getStoreFileContentMD5()) {
19501952
throw new IllegalArgumentException(SR.FILE_MD5_NOT_POSSIBLE);
19511953
}
19521954

1953-
this.create(length, accessCondition, options, opContext);
1954-
}
1955-
else {
19561955
this.downloadAttributes(accessCondition, options, opContext);
19571956
length = this.getProperties().getLength();
19581957
}
@@ -2557,8 +2556,8 @@ public void upload(final InputStream sourceStream, final long length) throws Sto
25572556
* @param sourceStream
25582557
* An {@link InputStream} object to read from.
25592558
* @param length
2560-
* A <code>long</code> which represents the length, in bytes, of the stream data. This must be great than
2561-
* zero.
2559+
* A <code>long</code> which represents the length, in bytes, of the stream data. This must be greater than
2560+
* or equal to zero.
25622561
* @param accessCondition
25632562
* An {@link AccessCondition} object which represents the access conditions for the file.
25642563
* @param options
@@ -2584,7 +2583,7 @@ public void upload(final InputStream sourceStream, final long length, final Acce
25842583

25852584
options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
25862585

2587-
if (length <= 0) {
2586+
if (length < 0) {
25882587
throw new IllegalArgumentException(SR.INVALID_FILE_LENGTH);
25892588
}
25902589

0 commit comments

Comments
 (0)