Skip to content

Commit 49eca7e

Browse files
Add comprehensive integration tests for download with StorageContentValidationDecoderPolicy
Co-authored-by: gunjansingh-msft <[email protected]>
1 parent 3cfe426 commit 49eca7e

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/specialized/BlobBaseAsyncApiTests.java

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,96 @@ public void downloadStreamWithResponseContentValidationRange() throws IOExceptio
607607
}).verifyComplete();
608608
}
609609

610+
@Test
611+
public void downloadStreamWithResponseContentValidationLargeBlob() throws IOException {
612+
// Test with larger data to verify chunking works correctly
613+
byte[] randomData = getRandomByteArray(5 * Constants.KB);
614+
StructuredMessageEncoder encoder
615+
= new StructuredMessageEncoder(randomData.length, 1024, StructuredMessageFlags.STORAGE_CRC64);
616+
ByteBuffer encodedData = encoder.encode(ByteBuffer.wrap(randomData));
617+
618+
Flux<ByteBuffer> input = Flux.just(encodedData);
619+
620+
DownloadContentValidationOptions validationOptions
621+
= new DownloadContentValidationOptions().setStructuredMessageValidationEnabled(true);
622+
623+
StepVerifier
624+
.create(bc.upload(input, null, true)
625+
.then(bc.downloadStreamWithResponse(null, null, null, false, validationOptions))
626+
.flatMap(r -> FluxUtil.collectBytesInByteBufferStream(r.getValue())))
627+
.assertNext(r -> TestUtils.assertArraysEqual(r, randomData))
628+
.verifyComplete();
629+
}
630+
631+
@Test
632+
public void downloadStreamWithResponseContentValidationMultipleSegments() throws IOException {
633+
// Test with multiple segments to ensure all segments are decoded correctly
634+
byte[] randomData = getRandomByteArray(2 * Constants.KB);
635+
StructuredMessageEncoder encoder
636+
= new StructuredMessageEncoder(randomData.length, 512, StructuredMessageFlags.STORAGE_CRC64);
637+
ByteBuffer encodedData = encoder.encode(ByteBuffer.wrap(randomData));
638+
639+
Flux<ByteBuffer> input = Flux.just(encodedData);
640+
641+
DownloadContentValidationOptions validationOptions
642+
= new DownloadContentValidationOptions().setStructuredMessageValidationEnabled(true);
643+
644+
StepVerifier
645+
.create(bc.upload(input, null, true)
646+
.then(bc.downloadStreamWithResponse(null, null, null, false, validationOptions))
647+
.flatMap(r -> FluxUtil.collectBytesInByteBufferStream(r.getValue())))
648+
.assertNext(r -> TestUtils.assertArraysEqual(r, randomData))
649+
.verifyComplete();
650+
}
651+
652+
@Test
653+
public void downloadStreamWithResponseNoValidation() throws IOException {
654+
// Test that download works normally when validation is not enabled
655+
byte[] randomData = getRandomByteArray(Constants.KB);
656+
StructuredMessageEncoder encoder
657+
= new StructuredMessageEncoder(randomData.length, 512, StructuredMessageFlags.STORAGE_CRC64);
658+
ByteBuffer encodedData = encoder.encode(ByteBuffer.wrap(randomData));
659+
660+
Flux<ByteBuffer> input = Flux.just(encodedData);
661+
662+
// No validation options - should download encoded data as-is
663+
StepVerifier
664+
.create(bc.upload(input, null, true)
665+
.then(bc.downloadStreamWithResponse(null, null, null, false))
666+
.flatMap(r -> FluxUtil.collectBytesInByteBufferStream(r.getValue())))
667+
.assertNext(r -> {
668+
assertNotNull(r);
669+
// Should get encoded data, not decoded
670+
assertTrue(r.length > randomData.length); // Encoded data is larger
671+
})
672+
.verifyComplete();
673+
}
674+
675+
@Test
676+
public void downloadStreamWithResponseValidationDisabled() throws IOException {
677+
// Test with validation options but validation disabled
678+
byte[] randomData = getRandomByteArray(Constants.KB);
679+
StructuredMessageEncoder encoder
680+
= new StructuredMessageEncoder(randomData.length, 512, StructuredMessageFlags.STORAGE_CRC64);
681+
ByteBuffer encodedData = encoder.encode(ByteBuffer.wrap(randomData));
682+
683+
Flux<ByteBuffer> input = Flux.just(encodedData);
684+
685+
DownloadContentValidationOptions validationOptions
686+
= new DownloadContentValidationOptions().setStructuredMessageValidationEnabled(false);
687+
688+
StepVerifier
689+
.create(bc.upload(input, null, true)
690+
.then(bc.downloadStreamWithResponse(null, null, null, false, validationOptions))
691+
.flatMap(r -> FluxUtil.collectBytesInByteBufferStream(r.getValue())))
692+
.assertNext(r -> {
693+
assertNotNull(r);
694+
// Should get encoded data, not decoded
695+
assertTrue(r.length > randomData.length); // Encoded data is larger
696+
})
697+
.verifyComplete();
698+
}
699+
610700
@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
611701
@Test
612702
public void copyFromURLSourceErrorAndStatusCode() {

0 commit comments

Comments
 (0)