Search in sources :

Example 11 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class AwsCrtS3V4aSignerTest method testS3ChunkedSigning.

@Test
public void testS3ChunkedSigning() {
    SigningTestCase testCase = SignerTestUtils.createBasicChunkedSigningTestCase();
    ExecutionAttributes executionAttributes = SignerTestUtils.buildBasicExecutionAttributes(testCase);
    SdkHttpFullRequest.Builder requestBuilder = testCase.requestBuilder;
    requestBuilder.uri(URI.create("http://demo.us-east-1.amazonaws.com"));
    SdkHttpFullRequest request = requestBuilder.build();
    SdkHttpFullRequest signedRequest = s3V4aSigner.sign(request, executionAttributes);
    assertThat(signedRequest.firstMatchingHeader("Authorization")).isPresent();
    assertThat(signedRequest.contentStreamProvider()).isPresent();
    assertThat(signedRequest.contentStreamProvider().get().newStream()).isInstanceOf(AwsSignedChunkedEncodingInputStream.class);
}
Also used : ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) Test(org.junit.Test)

Example 12 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class AwsCrtS3V4aSignerSigningScopeTest method signRequestWithScope.

protected SdkHttpFullRequest signRequestWithScope(SigningTestCase testCase, RegionScope defaultRegionScope, RegionScope regionScope) {
    ExecutionAttributes executionAttributes = SignerTestUtils.buildBasicExecutionAttributes(testCase);
    if (regionScope != null) {
        executionAttributes.putAttribute(AwsSignerExecutionAttribute.SIGNING_REGION_SCOPE, regionScope);
    }
    SdkHttpFullRequest request = testCase.requestBuilder.build();
    return AwsCrtS3V4aSigner.builder().defaultRegionScope(defaultRegionScope).build().sign(request, executionAttributes);
}
Also used : ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest)

Example 13 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class DefaultAwsCrtS3V4aSignerTest method when_credentials_are_anonymous_return_request.

@Test
public void when_credentials_are_anonymous_return_request() {
    SigningTestCase testCase = SignerTestUtils.createBasicHeaderSigningTestCase();
    ExecutionAttributes executionAttributes = SignerTestUtils.buildBasicExecutionAttributes(testCase);
    executionAttributes.putAttribute(AwsSignerExecutionAttribute.AWS_CREDENTIALS, AnonymousCredentialsProvider.create().resolveCredentials());
    SdkHttpFullRequest request = testCase.requestBuilder.build();
    SdkHttpFullRequest signedRequest = s3V4aSigner.sign(request, executionAttributes);
    assertThat(signedRequest).isEqualTo(request);
}
Also used : SigningTestCase(software.amazon.awssdk.authcrt.signer.SigningTestCase) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) Test(org.junit.Test)

Example 14 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class DefaultAwsCrtS3V4aSignerTest method payloadSigning_and_chunked_disabled_does_not_sign_payload.

@Test
public void payloadSigning_and_chunked_disabled_does_not_sign_payload() {
    SigningTestCase testCase = SignerTestUtils.createBasicHeaderSigningTestCase();
    ExecutionAttributes executionAttributes = SignerTestUtils.buildBasicExecutionAttributes(testCase);
    executionAttributes.putAttribute(S3SignerExecutionAttribute.ENABLE_PAYLOAD_SIGNING, true);
    executionAttributes.putAttribute(S3SignerExecutionAttribute.ENABLE_CHUNKED_ENCODING, false);
    SdkHttpFullRequest signedRequest = s3V4aSigner.sign(testCase.requestBuilder.build(), executionAttributes);
    verifyUnsignedPayload(signedRequest);
}
Also used : SigningTestCase(software.amazon.awssdk.authcrt.signer.SigningTestCase) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) Test(org.junit.Test)

Example 15 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class DefaultAwsCrtS3V4aSignerTest method setup.

@Before
public void setup() {
    configProvider = new SigningConfigProvider();
    s3V4aSigner = new DefaultAwsCrtS3V4aSigner(signerAdapter, configProvider);
    SdkHttpFullRequest unsignedPayloadSignedRequest = SignerTestUtils.createSignedHttpRequest("data");
    SdkHttpFullRequest signedPayloadSignedRequest = SignerTestUtils.createSignedPayloadHttpRequest("data");
    String signedPayloadSignature = SignerTestUtils.extractSignatureFromAuthHeader(signedPayloadSignedRequest);
    // when(configProvider.createS3CrtSigningConfig(any())).thenReturn(new AwsSigningConfig());
    when(signerAdapter.sign(any(), any())).thenReturn(new SdkSigningResult(signedPayloadSignature.getBytes(StandardCharsets.UTF_8), signedPayloadSignedRequest));
    when(signerAdapter.signRequest(any(), any())).thenReturn(unsignedPayloadSignedRequest);
}
Also used : SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) Before(org.junit.Before)

Aggregations

SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)178 Test (org.junit.Test)70 Test (org.junit.jupiter.api.Test)50 ExecutionAttributes (software.amazon.awssdk.core.interceptor.ExecutionAttributes)43 URI (java.net.URI)25 SigningTestCase (software.amazon.awssdk.authcrt.signer.SigningTestCase)23 ByteArrayInputStream (java.io.ByteArrayInputStream)18 SdkHttpRequest (software.amazon.awssdk.http.SdkHttpRequest)16 List (java.util.List)13 AwsCredentials (software.amazon.awssdk.auth.credentials.AwsCredentials)13 RequestExecutionContext (software.amazon.awssdk.core.internal.http.RequestExecutionContext)12 ByteBuffer (java.nio.ByteBuffer)11 AsyncRequestBody (software.amazon.awssdk.core.async.AsyncRequestBody)11 Map (java.util.Map)10 ContentStreamProvider (software.amazon.awssdk.http.ContentStreamProvider)10 Instant (java.time.Instant)9 AwsBasicCredentials (software.amazon.awssdk.auth.credentials.AwsBasicCredentials)9 Aws4SignerParams (software.amazon.awssdk.auth.signer.params.Aws4SignerParams)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8