Skip to content

Commit 733eab7

Browse files
authored
Fix presigned put bug with flex checksums (#3971)
## Motivation and Context <!--- Why is this change required? What problem does it solve? --> <!--- If it fixes an open issue, please link to the issue here --> Fixing bug reported in awslabs/aws-sdk-rust#1240 (comment) ## Description <!--- Describe your changes in detail --> ## Testing <!--- 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. --> Updated presigning integ tests to account for behavior specified in SEP, added new test for the user provided checksum case ## Checklist <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [x] For changes to the AWS SDK, generated SDK code, or SDK runtime crates, I have created a changelog entry Markdown file in the `.changelog` directory, specifying "aws-sdk-rust" in the `applies_to` key. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent 41ff31b commit 733eab7

File tree

5 files changed

+36312
-34111
lines changed

5 files changed

+36312
-34111
lines changed

.changelog/presigning-bugfix.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
applies_to: ["aws-sdk-rust"]
3+
authors: ["landonxjames"]
4+
references: ["aws-sdk-rust#1240"]
5+
breaking: false
6+
new_feature: false
7+
bug_fix: true
8+
---
9+
10+
Fix bug with presigned requests introduced by new flexibile checksums functionality

aws/rust-runtime/aws-inlineable/src/http_request_checksum.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -193,24 +193,22 @@ where
193193
.load::<RequestChecksumCalculation>()
194194
.unwrap_or(&RequestChecksumCalculation::WhenSupported);
195195

196-
// Determine if we actually calculate the checksum. If the user setting is WhenSupported (the default)
197-
// we always calculate it (because this interceptor isn't added if it isn't supported). If it is
198-
// WhenRequired we only calculate it if the checksum is marked required on the trait.
199-
let calculate_checksum = match request_checksum_calculation {
200-
RequestChecksumCalculation::WhenRequired => request_checksum_required,
201-
RequestChecksumCalculation::WhenSupported => true,
196+
// Need to know if this is a presigned req because we do not calculate checksums for those.
197+
let is_presigned_req = cfg.load::<PresigningMarker>().is_some();
198+
199+
// Determine if we actually calculate the checksum. If this is a presigned request we do not
200+
// If the user setting is WhenSupported (the default) we always calculate it (because this interceptor
201+
// isn't added if it isn't supported). If it is WhenRequired we only calculate it if the checksum
202+
// is marked required on the trait.
203+
let calculate_checksum = match (request_checksum_calculation, is_presigned_req) {
204+
(_, true) => false,
205+
(RequestChecksumCalculation::WhenRequired, false) => request_checksum_required,
206+
(RequestChecksumCalculation::WhenSupported, false) => true,
202207
_ => true,
203208
};
204209

205210
// Calculate the checksum if necessary
206211
if calculate_checksum {
207-
let is_presigned_req = cfg.load::<PresigningMarker>().is_some();
208-
209-
// If this is a presigned request and the user has not set a checksum we short circuit
210-
if is_presigned_req && checksum_algorithm.is_none() {
211-
return Ok(());
212-
}
213-
214212
// If a checksum override is set in the ConfigBag we use that instead (currently only used by S3Express)
215213
// If we have made it this far without a checksum being set we set the default (currently Crc32)
216214
let checksum_algorithm =

aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumDecorator.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ private fun HttpChecksumTrait.checksumAlgorithmToStr(
119119
// Checksums are required but a user can't set one, so we set crc32 for them
120120
rust("""let checksum_algorithm = Some("crc32");""")
121121
} else {
122-
// Use checksum algo set by user or crc32 if one has not been set
123-
rust("""let checksum_algorithm = checksum_algorithm.map(|algorithm| algorithm.as_str()).or(Some("crc32"));""")
122+
// Use checksum algo set by user
123+
rust("""let checksum_algorithm = checksum_algorithm.map(|algorithm| algorithm.as_str());""")
124124
}
125125

126126
// If a request checksum is not required and there's no way to set one, do nothing
@@ -205,17 +205,22 @@ class HttpRequestChecksumCustomization(
205205
// From the httpChecksum trait
206206
let http_checksum_required = $requestChecksumRequired;
207207
208+
let is_presigned_req = cfg.load::<#{PresigningMarker}>().is_some();
209+
210+
// If the request is presigned we do not set a default.
208211
// If the RequestChecksumCalculation is WhenSupported and the user has not set a checksum value or algo
209212
// we default to Crc32. If it is WhenRequired and a checksum is required by the trait and the user has not
210213
// set a checksum value or algo we also set the default. In all other cases we do nothing.
211214
match (
212215
request_checksum_calculation,
213216
http_checksum_required,
214217
user_set_checksum_value,
215-
user_set_checksum_algo
218+
user_set_checksum_algo,
219+
is_presigned_req,
216220
) {
217-
(#{RequestChecksumCalculation}::WhenSupported, _, false, false)
218-
| (#{RequestChecksumCalculation}::WhenRequired, true, false, false) => {
221+
(_, _, _, _, true) => {}
222+
(#{RequestChecksumCalculation}::WhenSupported, _, false, false, _)
223+
| (#{RequestChecksumCalculation}::WhenRequired, true, false, false, _) => {
219224
request.headers_mut().insert(${requestAlgoHeader.dq()}, "CRC32");
220225
}
221226
_ => {},
@@ -254,6 +259,7 @@ class HttpRequestChecksumCustomization(
254259
codegenContext.model,
255260
),
256261
),
262+
"PresigningMarker" to AwsRuntimeType.presigning().resolve("PresigningMarker"),
257263
)
258264
}
259265
}

0 commit comments

Comments
 (0)