diff --git a/aws/rust-runtime/Cargo.lock b/aws/rust-runtime/Cargo.lock index d0de775e906..fc1de1db377 100644 --- a/aws/rust-runtime/Cargo.lock +++ b/aws/rust-runtime/Cargo.lock @@ -149,7 +149,7 @@ dependencies = [ [[package]] name = "aws-runtime" -version = "1.4.3" +version = "1.4.4" dependencies = [ "arbitrary", "aws-credential-types", @@ -303,7 +303,7 @@ dependencies = [ [[package]] name = "aws-smithy-runtime" -version = "1.7.1" +version = "1.7.2" dependencies = [ "aws-smithy-async", "aws-smithy-http", @@ -343,7 +343,7 @@ dependencies = [ [[package]] name = "aws-smithy-types" -version = "1.2.7" +version = "1.2.8" dependencies = [ "base64-simd", "bytes", diff --git a/aws/rust-runtime/aws-config/Cargo.toml b/aws/rust-runtime/aws-config/Cargo.toml index bedb7d0bcc8..a5834759717 100644 --- a/aws/rust-runtime/aws-config/Cargo.toml +++ b/aws/rust-runtime/aws-config/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aws-config" -version = "1.5.7" +version = "1.5.8" authors = [ "AWS Rust SDK Team ", "Russell Cohen ", diff --git a/aws/rust-runtime/aws-inlineable/src/http_request_checksum.rs b/aws/rust-runtime/aws-inlineable/src/http_request_checksum.rs index 0d6be68c9c4..3c3edd49d5a 100644 --- a/aws/rust-runtime/aws-inlineable/src/http_request_checksum.rs +++ b/aws/rust-runtime/aws-inlineable/src/http_request_checksum.rs @@ -192,6 +192,7 @@ where cfg.interceptor_state() .store_append(SmithySdkFeature::FlexibleChecksumsReqCrc32c); } + #[allow(deprecated)] ChecksumAlgorithm::Md5 => { tracing::warn!(more_info = "Unsupported ChecksumAlgorithm MD5 set"); } diff --git a/aws/rust-runtime/aws-inlineable/src/http_response_checksum.rs b/aws/rust-runtime/aws-inlineable/src/http_response_checksum.rs index 4d5fa53f825..6a9ee2466a9 100644 --- a/aws/rust-runtime/aws-inlineable/src/http_response_checksum.rs +++ b/aws/rust-runtime/aws-inlineable/src/http_response_checksum.rs @@ -74,6 +74,25 @@ where layer.store_put(ResponseChecksumInterceptorState { validation_enabled }); cfg.push_layer(layer); + let response_checksum_validation = cfg + .load::() + .unwrap_or(&ResponseChecksumValidation::WhenSupported); + + // Set the user-agent feature metric for the response checksum config + match response_checksum_validation { + ResponseChecksumValidation::WhenSupported => { + cfg.interceptor_state() + .store_append(SmithySdkFeature::FlexibleChecksumsResWhenSupported); + } + ResponseChecksumValidation::WhenRequired => { + cfg.interceptor_state() + .store_append(SmithySdkFeature::FlexibleChecksumsResWhenRequired); + } + unsupported => tracing::warn!( + more_info = "Unsupported value of ResponseChecksumValidation when setting user-agent metrics", + unsupported = ?unsupported), + }; + Ok(()) } @@ -127,21 +146,6 @@ where } } - // Set the user-agent feature metric for the response checksum config - match response_checksum_validation { - ResponseChecksumValidation::WhenSupported => { - cfg.interceptor_state() - .store_append(SmithySdkFeature::FlexibleChecksumsResWhenSupported); - } - ResponseChecksumValidation::WhenRequired => { - cfg.interceptor_state() - .store_append(SmithySdkFeature::FlexibleChecksumsResWhenRequired); - } - unsupported => tracing::warn!( - more_info = "Unsupported value of ResponseChecksumValidation when setting user-agent metrics", - unsupported = ?unsupported), - }; - Ok(()) } } diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/HttpChecksumTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/HttpChecksumTest.kt index feefbb50a61..7c798b79639 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/HttpChecksumTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/HttpChecksumTest.kt @@ -141,6 +141,7 @@ internal class HttpChecksumTest { checksumResponseFailTests.map { createResponseChecksumValidationFailureTest(it, context) }.join("\n") val checksumStreamingRequestTestWritables = streamingRequestTests.map { createStreamingRequestChecksumCalculationTest(it, context) }.join("\n") + val miscTests = createMiscellaneousTests(context) // Shared imports for all test types val testBase = @@ -156,12 +157,36 @@ internal class HttpChecksumTest { use #{SdkBody}; use std::io::Write; use http_body::Body; + use #{HttpRequest}; """, *preludeScope, "Blob" to RuntimeType.smithyTypes(rc).resolve("Blob"), "Region" to AwsRuntimeType.awsTypes(rc).resolve("region::Region"), "pretty_assertions" to CargoDependency.PrettyAssertions.toType(), "SdkBody" to RuntimeType.smithyTypes(rc).resolve("body::SdkBody"), + "HttpRequest" to RuntimeType.smithyRuntimeApi(rc).resolve("client::orchestrator::HttpRequest"), + ) + } + + val uaExtractor = + writable { + rustTemplate( + """ + fn get_sdk_metric_str(req: &HttpRequest) -> &str { + req.headers() + .get("x-amz-user-agent") + .unwrap() + .split(" ") + .filter_map(|sec| { + if sec.starts_with("m/") { + Some(&sec[2..]) + } else { + None + } + }) + .collect::>()[0] + } + """.trimIndent(), ) } @@ -181,6 +206,10 @@ internal class HttpChecksumTest { rustCrate.integrationTest("streaming_request_checksums") { testBase.plus(checksumStreamingRequestTestWritables)() } + + rustCrate.integrationTest("misc_tests") { + testBase.plus(uaExtractor).plus(miscTests)() + } } } @@ -427,6 +456,128 @@ internal class HttpChecksumTest { ) } } + + /** + * Generate miscellaneous tests + */ + private fun createMiscellaneousTests(context: ClientCodegenContext): Writable { + val rc = context.runtimeConfig + val moduleName = context.moduleUseName() + return writable { + rustTemplate( + """ + // The following tests confirm that the user-agent business metrics header is correctly + // set for the request/response checksum config values + ##[::tokio::test] + async fn request_config_ua_required() { + let (http_client, rx) = #{capture_request}(None); + let config = $moduleName::Config::builder() + .region(Region::from_static("doesntmatter")) + .with_test_defaults() + .http_client(http_client) + .request_checksum_calculation( + aws_types::sdk_config::RequestChecksumCalculation::WhenRequired, + ) + .build(); + + let client = $moduleName::Client::from_conf(config); + let _ = client + .some_operation() + .body(Blob::new(b"Doesn't matter")) + .send() + .await; + let request = rx.expect_request(); + + let sdk_metrics = get_sdk_metric_str(&request); + assert!(sdk_metrics.contains("a")); + assert!(!sdk_metrics.contains("Z")); + } + + ##[::tokio::test] + async fn request_config_ua_supported() { + let (http_client, rx) = #{capture_request}(None); + let config = $moduleName::Config::builder() + .region(Region::from_static("doesntmatter")) + .with_test_defaults() + .http_client(http_client) + .build(); + + let client = $moduleName::Client::from_conf(config); + let _ = client + .some_operation() + .body(Blob::new(b"Doesn't matter")) + .send() + .await; + let request = rx.expect_request(); + + let sdk_metrics = get_sdk_metric_str(&request); + assert!(sdk_metrics.contains("Z")); + assert!(!sdk_metrics.contains("a")); + } + + ##[::tokio::test] + async fn response_config_ua_supported() { + let (http_client, rx) = #{capture_request}(Some( + http::Response::builder() + .header("x-amz-checksum-crc32", "i9aeUg==") + .body(SdkBody::from("Hello world")) + .unwrap(), + )); + let config = $moduleName::Config::builder() + .region(Region::from_static("doesntmatter")) + .with_test_defaults() + .http_client(http_client) + .build(); + + let client = $moduleName::Client::from_conf(config); + let _ = client + .some_operation() + .body(Blob::new(b"Doesn't matter")) + .send() + .await; + let request = rx.expect_request(); + + let sdk_metrics = get_sdk_metric_str(&request); + assert!(sdk_metrics.contains("b")); + assert!(!sdk_metrics.contains("c")); + } + + ##[::tokio::test] + async fn response_config_ua_required() { + let (http_client, rx) = #{capture_request}(Some( + http::Response::builder() + .header("x-amz-checksum-crc32", "i9aeUg==") + .body(SdkBody::from("Hello world")) + .unwrap(), + )); + let config = $moduleName::Config::builder() + .region(Region::from_static("doesntmatter")) + .with_test_defaults() + .http_client(http_client) + .response_checksum_validation( + aws_types::sdk_config::ResponseChecksumValidation::WhenRequired, + ) + .build(); + + let client = $moduleName::Client::from_conf(config); + let _ = client + .some_operation() + .body(Blob::new(b"Doesn't matter")) + .send() + .await; + let request = rx.expect_request(); + + let sdk_metrics = get_sdk_metric_str(&request); + assert!(sdk_metrics.contains("c")); + assert!(!sdk_metrics.contains("b")); + } + """, + *preludeScope, + "tokio" to CargoDependency.Tokio.toType(), + "capture_request" to RuntimeType.captureRequest(rc), + ) + } + } } // Classes and data for test definitions diff --git a/rust-runtime/Cargo.lock b/rust-runtime/Cargo.lock index 5acf1f25bf5..82ae4896e74 100644 --- a/rust-runtime/Cargo.lock +++ b/rust-runtime/Cargo.lock @@ -203,7 +203,7 @@ dependencies = [ "aws-smithy-async 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "aws-smithy-eventstream 0.60.5 (registry+https://github.com/rust-lang/crates.io-index)", "aws-smithy-http 0.60.11 (registry+https://github.com/rust-lang/crates.io-index)", - "aws-smithy-runtime 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "aws-smithy-runtime 1.7.1", "aws-smithy-runtime-api 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "aws-smithy-types 1.2.6", "aws-types", @@ -233,7 +233,7 @@ dependencies = [ "aws-smithy-eventstream 0.60.5 (registry+https://github.com/rust-lang/crates.io-index)", "aws-smithy-http 0.60.11 (registry+https://github.com/rust-lang/crates.io-index)", "aws-smithy-json 0.60.7 (registry+https://github.com/rust-lang/crates.io-index)", - "aws-smithy-runtime 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "aws-smithy-runtime 1.7.1", "aws-smithy-runtime-api 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "aws-smithy-types 1.2.6", "aws-smithy-xml 0.60.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -308,7 +308,7 @@ dependencies = [ name = "aws-smithy-cbor" version = "0.60.7" dependencies = [ - "aws-smithy-types 1.2.7", + "aws-smithy-types 1.2.8", "criterion", "minicbor", ] @@ -339,7 +339,7 @@ name = "aws-smithy-checksums" version = "0.62.0" dependencies = [ "aws-smithy-http 0.60.11", - "aws-smithy-types 1.2.7", + "aws-smithy-types 1.2.8", "bytes", "bytes-utils", "crc32c", @@ -366,7 +366,7 @@ name = "aws-smithy-compression" version = "0.0.2" dependencies = [ "aws-smithy-runtime-api 1.7.2", - "aws-smithy-types 1.2.7", + "aws-smithy-types 1.2.8", "bytes", "bytes-utils", "flate2", @@ -387,7 +387,7 @@ name = "aws-smithy-eventstream" version = "0.60.5" dependencies = [ "arbitrary", - "aws-smithy-types 1.2.7", + "aws-smithy-types 1.2.8", "bytes", "bytes-utils", "crc32fast", @@ -410,9 +410,9 @@ name = "aws-smithy-experimental" version = "0.1.4" dependencies = [ "aws-smithy-async 1.2.1", - "aws-smithy-runtime 1.7.1", + "aws-smithy-runtime 1.7.2", "aws-smithy-runtime-api 1.7.2", - "aws-smithy-types 1.2.7", + "aws-smithy-types 1.2.8", "h2 0.4.6", "http 1.1.0", "hyper 1.4.1", @@ -433,7 +433,7 @@ dependencies = [ "async-stream", "aws-smithy-eventstream 0.60.5", "aws-smithy-runtime-api 1.7.2", - "aws-smithy-types 1.2.7", + "aws-smithy-types 1.2.8", "bytes", "bytes-utils", "futures-core", @@ -483,7 +483,7 @@ dependencies = [ "aws-smithy-http 0.60.11", "aws-smithy-json 0.60.7", "aws-smithy-runtime-api 1.7.2", - "aws-smithy-types 1.2.7", + "aws-smithy-types 1.2.8", "aws-smithy-xml 0.60.9", "bytes", "futures-util", @@ -513,7 +513,7 @@ dependencies = [ "aws-smithy-http 0.60.11", "aws-smithy-http-server", "aws-smithy-json 0.60.7", - "aws-smithy-types 1.2.7", + "aws-smithy-types 1.2.8", "aws-smithy-xml 0.60.9", "bytes", "futures", @@ -553,7 +553,7 @@ version = "0.60.3" name = "aws-smithy-json" version = "0.60.7" dependencies = [ - "aws-smithy-types 1.2.7", + "aws-smithy-types 1.2.8", "proptest", "serde_json", ] @@ -573,7 +573,7 @@ version = "0.2.1" dependencies = [ "aws-sdk-s3", "aws-smithy-runtime-api 1.7.2", - "aws-smithy-types 1.2.7", + "aws-smithy-types 1.2.8", "tokio", ] @@ -617,26 +617,25 @@ dependencies = [ name = "aws-smithy-query" version = "0.60.7" dependencies = [ - "aws-smithy-types 1.2.7", + "aws-smithy-types 1.2.8", "urlencoding", ] [[package]] name = "aws-smithy-runtime" version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1ce695746394772e7000b39fe073095db6d45a862d0767dd5ad0ac0d7f8eb87" dependencies = [ - "approx", - "aws-smithy-async 1.2.1", - "aws-smithy-http 0.60.11", - "aws-smithy-protocol-test 0.62.0", - "aws-smithy-runtime-api 1.7.2", - "aws-smithy-types 1.2.7", + "aws-smithy-async 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "aws-smithy-http 0.60.11 (registry+https://github.com/rust-lang/crates.io-index)", + "aws-smithy-protocol-test 0.62.0 (registry+https://github.com/rust-lang/crates.io-index)", + "aws-smithy-runtime-api 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "aws-smithy-types 1.2.6", "bytes", "fastrand", - "futures-util", "h2 0.3.26", "http 0.2.12", - "http 1.1.0", "http-body 0.4.6", "http-body 1.0.1", "httparse", @@ -646,31 +645,30 @@ dependencies = [ "once_cell", "pin-project-lite", "pin-utils", - "pretty_assertions", "rustls 0.21.12", "serde", "serde_json", "tokio", "tracing", "tracing-subscriber", - "tracing-test", ] [[package]] name = "aws-smithy-runtime" -version = "1.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1ce695746394772e7000b39fe073095db6d45a862d0767dd5ad0ac0d7f8eb87" +version = "1.7.2" dependencies = [ - "aws-smithy-async 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "aws-smithy-http 0.60.11 (registry+https://github.com/rust-lang/crates.io-index)", - "aws-smithy-protocol-test 0.62.0 (registry+https://github.com/rust-lang/crates.io-index)", - "aws-smithy-runtime-api 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "aws-smithy-types 1.2.6", + "approx", + "aws-smithy-async 1.2.1", + "aws-smithy-http 0.60.11", + "aws-smithy-protocol-test 0.62.0", + "aws-smithy-runtime-api 1.7.2", + "aws-smithy-types 1.2.8", "bytes", "fastrand", + "futures-util", "h2 0.3.26", "http 0.2.12", + "http 1.1.0", "http-body 0.4.6", "http-body 1.0.1", "httparse", @@ -680,12 +678,14 @@ dependencies = [ "once_cell", "pin-project-lite", "pin-utils", + "pretty_assertions", "rustls 0.21.12", "serde", "serde_json", "tokio", "tracing", "tracing-subscriber", + "tracing-test", ] [[package]] @@ -693,7 +693,7 @@ name = "aws-smithy-runtime-api" version = "1.7.2" dependencies = [ "aws-smithy-async 1.2.1", - "aws-smithy-types 1.2.7", + "aws-smithy-types 1.2.8", "bytes", "http 0.2.12", "http 1.1.0", @@ -749,7 +749,7 @@ dependencies = [ [[package]] name = "aws-smithy-types" -version = "1.2.7" +version = "1.2.8" dependencies = [ "base64 0.13.1", "base64-simd", @@ -786,7 +786,7 @@ name = "aws-smithy-types-convert" version = "0.60.8" dependencies = [ "aws-smithy-async 1.2.1", - "aws-smithy-types 1.2.7", + "aws-smithy-types 1.2.8", "chrono", "futures-core", "time", @@ -798,7 +798,7 @@ version = "0.1.3" dependencies = [ "aws-smithy-http 0.60.11", "aws-smithy-runtime-api 1.7.2", - "aws-smithy-types 1.2.7", + "aws-smithy-types 1.2.8", "bytes", "http 1.1.0", "tracing", @@ -1998,9 +1998,9 @@ dependencies = [ "aws-smithy-compression", "aws-smithy-http 0.60.11", "aws-smithy-json 0.60.7", - "aws-smithy-runtime 1.7.1", + "aws-smithy-runtime 1.7.2", "aws-smithy-runtime-api 1.7.2", - "aws-smithy-types 1.2.7", + "aws-smithy-types 1.2.8", "aws-smithy-xml 0.60.9", "bytes", "fastrand", diff --git a/rust-runtime/aws-smithy-types/Cargo.toml b/rust-runtime/aws-smithy-types/Cargo.toml index 7b52b8b6d8a..3fd9186d0f7 100644 --- a/rust-runtime/aws-smithy-types/Cargo.toml +++ b/rust-runtime/aws-smithy-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aws-smithy-types" -version = "1.2.7" +version = "1.2.8" authors = [ "AWS Rust SDK Team ", "Russell Cohen ",