Search in sources :

Example 1 with ChecksumMode

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));
}
Also used : GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Test(org.junit.jupiter.api.Test)

Example 2 with ChecksumMode

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");
}
Also used : GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Test(org.junit.jupiter.api.Test)

Example 3 with ChecksumMode

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");
}
Also used : GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Test(org.junit.jupiter.api.Test)

Example 4 with ChecksumMode

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");
}
Also used : GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Test(org.junit.jupiter.api.Test)

Example 5 with ChecksumMode

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();
}
Also used : ChecksumMode(software.amazon.awssdk.services.s3.model.ChecksumMode) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) WireMock.any(com.github.tomakehurst.wiremock.client.WireMock.any) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) Function(java.util.function.Function) GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) ResponseInputStream(software.amazon.awssdk.core.ResponseInputStream) AsyncResponseTransformer(software.amazon.awssdk.core.async.AsyncResponseTransformer) URI(java.net.URI) Region(software.amazon.awssdk.regions.Region) CaptureChecksumValidationInterceptor(software.amazon.awssdk.services.s3.utils.CaptureChecksumValidationInterceptor) ChecksumValidation(software.amazon.awssdk.core.checksums.ChecksumValidation) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) S3Client(software.amazon.awssdk.services.s3.S3Client) WireMockRuntimeInfo(com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) S3AsyncClientBuilder(software.amazon.awssdk.services.s3.S3AsyncClientBuilder) Algorithm(software.amazon.awssdk.core.checksums.Algorithm) S3ClientBuilder(software.amazon.awssdk.services.s3.S3ClientBuilder) WireMockTest(com.github.tomakehurst.wiremock.junit5.WireMockTest) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) WireMock.anyUrl(com.github.tomakehurst.wiremock.client.WireMock.anyUrl) BufferedReader(java.io.BufferedReader) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) InputStream(java.io.InputStream) GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) S3Client(software.amazon.awssdk.services.s3.S3Client) Test(org.junit.jupiter.api.Test) WireMockTest(com.github.tomakehurst.wiremock.junit5.WireMockTest)

Aggregations

BufferedReader (java.io.BufferedReader)13 InputStreamReader (java.io.InputStreamReader)13 Test (org.junit.jupiter.api.Test)13 GetObjectResponse (software.amazon.awssdk.services.s3.model.GetObjectResponse)13 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)6 WireMock.any (com.github.tomakehurst.wiremock.client.WireMock.any)6 WireMock.anyUrl (com.github.tomakehurst.wiremock.client.WireMock.anyUrl)6 WireMock.stubFor (com.github.tomakehurst.wiremock.client.WireMock.stubFor)6 WireMockRuntimeInfo (com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo)6 WireMockTest (com.github.tomakehurst.wiremock.junit5.WireMockTest)6 InputStream (java.io.InputStream)6 URI (java.net.URI)6 StandardCharsets (java.nio.charset.StandardCharsets)6 Function (java.util.function.Function)6 Collectors (java.util.stream.Collectors)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 AfterEach (org.junit.jupiter.api.AfterEach)6 AwsBasicCredentials (software.amazon.awssdk.auth.credentials.AwsBasicCredentials)6 StaticCredentialsProvider (software.amazon.awssdk.auth.credentials.StaticCredentialsProvider)6 ResponseInputStream (software.amazon.awssdk.core.ResponseInputStream)6