Skip to content

Commit 1ae8ec8

Browse files
committed
chore: add support for SESv2 Sigv4a (not yet used because SESv2 hasn't rolled out support)
1 parent 8487823 commit 1ae8ec8

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/SigV4AsymmetricTraitCustomization.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class SigV4AsymmetricTraitCustomization : KotlinIntegration {
2626
override val order: Byte = -60
2727

2828
// services which support SigV4A but don't model it
29-
private val unmodeledSigV4aServices = listOf("s3", "eventbridge")
29+
private val unmodeledSigV4aServices = listOf("s3", "eventbridge", "sesv2")
3030

3131
override fun enabledForService(model: Model, settings: KotlinSettings): Boolean =
3232
unmodeledSigV4aServices.contains(settings.sdkId.lowercase()) && !model.isTraitApplied(SigV4ATrait::class.java)

services/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ subprojects {
9696
}
9797
}
9898

99+
if (project.name == "sesv2") {
100+
dependencies {
101+
implementation(libs.smithy.kotlin.aws.signing.crt) // needed for E2E test of SigV4a
102+
}
103+
}
104+
99105
// Run the tests with the classpath containing the compile dependencies (including 'main'),
100106
// runtime dependencies, and the outputs of this compilation:
101107
classpath = compileDependencyFiles + runtimeDependencyFiles + output.allOutputs
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import aws.sdk.kotlin.services.sesv2.SesV2Client
7+
import aws.sdk.kotlin.services.sesv2.sendEmail
8+
import aws.smithy.kotlin.runtime.auth.awssigning.crt.CrtAwsSigner
9+
import aws.smithy.kotlin.runtime.client.ProtocolRequestInterceptorContext
10+
import aws.smithy.kotlin.runtime.http.HttpException
11+
import aws.smithy.kotlin.runtime.http.auth.SigV4AsymmetricAuthScheme
12+
import aws.smithy.kotlin.runtime.http.interceptors.HttpInterceptor
13+
import aws.smithy.kotlin.runtime.http.request.HttpRequest
14+
import kotlinx.coroutines.runBlocking
15+
import kotlin.test.Ignore
16+
import kotlin.test.Test
17+
import kotlin.test.assertContains
18+
import kotlin.test.assertEquals
19+
import kotlin.test.assertFailsWith
20+
import kotlin.test.assertNotNull
21+
22+
class Sigv4aTest {
23+
@Test
24+
@Ignore // TODO enable once SESv2 model adds endpointId and Sigv4a
25+
26+
fun testSigv4a() = runBlocking {
27+
val interceptor = RequestCapturingInterceptor()
28+
29+
SesV2Client.fromEnvironment {
30+
retryStrategy {
31+
maxAttempts = 1 // The call is intended to fail, no sense trying more than once
32+
}
33+
34+
interceptors += interceptor
35+
36+
authSchemes = listOf(SigV4AsymmetricAuthScheme(CrtAwsSigner, "ses"))
37+
}.use { ses ->
38+
assertFailsWith<HttpException> {
39+
ses.sendEmail {
40+
// endpointId = "bdm3x3zl.n5x" // TODO uncomment
41+
}
42+
}
43+
}
44+
45+
assertEquals(1, interceptor.requests.size)
46+
val request = interceptor.requests.single()
47+
48+
assertContains("bdm3x3zl.n5x.endpoints.email.amazonaws.com", request.url.host.toString()) // Correct endpoint?
49+
50+
val authHeader = assertNotNull(
51+
request.headers["Authorization"],
52+
"Missing Authorization header, found: ${request.headers.entries().map { it.key }}",
53+
)
54+
assertContains(authHeader, "AWS4-ECDSA-P256-SHA256") // Verify that request was signed with Sigv4a
55+
}
56+
}
57+
58+
private class RequestCapturingInterceptor : HttpInterceptor {
59+
val requests = mutableListOf<HttpRequest>()
60+
61+
override fun readBeforeTransmit(context: ProtocolRequestInterceptorContext<Any, HttpRequest>) {
62+
requests += context.protocolRequest
63+
}
64+
}

services/sesv2/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"sdkId": "SESv2",
3+
"enableEndpointAuthProvider": true
4+
}

0 commit comments

Comments
 (0)