Search in sources :

Example 21 with AwsRequestOverrideConfiguration

use of software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration in project aws-sdk-java-v2 by aws.

the class S3PresignerTest method putObject_NonSigV4SignersRaisesException.

@Test
public void putObject_NonSigV4SignersRaisesException() {
    AwsRequestOverrideConfiguration override = AwsRequestOverrideConfiguration.builder().signer(new NoOpSigner()).build();
    assertThatThrownBy(() -> presigner.presignPutObject(r -> r.signatureDuration(Duration.ofMinutes(5)).putObjectRequest(go -> go.bucket("foo34343434").key("bar").overrideConfiguration(override)))).isInstanceOf(IllegalStateException.class).hasMessageContaining("NoOpSigner");
}
Also used : Offset(org.assertj.core.data.Offset) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) RunWith(org.junit.runner.RunWith) AbstractAwsS3V4Signer(software.amazon.awssdk.auth.signer.internal.AbstractAwsS3V4Signer) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) AwsS3V4SignerParams(software.amazon.awssdk.auth.signer.params.AwsS3V4SignerParams) ChecksumConstant(software.amazon.awssdk.services.s3.checksums.ChecksumConstant) NoOpSigner(software.amazon.awssdk.core.signer.NoOpSigner) RequestPayer(software.amazon.awssdk.services.s3.model.RequestPayer) S3Presigner(software.amazon.awssdk.services.s3.presigner.S3Presigner) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SignerConstant(software.amazon.awssdk.auth.signer.internal.SignerConstant) Duration(java.time.Duration) After(org.junit.After) PresignedPutObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedPutObjectRequest) Aws4SignerRequestParams(software.amazon.awssdk.auth.signer.internal.Aws4SignerRequestParams) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) URI(java.net.URI) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) Region(software.amazon.awssdk.regions.Region) Aws4PresignerParams(software.amazon.awssdk.auth.signer.params.Aws4PresignerParams) Before(org.junit.Before) PresignedGetObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedGetObjectRequest) AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) Test(org.junit.Test) AwsS3V4Signer(software.amazon.awssdk.auth.signer.AwsS3V4Signer) Instant(java.time.Instant) ZoneId(java.time.ZoneId) AbstractAws4Signer(software.amazon.awssdk.auth.signer.internal.AbstractAws4Signer) Mockito(org.mockito.Mockito) LocalDate(java.time.LocalDate) Clock(java.time.Clock) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) DateUtils(software.amazon.awssdk.utils.DateUtils) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration) NoOpSigner(software.amazon.awssdk.core.signer.NoOpSigner) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration) Test(org.junit.Test)

Example 22 with AwsRequestOverrideConfiguration

use of software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration in project aws-sdk-java-v2 by aws.

the class S3PresignerTest method getObject_Sigv4PresignerHonorsSignatureDuration.

@Test
public void getObject_Sigv4PresignerHonorsSignatureDuration() {
    AwsRequestOverrideConfiguration override = AwsRequestOverrideConfiguration.builder().signer(AwsS3V4Signer.create()).build();
    PresignedGetObjectRequest presigned = presigner.presignGetObject(r -> r.signatureDuration(Duration.ofSeconds(1234)).getObjectRequest(gor -> gor.bucket("a").key("b").overrideConfiguration(override)));
    assertThat(presigned.httpRequest().rawQueryParameters().get("X-Amz-Expires").get(0)).satisfies(expires -> {
        assertThat(expires).containsOnlyDigits();
        assertThat(Integer.parseInt(expires)).isCloseTo(1234, Offset.offset(2));
    });
}
Also used : Offset(org.assertj.core.data.Offset) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) RunWith(org.junit.runner.RunWith) AbstractAwsS3V4Signer(software.amazon.awssdk.auth.signer.internal.AbstractAwsS3V4Signer) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) AwsS3V4SignerParams(software.amazon.awssdk.auth.signer.params.AwsS3V4SignerParams) ChecksumConstant(software.amazon.awssdk.services.s3.checksums.ChecksumConstant) NoOpSigner(software.amazon.awssdk.core.signer.NoOpSigner) RequestPayer(software.amazon.awssdk.services.s3.model.RequestPayer) S3Presigner(software.amazon.awssdk.services.s3.presigner.S3Presigner) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SignerConstant(software.amazon.awssdk.auth.signer.internal.SignerConstant) Duration(java.time.Duration) After(org.junit.After) PresignedPutObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedPutObjectRequest) Aws4SignerRequestParams(software.amazon.awssdk.auth.signer.internal.Aws4SignerRequestParams) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) URI(java.net.URI) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) Region(software.amazon.awssdk.regions.Region) Aws4PresignerParams(software.amazon.awssdk.auth.signer.params.Aws4PresignerParams) Before(org.junit.Before) PresignedGetObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedGetObjectRequest) AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) Test(org.junit.Test) AwsS3V4Signer(software.amazon.awssdk.auth.signer.AwsS3V4Signer) Instant(java.time.Instant) ZoneId(java.time.ZoneId) AbstractAws4Signer(software.amazon.awssdk.auth.signer.internal.AbstractAws4Signer) Mockito(org.mockito.Mockito) LocalDate(java.time.LocalDate) Clock(java.time.Clock) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) DateUtils(software.amazon.awssdk.utils.DateUtils) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration) PresignedGetObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedGetObjectRequest) Test(org.junit.Test)

