use of software.amazon.awssdk.services.s3.model.ChecksumMode in project aws-sdk-java-v2 by aws.
the class HttpChecksumIntegrationTest method syncSignedPayloadForHugeMessage.
@Test
public void syncSignedPayloadForHugeMessage() {
s3.putObject(PutObjectRequest.builder().bucket(BUCKET).key(KEY).checksumAlgorithm(ChecksumAlgorithm.CRC32).build(), RequestBody.fromString(createDataSize(HUGE_MSG_SIZE)));
assertThat(interceptor.requestChecksumInTrailer()).isEqualTo("x-amz-checksum-crc32");
assertThat(interceptor.requestChecksumInHeader()).isNull();
ResponseInputStream<GetObjectResponse> s3HttpsObject = s3.getObject(GetObjectRequest.builder().bucket(BUCKET).checksumMode(ChecksumMode.ENABLED).key(KEY).build());
String text = new BufferedReader(new InputStreamReader(s3HttpsObject, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
assertThat(interceptor.validationAlgorithm()).isEqualTo(Algorithm.CRC32);
assertThat(interceptor.responseValidation()).isEqualTo(ChecksumValidation.VALIDATED);
assertThat(text).isEqualTo(createDataSize(HUGE_MSG_SIZE));
}
use of software.amazon.awssdk.services.s3.model.ChecksumMode in project aws-sdk-java-v2 by aws.
the class HttpChecksumIntegrationTest method syncValidSignedTrailerChecksumCalculatedBySdkClientWithSigv4a.
@Test
public void syncValidSignedTrailerChecksumCalculatedBySdkClientWithSigv4a() {
s3.putObject(PutObjectRequest.builder().bucket(BUCKET).key(KEY).checksumAlgorithm(ChecksumAlgorithm.CRC32).overrideConfiguration(o -> o.signer(DefaultAwsCrtS3V4aSigner.create())).build(), RequestBody.fromString("Hello world"));
assertThat(interceptor.requestChecksumInTrailer()).isEqualTo("x-amz-checksum-crc32");
assertThat(interceptor.requestChecksumInHeader()).isNull();
ResponseInputStream<GetObjectResponse> s3HttpsObject = s3.getObject(GetObjectRequest.builder().bucket(BUCKET).key(KEY).checksumMode(ChecksumMode.ENABLED).build());
String text = new BufferedReader(new InputStreamReader(s3HttpsObject, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
assertThat(interceptor.validationAlgorithm()).isEqualTo(Algorithm.CRC32);
assertThat(interceptor.responseValidation()).isEqualTo(ChecksumValidation.VALIDATED);
assertThat(text).isEqualTo("Hello world");
}
use of software.amazon.awssdk.services.s3.model.ChecksumMode in project aws-sdk-java-v2 by aws.
the class HttpChecksumIntegrationTest method syncValidUnsignedTrailerChecksumCalculatedBySdkClient.
@Test
public void syncValidUnsignedTrailerChecksumCalculatedBySdkClient() throws InterruptedException {
s3Https.putObject(PutObjectRequest.builder().bucket(BUCKET).key(KEY).checksumAlgorithm(ChecksumAlgorithm.CRC32).build(), RequestBody.fromString("Hello world"));
assertThat(interceptor.requestChecksumInTrailer()).isEqualTo("x-amz-checksum-crc32");
assertThat(interceptor.requestChecksumInHeader()).isNull();
ResponseInputStream<GetObjectResponse> s3HttpsObject = s3Https.getObject(GetObjectRequest.builder().bucket(BUCKET).key(KEY).checksumMode(ChecksumMode.ENABLED).build());
String text = new BufferedReader(new InputStreamReader(s3HttpsObject, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
assertThat(interceptor.validationAlgorithm()).isEqualTo(Algorithm.CRC32);
assertThat(interceptor.responseValidation()).isEqualTo(ChecksumValidation.VALIDATED);
assertThat(text).isEqualTo("Hello world");
}
use of software.amazon.awssdk.services.s3.model.ChecksumMode in project aws-sdk-java-v2 by aws.
the class HttpChecksumIntegrationTest method syncValidUnsignedTrailerChecksumCalculatedBySdkClientWithSigv4a.
@Test
public void syncValidUnsignedTrailerChecksumCalculatedBySdkClientWithSigv4a() {
s3.putObject(PutObjectRequest.builder().bucket(BUCKET).key(KEY).checksumAlgorithm(ChecksumAlgorithm.CRC32).overrideConfiguration(o -> o.signer(DefaultAwsCrtS3V4aSigner.create())).build(), RequestBody.fromString("Hello world"));
assertThat(interceptor.requestChecksumInTrailer()).isEqualTo("x-amz-checksum-crc32");
assertThat(interceptor.requestChecksumInHeader()).isNull();
ResponseInputStream<GetObjectResponse> s3HttpsObject = s3.getObject(GetObjectRequest.builder().bucket(BUCKET).key(KEY).checksumMode(ChecksumMode.ENABLED).build());
String text = new BufferedReader(new InputStreamReader(s3HttpsObject, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
assertThat(interceptor.validationAlgorithm()).isEqualTo(Algorithm.CRC32);
assertThat(interceptor.responseValidation()).isEqualTo(ChecksumValidation.VALIDATED);
assertThat(text).isEqualTo("Hello world");
}
use of software.amazon.awssdk.services.s3.model.ChecksumMode 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();
}
Aggregations