Skip to content

Commit

Permalink
Misc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
0marperez committed Jan 17, 2024
1 parent 84ab837 commit fadf63d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,10 +21,9 @@ import aws.smithy.kotlin.runtime.http.response.HttpResponse
public class UnsupportedSigningAlgorithmInterceptor : HttpInterceptor {
override suspend fun modifyBeforeCompletion(context: ResponseInterceptorContext<Any, Any, HttpRequest?, HttpResponse?>): Result<Any> {
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
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<UnsupportedSigningAlgorithmException>(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<UnsupportedSigningAlgorithmException>(exception)
assertEquals(exception.signingAlgorithm, AwsSigningAlgorithm.SIGV4)
assertEquals("SIGV4 support is not yet implemented for the default signer.", exception.message)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit fadf63d

Please sign in to comment.