-
Notifications
You must be signed in to change notification settings - Fork 55
chore: add support for SESv2 Sigv4a (not yet used because SESv2 hasn't rolled out support) #1452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import aws.sdk.kotlin.services.sesv2.SesV2Client | ||
| import aws.sdk.kotlin.services.sesv2.sendEmail | ||
| import aws.smithy.kotlin.runtime.auth.awssigning.crt.CrtAwsSigner | ||
| import aws.smithy.kotlin.runtime.client.ProtocolRequestInterceptorContext | ||
| import aws.smithy.kotlin.runtime.http.HttpException | ||
| import aws.smithy.kotlin.runtime.http.auth.SigV4AsymmetricAuthScheme | ||
| import aws.smithy.kotlin.runtime.http.interceptors.HttpInterceptor | ||
| import aws.smithy.kotlin.runtime.http.request.HttpRequest | ||
| import kotlinx.coroutines.runBlocking | ||
| import kotlin.test.Ignore | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertContains | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertFailsWith | ||
| import kotlin.test.assertNotNull | ||
|
|
||
| class Sigv4aTest { | ||
| @Test | ||
| @Ignore // TODO enable once SESv2 model adds endpointId and Sigv4a | ||
|
|
||
| fun testSigv4a() = runBlocking { | ||
| val interceptor = RequestCapturingInterceptor() | ||
|
|
||
| SesV2Client.fromEnvironment { | ||
| retryStrategy { | ||
| maxAttempts = 1 // The call is intended to fail, no sense trying more than once | ||
| } | ||
|
|
||
| interceptors += interceptor | ||
|
|
||
| authSchemes = listOf(SigV4AsymmetricAuthScheme(CrtAwsSigner, "ses")) | ||
| }.use { ses -> | ||
| assertFailsWith<HttpException> { | ||
| ses.sendEmail { | ||
| // endpointId = "bdm3x3zl.n5x" // TODO uncomment | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this TODO be completed in this PR?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we'll need to follow up. There's no public issue to track for doing so. |
||
| } | ||
| } | ||
| } | ||
|
|
||
| assertEquals(1, interceptor.requests.size) | ||
| val request = interceptor.requests.single() | ||
|
|
||
| assertContains("bdm3x3zl.n5x.endpoints.email.amazonaws.com", request.url.host.toString()) // Correct endpoint? | ||
|
||
|
|
||
| val authHeader = assertNotNull( | ||
| request.headers["Authorization"], | ||
| "Missing Authorization header, found: ${request.headers.entries().map { it.key }}", | ||
| ) | ||
| assertContains(authHeader, "AWS4-ECDSA-P256-SHA256") // Verify that request was signed with Sigv4a | ||
| } | ||
| } | ||
|
|
||
| private class RequestCapturingInterceptor : HttpInterceptor { | ||
| val requests = mutableListOf<HttpRequest>() | ||
|
|
||
| override fun readBeforeTransmit(context: ProtocolRequestInterceptorContext<Any, HttpRequest>) { | ||
| requests += context.protocolRequest | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "sdkId": "SESv2", | ||
| "enableEndpointAuthProvider": true | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove blank line