diff --git a/test/codegen-generated-classes-test/pom.xml b/test/codegen-generated-classes-test/pom.xml index 0c69e72be46f..cecd6a84400f 100644 --- a/test/codegen-generated-classes-test/pom.xml +++ b/test/codegen-generated-classes-test/pom.xml @@ -274,6 +274,12 @@ ${awsjavasdk.version} test + + software.amazon.awssdk + http-auth-aws-crt + ${awsjavasdk.version} + test + org.mockito mockito-junit-jupiter diff --git a/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/SignerOverrideTest.java b/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/SignerOverrideTest.java deleted file mode 100644 index d99a46683f38..000000000000 --- a/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/SignerOverrideTest.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package software.amazon.awssdk.services; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static software.amazon.awssdk.core.client.config.SdkAdvancedClientOption.SIGNER; - -import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; -import com.github.tomakehurst.wiremock.junit5.WireMockTest; -import java.net.URI; -import java.nio.ByteBuffer; -import java.util.concurrent.CompletableFuture; -import org.junit.Test; -import org.junit.jupiter.api.BeforeEach; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.reactivestreams.Publisher; -import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; -import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; -import software.amazon.awssdk.awscore.AwsRequest; -import software.amazon.awssdk.core.SdkRequest; -import software.amazon.awssdk.core.async.AsyncRequestBody; -import software.amazon.awssdk.core.interceptor.Context; -import software.amazon.awssdk.core.interceptor.ExecutionAttributes; -import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; -import software.amazon.awssdk.core.signer.Signer; -import software.amazon.awssdk.core.sync.RequestBody; -import software.amazon.awssdk.http.SdkHttpClient; -import software.amazon.awssdk.http.SdkHttpFullRequest; -import software.amazon.awssdk.http.SdkHttpRequest; -import software.amazon.awssdk.http.async.SdkAsyncHttpClient; -import software.amazon.awssdk.http.auth.aws.scheme.AwsV4AuthScheme; -import software.amazon.awssdk.http.auth.aws.signer.AwsV4HttpSigner; -import software.amazon.awssdk.http.auth.spi.signer.AsyncSignRequest; -import software.amazon.awssdk.http.auth.spi.signer.AsyncSignedRequest; -import software.amazon.awssdk.http.auth.spi.signer.SignRequest; -import software.amazon.awssdk.http.auth.spi.signer.SignedRequest; -import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity; -import software.amazon.awssdk.identity.spi.IdentityProvider; -import software.amazon.awssdk.identity.spi.IdentityProviders; -import software.amazon.awssdk.regions.Region; -import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClient; -import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient; -import software.amazon.awssdk.services.protocolrestjson.model.AllTypesRequest; -import software.amazon.awssdk.services.protocolrestjson.model.StreamingInputOperationRequest; -import software.amazon.awssdk.services.testutil.ValidSdkObjects; -import software.amazon.awssdk.testutils.service.http.MockAsyncHttpClient; -import software.amazon.awssdk.testutils.service.http.MockSyncHttpClient; - -@RunWith(MockitoJUnitRunner.class) -public class SignerOverrideTest { - @Mock - public Signer mockSigner; - - @Mock - public static AwsV4HttpSigner mockHttpSigner; - - @Mock - public SignedRequest signedRequest; - @Mock - public AsyncSignedRequest asyncSignedRequest; - - @BeforeEach - public void setup() { - SdkHttpRequest sdkHttpRequest = ValidSdkObjects.sdkHttpFullRequest().build(); - Publisher signedPayload = AsyncRequestBody.fromString("signed async request body"); - - when(mockHttpSigner.sign(any(SignRequest.class))).thenReturn(SignedRequest.builder().build()); - - CompletableFuture requestFuture = new CompletableFuture<>(); - requestFuture.complete(asyncSignedRequest); - when(mockHttpSigner.signAsync(any(AsyncSignRequest.class))) - .thenReturn( - CompletableFuture.completedFuture(AsyncSignedRequest.builder() - .request(sdkHttpRequest) - .payload(signedPayload) - .build())); - } - - /** - * Test to ensure that operations that use the {@link software.amazon.awssdk.auth.signer.AsyncAws4Signer} don't apply - * the override when the signer is overridden by the customer. - */ - @Test - public void test_signerOverriddenForStreamingInput_takesPrecedence() { - ProtocolRestJsonAsyncClient asyncClient = ProtocolRestJsonAsyncClient.builder() - .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))) - .region(Region.US_WEST_2) - .overrideConfiguration(o -> o.putAdvancedOption(SIGNER, mockSigner)) - .build(); - - try { - asyncClient.streamingInputOperation(StreamingInputOperationRequest.builder().build(), - AsyncRequestBody.fromString("test")).join(); - } catch (Exception expected) { - } - - verify(mockSigner).sign(any(SdkHttpFullRequest.class), any(ExecutionAttributes.class)); - } - - @Test - public void asyncClient_oldSignerOverriddenInExecutionInterceptor_takesPrecedence() { - try (ProtocolRestJsonAsyncClient asyncClient = ProtocolRestJsonAsyncClient.builder() - .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))) - .region(Region.US_WEST_2) - .endpointOverride(URI.create("http://localhost:8080")) - .overrideConfiguration(o -> o.addExecutionInterceptor(signerOverrideExecutionInterceptor(mockSigner))) - .build()) { - asyncClient.allTypes(AllTypesRequest.builder().build()).join(); - } catch (Exception expected) { - // Doesn't matter if the request succeeds or not - } - - verify(mockSigner).sign(any(SdkHttpFullRequest.class), any(ExecutionAttributes.class)); - } - - @Test - public void syncClient_oldSignerOverriddenInExecutionInterceptor_takesPrecedence() { - try (ProtocolRestJsonClient client = ProtocolRestJsonClient.builder() - .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))) - .region(Region.US_WEST_2) - .endpointOverride(URI.create("http://localhost:8080")) - .overrideConfiguration(o -> o.addExecutionInterceptor(signerOverrideExecutionInterceptor(mockSigner))) - .build()) { - client.allTypes(AllTypesRequest.builder().build()); - } catch (Exception expected) { - // Doesn't matter if the request succeeds or not - } - - verify(mockSigner).sign(any(SdkHttpFullRequest.class), any(ExecutionAttributes.class)); - } - - @Test - public void sync_httpSignerOverride_takesPrecedence() { - try (ProtocolRestJsonClient client = ProtocolRestJsonClient.builder() - .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))) - .region(Region.US_WEST_2) - .putAuthScheme(new MockAuthScheme()) - .build()) { - - assertThatThrownBy(() -> client.streamingInputOperation(StreamingInputOperationRequest.builder().build(), - RequestBody.fromString("test"))).isInstanceOf(NullPointerException.class); - verify(mockHttpSigner).sign(any(SignRequest.class)); - } - } - - @Test - public void async_httpSignerOverride_takesPrecedence() { - try(ProtocolRestJsonAsyncClient asyncClient = ProtocolRestJsonAsyncClient.builder() - .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))) - .region(Region.US_WEST_2) - .putAuthScheme(new MockAuthScheme()) - .build()) { - assertThatThrownBy(() -> asyncClient.streamingInputOperation(StreamingInputOperationRequest.builder().build(), - AsyncRequestBody.fromString("test")).join()).hasRootCauseInstanceOf(NullPointerException.class); - } - verify(mockHttpSigner).signAsync(any(AsyncSignRequest.class)); - } - - - private ExecutionInterceptor signerOverrideExecutionInterceptor(Signer signer) { - return new ExecutionInterceptor() { - @Override - public SdkRequest modifyRequest(Context.ModifyRequest context, ExecutionAttributes executionAttributes) { - AwsRequest.Builder builder = (AwsRequest.Builder) context.request().toBuilder(); - builder.overrideConfiguration(c -> c.signer(signer) - .build()); - - return builder.build(); - } - }; - } - - private static class MockAuthScheme implements AwsV4AuthScheme { - @Override - public IdentityProvider identityProvider(IdentityProviders providers) { - return providers.identityProvider(AwsCredentialsIdentity.class); - } - - @Override - public AwsV4HttpSigner signer() { - return mockHttpSigner; - } - - @Override - public String schemeId() { - return SCHEME_ID; - } - } -} diff --git a/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/auth/AuthTestUtils.java b/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/auth/AuthTestUtils.java new file mode 100644 index 000000000000..8277a6a9f244 --- /dev/null +++ b/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/auth/AuthTestUtils.java @@ -0,0 +1,64 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package software.amazon.awssdk.services.auth; + +import java.util.function.Supplier; +import software.amazon.awssdk.http.auth.spi.scheme.AuthScheme; +import software.amazon.awssdk.http.auth.spi.signer.HttpSigner; +import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity; +import software.amazon.awssdk.identity.spi.IdentityProvider; +import software.amazon.awssdk.identity.spi.IdentityProviders; + +public class AuthTestUtils { + + public static AuthScheme authScheme(String schemeId, HttpSigner signer) { + return new AuthScheme() { + @Override + public String schemeId() { + return schemeId; + } + + @Override + public IdentityProvider identityProvider(IdentityProviders providers) { + return providers.identityProvider(AwsCredentialsIdentity.class); + } + + @Override + public HttpSigner signer() { + return signer; + } + }; + } + + public static AuthScheme authScheme(String schemeId, Supplier> supplier) { + return new AuthScheme() { + @Override + public String schemeId() { + return schemeId; + } + + @Override + public IdentityProvider identityProvider(IdentityProviders providers) { + return providers.identityProvider(AwsCredentialsIdentity.class); + } + + @Override + public HttpSigner signer() { + return supplier.get(); + } + }; + } +} diff --git a/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/endpointauth/EndpointAuthSigningPropertiesTest.java b/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/auth/EndpointAuthSigningPropertiesTest.java similarity index 76% rename from test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/endpointauth/EndpointAuthSigningPropertiesTest.java rename to test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/auth/EndpointAuthSigningPropertiesTest.java index 4f17629b4c2a..cde58908c0fe 100644 --- a/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/endpointauth/EndpointAuthSigningPropertiesTest.java +++ b/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/auth/EndpointAuthSigningPropertiesTest.java @@ -13,7 +13,7 @@ * permissions and limitations under the License. */ -package software.amazon.awssdk.services.endpointauth; +package software.amazon.awssdk.services.auth; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @@ -22,6 +22,8 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; +import java.net.URI; +import java.util.Collections; import java.util.concurrent.CompletableFuture; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -32,7 +34,10 @@ import org.mockito.MockitoAnnotations; import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; +import software.amazon.awssdk.awscore.endpoints.AwsEndpointAttribute; +import software.amazon.awssdk.awscore.endpoints.authscheme.SigV4aAuthScheme; import software.amazon.awssdk.core.SdkSystemSetting; +import software.amazon.awssdk.endpoints.Endpoint; import software.amazon.awssdk.http.SdkHttpClient; import software.amazon.awssdk.http.auth.aws.signer.AwsV4aHttpSigner; import software.amazon.awssdk.http.auth.aws.signer.RegionSet; @@ -47,9 +52,15 @@ import software.amazon.awssdk.identity.spi.IdentityProvider; import software.amazon.awssdk.identity.spi.IdentityProviders; import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.endpointauth.EndpointAuthClient; +import software.amazon.awssdk.services.endpointauth.EndpointAuthClientBuilder; +import software.amazon.awssdk.services.endpointauth.endpoints.EndpointAuthEndpointProvider; import software.amazon.awssdk.testutils.EnvironmentVariableHelper; import software.amazon.awssdk.utils.CompletableFutureUtils; +/** + * Tests verifying legacy endpoint based auth, i.e., services with enableEndpointAuthSchemeParams = true customization + */ @DisplayName("Endpoint-Auth Tests") class EndpointAuthSigningPropertiesTest { @@ -135,13 +146,55 @@ void clientConfiguredRegionSetTakesPrecedenceOverEndpointRegionSet() { () -> assertThatThrownBy(() -> client.allAuthPropertiesInEndpointRules(r -> r.stringMember(""))) .hasMessageContaining("stop"), - () -> assertThat(signer.request.property(AwsV4aHttpSigner.REGION_SET)) - .isEqualTo(RegionSet.create(MULTI_REGION_SET)), + () -> assertThat(signer.request.property(AwsV4aHttpSigner.REGION_SET).asString()) + .isEqualTo(RegionSet.create(MULTI_REGION_SET).asString()), () -> assertThat(signer.request.property(AwsV4aHttpSigner.SERVICE_SIGNING_NAME)) .isEqualTo("sigv4afromruleset") ); } + @Test + @DisplayName("Signer properties from endpoint auth scheme takes precedence") + void endpointAuthSchemesPresent_shouldHonor() { + EndpointAuthClient client = + EndpointAuthClient.builder() + .httpClient(mockHttpClient) + .region(Region.US_WEST_2) + .putAuthScheme(authScheme("aws.auth#sigv4a", signer)) + .endpointProvider(v4aEndpointProviderOverride()) + .build(); + + assertThatThrownBy(() -> client.allAuthPropertiesInEndpointRules(r -> r.stringMember(""))) + .hasMessageContaining("stop"); + + assertThat(signer.request.property(AwsV4aHttpSigner.REGION_SET).asString()) + .isEqualTo("region-from-endpoint"); + + assertThat(signer.request.property(AwsV4aHttpSigner.SERVICE_SIGNING_NAME)) + .isEqualTo("service-name-from-endpoint"); + + assertThat(signer.request.property(AwsV4aHttpSigner.DOUBLE_URL_ENCODE)) + .isFalse(); + } + + public EndpointAuthEndpointProvider v4aEndpointProviderOverride() { + return x -> { + Endpoint endpoint = + Endpoint.builder() + .url(URI.create("https://testv4a.query.us-east-1")) + .putAttribute( + AwsEndpointAttribute.AUTH_SCHEMES, + Collections.singletonList(SigV4aAuthScheme.builder() + .addSigningRegion("region-from-endpoint") + .signingName("service-name-from-endpoint") + .disableDoubleEncoding(true) + .build())) + .build(); + + return CompletableFuture.completedFuture(endpoint); + }; + } + @Test @DisplayName("Environment variable config should take precedence over endpoint rules") void environmentVariableRegionSetTakesPrecedenceOverEndpointRegionSet() { diff --git a/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/auth/LegacySignerOverrideTest.java b/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/auth/LegacySignerOverrideTest.java new file mode 100644 index 000000000000..e5907a1e99f1 --- /dev/null +++ b/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/auth/LegacySignerOverrideTest.java @@ -0,0 +1,493 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package software.amazon.awssdk.services.auth; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static software.amazon.awssdk.core.client.config.SdkAdvancedClientOption.SIGNER; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; +import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; +import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; +import software.amazon.awssdk.auth.signer.AwsSignerExecutionAttribute; +import software.amazon.awssdk.awscore.AwsRequest; +import software.amazon.awssdk.awscore.endpoints.AwsEndpointAttribute; +import software.amazon.awssdk.awscore.endpoints.authscheme.SigV4AuthScheme; +import software.amazon.awssdk.awscore.endpoints.authscheme.SigV4aAuthScheme; +import software.amazon.awssdk.core.SdkRequest; +import software.amazon.awssdk.core.async.AsyncRequestBody; +import software.amazon.awssdk.core.interceptor.Context; +import software.amazon.awssdk.core.interceptor.ExecutionAttributes; +import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; +import software.amazon.awssdk.core.signer.Signer; +import software.amazon.awssdk.endpoints.Endpoint; +import software.amazon.awssdk.http.SdkHttpFullRequest; +import software.amazon.awssdk.http.auth.aws.scheme.AwsV4AuthScheme; +import software.amazon.awssdk.http.auth.aws.signer.AwsV4FamilyHttpSigner; +import software.amazon.awssdk.http.auth.aws.signer.AwsV4HttpSigner; +import software.amazon.awssdk.http.auth.aws.signer.AwsV4aHttpSigner; +import software.amazon.awssdk.http.auth.aws.signer.RegionSet; +import software.amazon.awssdk.http.auth.spi.scheme.AuthSchemeOption; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.defaultendpointprovider.DefaultEndpointProviderAsyncClient; +import software.amazon.awssdk.services.defaultendpointprovider.DefaultEndpointProviderClient; +import software.amazon.awssdk.services.defaultendpointprovider.auth.scheme.DefaultEndpointProviderAuthSchemeProvider; +import software.amazon.awssdk.services.endpointauth.EndpointAuthAsyncClient; +import software.amazon.awssdk.services.endpointauth.EndpointAuthClient; +import software.amazon.awssdk.services.endpointauth.endpoints.EndpointAuthEndpointProvider; +import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClient; +import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient; +import software.amazon.awssdk.services.protocolrestjson.model.AllTypesRequest; +import software.amazon.awssdk.services.protocolrestjson.model.StreamingInputOperationRequest; +import software.amazon.awssdk.services.sigv4aauth.Sigv4AauthAsyncClient; +import software.amazon.awssdk.services.sigv4aauth.Sigv4AauthClient; +import software.amazon.awssdk.services.sigv4aauth.auth.scheme.Sigv4AauthAuthSchemeProvider; +import software.amazon.awssdk.services.testutil.ValidSdkObjects; + +/** + * Tests to ensure that parameters set on either endpoints-based (legacy) or model-based auth schemes get + * propagated to the legacy signer (i.e., pre-SRA signers). + */ +public class LegacySignerOverrideTest { + private static final String REGION_FROM_EP = "region-from-ep"; + private static final String SIGNING_NAME_FROM_EP = "signing-name-from-ep"; + private static final String REGION_FROM_SERVICE = "region-from-service"; + private static final String SIGNING_NAME_FROM_SERVICE = "signing-name-from-service"; + + private Signer mockSigner; + + private FailRequestInterceptor interceptor = new FailRequestInterceptor(); + + @BeforeEach + public void setup() { + mockSigner = Mockito.mock(Signer.class); + when(mockSigner.sign(any(), any())).thenReturn(ValidSdkObjects.sdkHttpFullRequest().build()); + } + + @Test + public void asyncClient_signerOverriddenInConfig_takesPrecedence() { + ProtocolRestJsonAsyncClient asyncClient = ProtocolRestJsonAsyncClient.builder() + .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))) + .region(Region.US_WEST_2) + .overrideConfiguration(o -> o.putAdvancedOption(SIGNER, mockSigner).addExecutionInterceptor(interceptor)) + .build(); + + assertThatThrownBy(() -> asyncClient.streamingInputOperation(StreamingInputOperationRequest.builder().build(), + AsyncRequestBody.fromString("test")).join()).hasMessageContaining("boom!"); + + verify(mockSigner).sign(any(SdkHttpFullRequest.class), any(ExecutionAttributes.class)); + } + + @Test + public void asyncClient_signerOverriddenInExecutionInterceptor_takesPrecedence() { + ProtocolRestJsonAsyncClient asyncClient = ProtocolRestJsonAsyncClient.builder() + .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))) + .region(Region.US_WEST_2) + .overrideConfiguration(o -> o.addExecutionInterceptor(signerOverrideExecutionInterceptor(mockSigner)).addExecutionInterceptor(interceptor)) + .build(); + assertThatThrownBy(() -> asyncClient.allTypes(AllTypesRequest.builder().build()).join()).hasMessageContaining("boom!"); + verify(mockSigner).sign(any(SdkHttpFullRequest.class), any(ExecutionAttributes.class)); + } + + @Test + public void syncClient_signerOverriddenInExecutionInterceptor_takesPrecedence() { + ProtocolRestJsonClient client = ProtocolRestJsonClient.builder() + .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))) + .region(Region.US_WEST_2) + .overrideConfiguration(o -> o.addExecutionInterceptor(signerOverrideExecutionInterceptor(mockSigner)).addExecutionInterceptor(interceptor)) + .build(); + assertThatThrownBy(() -> client.allTypes(AllTypesRequest.builder().build())).hasMessageContaining("boom!"); + + verify(mockSigner).sign(any(SdkHttpFullRequest.class), any(ExecutionAttributes.class)); + } + + @Test + public void syncClient_signerOverriddenInConfig_takesPrecedence() { + ProtocolRestJsonClient client = ProtocolRestJsonClient.builder() + .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))) + .region(Region.US_WEST_2) + .overrideConfiguration(o -> o.addExecutionInterceptor(signerOverrideExecutionInterceptor(mockSigner)).addExecutionInterceptor(interceptor)) + .build(); + assertThatThrownBy(() -> client.allTypes(AllTypesRequest.builder().build())).hasMessageContaining("boom!"); + + verify(mockSigner).sign(any(SdkHttpFullRequest.class), any(ExecutionAttributes.class)); + } + + @Test + void v4EndpointAuthSchemeSync_signerOverride_endpointParamsShouldPropagateToSigner() { + EndpointAuthClient client = EndpointAuthClient + .builder() + .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))) + .endpointProvider(v4EndpointProviderOverride()) + .overrideConfiguration(o -> o.putAdvancedOption(SIGNER, mockSigner).addExecutionInterceptor(interceptor)) + .build(); + + assertThatThrownBy(() -> client.allAuthPropertiesInEndpointRules(r -> { + })).hasMessageContaining("boom!"); + verifySigV4SignerAttributes(mockSigner, AuthType.EP); + } + + @Test + void v4EndpointAuthSchemeAsync_signerOverride_endpointParamsShouldPropagateToSigner() { + EndpointAuthAsyncClient client = EndpointAuthAsyncClient + .builder() + .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))) + .endpointProvider(v4EndpointProviderOverride()) + .overrideConfiguration(o -> o.putAdvancedOption(SIGNER, mockSigner).addExecutionInterceptor(interceptor)) + .build(); + + assertThatThrownBy(() -> client.allAuthPropertiesInEndpointRules(r -> { + }).join()).hasMessageContaining("boom!"); + verifySigV4SignerAttributes(mockSigner, AuthType.EP); + } + + @Test + void v4aEndpointAuthSchemeSync_signerOverride_thenEndpointParamsShouldPropagateToSigner() { + EndpointAuthClient client = EndpointAuthClient + .builder() + .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))) + .endpointProvider(v4aEndpointProviderOverride()) + .overrideConfiguration( + o -> o.putAdvancedOption(SIGNER, mockSigner) + .addExecutionInterceptor(interceptor)) + .build(); + + assertThatThrownBy(() -> client.allAuthPropertiesInEndpointRules(r -> { + })).hasMessageContaining("boom!"); + verifySigV4aSignerAttributes(mockSigner, AuthType.EP); + } + + @Test + void v4aEndpointAuthSchemeAsync_signerOverride_thenEndpointParamsShouldPropagateToSigner() { + EndpointAuthAsyncClient client = EndpointAuthAsyncClient + .builder() + .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))) + .endpointProvider(v4aEndpointProviderOverride()) + .overrideConfiguration( + o -> o.putAdvancedOption(SIGNER, mockSigner) + .addExecutionInterceptor(interceptor)) + .build(); + + assertThatThrownBy(() -> client.allAuthPropertiesInEndpointRules(r -> { + }).join()).hasMessageContaining("boom!"); + verifySigV4aSignerAttributes(mockSigner, AuthType.EP); + } + + @Test + void v4ModelAuthSync_signerOverride_signerPropertiesShouldPropagateToSigner() { + DefaultEndpointProviderClient client = DefaultEndpointProviderClient + .builder() + .authSchemeProvider(v4AuthSchemeProviderOverride()) + .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))) + .overrideConfiguration(o -> o.putAdvancedOption(SIGNER, mockSigner).addExecutionInterceptor(interceptor)) + .build(); + + assertThatThrownBy(() -> client.oneOperation(r -> { + })).hasMessageContaining("boom!"); + verifySigV4SignerAttributes(mockSigner, AuthType.MODEL); + } + + @Test + void v4BothAuthSync_signerOverride_endpointSignerPropertiesShouldPropagateToSigner() { + DefaultEndpointProviderClient client = DefaultEndpointProviderClient + .builder() + .authSchemeProvider(v4AuthSchemeProviderOverride()) + .endpointProvider(x -> { + Endpoint endpoint = + Endpoint.builder() + .url(URI.create("https://testv4.query.us-east-1")) + .putAttribute( + AwsEndpointAttribute.AUTH_SCHEMES, + Collections.singletonList(SigV4AuthScheme.builder() + .signingRegion(REGION_FROM_EP) + .signingName(SIGNING_NAME_FROM_EP) + .disableDoubleEncoding(true) + .build())) + .build(); + + return CompletableFuture.completedFuture(endpoint); + }) + .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))) + .overrideConfiguration(o -> o.putAdvancedOption(SIGNER, mockSigner).addExecutionInterceptor(interceptor)) + .build(); + + assertThatThrownBy(() -> client.oneOperation(r -> { + })).hasMessageContaining("boom!"); + verifySigV4SignerAttributes(mockSigner, AuthType.EP); + } + + @Test + void v4ModelAuthAsync_signerOverride_signerPropertiesShouldPropagateToSigner() { + DefaultEndpointProviderAsyncClient client = DefaultEndpointProviderAsyncClient + .builder() + .authSchemeProvider(v4AuthSchemeProviderOverride()) + .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))) + .overrideConfiguration(o -> o.putAdvancedOption(SIGNER, mockSigner).addExecutionInterceptor(interceptor)) + .build(); + + assertThatThrownBy(() -> client.oneOperation(r -> { + }).join()).hasMessageContaining("boom!"); + verifySigV4SignerAttributes(mockSigner, AuthType.MODEL); + } + + // TODO: fix the logic, tracking in JAVA-8567 + @Disabled("regionSet from EP should be getting used") + @Test + void v4aBothAuthProviderAndEndpointAuth_signerOverride_endpointSignerPropertiesShouldPropagateToSigner() { + Sigv4AauthClient client = Sigv4AauthClient + .builder() + .authSchemeProvider(i -> { + List options = new ArrayList<>(); + options.add( + AuthSchemeOption.builder().schemeId("aws.auth#sigv4a") + .putSignerProperty(AwsV4FamilyHttpSigner.SERVICE_SIGNING_NAME, SIGNING_NAME_FROM_SERVICE) + .putSignerProperty(AwsV4aHttpSigner.REGION_SET, RegionSet.create(REGION_FROM_SERVICE)) + .putSignerProperty(AwsV4aHttpSigner.DOUBLE_URL_ENCODE, false) + .build() + ); + return Collections.unmodifiableList(options); + }) + .endpointProvider(x -> { + Endpoint endpoint = + Endpoint.builder() + .url(URI.create("https://testv4a.query.us-east-1")) + .putAttribute( + AwsEndpointAttribute.AUTH_SCHEMES, + Collections.singletonList(SigV4aAuthScheme.builder() + .signingRegionSet(Arrays.asList(REGION_FROM_EP)) + .signingName(SIGNING_NAME_FROM_EP) + .disableDoubleEncoding(true) + .build())) + .build(); + + return CompletableFuture.completedFuture(endpoint); + }) + .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))) + .overrideConfiguration(o -> o.putAdvancedOption(SIGNER, mockSigner).addExecutionInterceptor(interceptor)) + .build(); + + assertThatThrownBy(() -> client.simpleOperationWithNoEndpointParams(r -> { + })).hasMessageContaining("boom!"); + verifySigV4aSignerAttributes(mockSigner, AuthType.EP); + } + + @Test + void v4aModelAuthSync_signerOverride_signerPropertiesShouldPropagateToSigner() { + Sigv4AauthClient client = Sigv4AauthClient + .builder() + .authSchemeProvider(v4aAuthSchemeProviderOverride()) + .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))) + .overrideConfiguration(o -> o.putAdvancedOption(SIGNER, mockSigner).addExecutionInterceptor(interceptor)) + + .build(); + + assertThatThrownBy(() -> client.simpleOperationWithNoEndpointParams(r -> { + })).hasMessageContaining("boom!"); + verifySigV4aSignerAttributes(mockSigner, AuthType.MODEL); + } + + @Test + void v4aModelAuthAsync_signerOverride_signerPropertiesShouldPropagateToSigner() { + Sigv4AauthAsyncClient client = Sigv4AauthAsyncClient + .builder() + .authSchemeProvider(v4aAuthSchemeProviderOverride()) + .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))) + .overrideConfiguration(o -> o.putAdvancedOption(SIGNER, mockSigner).addExecutionInterceptor(interceptor)) + + .build(); + + assertThatThrownBy(() -> client.simpleOperationWithNoEndpointParams(r -> { + }).join()).hasMessageContaining("boom!"); + verifySigV4aSignerAttributes(mockSigner, AuthType.MODEL); + } + + private ExecutionInterceptor signerOverrideExecutionInterceptor(Signer signer) { + return new ExecutionInterceptor() { + @Override + public SdkRequest modifyRequest(Context.ModifyRequest context, ExecutionAttributes executionAttributes) { + AwsRequest.Builder builder = (AwsRequest.Builder) context.request().toBuilder(); + builder.overrideConfiguration(c -> c.signer(signer) + .build()); + + return builder.build(); + } + }; + } + + private static void verifySigV4SignerAttributes(Signer signer, AuthType authType) { + ArgumentCaptor httpRequest = ArgumentCaptor.forClass(SdkHttpFullRequest.class); + ArgumentCaptor attributes = ArgumentCaptor.forClass(ExecutionAttributes.class); + verify(signer).sign(httpRequest.capture(), attributes.capture()); + + ExecutionAttributes actualAttributes = attributes.getValue(); + String expectedRegion; + String expectedSigningName; + switch (authType) { + case EP: + expectedRegion = REGION_FROM_EP; + expectedSigningName = SIGNING_NAME_FROM_EP; + break; + case MODEL: + expectedRegion = REGION_FROM_SERVICE; + expectedSigningName = SIGNING_NAME_FROM_SERVICE; + break; + default: + throw new UnsupportedOperationException("unsupported auth type " + authType); + } + + assertThat(actualAttributes.getAttribute(AwsSignerExecutionAttribute.SIGNING_REGION).id()).isEqualTo(expectedRegion); + assertThat(actualAttributes.getAttribute(AwsSignerExecutionAttribute.SERVICE_SIGNING_NAME)).isEqualTo(expectedSigningName); + assertThat(actualAttributes.getAttribute(AwsSignerExecutionAttribute.SIGNER_DOUBLE_URL_ENCODE)).isFalse(); + } + + private static void verifySigV4aSignerAttributes(Signer signer, AuthType authType) { + ArgumentCaptor httpRequest = ArgumentCaptor.forClass(SdkHttpFullRequest.class); + ArgumentCaptor attributes = ArgumentCaptor.forClass(ExecutionAttributes.class); + verify(signer).sign(httpRequest.capture(), attributes.capture()); + + ExecutionAttributes actualAttributes = attributes.getValue(); + String expectedRegion; + String expectedSigningName; + switch (authType) { + case EP: + expectedRegion = REGION_FROM_EP; + expectedSigningName = SIGNING_NAME_FROM_EP; + break; + case MODEL: + expectedRegion = REGION_FROM_SERVICE; + expectedSigningName = SIGNING_NAME_FROM_SERVICE; + break; + default: + throw new UnsupportedOperationException("unsupported auth type " + authType); + } + + assertThat(actualAttributes.getAttribute(AwsSignerExecutionAttribute.SIGNING_REGION_SCOPE).id()).isEqualTo(expectedRegion); + assertThat(actualAttributes.getAttribute(AwsSignerExecutionAttribute.SERVICE_SIGNING_NAME)).isEqualTo(expectedSigningName); + assertThat(actualAttributes.getAttribute(AwsSignerExecutionAttribute.SIGNER_DOUBLE_URL_ENCODE)).isFalse(); + } + + private enum AuthType { + EP, + MODEL + } + + private static DefaultEndpointProviderAuthSchemeProvider v4AuthSchemeProviderOverride() { + return x -> { + List options = new ArrayList<>(); + options.add( + AuthSchemeOption.builder().schemeId(AwsV4AuthScheme.SCHEME_ID) + .putSignerProperty(AwsV4FamilyHttpSigner.SERVICE_SIGNING_NAME, SIGNING_NAME_FROM_SERVICE) + .putSignerProperty(AwsV4HttpSigner.REGION_NAME, REGION_FROM_SERVICE) + .putSignerProperty(AwsV4aHttpSigner.DOUBLE_URL_ENCODE, false) + .build() + ); + return Collections.unmodifiableList(options); + }; + } + + private static Sigv4AauthAuthSchemeProvider v4aAuthSchemeProviderOverride() { + return i -> { + List options = new ArrayList<>(); + options.add( + AuthSchemeOption.builder().schemeId("aws.auth#sigv4a") + .putSignerProperty(AwsV4FamilyHttpSigner.SERVICE_SIGNING_NAME, SIGNING_NAME_FROM_SERVICE) + .putSignerProperty(AwsV4aHttpSigner.REGION_SET, RegionSet.create(REGION_FROM_SERVICE)) + .putSignerProperty(AwsV4aHttpSigner.DOUBLE_URL_ENCODE, false) + .build() + ); + return Collections.unmodifiableList(options); + }; + } + + private static EndpointAuthEndpointProvider v4EndpointProviderOverride() { + return i -> { + Endpoint endpoint = + Endpoint.builder() + .url(URI.create("https://testv4.query.us-west-1")) + .putAttribute( + AwsEndpointAttribute.AUTH_SCHEMES, + Collections.singletonList(SigV4AuthScheme.builder() + .signingRegion(REGION_FROM_EP) + .signingName(SIGNING_NAME_FROM_EP) + .disableDoubleEncoding(true) + .build())) + .build(); + + return CompletableFuture.completedFuture(endpoint); + }; + } + + private static EndpointAuthEndpointProvider v4aEndpointProviderOverride() { + return x -> { + Endpoint endpoint = + Endpoint.builder() + .url(URI.create("https://testv4a.query.us-east-1")) + .putAttribute( + AwsEndpointAttribute.AUTH_SCHEMES, + Collections.singletonList(SigV4aAuthScheme.builder() + .addSigningRegion(REGION_FROM_EP) + .signingName(SIGNING_NAME_FROM_EP) + .disableDoubleEncoding(true) + .build())) + .build(); + + return CompletableFuture.completedFuture(endpoint); + }; + } + + private static EndpointAuthEndpointProvider sigv4aAuthEndpointProvider() { + return x -> { + Endpoint endpoint = + Endpoint.builder() + .url(URI.create("https://testv4a.query.us-east-1")) + .putAttribute( + AwsEndpointAttribute.AUTH_SCHEMES, + Collections.singletonList(SigV4aAuthScheme.builder() + .addSigningRegion(REGION_FROM_EP) + .signingName(SIGNING_NAME_FROM_EP) + .disableDoubleEncoding(true) + .build())) + .build(); + + return CompletableFuture.completedFuture(endpoint); + }; + } + + private static class FailRequestInterceptor implements ExecutionInterceptor { + private Context.BeforeTransmission context; + private ExecutionAttributes executionAttributes; + + @Override + public void beforeTransmission(Context.BeforeTransmission context, ExecutionAttributes executionAttributes) { + this.context = context; + this.executionAttributes = executionAttributes; + throw new RuntimeException("boom!"); + } + } +} diff --git a/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/multiauth/AuthSchemePreferenceResolverFunctionalTest.java b/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/auth/multiauth/AuthSchemePreferenceResolverFunctionalTest.java similarity index 98% rename from test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/multiauth/AuthSchemePreferenceResolverFunctionalTest.java rename to test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/auth/multiauth/AuthSchemePreferenceResolverFunctionalTest.java index 502f5aa20be9..40d272541bb5 100644 --- a/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/multiauth/AuthSchemePreferenceResolverFunctionalTest.java +++ b/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/auth/multiauth/AuthSchemePreferenceResolverFunctionalTest.java @@ -13,7 +13,7 @@ * permissions and limitations under the License. */ -package software.amazon.awssdk.services.multiauth; +package software.amazon.awssdk.services.auth.multiauth; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -46,6 +46,8 @@ import software.amazon.awssdk.profiles.ProfileFile; import software.amazon.awssdk.profiles.ProfileProperty; import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.multiauth.MultiauthClient; +import software.amazon.awssdk.services.multiauth.MultiauthClientBuilder; import software.amazon.awssdk.services.multiauth.auth.scheme.MultiauthAuthSchemeProvider; import software.amazon.awssdk.services.multiauth.model.MultiAuthWithOnlySigv4AAndSigv4Request; import software.amazon.awssdk.testutils.EnvironmentVariableHelper; diff --git a/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/multiauth/MultiAuthSigningPropertiesTest.java b/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/auth/multiauth/MultiAuthSigningPropertiesTest.java similarity index 89% rename from test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/multiauth/MultiAuthSigningPropertiesTest.java rename to test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/auth/multiauth/MultiAuthSigningPropertiesTest.java index 639f5097146b..f4ab5f1d60ec 100644 --- a/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/multiauth/MultiAuthSigningPropertiesTest.java +++ b/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/auth/multiauth/MultiAuthSigningPropertiesTest.java @@ -13,7 +13,7 @@ * permissions and limitations under the License. */ -package software.amazon.awssdk.services.multiauth; +package software.amazon.awssdk.services.auth.multiauth; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @@ -22,6 +22,7 @@ import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static software.amazon.awssdk.services.auth.AuthTestUtils.authScheme; import java.util.Arrays; import java.util.StringJoiner; @@ -39,7 +40,6 @@ import software.amazon.awssdk.http.auth.aws.signer.AwsV4HttpSigner; import software.amazon.awssdk.http.auth.aws.signer.AwsV4aHttpSigner; import software.amazon.awssdk.http.auth.aws.signer.RegionSet; -import software.amazon.awssdk.http.auth.spi.scheme.AuthScheme; import software.amazon.awssdk.http.auth.spi.signer.AsyncSignRequest; import software.amazon.awssdk.http.auth.spi.signer.AsyncSignedRequest; import software.amazon.awssdk.http.auth.spi.signer.BaseSignRequest; @@ -47,9 +47,9 @@ import software.amazon.awssdk.http.auth.spi.signer.SignRequest; import software.amazon.awssdk.http.auth.spi.signer.SignedRequest; import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity; -import software.amazon.awssdk.identity.spi.IdentityProvider; -import software.amazon.awssdk.identity.spi.IdentityProviders; import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.multiauth.MultiauthClient; +import software.amazon.awssdk.services.multiauth.MultiauthClientBuilder; import software.amazon.awssdk.testutils.EnvironmentVariableHelper; import software.amazon.awssdk.utils.CompletableFutureUtils; @@ -121,12 +121,12 @@ void endpointParamsDefinedAsGlobalUsedWhenNoRegionSetConfigured() { assertThatThrownBy(() -> client.multiAuthWithRegionSetInEndpointParams(r -> r.stringMember(""))) .hasMessageContaining("stop"); - assertThat(signer.request.property(AwsV4aHttpSigner.REGION_SET)) - .isEqualTo(RegionSet.GLOBAL); + assertThat(signer.request.property(AwsV4aHttpSigner.REGION_SET).asString()) + .isEqualTo(RegionSet.GLOBAL.asString()); } @Test - @DisplayName("Should use the Region set from Endpoint RuleSet when no RegionSet configured") + @DisplayName("Region set configured on the client takes precedence") void clientApiConfiguredRegionSetTakePrecedenceOverEndpointRulesRegionSet() { CapturingSigner signer = new CapturingSigner(); MultiauthClient client = MultiauthClient.builder() @@ -142,8 +142,8 @@ void clientApiConfiguredRegionSetTakePrecedenceOverEndpointRulesRegionSet() { assertThatThrownBy(() -> client.multiAuthWithRegionSetInEndpointParams(r -> r.stringMember(""))) .hasMessageContaining("stop"); - assertThat(signer.request.property(AwsV4aHttpSigner.REGION_SET)) - .isEqualTo(RegionSet.create("us-west-2,us-gov-east-1")); + assertThat(signer.request.property(AwsV4aHttpSigner.REGION_SET).asString()) + .isEqualTo(RegionSet.create("us-west-2,us-gov-east-1").asString()); } } @@ -157,10 +157,12 @@ void shouldThrowErrorWhenNoFallback() { MultiauthClient client = MultiauthClient.builder() .httpClient(mockHttpClient) .region(Region.US_WEST_2) - .build(); + .putAuthScheme(authScheme("aws.auth#sigv4a", () -> { + throw new RuntimeException("dependency not available"); + })).build(); assertThatThrownBy(() -> client.multiAuthWithOnlySigv4a(r -> r.stringMember(""))) - .hasMessageContaining(CRT_DEPENDENCY_ERROR_MESSAGE); + .hasMessageContaining("dependency not available"); } @Test @@ -231,23 +233,6 @@ public CompletableFuture signAsync( } } - private static AuthScheme authScheme(String schemeId, HttpSigner signer) { - return new AuthScheme() { - @Override - public String schemeId() { - return schemeId; - } - - @Override - public IdentityProvider identityProvider(IdentityProviders providers) { - return providers.identityProvider(AwsCredentialsIdentity.class); - } - - @Override - public HttpSigner signer() { - return signer; - } - }; - } + } \ No newline at end of file diff --git a/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/multiauth/Sigv4aOnlyMultiAuthTest.java b/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/auth/multiauth/Sigv4aOnlyMultiAuthTest.java similarity index 87% rename from test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/multiauth/Sigv4aOnlyMultiAuthTest.java rename to test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/auth/multiauth/Sigv4aOnlyMultiAuthTest.java index 736d909edad2..128a5d39ca38 100644 --- a/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/multiauth/Sigv4aOnlyMultiAuthTest.java +++ b/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/auth/multiauth/Sigv4aOnlyMultiAuthTest.java @@ -13,11 +13,12 @@ * permissions and limitations under the License. */ -package software.amazon.awssdk.services.multiauth; +package software.amazon.awssdk.services.auth.multiauth; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; +import static software.amazon.awssdk.services.auth.AuthTestUtils.authScheme; import java.util.concurrent.CompletableFuture; import org.assertj.core.api.Assertions; @@ -49,37 +50,14 @@ public class Sigv4aOnlyMultiAuthTest { - private static final String MOCK_HTTP_CLIENT_NAME = "MockHttpClient"; private static final String EXPECTED_EXCEPTION_MESSAGE = "expected exception"; - private static final String CRT_DEPENDENCY_ERROR_MESSAGE = - "You must add a dependency on the 'software.amazon.awssdk:http-auth-aws-crt' module to enable the CRT-V4a signing " - + "feature"; private final EnvironmentVariableHelper environmentVariableHelper = new EnvironmentVariableHelper(); @Mock private SdkHttpClient mockHttpClient; - private static AuthScheme authScheme(String schemeId, HttpSigner signer) { - return new AuthScheme() { - @Override - public String schemeId() { - return schemeId; - } - - @Override - public IdentityProvider identityProvider(IdentityProviders providers) { - return providers.identityProvider(AwsCredentialsIdentity.class); - } - - @Override - public HttpSigner signer() { - return signer; - } - }; - } - @BeforeEach void setUp() { MockitoAnnotations.openMocks(this); @@ -119,12 +97,13 @@ void shouldThrowErrorWhenNoFallback() { Sigv4AauthClient client = Sigv4AauthClient.builder() .httpClient(mockHttpClient) .region(Region.US_WEST_2) - .build(); + .putAuthScheme(authScheme("aws.auth#sigv4a", () -> { + throw new RuntimeException("dependency not available"); + })).build(); assertThatThrownBy(() -> client.simpleOperationWithNoEndpointParams(r -> r.stringMember(""))) - .hasMessageContaining(CRT_DEPENDENCY_ERROR_MESSAGE); + .hasMessageContaining("dependency not available"); } - } @Nested