From 60b6a5238a10f010ec4914cf2b88a7f709497bd4 Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Wed, 11 Oct 2023 16:19:59 -0400 Subject: [PATCH] AWS Integration tests passing --- .../aws-config/src/sts/assume_role.rs | 4 +- .../dynamodb/tests/movies.rs | 3 +- .../kms/tests/integration.rs | 3 +- .../qldbsession/tests/integration.rs | 2 + .../integration-tests/s3/tests/checksums.rs | 2 + .../integration-tests/s3/tests/endpoints.rs | 20 +++++---- .../s3/tests/ignore-invalid-xml-body-root.rs | 2 + .../s3/tests/naughty-string-metadata.rs | 2 + .../integration-tests/s3/tests/presigning.rs | 4 +- .../query-strings-are-correctly-encoded.rs | 2 + .../integration-tests/s3/tests/signing-it.rs | 2 + .../integration-tests/s3control/Cargo.toml | 4 ++ .../src/client/orchestrator/endpoints.rs | 45 ++++++++++++++++--- 13 files changed, 76 insertions(+), 19 deletions(-) diff --git a/aws/rust-runtime/aws-config/src/sts/assume_role.rs b/aws/rust-runtime/aws-config/src/sts/assume_role.rs index 6372581b77c..84c60c9a963 100644 --- a/aws/rust-runtime/aws-config/src/sts/assume_role.rs +++ b/aws/rust-runtime/aws-config/src/sts/assume_role.rs @@ -383,7 +383,7 @@ mod test { let req = request.expect_request(); let str_body = std::str::from_utf8(req.body().bytes().unwrap()).unwrap(); assert!(str_body.contains("1234567"), "{}", str_body); - assert_eq!(req.uri(), "https://sts.us-east-1.amazonaws.com"); + assert_eq!(req.uri(), "https://sts.us-east-1.amazonaws.com/"); } #[tokio::test] @@ -411,7 +411,7 @@ mod test { .await; let _ = dbg!(provider.provide_credentials().await); let req = request.expect_request(); - assert_eq!(req.uri(), "https://sts.us-west-2.amazonaws.com"); + assert_eq!(req.uri(), "https://sts.us-west-2.amazonaws.com/"); } /// Test that `build()` where no provider is passed still works diff --git a/aws/sdk/integration-tests/dynamodb/tests/movies.rs b/aws/sdk/integration-tests/dynamodb/tests/movies.rs index 7a444c468fd..28801001065 100644 --- a/aws/sdk/integration-tests/dynamodb/tests/movies.rs +++ b/aws/sdk/integration-tests/dynamodb/tests/movies.rs @@ -14,6 +14,7 @@ use dynamodb::types::{ ScalarAttributeType, TableStatus, }; use dynamodb::Client; +use http::header::AUTHORIZATION; use http::Uri; use serde_json::Value; use std::collections::HashMap; @@ -186,7 +187,7 @@ async fn movies_it() { ] ); - http_client.assert_requests_match(&["AUTHORIZATION", "x-amz-date"]); + http_client.assert_requests_match(&[AUTHORIZATION.as_str(), "x-amz-date"]); } /// Test connection for the movies IT diff --git a/aws/sdk/integration-tests/kms/tests/integration.rs b/aws/sdk/integration-tests/kms/tests/integration.rs index 3a7bd611044..624dfd9d396 100644 --- a/aws/sdk/integration-tests/kms/tests/integration.rs +++ b/aws/sdk/integration-tests/kms/tests/integration.rs @@ -8,6 +8,7 @@ use aws_sdk_kms::operation::RequestId; use aws_smithy_http::body::SdkBody; use aws_smithy_http::result::SdkError; use aws_smithy_runtime::client::http::test_util::{ReplayEvent, StaticReplayClient}; +use http::header::AUTHORIZATION; use http::Uri; use kms::config::{Config, Credentials, Region}; @@ -165,5 +166,5 @@ async fn generate_random_keystore_not_found() { inner.request_id(), Some("bfe81a0a-9a08-4e71-9910-cdb5ab6ea3b6") ); - http_client.assert_requests_match(&["AUTHORIZATION"]); + http_client.assert_requests_match(&[AUTHORIZATION.as_str()]); } diff --git a/aws/sdk/integration-tests/qldbsession/tests/integration.rs b/aws/sdk/integration-tests/qldbsession/tests/integration.rs index 0c167712d75..61f0a7e5395 100644 --- a/aws/sdk/integration-tests/qldbsession/tests/integration.rs +++ b/aws/sdk/integration-tests/qldbsession/tests/integration.rs @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#![cfg(feature = "test-util")] + use aws_sdk_qldbsession::config::{Config, Credentials, Region}; use aws_sdk_qldbsession::types::StartSessionRequest; use aws_sdk_qldbsession::Client; diff --git a/aws/sdk/integration-tests/s3/tests/checksums.rs b/aws/sdk/integration-tests/s3/tests/checksums.rs index 936afc50eac..b7b3d5be8a3 100644 --- a/aws/sdk/integration-tests/s3/tests/checksums.rs +++ b/aws/sdk/integration-tests/s3/tests/checksums.rs @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#![cfg(feature = "test-util")] + use aws_config::SdkConfig; use aws_credential_types::provider::SharedCredentialsProvider; use aws_sdk_s3::config::{Credentials, Region}; diff --git a/aws/sdk/integration-tests/s3/tests/endpoints.rs b/aws/sdk/integration-tests/s3/tests/endpoints.rs index 9d35449ac50..3e9eb79b06c 100644 --- a/aws/sdk/integration-tests/s3/tests/endpoints.rs +++ b/aws/sdk/integration-tests/s3/tests/endpoints.rs @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#![cfg(feature = "test-util")] + use aws_credential_types::provider::SharedCredentialsProvider; use aws_sdk_s3::config::Builder; use aws_sdk_s3::config::{Credentials, Region}; @@ -136,14 +138,16 @@ async fn s3_object_lambda_no_cross_region() { #[tokio::test] async fn write_get_object_response() { let (req, client) = test_client(|b| b); - let _write = client - .write_get_object_response() - .request_route("req-route") - .request_token("token") - .status_code(200) - .body(vec![1, 2, 3].into()) - .send() - .await; + let _write = dbg!( + client + .write_get_object_response() + .request_route("req-route") + .request_token("token") + .status_code(200) + .body(vec![1, 2, 3].into()) + .send() + .await + ); let captured_request = req.expect_request(); assert_eq!( diff --git a/aws/sdk/integration-tests/s3/tests/ignore-invalid-xml-body-root.rs b/aws/sdk/integration-tests/s3/tests/ignore-invalid-xml-body-root.rs index 8487cfdca09..3b8034a6739 100644 --- a/aws/sdk/integration-tests/s3/tests/ignore-invalid-xml-body-root.rs +++ b/aws/sdk/integration-tests/s3/tests/ignore-invalid-xml-body-root.rs @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#![cfg(feature = "test-util")] + use aws_credential_types::provider::SharedCredentialsProvider; use aws_sdk_s3::Config; use aws_sdk_s3::{config::Credentials, config::Region, types::ObjectAttributes, Client}; diff --git a/aws/sdk/integration-tests/s3/tests/naughty-string-metadata.rs b/aws/sdk/integration-tests/s3/tests/naughty-string-metadata.rs index ad3d5fcfa4b..3b6bd970029 100644 --- a/aws/sdk/integration-tests/s3/tests/naughty-string-metadata.rs +++ b/aws/sdk/integration-tests/s3/tests/naughty-string-metadata.rs @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#![cfg(feature = "test-util")] + use aws_credential_types::provider::SharedCredentialsProvider; use aws_sdk_s3::Config; use aws_sdk_s3::{config::Credentials, config::Region, primitives::ByteStream, Client}; diff --git a/aws/sdk/integration-tests/s3/tests/presigning.rs b/aws/sdk/integration-tests/s3/tests/presigning.rs index 1ac08ca242e..b97c9480fb2 100644 --- a/aws/sdk/integration-tests/s3/tests/presigning.rs +++ b/aws/sdk/integration-tests/s3/tests/presigning.rs @@ -109,7 +109,7 @@ async fn test_presigning_with_payload_headers() { .put_object() .bucket("test-bucket") .key("test-key") - .content_length(123456) + .content_length(12345) .content_type("application/x-test") }) .await; @@ -145,7 +145,7 @@ async fn test_presigning_with_payload_headers() { presigned.headers().get(CONTENT_TYPE), Some("application/x-test") ); - assert_eq!(presigned.headers().get(CONTENT_LENGTH), Some("123456")); + assert_eq!(presigned.headers().get(CONTENT_LENGTH), Some("12345")); assert_eq!(presigned.headers().iter().count(), 2); } diff --git a/aws/sdk/integration-tests/s3/tests/query-strings-are-correctly-encoded.rs b/aws/sdk/integration-tests/s3/tests/query-strings-are-correctly-encoded.rs index d6d308f2609..528f9f1bbdf 100644 --- a/aws/sdk/integration-tests/s3/tests/query-strings-are-correctly-encoded.rs +++ b/aws/sdk/integration-tests/s3/tests/query-strings-are-correctly-encoded.rs @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#![cfg(feature = "test-util")] + use aws_credential_types::provider::SharedCredentialsProvider; use aws_sdk_s3::config::{Credentials, Region}; use aws_sdk_s3::{Client, Config}; diff --git a/aws/sdk/integration-tests/s3/tests/signing-it.rs b/aws/sdk/integration-tests/s3/tests/signing-it.rs index 22dcf7c3d9a..d690e31cf3f 100644 --- a/aws/sdk/integration-tests/s3/tests/signing-it.rs +++ b/aws/sdk/integration-tests/s3/tests/signing-it.rs @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#![cfg(feature = "test-util")] + use aws_credential_types::provider::SharedCredentialsProvider; use aws_sdk_s3::config::{Credentials, Region}; use aws_sdk_s3::{Client, Config}; diff --git a/aws/sdk/integration-tests/s3control/Cargo.toml b/aws/sdk/integration-tests/s3control/Cargo.toml index bd1923c1419..cf1fd7f23b4 100644 --- a/aws/sdk/integration-tests/s3control/Cargo.toml +++ b/aws/sdk/integration-tests/s3control/Cargo.toml @@ -27,3 +27,7 @@ http = "0.2.0" serde_json = "1.0.0" tokio = { version = "1.23.1", features = ["full", "test-util"] } tracing-subscriber = { version = "0.3.15", features = ["env-filter"] } + +[[test]] +name = "signing-it" +required-features = ["test-util"] diff --git a/rust-runtime/aws-smithy-runtime/src/client/orchestrator/endpoints.rs b/rust-runtime/aws-smithy-runtime/src/client/orchestrator/endpoints.rs index f749d09a649..5434c54aaad 100644 --- a/rust-runtime/aws-smithy-runtime/src/client/orchestrator/endpoints.rs +++ b/rust-runtime/aws-smithy-runtime/src/client/orchestrator/endpoints.rs @@ -15,7 +15,9 @@ use aws_smithy_runtime_api::client::runtime_components::RuntimeComponents; use aws_smithy_types::config_bag::{ConfigBag, Storable, StoreReplace}; use aws_smithy_types::endpoint::Endpoint; use http::header::HeaderName; -use http::HeaderValue; +use http::uri::PathAndQuery; +use http::{HeaderValue, Uri}; +use std::borrow::Cow; use std::fmt::Debug; use std::str::FromStr; use tracing::trace; @@ -141,10 +143,23 @@ fn apply_endpoint( endpoint: &Endpoint, endpoint_prefix: Option<&EndpointPrefix>, ) -> Result<(), BoxError> { - let prefix = endpoint_prefix - .map(EndpointPrefix::as_str) - .unwrap_or_default(); - let endpoint_url = format!("{}{}", prefix, endpoint.url()); + let endpoint_url = match endpoint_prefix { + None => Cow::Borrowed(endpoint.url()), + Some(prefix) => { + let parsed = endpoint.url().parse::()?; + let scheme = parsed.scheme_str().unwrap_or_default(); + let prefix = prefix.as_str(); + let authority = parsed + .authority() + .map(|auth| auth.as_str()) + .unwrap_or_default(); + let path_and_query = parsed + .path_and_query() + .map(PathAndQuery::as_str) + .unwrap_or_default(); + Cow::Owned(format!("{scheme}://{prefix}{authority}{path_and_query}")) + } + }; request .uri_mut() @@ -174,3 +189,23 @@ fn apply_endpoint( } Ok(()) } + +#[cfg(test)] +mod test { + use aws_smithy_http::endpoint::EndpointPrefix; + use aws_smithy_runtime_api::client::orchestrator::HttpRequest; + use aws_smithy_types::endpoint::Endpoint; + + #[test] + fn test_apply_endpoint() { + let mut req = HttpRequest::empty(); + req.set_uri("/foo?bar=1").unwrap(); + let endpoint = Endpoint::builder().url("https://s3.amazon.com").build(); + let prefix = EndpointPrefix::new("prefix.subdomain.").unwrap(); + super::apply_endpoint(&mut req, &endpoint, Some(&prefix)).expect("should succeed"); + assert_eq!( + req.uri(), + "https://prefix.subdomain.s3.amazon.com/foo?bar=1" + ); + } +}