diff --git a/aws-runtime/aws-http/common/src/aws/sdk/kotlin/runtime/http/interceptors/UnsupportedSigningAlgorithmInterceptor.kt b/aws-runtime/aws-http/common/src/aws/sdk/kotlin/runtime/http/interceptors/UnsupportedSigningAlgorithmInterceptor.kt index 4d0de0611e6..15d8df40f73 100644 --- a/aws-runtime/aws-http/common/src/aws/sdk/kotlin/runtime/http/interceptors/UnsupportedSigningAlgorithmInterceptor.kt +++ b/aws-runtime/aws-http/common/src/aws/sdk/kotlin/runtime/http/interceptors/UnsupportedSigningAlgorithmInterceptor.kt @@ -5,7 +5,8 @@ package aws.sdk.kotlin.runtime.http.interceptors import aws.sdk.kotlin.runtime.InternalSdkApi -import aws.smithy.kotlin.runtime.auth.awssigning.UnsupportedSigningAlgorithm +import aws.smithy.kotlin.runtime.auth.awssigning.AwsSigningAlgorithm +import aws.smithy.kotlin.runtime.auth.awssigning.UnsupportedSigningAlgorithmException import aws.smithy.kotlin.runtime.client.ResponseInterceptorContext import aws.smithy.kotlin.runtime.http.interceptors.HttpInterceptor import aws.smithy.kotlin.runtime.http.request.HttpRequest @@ -20,10 +21,9 @@ import aws.smithy.kotlin.runtime.http.response.HttpResponse public class UnsupportedSigningAlgorithmInterceptor : HttpInterceptor { override suspend fun modifyBeforeCompletion(context: ResponseInterceptorContext): Result { context.response.exceptionOrNull()?.let { - if (it is UnsupportedSigningAlgorithm && it.isSigV4a) { - throw UnsupportedSigningAlgorithm( - it.message!!, // TODO: Add a message and link pointing to AWS SDK for Kotlin developer guide - true, + if (it is UnsupportedSigningAlgorithmException && it.signingAlgorithm == AwsSigningAlgorithm.SIGV4_ASYMMETRIC) { + return Result.failure( + it, // TODO: Add a message and link pointing to AWS SDK for Kotlin developer guide ) } } diff --git a/aws-runtime/aws-http/common/test/aws/sdk/kotlin/runtime/http/interceptors/UnsupportedSigningAlgorithmInterceptorTest.kt b/aws-runtime/aws-http/common/test/aws/sdk/kotlin/runtime/http/interceptors/UnsupportedSigningAlgorithmInterceptorTest.kt index 05025b42eca..7a5020aab9f 100644 --- a/aws-runtime/aws-http/common/test/aws/sdk/kotlin/runtime/http/interceptors/UnsupportedSigningAlgorithmInterceptorTest.kt +++ b/aws-runtime/aws-http/common/test/aws/sdk/kotlin/runtime/http/interceptors/UnsupportedSigningAlgorithmInterceptorTest.kt @@ -4,7 +4,8 @@ */ package aws.sdk.kotlin.runtime.http.interceptors -import aws.smithy.kotlin.runtime.auth.awssigning.UnsupportedSigningAlgorithm +import aws.smithy.kotlin.runtime.auth.awssigning.AwsSigningAlgorithm +import aws.smithy.kotlin.runtime.auth.awssigning.UnsupportedSigningAlgorithmException import aws.smithy.kotlin.runtime.client.ResponseInterceptorContext import aws.smithy.kotlin.runtime.client.SdkClientOption import aws.smithy.kotlin.runtime.http.request.HttpRequest @@ -13,42 +14,54 @@ import aws.smithy.kotlin.runtime.operation.ExecutionContext import kotlinx.coroutines.test.runTest import kotlin.test.Test import kotlin.test.assertEquals -import kotlin.test.assertFails +import kotlin.test.assertIs +import kotlin.test.assertTrue class UnsupportedSigningAlgorithmInterceptorTest { @Test fun testUnsupportedSigningAlgorithmSigV4a() = runTest { - val exception = assertFails { + val result = UnsupportedSigningAlgorithmInterceptor() .modifyBeforeCompletion( context( Result.failure( - UnsupportedSigningAlgorithm( + UnsupportedSigningAlgorithmException( "SIGV4A support is not yet implemented for the default signer.", - true, + AwsSigningAlgorithm.SIGV4_ASYMMETRIC, ), ), ), ) - } - assertEquals(UnsupportedSigningAlgorithm::class, exception::class) + val exception = result.exceptionOrNull() + + assertTrue(result.isFailure) + assertIs(exception) + assertEquals(exception.signingAlgorithm, AwsSigningAlgorithm.SIGV4_ASYMMETRIC) assertEquals("SIGV4A support is not yet implemented for the default signer.", exception.message) } @Test - fun testUnsupportedSigningAlgorithmNotSigV4aNoException() = runTest { - UnsupportedSigningAlgorithmInterceptor() - .modifyBeforeCompletion( - context( - Result.failure( - UnsupportedSigningAlgorithm( - "SIGV5 support is not yet implemented for the default signer.", - false, + fun testUnsupportedSigningAlgorithmNotSigV4a() = runTest { + val result = + UnsupportedSigningAlgorithmInterceptor() + .modifyBeforeCompletion( + context( + Result.failure( + UnsupportedSigningAlgorithmException( + "SIGV4 support is not yet implemented for the default signer.", + AwsSigningAlgorithm.SIGV4, + ), ), ), - ), - ) + ) + + val exception = result.exceptionOrNull() + + assertTrue(result.isFailure) + assertIs(exception) + assertEquals(exception.signingAlgorithm, AwsSigningAlgorithm.SIGV4) + assertEquals("SIGV4 support is not yet implemented for the default signer.", exception.message) } } diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/SigV4AsymmetricTraitCustomization.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/SigV4AsymmetricTraitCustomization.kt index b1f94ee64ca..0fdabe539dd 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/SigV4AsymmetricTraitCustomization.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/SigV4AsymmetricTraitCustomization.kt @@ -21,6 +21,7 @@ import software.amazon.smithy.model.transform.ModelTransformer * NOTE: Won't add sigV4 trait (services that support sigV4A MUST support sigV4) */ class SigV4AsymmetricTraitCustomization : KotlinIntegration { + // Needs to happen before the `SigV4AsymmetricAuthSchemeIntegration` & `SigV4AuthSchemeIntegration` (-50 & -50) override val order: Byte = -60 override fun enabledForService(model: Model, settings: KotlinSettings): Boolean =