|
13 | 13 | * permissions and limitations under the License. |
14 | 14 | */ |
15 | 15 |
|
16 | | -package software.amazon.awssdk.services.endpointauth; |
| 16 | +package software.amazon.awssdk.services.auth; |
17 | 17 |
|
18 | 18 |
|
19 | 19 | import static org.assertj.core.api.AssertionsForClassTypes.assertThat; |
|
22 | 22 | import static org.mockito.ArgumentMatchers.any; |
23 | 23 | import static org.mockito.Mockito.when; |
24 | 24 |
|
| 25 | +import java.net.URI; |
| 26 | +import java.util.Collections; |
25 | 27 | import java.util.concurrent.CompletableFuture; |
26 | 28 | import org.junit.jupiter.api.AfterEach; |
27 | 29 | import org.junit.jupiter.api.BeforeEach; |
|
32 | 34 | import org.mockito.MockitoAnnotations; |
33 | 35 | import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; |
34 | 36 | import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; |
| 37 | +import software.amazon.awssdk.awscore.endpoints.AwsEndpointAttribute; |
| 38 | +import software.amazon.awssdk.awscore.endpoints.authscheme.SigV4aAuthScheme; |
35 | 39 | import software.amazon.awssdk.core.SdkSystemSetting; |
| 40 | +import software.amazon.awssdk.endpoints.Endpoint; |
36 | 41 | import software.amazon.awssdk.http.SdkHttpClient; |
37 | 42 | import software.amazon.awssdk.http.auth.aws.signer.AwsV4aHttpSigner; |
38 | 43 | import software.amazon.awssdk.http.auth.aws.signer.RegionSet; |
|
47 | 52 | import software.amazon.awssdk.identity.spi.IdentityProvider; |
48 | 53 | import software.amazon.awssdk.identity.spi.IdentityProviders; |
49 | 54 | 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; |
50 | 58 | import software.amazon.awssdk.testutils.EnvironmentVariableHelper; |
51 | 59 | import software.amazon.awssdk.utils.CompletableFutureUtils; |
52 | 60 |
|
| 61 | +/** |
| 62 | + * Tests verifying legacy endpoint based auth, i.e., services with enableEndpointAuthSchemeParams = true customization |
| 63 | + */ |
53 | 64 | @DisplayName("Endpoint-Auth Tests") |
54 | 65 | class EndpointAuthSigningPropertiesTest { |
55 | 66 |
|
@@ -135,13 +146,55 @@ void clientConfiguredRegionSetTakesPrecedenceOverEndpointRegionSet() { |
135 | 146 | () -> assertThatThrownBy(() -> |
136 | 147 | client.allAuthPropertiesInEndpointRules(r -> r.stringMember(""))) |
137 | 148 | .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()), |
140 | 151 | () -> assertThat(signer.request.property(AwsV4aHttpSigner.SERVICE_SIGNING_NAME)) |
141 | 152 | .isEqualTo("sigv4afromruleset") |
142 | 153 | ); |
143 | 154 | } |
144 | 155 |
|
| 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 | + |
145 | 198 | @Test |
146 | 199 | @DisplayName("Environment variable config should take precedence over endpoint rules") |
147 | 200 | void environmentVariableRegionSetTakesPrecedenceOverEndpointRegionSet() { |
|
0 commit comments