Example 23 with AwsRequestOverrideConfiguration

use of software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration in project aws-sdk-java-v2 by aws.

the class S3PresignerTest method getObject_AdditionalHeadersAndQueryStringsCanBeAdded.

@Test
public void getObject_AdditionalHeadersAndQueryStringsCanBeAdded() {
    AwsRequestOverrideConfiguration override = AwsRequestOverrideConfiguration.builder().putHeader("X-Amz-AdditionalHeader", "foo1").putRawQueryParameter("additionalQueryParam", "foo2").build();
    PresignedGetObjectRequest presigned = presigner.presignGetObject(r -> r.signatureDuration(Duration.ofMinutes(5)).getObjectRequest(go -> go.bucket("foo34343434").key("bar").overrideConfiguration(override)));
    assertThat(presigned.isBrowserExecutable()).isFalse();
    assertThat(presigned.signedHeaders()).containsOnlyKeys("host", "x-amz-additionalheader");
    assertThat(presigned.signedHeaders().get("x-amz-additionalheader")).containsExactly("foo1");
    assertThat(presigned.httpRequest().headers()).containsKeys("x-amz-additionalheader");
    assertThat(presigned.httpRequest().rawQueryParameters().get("additionalQueryParam").get(0)).isEqualTo("foo2");
}
Also used : Offset(org.assertj.core.data.Offset) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) RunWith(org.junit.runner.RunWith) AbstractAwsS3V4Signer(software.amazon.awssdk.auth.signer.internal.AbstractAwsS3V4Signer) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) AwsS3V4SignerParams(software.amazon.awssdk.auth.signer.params.AwsS3V4SignerParams) ChecksumConstant(software.amazon.awssdk.services.s3.checksums.ChecksumConstant) NoOpSigner(software.amazon.awssdk.core.signer.NoOpSigner) RequestPayer(software.amazon.awssdk.services.s3.model.RequestPayer) S3Presigner(software.amazon.awssdk.services.s3.presigner.S3Presigner) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SignerConstant(software.amazon.awssdk.auth.signer.internal.SignerConstant) Duration(java.time.Duration) After(org.junit.After) PresignedPutObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedPutObjectRequest) Aws4SignerRequestParams(software.amazon.awssdk.auth.signer.internal.Aws4SignerRequestParams) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) URI(java.net.URI) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) Region(software.amazon.awssdk.regions.Region) Aws4PresignerParams(software.amazon.awssdk.auth.signer.params.Aws4PresignerParams) Before(org.junit.Before) PresignedGetObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedGetObjectRequest) AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) Test(org.junit.Test) AwsS3V4Signer(software.amazon.awssdk.auth.signer.AwsS3V4Signer) Instant(java.time.Instant) ZoneId(java.time.ZoneId) AbstractAws4Signer(software.amazon.awssdk.auth.signer.internal.AbstractAws4Signer) Mockito(org.mockito.Mockito) LocalDate(java.time.LocalDate) Clock(java.time.Clock) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) DateUtils(software.amazon.awssdk.utils.DateUtils) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration) PresignedGetObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedGetObjectRequest) Test(org.junit.Test)

Aggregations

AwsRequestOverrideConfiguration (software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration)23 SdkInternalApi (software.amazon.awssdk.annotations.SdkInternalApi)13 URI (java.net.URI)11 List (java.util.List)11 Generated (software.amazon.awssdk.annotations.Generated)11 AwsServiceException (software.amazon.awssdk.awscore.exception.AwsServiceException)11 Duration (java.time.Duration)10 Consumer (java.util.function.Consumer)10 ExecutionAttributes (software.amazon.awssdk.core.interceptor.ExecutionAttributes)10 Collections (java.util.Collections)9 RequestOverrideConfiguration (software.amazon.awssdk.core.RequestOverrideConfiguration)9 SdkClientConfiguration (software.amazon.awssdk.core.client.config.SdkClientConfiguration)9 SdkClientOption (software.amazon.awssdk.core.client.config.SdkClientOption)9 ClientExecutionParams (software.amazon.awssdk.core.client.handler.ClientExecutionParams)9 HttpResponseHandler (software.amazon.awssdk.core.http.HttpResponseHandler)9 Clock (java.time.Clock)8 Instant (java.time.Instant)8 LocalDate (java.time.LocalDate)8 LocalDateTime (java.time.LocalDateTime)8 ZoneId (java.time.ZoneId)8