|
22 | 22 | import org.junit.jupiter.api.Test; |
23 | 23 | import org.junit.jupiter.params.ParameterizedTest; |
24 | 24 | import org.junit.jupiter.params.provider.ValueSource; |
| 25 | +import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; |
25 | 26 | import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; |
| 27 | +import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; |
26 | 28 | import software.amazon.awssdk.auth.signer.AwsS3V4Signer; |
27 | 29 | import software.amazon.awssdk.core.async.AsyncRequestBody; |
28 | 30 | import software.amazon.awssdk.core.async.AsyncResponseTransformer; |
|
31 | 33 | import software.amazon.awssdk.core.interceptor.ExecutionAttributes; |
32 | 34 | import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; |
33 | 35 | import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute; |
| 36 | +import software.amazon.awssdk.http.SdkHttpExecutionAttributes; |
34 | 37 | import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity; |
35 | 38 | import software.amazon.awssdk.identity.spi.IdentityProvider; |
| 39 | +import software.amazon.awssdk.regions.Region; |
36 | 40 | import software.amazon.awssdk.services.s3.DelegatingS3AsyncClient; |
37 | 41 | import software.amazon.awssdk.services.s3.S3AsyncClient; |
38 | 42 | import software.amazon.awssdk.services.s3.endpoints.S3ClientContextParams; |
@@ -161,4 +165,75 @@ void build_withAdvancedOptions() { |
161 | 165 | assertThat(client).isInstanceOf(DefaultS3CrtAsyncClient.class); |
162 | 166 | } |
163 | 167 | } |
| 168 | + |
| 169 | + @Test |
| 170 | + void s3ExpressBucket_defaultConfig_useS3ExpressAuthIsTrue() { |
| 171 | + AtomicReference<Boolean> capturedUseS3ExpressAuth = new AtomicReference<>(); |
| 172 | + |
| 173 | + ExecutionInterceptor captor = new ExecutionInterceptor() { |
| 174 | + @Override |
| 175 | + public void beforeTransmission(Context.BeforeTransmission context, ExecutionAttributes executionAttributes) { |
| 176 | + SdkHttpExecutionAttributes httpAttrs = |
| 177 | + executionAttributes.getAttribute(SdkInternalExecutionAttribute.SDK_HTTP_EXECUTION_ATTRIBUTES); |
| 178 | + if (httpAttrs != null) { |
| 179 | + capturedUseS3ExpressAuth.set(httpAttrs.getAttribute(S3InternalSdkHttpExecutionAttribute.USE_S3_EXPRESS_AUTH)); |
| 180 | + } |
| 181 | + throw new RuntimeException("STOP"); |
| 182 | + } |
| 183 | + }; |
| 184 | + |
| 185 | + DefaultS3CrtAsyncClient.DefaultS3CrtClientBuilder builder = |
| 186 | + (DefaultS3CrtAsyncClient.DefaultS3CrtClientBuilder) S3CrtAsyncClient.builder(); |
| 187 | + builder.addExecutionInterceptor(captor); |
| 188 | + |
| 189 | + try (S3AsyncClient client = builder |
| 190 | + .region(Region.US_EAST_1) |
| 191 | + .credentialsProvider(StaticCredentialsProvider.create( |
| 192 | + AwsBasicCredentials.create("key", "secret"))) |
| 193 | + .build()) { |
| 194 | + |
| 195 | + assertThatThrownBy(() -> client.getObject( |
| 196 | + r -> r.bucket("my-bucket--usw2-az1--x-s3").key("key"), |
| 197 | + AsyncResponseTransformer.toBytes()).join()) |
| 198 | + .hasMessageContaining("STOP"); |
| 199 | + } |
| 200 | + |
| 201 | + assertThat(capturedUseS3ExpressAuth.get()).isTrue(); |
| 202 | + } |
| 203 | + |
| 204 | + @Test |
| 205 | + void s3ExpressBucket_disableS3ExpressSessionAuth_useS3ExpressAuthIsFalse() { |
| 206 | + AtomicReference<Boolean> capturedUseS3ExpressAuth = new AtomicReference<>(); |
| 207 | + |
| 208 | + ExecutionInterceptor captor = new ExecutionInterceptor() { |
| 209 | + @Override |
| 210 | + public void beforeTransmission(Context.BeforeTransmission context, ExecutionAttributes executionAttributes) { |
| 211 | + SdkHttpExecutionAttributes httpAttrs = |
| 212 | + executionAttributes.getAttribute(SdkInternalExecutionAttribute.SDK_HTTP_EXECUTION_ATTRIBUTES); |
| 213 | + if (httpAttrs != null) { |
| 214 | + capturedUseS3ExpressAuth.set(httpAttrs.getAttribute(S3InternalSdkHttpExecutionAttribute.USE_S3_EXPRESS_AUTH)); |
| 215 | + } |
| 216 | + throw new RuntimeException("STOP"); |
| 217 | + } |
| 218 | + }; |
| 219 | + |
| 220 | + DefaultS3CrtAsyncClient.DefaultS3CrtClientBuilder builder = |
| 221 | + (DefaultS3CrtAsyncClient.DefaultS3CrtClientBuilder) S3CrtAsyncClient.builder(); |
| 222 | + builder.addExecutionInterceptor(captor); |
| 223 | + |
| 224 | + try (S3AsyncClient client = builder |
| 225 | + .region(Region.US_EAST_1) |
| 226 | + .credentialsProvider(StaticCredentialsProvider.create( |
| 227 | + AwsBasicCredentials.create("key", "secret"))) |
| 228 | + .disableS3ExpressSessionAuth(true) |
| 229 | + .build()) { |
| 230 | + |
| 231 | + assertThatThrownBy(() -> client.getObject( |
| 232 | + r -> r.bucket("my-bucket--usw2-az1--x-s3").key("key"), |
| 233 | + AsyncResponseTransformer.toBytes()).join()) |
| 234 | + .hasMessageContaining("STOP"); |
| 235 | + } |
| 236 | + |
| 237 | + assertThat(capturedUseS3ExpressAuth.get()).isFalse(); |
| 238 | + } |
164 | 239 | } |
0 commit comments