|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | +package aws.sdk.kotlin.services.s3 |
| 6 | + |
| 7 | +import aws.sdk.kotlin.runtime.client.AwsClientOption |
| 8 | +import aws.smithy.kotlin.runtime.auth.AuthSchemeId |
| 9 | +import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProvider |
| 10 | +import aws.smithy.kotlin.runtime.auth.awssigning.AwsSignedBodyHeader |
| 11 | +import aws.smithy.kotlin.runtime.auth.awssigning.AwsSigningAttributes |
| 12 | +import aws.smithy.kotlin.runtime.client.RequestInterceptorContext |
| 13 | +import aws.smithy.kotlin.runtime.client.SdkClientOption |
| 14 | +import aws.smithy.kotlin.runtime.collections.get |
| 15 | +import aws.smithy.kotlin.runtime.http.auth.* |
| 16 | +import aws.smithy.kotlin.runtime.http.interceptors.HttpInterceptor |
| 17 | +import aws.smithy.kotlin.runtime.httptest.buildTestConnection |
| 18 | +import aws.smithy.kotlin.runtime.identity.IdentityProvider |
| 19 | +import aws.smithy.kotlin.runtime.identity.IdentityProviderConfig |
| 20 | +import aws.smithy.kotlin.runtime.io.use |
| 21 | +import kotlinx.coroutines.test.runTest |
| 22 | +import kotlin.test.Test |
| 23 | +import kotlin.test.assertEquals |
| 24 | +import kotlin.test.assertNotNull |
| 25 | + |
| 26 | +class DefaultsTest { |
| 27 | + |
| 28 | + /** |
| 29 | + * Test execution context gets filled with defaults. This applies to any generated client but S3 has some additional |
| 30 | + * things added. |
| 31 | + * |
| 32 | + * See [aws-sdk-kotlin#1164](https://github.com/awslabs/aws-sdk-kotlin/issues/1165S) |
| 33 | + */ |
| 34 | + @Test |
| 35 | + fun testDefaultExecutionContext() = runTest { |
| 36 | + val mockEngine = buildTestConnection { expect() } |
| 37 | + val noAuth = object : AuthScheme { |
| 38 | + override val schemeId: AuthSchemeId = AuthSchemeId.AwsSigV4 |
| 39 | + override val signer: HttpSigner = AnonymousHttpSigner |
| 40 | + override fun identityProvider(identityProviderConfig: IdentityProviderConfig): IdentityProvider = AnonymousIdentityProvider |
| 41 | + } |
| 42 | + |
| 43 | + S3Client { |
| 44 | + region = "us-east-1" |
| 45 | + httpClient = mockEngine |
| 46 | + authSchemes = listOf(noAuth) |
| 47 | + interceptors += object : HttpInterceptor { |
| 48 | + override fun readBeforeExecution(context: RequestInterceptorContext<Any>) { |
| 49 | + assertNotNull(context.executionContext[SdkClientOption.ClientName]) |
| 50 | + assertNotNull(context.executionContext[SdkClientOption.LogMode]) |
| 51 | + assertNotNull(context.executionContext[AwsSigningAttributes.CredentialsProvider]) |
| 52 | + |
| 53 | + assertEquals(region, context.executionContext[AwsClientOption.Region]) |
| 54 | + assertEquals(region, context.executionContext[AwsSigningAttributes.SigningRegion]) |
| 55 | + assertEquals("s3", context.executionContext[AwsSigningAttributes.SigningService]) |
| 56 | + |
| 57 | + // S3 specific |
| 58 | + assertEquals(false, context.executionContext[AwsSigningAttributes.NormalizeUriPath]) |
| 59 | + assertEquals(false, context.executionContext[AwsSigningAttributes.UseDoubleUriEncode]) |
| 60 | + assertEquals(AwsSignedBodyHeader.X_AMZ_CONTENT_SHA256, context.executionContext[AwsSigningAttributes.SignedBodyHeader]) |
| 61 | + } |
| 62 | + } |
| 63 | + }.use { s3 -> |
| 64 | + s3.listBuckets() |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments