|
| 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.runtime.http.interceptors |
| 6 | + |
| 7 | +import aws.smithy.kotlin.runtime.auth.awssigning.AwsSigningAlgorithm |
| 8 | +import aws.smithy.kotlin.runtime.auth.awssigning.UnsupportedSigningAlgorithmException |
| 9 | +import aws.smithy.kotlin.runtime.client.ResponseInterceptorContext |
| 10 | +import aws.smithy.kotlin.runtime.client.SdkClientOption |
| 11 | +import aws.smithy.kotlin.runtime.http.request.HttpRequest |
| 12 | +import aws.smithy.kotlin.runtime.http.response.HttpResponse |
| 13 | +import aws.smithy.kotlin.runtime.operation.ExecutionContext |
| 14 | +import kotlinx.coroutines.test.runTest |
| 15 | +import kotlin.test.Test |
| 16 | +import kotlin.test.assertEquals |
| 17 | +import kotlin.test.assertIs |
| 18 | +import kotlin.test.assertTrue |
| 19 | + |
| 20 | +class UnsupportedSigningAlgorithmInterceptorTest { |
| 21 | + @Test |
| 22 | + fun testUnsupportedSigningAlgorithmSigV4a() = runTest { |
| 23 | + val result = |
| 24 | + UnsupportedSigningAlgorithmInterceptor() |
| 25 | + .modifyBeforeCompletion( |
| 26 | + context( |
| 27 | + Result.failure( |
| 28 | + UnsupportedSigningAlgorithmException( |
| 29 | + "SIGV4A support is not yet implemented for the default signer.", |
| 30 | + AwsSigningAlgorithm.SIGV4_ASYMMETRIC, |
| 31 | + ), |
| 32 | + ), |
| 33 | + ), |
| 34 | + ) |
| 35 | + |
| 36 | + val exception = result.exceptionOrNull() |
| 37 | + |
| 38 | + assertTrue(result.isFailure) |
| 39 | + assertIs<UnsupportedSigningAlgorithmException>(exception) |
| 40 | + assertEquals(exception.signingAlgorithm, AwsSigningAlgorithm.SIGV4_ASYMMETRIC) |
| 41 | + assertEquals( |
| 42 | + "SIGV4A support is not yet implemented for the default signer. For more information on how to enable it with the CRT signer, please refer to: https://a.co/3sf8533", |
| 43 | + exception.message, |
| 44 | + ) |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + fun testUnsupportedSigningAlgorithmNotSigV4a() = runTest { |
| 49 | + val result = |
| 50 | + UnsupportedSigningAlgorithmInterceptor() |
| 51 | + .modifyBeforeCompletion( |
| 52 | + context( |
| 53 | + Result.failure( |
| 54 | + UnsupportedSigningAlgorithmException( |
| 55 | + "SIGV4 support is not yet implemented for the default signer.", |
| 56 | + AwsSigningAlgorithm.SIGV4, |
| 57 | + ), |
| 58 | + ), |
| 59 | + ), |
| 60 | + ) |
| 61 | + |
| 62 | + val exception = result.exceptionOrNull() |
| 63 | + |
| 64 | + assertTrue(result.isFailure) |
| 65 | + assertIs<UnsupportedSigningAlgorithmException>(exception) |
| 66 | + assertEquals(exception.signingAlgorithm, AwsSigningAlgorithm.SIGV4) |
| 67 | + assertEquals("SIGV4 support is not yet implemented for the default signer.", exception.message) |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +private fun context(response: Result<Any>) = |
| 72 | + object : ResponseInterceptorContext<Any, Any, HttpRequest?, HttpResponse?> { |
| 73 | + override val executionContext = ExecutionContext.build { attributes[SdkClientOption.OperationName] = "test" } |
| 74 | + override val request = Unit |
| 75 | + override val response = response |
| 76 | + override val protocolRequest = HttpRequest { } |
| 77 | + override val protocolResponse = null |
| 78 | + } |
0 commit comments