Skip to content

Commit

Permalink
Fix aws-sdk-rust#930 (PutSnapshotBlock) (#3126)
Browse files Browse the repository at this point in the history
## Motivation and Context
A regression in 0.56 caused `X-Amz-Content-sha256` to be omitted when
the `UnsignedPayload` trait was present. This re-enables the old
behavior and fixes this operation.
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here -->

## Description
Enable the `x-amz-content-sha256` header whenever the unsigned payload
trait is present.

Old code:
https://github.com/awslabs/smithy-rs/blob/smithy-rs-release-0.54.x/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SigV4SigningDecorator.kt#L168

## Testing
- [x] Manual integration test
- [x] Modeled protocol test that ensures that header is set
<!--- Please describe in detail how you tested your changes -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
  • Loading branch information
rcoh authored Nov 1, 2023
1 parent 722c141 commit 426e77f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ message = "Upgrade `ring` to 0.17.5."
references = ["smithy-rs#3112", "smithy-rs#3116"]
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client" }
author = "jdisanti"

[[aws-sdk-rust]]
message = "Fix aws-sdk-rust#930 (PutSnapshotBlock)"
references = ["smithy-rs#3126", "aws-sdk-rust#930"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "rcoh"
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private class AuthOperationCustomization(private val codegenContext: ClientCodeg
if (authSchemes.containsKey(SigV4Trait.ID)) {
val unsignedPayload = section.operationShape.hasTrait<UnsignedPayloadTrait>()
val doubleUriEncode = unsignedPayload || !disableDoubleEncode(codegenContext.serviceShape)
val contentSha256Header = needsAmzSha256(codegenContext.serviceShape)
val contentSha256Header = needsAmzSha256(codegenContext.serviceShape) || unsignedPayload
val normalizeUrlPath = !disableUriPathNormalization(codegenContext.serviceShape)
rustTemplate(
"""
Expand Down
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
*/
package software.amazon.smithy.rustsdk

import org.junit.jupiter.api.Test
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel

class SigV4AuthDecoratorTest {
private val modelWithSigV4AuthScheme = """
namespace test
use aws.auth#sigv4
use aws.api#service
use aws.protocols#restJson1
use smithy.rules#endpointRuleSet
use aws.auth#unsignedPayload
use smithy.test#httpRequestTests
@auth([sigv4])
@sigv4(name: "dontcare")
@restJson1
@endpointRuleSet({
"version": "1.0",
"rules": [{ "type": "endpoint", "conditions": [], "endpoint": { "url": "https://example.com" } }],
"parameters": {
"endpoint": { "required": true, "type": "string", "builtIn": "SDK::Endpoint" },
}
})
@service(sdkId: "dontcare")
service TestService { version: "2023-01-01", operations: [SomeOperation] }
structure SomeOutput { something: String }
structure SomeInput {
@httpPayload
something: Bytestream
}
@streaming
blob Bytestream
@httpRequestTests([{
id: "unsignedPayload",
protocol: restJson1,
method: "POST",
uri: "/",
params: {
something: "hello"
},
headers: {
"x-amz-content-sha256": "UNSIGNED-PAYLOAD",
},
}])
@unsignedPayload
@http(uri: "/", method: "POST")
operation SomeOperation { input: SomeInput, output: SomeOutput }
""".asSmithyModel()

@Test
fun unsignedPayloadSetsCorrectHeader() {
awsSdkIntegrationTest(modelWithSigV4AuthScheme) { _, _ -> }
}
}

0 comments on commit 426e77f

Please sign in to comment.