use of software.amazon.awssdk.services.s3.utils.CaptureChecksumValidationInterceptor in project aws-sdk-java-v2 by aws.
the class GetObjectWithChecksumTest method async_getObject_with_correct_http_checksum.
@Test
public void async_getObject_with_correct_http_checksum(WireMockRuntimeInfo wm) {
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withHeader("x-amz-checksum-crc32", "i9aeUg==").withBody(EXAMPLE_RESPONSE_BODY)));
S3AsyncClient s3Client = getAsyncClientBuilder(wm).overrideConfiguration(o -> o.addExecutionInterceptor(captureChecksumValidationInterceptor)).build();
String response = s3Client.getObject(r -> r.bucket(EXAMPLE_BUCKET).key("key").checksumMode(ChecksumMode.ENABLED), AsyncResponseTransformer.toBytes()).join().asUtf8String();
assertThat(response).isEqualTo("Hello world");
assertThat(captureChecksumValidationInterceptor.responseValidation()).isEqualTo(ChecksumValidation.VALIDATED);
assertThat(captureChecksumValidationInterceptor.validationAlgorithm()).isEqualTo(Algorithm.CRC32);
}
use of software.amazon.awssdk.services.s3.utils.CaptureChecksumValidationInterceptor in project aws-sdk-java-v2 by aws.
the class GetObjectWithChecksumTest method sync_getObject_with_correct_http_checksum.
@Test
public void sync_getObject_with_correct_http_checksum(WireMockRuntimeInfo wm) {
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withHeader("x-amz-checksum-crc32", "i9aeUg==").withBody(EXAMPLE_RESPONSE_BODY)));
S3Client s3Client = getSyncClientBuilder(wm).overrideConfiguration(o -> o.addExecutionInterceptor(captureChecksumValidationInterceptor)).build();
ResponseInputStream<GetObjectResponse> getObject = s3Client.getObject(r -> r.bucket(EXAMPLE_BUCKET).key("key").checksumMode(ChecksumMode.ENABLED));
assertThat(stringFromStream.apply(getObject)).isEqualTo("Hello world");
assertThat(captureChecksumValidationInterceptor.responseValidation()).isEqualTo(ChecksumValidation.VALIDATED);
assertThat(captureChecksumValidationInterceptor.validationAlgorithm()).isEqualTo(Algorithm.CRC32);
}
use of software.amazon.awssdk.services.s3.utils.CaptureChecksumValidationInterceptor in project aws-sdk-java-v2 by aws.
the class GetObjectWithChecksumTest method sync_getObject_with_customized_multipart_checksum.
@Test
public void sync_getObject_with_customized_multipart_checksum(WireMockRuntimeInfo wm) {
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withHeader("x-amz-checksum-crc32", "i9aeUg==-12").withBody(EXAMPLE_RESPONSE_BODY)));
S3Client s3Client = getSyncClientBuilder(wm).overrideConfiguration(o -> o.addExecutionInterceptor(captureChecksumValidationInterceptor)).build();
ResponseInputStream<GetObjectResponse> getObject = s3Client.getObject(r -> r.bucket(EXAMPLE_BUCKET).key("key").checksumMode(ChecksumMode.ENABLED));
assertThat(stringFromStream.apply(getObject)).isEqualTo("Hello world");
assertThat(captureChecksumValidationInterceptor.responseValidation()).isEqualTo(ChecksumValidation.FORCE_SKIP);
assertThat(captureChecksumValidationInterceptor.validationAlgorithm()).isNull();
}
use of software.amazon.awssdk.services.s3.utils.CaptureChecksumValidationInterceptor in project aws-sdk-java-v2 by aws.
the class GetObjectWithChecksumTest method async_getObject_with_customized_multipart_checksum.
@Test
public void async_getObject_with_customized_multipart_checksum(WireMockRuntimeInfo wm) {
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withHeader("x-amz-checksum-crc32", "abcdef==-12").withBody(EXAMPLE_RESPONSE_BODY)));
S3AsyncClient s3Client = getAsyncClientBuilder(wm).overrideConfiguration(o -> o.addExecutionInterceptor(captureChecksumValidationInterceptor)).build();
String response = s3Client.getObject(r -> r.bucket(EXAMPLE_BUCKET).key("key").checksumMode(ChecksumMode.ENABLED), AsyncResponseTransformer.toBytes()).join().asUtf8String();
assertThat(response).isEqualTo("Hello world");
assertThat(captureChecksumValidationInterceptor.responseValidation()).isEqualTo(ChecksumValidation.FORCE_SKIP);
assertThat(captureChecksumValidationInterceptor.validationAlgorithm()).isNull();
}
use of software.amazon.awssdk.services.s3.utils.CaptureChecksumValidationInterceptor in project aws-sdk-java-v2 by aws.
the class GetObjectWithChecksumTest method sync_getObject_with_validation_not_enabled_incorrect_http_checksum.
@Test
public void sync_getObject_with_validation_not_enabled_incorrect_http_checksum(WireMockRuntimeInfo wm) {
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withHeader("x-amz-checksum-crc32", "incorrect").withBody(EXAMPLE_RESPONSE_BODY)));
S3Client s3Client = getSyncClientBuilder(wm).overrideConfiguration(o -> o.addExecutionInterceptor(captureChecksumValidationInterceptor)).build();
ResponseInputStream<GetObjectResponse> getObject = s3Client.getObject(r -> r.bucket(EXAMPLE_BUCKET).key("key"));
assertThat(stringFromStream.apply(getObject)).isEqualTo("Hello world");
assertThat(captureChecksumValidationInterceptor.responseValidation()).isNull();
assertThat(captureChecksumValidationInterceptor.validationAlgorithm()).isNull();
}
Aggregations