Search in sources :

Example 1 with CaptureChecksumValidationInterceptor

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);
}
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) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) Test(org.junit.jupiter.api.Test) WireMockTest(com.github.tomakehurst.wiremock.junit5.WireMockTest)

Example 2 with CaptureChecksumValidationInterceptor

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);
}
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)

Example 3 with CaptureChecksumValidationInterceptor

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();
}
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)

Example 4 with CaptureChecksumValidationInterceptor

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();
}
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) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) Test(org.junit.jupiter.api.Test) WireMockTest(com.github.tomakehurst.wiremock.junit5.WireMockTest)

Example 5 with CaptureChecksumValidationInterceptor

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();
}
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

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