Skip to content

Commit

Permalink
Blob upload input stream overwrite bug (#42582)
Browse files Browse the repository at this point in the history
* fixing overwrite bug and adding tests

* updating changelog

* updating test recordings
  • Loading branch information
ibrandes authored Oct 25, 2024
1 parent a279063 commit 862517e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-blob-cryptography/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/storage/azure-storage-blob-cryptography",
"Tag": "java/storage/azure-storage-blob-cryptography_9fd41be58a"
"Tag": "java/storage/azure-storage-blob-cryptography_da06ce0fc7"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,7 @@ public void downloadRequiresEncryption() {

@Test
public void encryptionUploadISOverwriteFails() {
assertThrows(BlobStorageException.class, () -> ebc.upload(DATA.getDefaultBinaryData()));
assertThrows(BlobStorageException.class, () -> ebc.upload(DATA.getDefaultInputStream()));
}

@Test
Expand Down Expand Up @@ -1602,7 +1602,7 @@ public void encryptionUploadISNoLength() {
byte[] randomData = getRandomByteArray(Constants.KB);
ByteArrayInputStream input = new ByteArrayInputStream(randomData);

ebc.upload(input);
ebc.upload(input, true);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ebc.downloadStream(stream);

Expand Down
1 change: 1 addition & 0 deletions sdk/storage/azure-storage-blob/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Breaking Changes

### Bugs Fixed
- Fixed an issue where BlobClient.upload(InputStream data) would overwrite an existing blob by default.

### Other Changes

Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-blob/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/storage/azure-storage-blob",
"Tag": "java/storage/azure-storage-blob_489177f72d"
"Tag": "java/storage/azure-storage-blob_4863e111dc"
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public PageBlobClient getPageBlobClient() {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void upload(InputStream data) {
uploadWithResponse(new BlobParallelUploadOptions(data), null, null);
upload(data, false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ public void cleanup() {
createdFiles.forEach(File::delete);
}

@Test
public void uploadInputStreamMinOverwriteFails() {
assertThrows(BlobStorageException.class, () -> bc.upload(DATA.getDefaultInputStream()));
}

@Test
public void uploadInputStreamOverwriteFails() {
assertThrows(BlobStorageException.class, () -> bc.upload(DATA.getDefaultInputStream(),
Expand Down Expand Up @@ -258,6 +263,7 @@ public void uploadReturnValueBinaryData() {

@Test
public void uploadInputStreamMin() {
bc = cc.getBlobClient(generateBlobName());
assertDoesNotThrow(() -> bc.upload(DATA.getDefaultInputStream()));
TestUtils.assertArraysEqual(bc.downloadContent().toBytes(), DATA.getDefaultBytes());
}
Expand Down

0 comments on commit 862517e

Please sign in to comment.