Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/codegen-generated-classes-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@
<version>${awsjavasdk.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>http-auth-aws-crt</artifactId>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added CRT dependency to be able to run sigV4a tests (otherwise it'd throw CRT not available error). There is a module to test functionalities w/o CRT https://github.com/aws/aws-sdk-java-v2/tree/master/test/crt-unavailable-tests

<version>${awsjavasdk.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<AwsCredentialsIdentity> signer) {
return new AuthScheme<AwsCredentialsIdentity>() {
@Override
public String schemeId() {
return schemeId;
}

@Override
public IdentityProvider<AwsCredentialsIdentity> identityProvider(IdentityProviders providers) {
return providers.identityProvider(AwsCredentialsIdentity.class);
}

@Override
public HttpSigner<AwsCredentialsIdentity> signer() {
return signer;
}
};
}

public static AuthScheme<?> authScheme(String schemeId, Supplier<HttpSigner<AwsCredentialsIdentity>> supplier) {
return new AuthScheme<AwsCredentialsIdentity>() {
@Override
public String schemeId() {
return schemeId;
}

@Override
public IdentityProvider<AwsCredentialsIdentity> identityProvider(IdentityProviders providers) {
return providers.identityProvider(AwsCredentialsIdentity.class);
}

@Override
public HttpSigner<AwsCredentialsIdentity> signer() {
return supplier.get();
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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() {
Expand Down
Loading
Loading