From f9d56464e0c73efdeafb833f59101b946c1f3e5b Mon Sep 17 00:00:00 2001 From: Saito Date: Fri, 21 Oct 2022 10:05:40 -0500 Subject: [PATCH 1/3] Add test for excluded headers list This commit adds a test for the functionality added in #1381. Technically, there was an existing test `presigning_header_exclusion` that exercised the said functionality but it only covered the behavior partially, i.e. only a case where the `excluded_headers` field in `SigningSettings` contained just `user-agent`. The new test will randomly add headers to `excluded_headers` and verify the functionality works as expected. --- .../src/http_request/canonical_request.rs | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/aws/rust-runtime/aws-sigv4/src/http_request/canonical_request.rs b/aws/rust-runtime/aws-sigv4/src/http_request/canonical_request.rs index 8bd0e0b931..75413bfd5a 100644 --- a/aws/rust-runtime/aws-sigv4/src/http_request/canonical_request.rs +++ b/aws/rust-runtime/aws-sigv4/src/http_request/canonical_request.rs @@ -507,10 +507,10 @@ mod tests { }; use crate::http_request::{SignatureLocation, SigningParams}; use crate::sign::sha256_hex_string; - use http::HeaderValue; use http::Uri; + use http::{header::HeaderName, HeaderValue}; use pretty_assertions::assert_eq; - use proptest::proptest; + use proptest::{prelude::*, proptest}; use std::time::Duration; fn signing_params(settings: SigningSettings) -> SigningParams<'static> { @@ -707,6 +707,47 @@ mod tests { ); } + proptest! { + #[test] + fn presigning_header_exclusion_with_explicit_exclusion_list_specified( + excluded_headers in prop::collection::vec("[a-z]{1,20}", 1..10), + ) { + let mut request_builder = http::Request::builder() + .uri("https://some-endpoint.some-region.amazonaws.com") + .header("content-type", "application/xml") + .header("content-length", "0"); + for key in &excluded_headers { + request_builder = request_builder.header(key, "value"); + } + let request = request_builder.body("").unwrap(); + + let request = SignableRequest::from(&request); + + let settings = SigningSettings { + signature_location: SignatureLocation::QueryParams, + expires_in: Some(Duration::from_secs(30)), + excluded_headers: Some( + excluded_headers + .into_iter() + .map(|header_string| { + HeaderName::from_static(Box::leak(header_string.into_boxed_str())) + }) + .collect(), + ), + ..Default::default() + }; + + let signing_params = signing_params(settings); + let canonical = CanonicalRequest::from(&request, &signing_params).unwrap(); + + let values = canonical.values.into_query_params().unwrap(); + assert_eq!( + "content-length;content-type;host", + values.signed_headers.as_str() + ); + } + } + #[test] fn test_trim_all_handles_spaces_correctly() { // Can't compare a byte array to a Cow so we convert both to slices before comparing From ef8f73492e620a39e181c4210e08b0c5b199ac2e Mon Sep 17 00:00:00 2001 From: Saito Date: Fri, 21 Oct 2022 10:21:24 -0500 Subject: [PATCH 2/3] Update CHANGELOG.next.toml --- CHANGELOG.next.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 3715ae298c..75e9d4f42d 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -192,3 +192,9 @@ message = "Fix aws-sigv4 canonical request formatting fallibility." references = ["smithy-rs#1656"] meta = { "breaking" = false, "tada" = false, "bug" = true } author = "ysaito1001" + +[[smithy-rs]] +message = "Add test to exercise excluded headers in aws-sigv4." +references = ["smithy-rs#1890"] +meta = { "breaking" = false, "tada" = false, "bug" = false } +author = "ysaito1001" From af3df8a99d991044af91678112ba02b5c473e187 Mon Sep 17 00:00:00 2001 From: ysaito1001 Date: Fri, 21 Oct 2022 12:37:52 -0500 Subject: [PATCH 3/3] Update CHANGELOG.next.toml Co-authored-by: John DiSanti --- CHANGELOG.next.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 75e9d4f42d..b09f7fb805 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -193,7 +193,7 @@ references = ["smithy-rs#1656"] meta = { "breaking" = false, "tada" = false, "bug" = true } author = "ysaito1001" -[[smithy-rs]] +[[aws-sdk-rust]] message = "Add test to exercise excluded headers in aws-sigv4." references = ["smithy-rs#1890"] meta = { "breaking" = false, "tada" = false, "bug" = false }