Skip to content

Commit 27d33d2

Browse files
authored
Add tests to verify legacy signer code path (#6473)
* Add more auth and signer tests and refactor existing tests * Fix tests
1 parent 5e03e42 commit 27d33d2

File tree

8 files changed

+642
-267
lines changed

8 files changed

+642
-267
lines changed

test/codegen-generated-classes-test/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@
274274
<version>${awsjavasdk.version}</version>
275275
<scope>test</scope>
276276
</dependency>
277+
<dependency>
278+
<groupId>software.amazon.awssdk</groupId>
279+
<artifactId>http-auth-aws-crt</artifactId>
280+
<version>${awsjavasdk.version}</version>
281+
<scope>test</scope>
282+
</dependency>
277283
<dependency>
278284
<groupId>org.mockito</groupId>
279285
<artifactId>mockito-junit-jupiter</artifactId>

test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/SignerOverrideTest.java

Lines changed: 0 additions & 207 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.services.auth;
17+
18+
import java.util.function.Supplier;
19+
import software.amazon.awssdk.http.auth.spi.scheme.AuthScheme;
20+
import software.amazon.awssdk.http.auth.spi.signer.HttpSigner;
21+
import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity;
22+
import software.amazon.awssdk.identity.spi.IdentityProvider;
23+
import software.amazon.awssdk.identity.spi.IdentityProviders;
24+
25+
public class AuthTestUtils {
26+
27+
public static AuthScheme<?> authScheme(String schemeId, HttpSigner<AwsCredentialsIdentity> signer) {
28+
return new AuthScheme<AwsCredentialsIdentity>() {
29+
@Override
30+
public String schemeId() {
31+
return schemeId;
32+
}
33+
34+
@Override
35+
public IdentityProvider<AwsCredentialsIdentity> identityProvider(IdentityProviders providers) {
36+
return providers.identityProvider(AwsCredentialsIdentity.class);
37+
}
38+
39+
@Override
40+
public HttpSigner<AwsCredentialsIdentity> signer() {
41+
return signer;
42+
}
43+
};
44+
}
45+
46+
public static AuthScheme<?> authScheme(String schemeId, Supplier<HttpSigner<AwsCredentialsIdentity>> supplier) {
47+
return new AuthScheme<AwsCredentialsIdentity>() {
48+
@Override
49+
public String schemeId() {
50+
return schemeId;
51+
}
52+
53+
@Override
54+
public IdentityProvider<AwsCredentialsIdentity> identityProvider(IdentityProviders providers) {
55+
return providers.identityProvider(AwsCredentialsIdentity.class);
56+
}
57+
58+
@Override
59+
public HttpSigner<AwsCredentialsIdentity> signer() {
60+
return supplier.get();
61+
}
62+
};
63+
}
64+
}

test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/endpointauth/EndpointAuthSigningPropertiesTest.java renamed to test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/auth/EndpointAuthSigningPropertiesTest.java

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
package software.amazon.awssdk.services.endpointauth;
16+
package software.amazon.awssdk.services.auth;
1717

1818

1919
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
@@ -22,6 +22,8 @@
2222
import static org.mockito.ArgumentMatchers.any;
2323
import static org.mockito.Mockito.when;
2424

25+
import java.net.URI;
26+
import java.util.Collections;
2527
import java.util.concurrent.CompletableFuture;
2628
import org.junit.jupiter.api.AfterEach;
2729
import org.junit.jupiter.api.BeforeEach;
@@ -32,7 +34,10 @@
3234
import org.mockito.MockitoAnnotations;
3335
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
3436
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
37+
import software.amazon.awssdk.awscore.endpoints.AwsEndpointAttribute;
38+
import software.amazon.awssdk.awscore.endpoints.authscheme.SigV4aAuthScheme;
3539
import software.amazon.awssdk.core.SdkSystemSetting;
40+
import software.amazon.awssdk.endpoints.Endpoint;
3641
import software.amazon.awssdk.http.SdkHttpClient;
3742
import software.amazon.awssdk.http.auth.aws.signer.AwsV4aHttpSigner;
3843
import software.amazon.awssdk.http.auth.aws.signer.RegionSet;
@@ -47,9 +52,15 @@
4752
import software.amazon.awssdk.identity.spi.IdentityProvider;
4853
import software.amazon.awssdk.identity.spi.IdentityProviders;
4954
import software.amazon.awssdk.regions.Region;
55+
import software.amazon.awssdk.services.endpointauth.EndpointAuthClient;
56+
import software.amazon.awssdk.services.endpointauth.EndpointAuthClientBuilder;
57+
import software.amazon.awssdk.services.endpointauth.endpoints.EndpointAuthEndpointProvider;
5058
import software.amazon.awssdk.testutils.EnvironmentVariableHelper;
5159
import software.amazon.awssdk.utils.CompletableFutureUtils;
5260

61+
/**
62+
* Tests verifying legacy endpoint based auth, i.e., services with enableEndpointAuthSchemeParams = true customization
63+
*/
5364
@DisplayName("Endpoint-Auth Tests")
5465
class EndpointAuthSigningPropertiesTest {
5566

@@ -135,13 +146,55 @@ void clientConfiguredRegionSetTakesPrecedenceOverEndpointRegionSet() {
135146
() -> assertThatThrownBy(() ->
136147
client.allAuthPropertiesInEndpointRules(r -> r.stringMember("")))
137148
.hasMessageContaining("stop"),
138-
() -> assertThat(signer.request.property(AwsV4aHttpSigner.REGION_SET))
139-
.isEqualTo(RegionSet.create(MULTI_REGION_SET)),
149+
() -> assertThat(signer.request.property(AwsV4aHttpSigner.REGION_SET).asString())
150+
.isEqualTo(RegionSet.create(MULTI_REGION_SET).asString()),
140151
() -> assertThat(signer.request.property(AwsV4aHttpSigner.SERVICE_SIGNING_NAME))
141152
.isEqualTo("sigv4afromruleset")
142153
);
143154
}
144155

156+
@Test
157+
@DisplayName("Signer properties from endpoint auth scheme takes precedence")
158+
void endpointAuthSchemesPresent_shouldHonor() {
159+
EndpointAuthClient client =
160+
EndpointAuthClient.builder()
161+
.httpClient(mockHttpClient)
162+
.region(Region.US_WEST_2)
163+
.putAuthScheme(authScheme("aws.auth#sigv4a", signer))
164+
.endpointProvider(v4aEndpointProviderOverride())
165+
.build();
166+
167+
assertThatThrownBy(() -> client.allAuthPropertiesInEndpointRules(r -> r.stringMember("")))
168+
.hasMessageContaining("stop");
169+
170+
assertThat(signer.request.property(AwsV4aHttpSigner.REGION_SET).asString())
171+
.isEqualTo("region-from-endpoint");
172+
173+
assertThat(signer.request.property(AwsV4aHttpSigner.SERVICE_SIGNING_NAME))
174+
.isEqualTo("service-name-from-endpoint");
175+
176+
assertThat(signer.request.property(AwsV4aHttpSigner.DOUBLE_URL_ENCODE))
177+
.isFalse();
178+
}
179+
180+
public EndpointAuthEndpointProvider v4aEndpointProviderOverride() {
181+
return x -> {
182+
Endpoint endpoint =
183+
Endpoint.builder()
184+
.url(URI.create("https://testv4a.query.us-east-1"))
185+
.putAttribute(
186+
AwsEndpointAttribute.AUTH_SCHEMES,
187+
Collections.singletonList(SigV4aAuthScheme.builder()
188+
.addSigningRegion("region-from-endpoint")
189+
.signingName("service-name-from-endpoint")
190+
.disableDoubleEncoding(true)
191+
.build()))
192+
.build();
193+
194+
return CompletableFuture.completedFuture(endpoint);
195+
};
196+
}
197+
145198
@Test
146199
@DisplayName("Environment variable config should take precedence over endpoint rules")
147200
void environmentVariableRegionSetTakesPrecedenceOverEndpointRegionSet() {

0 commit comments

Comments
 (0)