diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCustomizableOperationDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCustomizableOperationDecorator.kt deleted file mode 100644 index 878c4a851f..0000000000 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCustomizableOperationDecorator.kt +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.rustsdk - -import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule -import software.amazon.smithy.rust.codegen.client.smithy.generators.client.CustomizableOperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.generators.client.CustomizableOperationSection -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.writable -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType - -class CustomizableOperationTestHelpers(runtimeConfig: RuntimeConfig) : - CustomizableOperationCustomization() { - private val codegenScope = arrayOf( - *RuntimeType.preludeScope, - "AwsUserAgent" to AwsRuntimeType.awsHttp(runtimeConfig).resolve("user_agent::AwsUserAgent"), - "BeforeTransmitInterceptorContextMut" to RuntimeType.beforeTransmitInterceptorContextMut(runtimeConfig), - "ConfigBag" to RuntimeType.configBag(runtimeConfig), - "http" to CargoDependency.Http.toType(), - "InterceptorContext" to RuntimeType.interceptorContext(runtimeConfig), - "RuntimeComponentsBuilder" to RuntimeType.runtimeComponentsBuilder(runtimeConfig), - "SharedInterceptor" to RuntimeType.smithyRuntimeApi(runtimeConfig).resolve("client::interceptors::SharedInterceptor"), - "StaticRuntimePlugin" to RuntimeType.smithyRuntimeApi(runtimeConfig).resolve("client::runtime_plugin::StaticRuntimePlugin"), - "StaticTimeSource" to CargoDependency.smithyAsync(runtimeConfig).toType().resolve("time::StaticTimeSource"), - "TestParamsSetterInterceptor" to testParamsSetterInterceptor(), - ) - - // TODO(enableNewSmithyRuntimeCleanup): Delete this once test helpers on `CustomizableOperation` have been removed - private fun testParamsSetterInterceptor(): RuntimeType = RuntimeType.forInlineFun("TestParamsSetterInterceptor", ClientRustModule.Client.customize) { - rustTemplate( - """ - mod test_params_setter_interceptor { - use aws_smithy_runtime_api::box_error::BoxError; - use aws_smithy_runtime_api::client::interceptors::context::BeforeTransmitInterceptorContextMut; - use aws_smithy_runtime_api::client::interceptors::Interceptor; - use aws_smithy_runtime_api::client::runtime_components::RuntimeComponents; - use aws_smithy_types::config_bag::ConfigBag; - use std::fmt; - - pub(super) struct TestParamsSetterInterceptor { f: F } - - impl fmt::Debug for TestParamsSetterInterceptor { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "TestParamsSetterInterceptor") - } - } - - impl TestParamsSetterInterceptor { - pub fn new(f: F) -> Self { Self { f } } - } - - impl Interceptor for TestParamsSetterInterceptor - where - F: Fn(&mut BeforeTransmitInterceptorContextMut<'_>, &mut ConfigBag) + Send + Sync + 'static, - { - fn name(&self) -> &'static str { - "TestParamsSetterInterceptor" - } - - fn modify_before_signing( - &self, - context: &mut BeforeTransmitInterceptorContextMut<'_>, - _runtime_components: &RuntimeComponents, - cfg: &mut ConfigBag, - ) -> Result<(), BoxError> { - (self.f)(context, cfg); - Ok(()) - } - } - } - use test_params_setter_interceptor::TestParamsSetterInterceptor; - """, - *codegenScope, - ) - } - - override fun section(section: CustomizableOperationSection): Writable = - writable { - if (section is CustomizableOperationSection.CustomizableOperationImpl) { - // TODO(enableNewSmithyRuntimeCleanup): Delete these utilities - rustTemplate( - """ - ##[doc(hidden)] - // This is a temporary method for testing. NEVER use it in production - pub fn request_time_for_tests(self, request_time: ::std::time::SystemTime) -> Self { - self.runtime_plugin( - #{StaticRuntimePlugin}::new() - .with_runtime_components( - #{RuntimeComponentsBuilder}::new("request_time_for_tests") - .with_time_source(Some(#{StaticTimeSource}::new(request_time))) - ) - ) - } - - ##[doc(hidden)] - // This is a temporary method for testing. NEVER use it in production - pub fn user_agent_for_tests(mut self) -> Self { - let interceptor = #{TestParamsSetterInterceptor}::new(|context: &mut #{BeforeTransmitInterceptorContextMut}<'_>, _: &mut #{ConfigBag}| { - let headers = context.request_mut().headers_mut(); - let user_agent = #{AwsUserAgent}::for_tests(); - headers.insert( - #{http}::header::USER_AGENT, - #{http}::HeaderValue::try_from(user_agent.ua_header()).unwrap(), - ); - headers.insert( - #{http}::HeaderName::from_static("x-amz-user-agent"), - #{http}::HeaderValue::try_from(user_agent.aws_ua_header()).unwrap(), - ); - }); - self.interceptors.push(#{SharedInterceptor}::new(interceptor)); - self - } - - ##[doc(hidden)] - // This is a temporary method for testing. NEVER use it in production - pub fn remove_invocation_id_for_tests(mut self) -> Self { - let interceptor = #{TestParamsSetterInterceptor}::new(|context: &mut #{BeforeTransmitInterceptorContextMut}<'_>, _: &mut #{ConfigBag}| { - context.request_mut().headers_mut().remove("amz-sdk-invocation-id"); - }); - self.interceptors.push(#{SharedInterceptor}::new(interceptor)); - self - } - """, - *codegenScope, - ) - } - } -} diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt index 3a1e6e6fbe..93fb926ffe 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt @@ -54,7 +54,7 @@ class AwsFluentClientDecorator : ClientCodegenDecorator { AwsPresignedFluentBuilderMethod(codegenContext), AwsFluentClientDocs(codegenContext), ), - ).render(rustCrate, listOf(CustomizableOperationTestHelpers(runtimeConfig))) + ).render(rustCrate, emptyList()) rustCrate.withModule(ClientRustModule.client) { AwsFluentClientExtensions(codegenContext, types).render(this) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/UserAgentDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/UserAgentDecorator.kt index 5d1ee8cb91..2619b224fc 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/UserAgentDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/UserAgentDecorator.kt @@ -105,6 +105,7 @@ class UserAgentDecorator : ClientCodegenDecorator { private val codegenScope = arrayOf( *preludeScope, "AppName" to AwsRuntimeType.awsTypes(runtimeConfig).resolve("app_name::AppName"), + "AwsUserAgent" to AwsRuntimeType.awsHttp(runtimeConfig).resolve("user_agent::AwsUserAgent"), ) override fun section(section: ServiceConfig): Writable = @@ -158,6 +159,15 @@ class UserAgentDecorator : ClientCodegenDecorator { ) } + is ServiceConfig.DefaultForTests -> writable { + rustTemplate( + """ + self.config.store_put(#{AwsUserAgent}::for_tests()); + """, + *codegenScope, + ) + } + else -> emptySection } } diff --git a/aws/sdk/integration-tests/kms/Cargo.toml b/aws/sdk/integration-tests/kms/Cargo.toml index a26e2dd672..0e84f1a0ec 100644 --- a/aws/sdk/integration-tests/kms/Cargo.toml +++ b/aws/sdk/integration-tests/kms/Cargo.toml @@ -10,11 +10,15 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +default = ["test-util"] +test-util = [] + [dev-dependencies] aws-credential-types = { path = "../../build/aws-sdk/sdk/aws-credential-types", features = ["test-util"] } aws-http = { path = "../../build/aws-sdk/sdk/aws-http" } aws-runtime = { path = "../../build/aws-sdk/sdk/aws-runtime" } -aws-sdk-kms = { path = "../../build/aws-sdk/sdk/kms" } +aws-sdk-kms = { path = "../../build/aws-sdk/sdk/kms", features = ["test-util"] } aws-smithy-async = { path = "../../build/aws-sdk/sdk/aws-smithy-async", features = ["test-util"] } aws-smithy-http = { path = "../../build/aws-sdk/sdk/aws-smithy-http" } aws-smithy-types = { path = "../../build/aws-sdk/sdk/aws-smithy-types" } diff --git a/aws/sdk/integration-tests/kms/tests/integration.rs b/aws/sdk/integration-tests/kms/tests/integration.rs index e02e32ab52..96c862c0e6 100644 --- a/aws/sdk/integration-tests/kms/tests/integration.rs +++ b/aws/sdk/integration-tests/kms/tests/integration.rs @@ -11,7 +11,6 @@ use aws_smithy_runtime::client::http::test_util::{ReplayEvent, StaticReplayClien use http::header::AUTHORIZATION; use http::Uri; use kms::config::{Config, Credentials, Region}; -use std::time::{Duration, UNIX_EPOCH}; // TODO(DVR): having the full HTTP requests right in the code is a bit gross, consider something // like https://github.com/davidbarsky/sigv4/blob/master/aws-sigv4/src/lib.rs#L283-L315 to store @@ -45,6 +44,7 @@ async fn generate_random_cn() { http_client.assert_requests_match(&[]); } +#[cfg(feature = "test-util")] #[tokio::test] async fn generate_random() { let http_client = StaticReplayClient::new(vec![ReplayEvent::new( @@ -52,9 +52,8 @@ async fn generate_random() { .header("content-type", "application/x-amz-json-1.1") .header("x-amz-target", "TrentService.GenerateRandom") .header("content-length", "20") - .header("authorization", "AWS4-HMAC-SHA256 Credential=ANOTREAL/20210305/us-east-1/kms/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date;x-amz-security-token;x-amz-target;x-amz-user-agent, Signature=2e0dd7259fba92523d553173c452eba8a6ee7990fb5b1f8e2eccdeb75309e9e1") - .header("x-amz-date", "20210305T134922Z") - .header("x-amz-security-token", "notarealsessiontoken") + .header("authorization", "AWS4-HMAC-SHA256 Credential=ANOTREAL/20090213/us-east-1/kms/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date;x-amz-target;x-amz-user-agent, Signature=53dcf70f6f852cb576185dcabef5aaa3d068704cf1b7ea7dc644efeaa46674d7") + .header("x-amz-date", "20090213T233130Z") .header("user-agent", "aws-sdk-rust/0.123.test os/windows/XPSP3 lang/rust/1.50.0") .header("x-amz-user-agent", "aws-sdk-rust/0.123.test api/test-service/0.123 os/windows/XPSP3 lang/rust/1.50.0") .uri(Uri::from_static("https://kms.us-east-1.amazonaws.com/")) @@ -67,6 +66,7 @@ async fn generate_random() { .http_client(http_client.clone()) .region(Region::new("us-east-1")) .credentials_provider(Credentials::for_tests_with_session_token()) + .with_test_defaults() .build(); let client = kms::Client::from_conf(conf); let resp = client @@ -77,8 +77,6 @@ async fn generate_random() { // Remove the invocation ID since the signed request above doesn't have it req.headers_mut().remove("amz-sdk-invocation-id"); }) - .request_time_for_tests(UNIX_EPOCH + Duration::from_secs(1614952162)) - .user_agent_for_tests() .send() .await .expect("request should succeed"); @@ -118,6 +116,7 @@ async fn generate_random_malformed_response() { .expect_err("response was malformed"); } +#[cfg(feature = "test-util")] #[tokio::test] async fn generate_random_keystore_not_found() { let http_client = StaticReplayClient::new(vec![ReplayEvent::new( @@ -125,9 +124,8 @@ async fn generate_random_keystore_not_found() { .header("content-type", "application/x-amz-json-1.1") .header("x-amz-target", "TrentService.GenerateRandom") .header("content-length", "56") - .header("authorization", "AWS4-HMAC-SHA256 Credential=ANOTREAL/20210305/us-east-1/kms/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-target, Signature=4ca5cde61676c0ee49fde9ba3c886967e8af16461b6aafdfaee18033eb4ac7a5") - .header("x-amz-date", "20210305T144724Z") - .header("x-amz-security-token", "notarealsessiontoken") + .header("authorization", "AWS4-HMAC-SHA256 Credential=ANOTREAL/20090213/us-east-1/kms/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-target, Signature=ffef92c6b75d66cc511daa896eb4a085ec053a2592e17d1f22ecaf167f2fa4bb") + .header("x-amz-date", "20090213T233130Z") .header("user-agent", "aws-sdk-rust/0.123.test os/windows/XPSP3 lang/rust/1.50.0") .header("x-amz-user-agent", "aws-sdk-rust/0.123.test api/test-service/0.123 os/windows/XPSP3 lang/rust/1.50.0") .uri(Uri::from_static("https://kms.us-east-1.amazonaws.com/")) @@ -147,6 +145,7 @@ async fn generate_random_keystore_not_found() { .http_client(http_client.clone()) .region(Region::new("us-east-1")) .credentials_provider(Credentials::for_tests_with_session_token()) + .with_test_defaults() .build(); let client = kms::Client::from_conf(conf); @@ -154,9 +153,6 @@ async fn generate_random_keystore_not_found() { .generate_random() .number_of_bytes(64) .custom_key_store_id("does not exist") - .customize() - .request_time_for_tests(UNIX_EPOCH + Duration::from_secs(1614955644)) - .user_agent_for_tests() .send() .await .expect_err("key store doesn't exist"); diff --git a/aws/sdk/integration-tests/qldbsession/Cargo.toml b/aws/sdk/integration-tests/qldbsession/Cargo.toml index 59256fb6cd..fecc6e1495 100644 --- a/aws/sdk/integration-tests/qldbsession/Cargo.toml +++ b/aws/sdk/integration-tests/qldbsession/Cargo.toml @@ -10,10 +10,14 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +default = ["test-util"] +test-util = [] + [dev-dependencies] aws-credential-types = { path = "../../build/aws-sdk/sdk/aws-credential-types", features = ["test-util"] } aws-http = { path = "../../build/aws-sdk/sdk/aws-http" } -aws-sdk-qldbsession = { path = "../../build/aws-sdk/sdk/qldbsession" } +aws-sdk-qldbsession = { path = "../../build/aws-sdk/sdk/qldbsession", features = ["test-util"] } aws-smithy-async = { path = "../../build/aws-sdk/sdk/aws-smithy-async" } aws-smithy-http = { path = "../../build/aws-sdk/sdk/aws-smithy-http" } aws-smithy-runtime = { path = "../../build/aws-sdk/sdk/aws-smithy-runtime", features = ["client", "test-util"] } diff --git a/aws/sdk/integration-tests/qldbsession/tests/integration.rs b/aws/sdk/integration-tests/qldbsession/tests/integration.rs index 18ba8e4999..0c167712d7 100644 --- a/aws/sdk/integration-tests/qldbsession/tests/integration.rs +++ b/aws/sdk/integration-tests/qldbsession/tests/integration.rs @@ -9,8 +9,8 @@ use aws_sdk_qldbsession::Client; use aws_smithy_http::body::SdkBody; use aws_smithy_runtime::client::http::test_util::{ReplayEvent, StaticReplayClient}; use http::Uri; -use std::time::{Duration, UNIX_EPOCH}; +#[cfg(feature = "test-util")] #[tokio::test] async fn signv4_use_correct_service_name() { let http_client = StaticReplayClient::new(vec![ReplayEvent::new( @@ -18,10 +18,9 @@ async fn signv4_use_correct_service_name() { .header("content-type", "application/x-amz-json-1.0") .header("x-amz-target", "QLDBSession.SendCommand") .header("content-length", "49") - .header("authorization", "AWS4-HMAC-SHA256 Credential=ANOTREAL/20210305/us-east-1/qldb/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date;x-amz-security-token;x-amz-target;x-amz-user-agent, Signature=350f957e9b736ac3f636d16c59c0a3cee8c2780b0ffadc99bbca841b7f15bee4") + .header("authorization", "AWS4-HMAC-SHA256 Credential=ANOTREAL/20090213/us-east-1/qldb/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date;x-amz-target;x-amz-user-agent, Signature=9a07c60550504d015fb9a2b0f1b175a4d906651f9dd4ee44bebb32a802d03815") // qldbsession uses the signing name 'qldb' in signature _________________________^^^^ - .header("x-amz-date", "20210305T134922Z") - .header("x-amz-security-token", "notarealsessiontoken") + .header("x-amz-date", "20090213T233130Z") .header("user-agent", "aws-sdk-rust/0.123.test os/windows/XPSP3 lang/rust/1.50.0") .uri(Uri::from_static("https://session.qldb.us-east-1.amazonaws.com/")) .body(SdkBody::from(r#"{"StartSession":{"LedgerName":"not-real-ledger"}}"#)).unwrap(), @@ -33,6 +32,7 @@ async fn signv4_use_correct_service_name() { .http_client(http_client.clone()) .region(Region::new("us-east-1")) .credentials_provider(Credentials::for_tests_with_session_token()) + .with_test_defaults() .build(); let client = Client::from_conf(conf); @@ -45,9 +45,6 @@ async fn signv4_use_correct_service_name() { .unwrap(), ) .customize() - // Fix the request time and user agent so the headers are stable - .request_time_for_tests(UNIX_EPOCH + Duration::from_secs(1614952162)) - .user_agent_for_tests() .mutate_request(|req| { // Remove the invocation ID since the signed request above doesn't have it req.headers_mut().remove("amz-sdk-invocation-id"); diff --git a/aws/sdk/integration-tests/s3/Cargo.toml b/aws/sdk/integration-tests/s3/Cargo.toml index a525f69815..1cf92d5d21 100644 --- a/aws/sdk/integration-tests/s3/Cargo.toml +++ b/aws/sdk/integration-tests/s3/Cargo.toml @@ -10,13 +10,17 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +default = ["test-util"] +test-util = [] + [dev-dependencies] async-std = "1.12.0" aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } aws-credential-types = { path = "../../build/aws-sdk/sdk/aws-credential-types", features = ["test-util"] } aws-http = { path = "../../build/aws-sdk/sdk/aws-http" } aws-runtime = { path = "../../build/aws-sdk/sdk/aws-runtime", features = ["test-util"] } -aws-sdk-s3 = { path = "../../build/aws-sdk/sdk/s3" } +aws-sdk-s3 = { path = "../../build/aws-sdk/sdk/s3", features = ["test-util"] } aws-sdk-sts = { path = "../../build/aws-sdk/sdk/sts" } aws-smithy-async = { path = "../../build/aws-sdk/sdk/aws-smithy-async", features = ["test-util", "rt-tokio"] } aws-smithy-http = { path = "../../build/aws-sdk/sdk/aws-smithy-http" } diff --git a/aws/sdk/integration-tests/s3/tests/checksums.rs b/aws/sdk/integration-tests/s3/tests/checksums.rs index 79b8f92900..b6ea28fef5 100644 --- a/aws/sdk/integration-tests/s3/tests/checksums.rs +++ b/aws/sdk/integration-tests/s3/tests/checksums.rs @@ -7,8 +7,8 @@ use aws_config::SdkConfig; use aws_credential_types::provider::SharedCredentialsProvider; use aws_sdk_s3::config::{Credentials, Region}; use aws_sdk_s3::types::ChecksumMode; -use aws_sdk_s3::Client; use aws_sdk_s3::{operation::get_object::GetObjectOutput, types::ChecksumAlgorithm}; +use aws_sdk_s3::{Client, Config}; use aws_smithy_http::body::SdkBody; use aws_smithy_runtime::client::http::test_util::{ capture_request, ReplayEvent, StaticReplayClient, @@ -25,30 +25,47 @@ fn new_checksum_validated_response_test_connection( checksum_header_name: &'static str, checksum_header_value: &'static str, ) -> StaticReplayClient { - StaticReplayClient::new(vec![ - ReplayEvent::new(http::Request::builder() - .header("x-amz-checksum-mode", "ENABLED") - .header("user-agent", "aws-sdk-rust/0.123.test os/windows/XPSP3 lang/rust/1.50.0") - .header("x-amz-date", "20210618T170728Z") - .header("x-amz-content-sha256", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") - .header("x-amz-user-agent", "aws-sdk-rust/0.123.test api/test-service/0.123 os/windows/XPSP3 lang/rust/1.50.0") - .header("authorization", "AWS4-HMAC-SHA256 Credential=ANOTREAL/20210618/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-checksum-mode;x-amz-content-sha256;x-amz-date;x-amz-security-token;x-amz-user-agent, Signature=eb9e58fa4fb04c8e6f160705017fdbb497ccff0efee4227b3a56f900006c3882") - .uri(Uri::from_static("https://some-test-bucket.s3.us-east-1.amazonaws.com/test.txt?x-id=GetObject")).body(SdkBody::empty()).unwrap(), - http::Response::builder() - .header("x-amz-request-id", "4B4NGF0EAWN0GE63") - .header("content-length", "11") - .header("etag", "\"3e25960a79dbc69b674cd4ec67a72c62\"") - .header(checksum_header_name, checksum_header_value) - .header("content-type", "application/octet-stream") - .header("server", "AmazonS3") - .header("content-encoding", "") - .header("last-modified", "Tue, 21 Jun 2022 16:29:14 GMT") - .header("date", "Tue, 21 Jun 2022 16:29:23 GMT") - .header("x-amz-id-2", "kPl+IVVZAwsN8ePUyQJZ40WD9dzaqtr4eNESArqE68GSKtVvuvCTDe+SxhTT+JTUqXB1HL4OxNM=") - .header("accept-ranges", "bytes") - .status(http::StatusCode::from_u16(200).unwrap()) - .body(SdkBody::from(r#"Hello world"#)).unwrap()), - ]) + StaticReplayClient::new(vec![ReplayEvent::new( + http::Request::builder() + .header("x-amz-checksum-mode", "ENABLED") + .header( + "user-agent", + "aws-sdk-rust/0.123.test os/windows/XPSP3 lang/rust/1.50.0", + ) + .header("x-amz-date", "20090213T233130Z") + .header( + "x-amz-content-sha256", + "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + ) + .header( + "x-amz-user-agent", + "aws-sdk-rust/0.123.test api/test-service/0.123 os/windows/XPSP3 lang/rust/1.50.0", + ) + .header("authorization", "not-relevant") + .uri(Uri::from_static( + "https://some-test-bucket.s3.us-east-1.amazonaws.com/test.txt?x-id=GetObject", + )) + .body(SdkBody::empty()) + .unwrap(), + http::Response::builder() + .header("x-amz-request-id", "4B4NGF0EAWN0GE63") + .header("content-length", "11") + .header("etag", "\"3e25960a79dbc69b674cd4ec67a72c62\"") + .header(checksum_header_name, checksum_header_value) + .header("content-type", "application/octet-stream") + .header("server", "AmazonS3") + .header("content-encoding", "") + .header("last-modified", "Tue, 21 Jun 2022 16:29:14 GMT") + .header("date", "Tue, 21 Jun 2022 16:29:23 GMT") + .header( + "x-amz-id-2", + "kPl+IVVZAwsN8ePUyQJZ40WD9dzaqtr4eNESArqE68GSKtVvuvCTDe+SxhTT+JTUqXB1HL4OxNM=", + ) + .header("accept-ranges", "bytes") + .status(http::StatusCode::from_u16(200).unwrap()) + .body(SdkBody::from(r#"Hello world"#)) + .unwrap(), + )]) } async fn test_checksum_on_streaming_response( @@ -59,22 +76,20 @@ async fn test_checksum_on_streaming_response( checksum_header_name, checksum_header_value, ); - let sdk_config = SdkConfig::builder() + let config = Config::builder() .credentials_provider(SharedCredentialsProvider::new(Credentials::for_tests())) .time_source(UNIX_EPOCH + Duration::from_secs(1624036048)) .region(Region::new("us-east-1")) .http_client(http_client.clone()) + .with_test_defaults() .build(); - - let client = Client::new(&sdk_config); + let client = Client::from_conf(config); let res = client .get_object() .bucket("some-test-bucket") .key("test.txt") .checksum_mode(aws_sdk_s3::types::ChecksumMode::Enabled) - .customize() - .user_agent_for_tests() .send() .await .unwrap(); @@ -150,13 +165,13 @@ async fn test_checksum_on_streaming_request<'a>( expected_aws_chunked_encoded_body: &'a str, ) { let (http_client, rcvr) = capture_request(None); - let sdk_config = SdkConfig::builder() + let config = Config::builder() .credentials_provider(SharedCredentialsProvider::new(Credentials::for_tests())) .region(Region::new("us-east-1")) .http_client(http_client.clone()) + .with_test_defaults() .build(); - - let client = Client::new(&sdk_config); + let client = Client::from_conf(config); // ByteStreams created from a file are streaming and have a known size let mut file = tempfile::NamedTempFile::new().unwrap(); @@ -178,9 +193,6 @@ async fn test_checksum_on_streaming_request<'a>( .key("test.txt") .body(body) .checksum_algorithm(checksum_algorithm) - .customize() - .request_time_for_tests(UNIX_EPOCH + Duration::from_secs(1624036048)) - .user_agent_for_tests() .send() .await .unwrap(); diff --git a/aws/sdk/integration-tests/s3/tests/config-override.rs b/aws/sdk/integration-tests/s3/tests/config-override.rs index 76598b764c..5c1b08eee3 100644 --- a/aws/sdk/integration-tests/s3/tests/config-override.rs +++ b/aws/sdk/integration-tests/s3/tests/config-override.rs @@ -86,7 +86,6 @@ async fn operation_overrides_credentials_provider() { Some(std::time::UNIX_EPOCH + std::time::Duration::from_secs(1669257290 + 3600)), "test", ))) - .request_time_for_tests(std::time::UNIX_EPOCH + std::time::Duration::from_secs(1669257290)) .send() .await; diff --git a/aws/sdk/integration-tests/s3/tests/customizable-operation.rs b/aws/sdk/integration-tests/s3/tests/customizable-operation.rs index b7c7dfbf55..dd838e7efb 100644 --- a/aws/sdk/integration-tests/s3/tests/customizable-operation.rs +++ b/aws/sdk/integration-tests/s3/tests/customizable-operation.rs @@ -3,17 +3,16 @@ * SPDX-License-Identifier: Apache-2.0 */ -use aws_config::SdkConfig; use aws_credential_types::provider::SharedCredentialsProvider; use aws_sdk_s3::config::{Credentials, Region}; -use aws_sdk_s3::Client; +use aws_sdk_s3::{Client, Config}; use aws_smithy_runtime::client::http::test_util::capture_request; -use std::time::{Duration, UNIX_EPOCH}; +use http::HeaderValue; #[tokio::test] async fn test_s3_ops_are_customizable() { let (http_client, rcvr) = capture_request(None); - let sdk_config = SdkConfig::builder() + let config = Config::builder() .credentials_provider(SharedCredentialsProvider::new( Credentials::for_tests_with_session_token(), )) @@ -21,38 +20,27 @@ async fn test_s3_ops_are_customizable() { .http_client(http_client.clone()) .build(); - let client = Client::new(&sdk_config); - - let op = client - .list_buckets() - .customize() - .request_time_for_tests(UNIX_EPOCH + Duration::from_secs(1624036048)) - .user_agent_for_tests(); + let client = Client::from_conf(config); // The response from the fake connection won't return the expected XML but we don't care about // that error in this test - let _ = op + let _ = client + .list_buckets() + .customize() + .mutate_request(|req| { + req.headers_mut() + .append("test-header", HeaderValue::from_static("test-value")); + }) .send() .await .expect_err("this will fail due to not receiving a proper XML response."); let expected_req = rcvr.expect_request(); - let auth_header = expected_req + let test_header = expected_req .headers() - .get("Authorization") + .get("test-header") .unwrap() .to_owned(); - // This is a snapshot test taken from a known working test result - let snapshot_signature = - "Signature=c2028dc806248952fc533ab4b1d9f1bafcdc9b3380ed00482f9935541ae11671"; - assert!( - auth_header - .to_str() - .unwrap() - .contains(snapshot_signature), - "authorization header signature did not match expected signature: got {}, expected it to contain {}", - auth_header.to_str().unwrap(), - snapshot_signature - ); + assert_eq!("test-value", test_header.to_str().unwrap(),); } diff --git a/aws/sdk/integration-tests/s3/tests/endpoints.rs b/aws/sdk/integration-tests/s3/tests/endpoints.rs index 2c31986007..e38269154d 100644 --- a/aws/sdk/integration-tests/s3/tests/endpoints.rs +++ b/aws/sdk/integration-tests/s3/tests/endpoints.rs @@ -3,22 +3,20 @@ * SPDX-License-Identifier: Apache-2.0 */ -use aws_config::SdkConfig; use aws_credential_types::provider::SharedCredentialsProvider; use aws_sdk_s3::config::Builder; use aws_sdk_s3::config::{Credentials, Region}; -use aws_sdk_s3::Client; +use aws_sdk_s3::{Client, Config}; use aws_smithy_runtime::client::http::test_util::{capture_request, CaptureRequestReceiver}; -use std::time::{Duration, UNIX_EPOCH}; fn test_client(update_builder: fn(Builder) -> Builder) -> (CaptureRequestReceiver, Client) { let (http_client, captured_request) = capture_request(None); - let sdk_config = SdkConfig::builder() + let config = Config::builder() .credentials_provider(SharedCredentialsProvider::new(Credentials::for_tests())) .region(Region::new("us-west-4")) .http_client(http_client) - .build(); - let client = Client::from_conf(update_builder(Builder::from(&sdk_config)).build()); + .with_test_defaults(); + let client = Client::from_conf(update_builder(config).build()); (captured_request, client) } @@ -69,9 +67,6 @@ async fn multi_region_access_points() { .get_object() .bucket("arn:aws:s3::123456789012:accesspoint/mfzwi23gnjvgw.mrap") .key("blah") - .customize() - .request_time_for_tests(UNIX_EPOCH + Duration::from_secs(1624036048)) - .user_agent_for_tests() .send() .await; let captured_request = captured_request.expect_request(); @@ -83,7 +78,7 @@ async fn multi_region_access_points() { let auth_header = auth_header.to_str().unwrap(); // Verifies that the sigv4a signing algorithm was used, that the signing scope doesn't include a region, and that the x-amz-region-set header was signed. let expected_start = - "AWS4-ECDSA-P256-SHA256 Credential=ANOTREAL/20210618/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-region-set;x-amz-user-agent, Signature="; + "AWS4-ECDSA-P256-SHA256 Credential=ANOTREAL/20090213/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-region-set;x-amz-user-agent, Signature="; assert!( auth_header.starts_with(expected_start), @@ -100,8 +95,6 @@ async fn s3_object_lambda() { .get_object() .bucket("arn:aws:s3-object-lambda:us-east-100:123412341234:accesspoint/myolap") .key("s3.txt") - .customize() - .request_time_for_tests(UNIX_EPOCH + Duration::from_secs(1234567890)) .send() .await .unwrap(); 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 25a7a34e0b..c9bd3749a3 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 @@ -4,12 +4,11 @@ */ use aws_credential_types::provider::SharedCredentialsProvider; +use aws_sdk_s3::Config; use aws_sdk_s3::{config::Credentials, config::Region, types::ObjectAttributes, Client}; use aws_smithy_http::body::SdkBody; use aws_smithy_runtime::client::http::test_util::{ReplayEvent, StaticReplayClient}; -use aws_types::SdkConfig; use http::header::AUTHORIZATION; -use std::time::{Duration, UNIX_EPOCH}; const RESPONSE_BODY_XML: &[u8] = b"\ne1AsOh9IyGCa4hLN+2Od7jlnP14="; @@ -19,10 +18,9 @@ async fn ignore_invalid_xml_body_root() { ReplayEvent::new(http::Request::builder() .header("x-amz-object-attributes", "Checksum") .header("x-amz-user-agent", "aws-sdk-rust/0.123.test api/test-service/0.123 os/windows/XPSP3 lang/rust/1.50.0") - .header("x-amz-date", "20210618T170728Z") + .header("x-amz-date", "20090213T233130Z") .header("authorization", "AWS4-HMAC-SHA256 Credential=ANOTREAL/20210618/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-object-attributes;x-amz-security-token;x-amz-user-agent, Signature=0e6ec749db5a0af07890a83f553319eda95be0e498d058c64880471a474c5378") .header("x-amz-content-sha256", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") - .header("x-amz-security-token", "notarealsessiontoken") .uri(http::Uri::from_static("https://some-test-bucket.s3.us-east-1.amazonaws.com/test.txt?attributes")) .body(SdkBody::empty()) .unwrap(), @@ -41,23 +39,21 @@ async fn ignore_invalid_xml_body_root() { .unwrap()) ]); - let sdk_config = SdkConfig::builder() + let config = Config::builder() .credentials_provider(SharedCredentialsProvider::new( Credentials::for_tests_with_session_token(), )) .region(Region::new("us-east-1")) .http_client(http_client.clone()) + .with_test_defaults() .build(); - let client = Client::new(&sdk_config); + let client = Client::from_conf(config); let _ = client .get_object_attributes() .bucket("some-test-bucket") .key("test.txt") .object_attributes(ObjectAttributes::Checksum) - .customize() - .request_time_for_tests(UNIX_EPOCH + Duration::from_secs(1624036048)) - .user_agent_for_tests() .send() .await .unwrap(); 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 422d64c899..8f43962763 100644 --- a/aws/sdk/integration-tests/s3/tests/naughty-string-metadata.rs +++ b/aws/sdk/integration-tests/s3/tests/naughty-string-metadata.rs @@ -4,11 +4,10 @@ */ use aws_credential_types::provider::SharedCredentialsProvider; +use aws_sdk_s3::Config; use aws_sdk_s3::{config::Credentials, config::Region, primitives::ByteStream, Client}; use aws_smithy_runtime::client::http::test_util::capture_request; -use aws_types::SdkConfig; use http::HeaderValue; -use std::time::{Duration, UNIX_EPOCH}; const NAUGHTY_STRINGS: &str = include_str!("blns/blns.txt"); @@ -49,14 +48,13 @@ const NAUGHTY_STRINGS: &str = include_str!("blns/blns.txt"); #[tokio::test] async fn test_s3_signer_with_naughty_string_metadata() { let (http_client, rcvr) = capture_request(None); - let sdk_config = SdkConfig::builder() + let config = Config::builder() .credentials_provider(SharedCredentialsProvider::new( Credentials::for_tests_with_session_token(), )) .region(Region::new("us-east-1")) .http_client(http_client.clone()) - .build(); - let config = aws_sdk_s3::config::Builder::from(&sdk_config) + .with_test_defaults() .force_path_style(true) .build(); @@ -77,13 +75,7 @@ async fn test_s3_signer_with_naughty_string_metadata() { } } - let _ = builder - .customize() - .request_time_for_tests(UNIX_EPOCH + Duration::from_secs(1624036048)) - .user_agent_for_tests() - .send() - .await - .unwrap(); + let _ = builder.send().await.unwrap(); let expected_req = rcvr.expect_request(); let auth_header = expected_req @@ -94,7 +86,7 @@ async fn test_s3_signer_with_naughty_string_metadata() { // This is a snapshot test taken from a known working test result let snapshot_signature = - "Signature=8dfa41f2db599a9fba53393b0ae5da646e5e452fa3685f7a1487d6eade5ec5c8"; + "Signature=a5115604df66219874a9e5a8eab4c9f7a28c992ab2d918037a285756c019f3b2"; assert!( auth_header .to_str() diff --git a/aws/sdk/integration-tests/s3/tests/no_auth.rs b/aws/sdk/integration-tests/s3/tests/no_auth.rs index f7e8f477ea..f3029e4a1d 100644 --- a/aws/sdk/integration-tests/s3/tests/no_auth.rs +++ b/aws/sdk/integration-tests/s3/tests/no_auth.rs @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +use aws_sdk_s3::{Client, Config}; use aws_smithy_protocol_test::MediaType; use aws_smithy_runtime::client::http::test_util::dvr::ReplayingClient; use aws_smithy_runtime::test_util::capture_test_logs::capture_test_logs; @@ -18,15 +19,16 @@ async fn list_objects() { .region("us-east-1") .load() .await; - let client = aws_sdk_s3::Client::new(&config); + let config = Config::from(&config) + .to_builder() + .with_test_defaults() + .build(); + let client = aws_sdk_s3::Client::from_conf(config); let result = client .list_objects() .bucket("gdc-organoid-pancreatic-phs001611-2-open") .max_keys(3) - .customize() - .remove_invocation_id_for_tests() - .user_agent_for_tests() .send() .await; dbg!(result).expect("success"); @@ -49,15 +51,16 @@ async fn list_objects_v2() { .region("us-east-1") .load() .await; - let client = aws_sdk_s3::Client::new(&config); + let config = Config::from(&config) + .to_builder() + .with_test_defaults() + .build(); + let client = Client::from_conf(config); let result = client .list_objects_v2() .bucket("gdc-organoid-pancreatic-phs001611-2-open") .max_keys(3) - .customize() - .remove_invocation_id_for_tests() - .user_agent_for_tests() .send() .await; dbg!(result).expect("success"); @@ -79,15 +82,16 @@ async fn head_object() { .region("us-east-1") .load() .await; - let client = aws_sdk_s3::Client::new(&config); + let config = Config::from(&config) + .to_builder() + .with_test_defaults() + .build(); + let client = Client::from_conf(config); let result = client .head_object() .bucket("gdc-organoid-pancreatic-phs001611-2-open") .key("0431cddc-a418-4a79-a34d-6c041394e8e4/a6ddcc84-8e4d-4c68-885c-2d51168eec97.FPKM-UQ.txt.gz") - .customize() - .remove_invocation_id_for_tests() - .user_agent_for_tests() .send() .await; dbg!(result).expect("success"); @@ -109,15 +113,16 @@ async fn get_object() { .region("us-east-1") .load() .await; - let client = aws_sdk_s3::Client::new(&config); + let config = Config::from(&config) + .to_builder() + .with_test_defaults() + .build(); + let client = Client::from_conf(config); let result = client .get_object() .bucket("gdc-organoid-pancreatic-phs001611-2-open") .key("0431cddc-a418-4a79-a34d-6c041394e8e4/a6ddcc84-8e4d-4c68-885c-2d51168eec97.FPKM-UQ.txt.gz") - .customize() - .remove_invocation_id_for_tests() - .user_agent_for_tests() .send() .await; dbg!(result).expect("success"); diff --git a/aws/sdk/integration-tests/s3/tests/normalize-uri-path.rs b/aws/sdk/integration-tests/s3/tests/normalize-uri-path.rs index ae8426d16c..a044a3e921 100644 --- a/aws/sdk/integration-tests/s3/tests/normalize-uri-path.rs +++ b/aws/sdk/integration-tests/s3/tests/normalize-uri-path.rs @@ -3,25 +3,24 @@ * SPDX-License-Identifier: Apache-2.0 */ -use aws_config::SdkConfig; use aws_credential_types::provider::SharedCredentialsProvider; use aws_sdk_s3::primitives::ByteStream; +use aws_sdk_s3::Config; use aws_sdk_s3::{config::Credentials, config::Region, Client}; use aws_smithy_runtime::client::http::test_util::capture_request; -use std::time::{Duration, UNIX_EPOCH}; #[tokio::test] async fn test_operation_should_not_normalize_uri_path() { let (http_client, rx) = capture_request(None); - let sdk_config = SdkConfig::builder() + let config = Config::builder() .credentials_provider(SharedCredentialsProvider::new( Credentials::for_tests_with_session_token(), )) .region(Region::new("us-east-1")) .http_client(http_client.clone()) + .with_test_defaults() .build(); - - let client = Client::new(&sdk_config); + let client = Client::from_conf(config); let bucket_name = "test-bucket-ad7c9f01-7f7b-4669-b550-75cc6d4df0f1"; @@ -30,9 +29,6 @@ async fn test_operation_should_not_normalize_uri_path() { .bucket(bucket_name) .key("a/.././b.txt") // object key with dot segments .body(ByteStream::from_static("Hello, world".as_bytes())) - .customize() - .request_time_for_tests(UNIX_EPOCH + Duration::from_secs(1669257290)) - .user_agent_for_tests() .send() .await .unwrap(); @@ -45,7 +41,7 @@ async fn test_operation_should_not_normalize_uri_path() { let expected_uri = "/a/.././b.txt"; assert_eq!(actual_uri, expected_uri); - let expected_sig = "Signature=4803b8b8c794b5ecc055933befd7c5547f8bf6585bb18e4ae33ff65220d5cdd7"; + let expected_sig = "Signature=2ac540538c84dc2616d92fb51d4fc6146ccd9ccc1ee85f518a1a686c5ef97b86"; assert!( actual_auth.contains(expected_sig), "authorization header signature did not match expected signature: expected {} but not found in {}", 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 9f688fe69b..55c68f6155 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,25 +3,23 @@ * SPDX-License-Identifier: Apache-2.0 */ -use aws_config::SdkConfig; use aws_credential_types::provider::SharedCredentialsProvider; use aws_sdk_s3::config::{Credentials, Region}; -use aws_sdk_s3::Client; +use aws_sdk_s3::{Client, Config}; use aws_smithy_runtime::client::http::test_util::capture_request; -use std::time::{Duration, UNIX_EPOCH}; #[tokio::test] async fn test_s3_signer_query_string_with_all_valid_chars() { let (http_client, rcvr) = capture_request(None); - let sdk_config = SdkConfig::builder() + let config = Config::builder() .credentials_provider(SharedCredentialsProvider::new( Credentials::for_tests_with_session_token(), )) .region(Region::new("us-east-1")) .http_client(http_client.clone()) + .with_test_defaults() .build(); - - let client = Client::new(&sdk_config); + let client = Client::from_conf(config); // Generate a string containing all printable ASCII chars let prefix: String = (32u8..127).map(char::from).collect(); @@ -32,9 +30,6 @@ async fn test_s3_signer_query_string_with_all_valid_chars() { .list_objects_v2() .bucket("test-bucket") .prefix(&prefix) - .customize() - .request_time_for_tests(UNIX_EPOCH + Duration::from_secs(1624036048)) - .user_agent_for_tests() .send() .await; @@ -47,7 +42,7 @@ async fn test_s3_signer_query_string_with_all_valid_chars() { // This is a snapshot test taken from a known working test result let snapshot_signature = - "Signature=647aa91c7f91f1f1c498ef376fea370b48d0cd8c80a53c8e2cd64e3fc527a5e0"; + "Signature=9a931d20606f93fa4e5553602866a9b5ccac2cd42b54ae5a4b17e4614fb443ce"; assert!( auth_header .to_str() diff --git a/aws/sdk/integration-tests/s3/tests/signing-it.rs b/aws/sdk/integration-tests/s3/tests/signing-it.rs index 1b3e59e373..22dcf7c3d9 100644 --- a/aws/sdk/integration-tests/s3/tests/signing-it.rs +++ b/aws/sdk/integration-tests/s3/tests/signing-it.rs @@ -3,39 +3,35 @@ * SPDX-License-Identifier: Apache-2.0 */ -use aws_config::SdkConfig; use aws_credential_types::provider::SharedCredentialsProvider; use aws_sdk_s3::config::{Credentials, Region}; -use aws_sdk_s3::Client; +use aws_sdk_s3::{Client, Config}; use aws_smithy_http::body::SdkBody; use aws_smithy_runtime::client::http::test_util::{ReplayEvent, StaticReplayClient}; -use std::time::{Duration, UNIX_EPOCH}; #[tokio::test] async fn test_signer() { let http_client = StaticReplayClient::new(vec![ReplayEvent::new( http::Request::builder() - .header("authorization", "AWS4-HMAC-SHA256 Credential=ANOTREAL/20210618/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token;x-amz-user-agent, Signature=ae78f74d26b6b0c3a403d9e8cc7ec3829d6264a2b33db672bf2b151bbb901786") + .header("authorization", "AWS4-HMAC-SHA256 Credential=ANOTREAL/20090213/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-user-agent, Signature=27e3f59ec3cffaa10e4f1c92112e8fb62d468a04cd32be39e68215f830404dbb") .uri("https://test-bucket.s3.us-east-1.amazonaws.com/?list-type=2&prefix=prefix~") .body(SdkBody::empty()) .unwrap(), http::Response::builder().status(200).body(SdkBody::empty()).unwrap(), )]); - let sdk_config = SdkConfig::builder() + let config = Config::builder() .credentials_provider(SharedCredentialsProvider::new( Credentials::for_tests_with_session_token(), )) .region(Region::new("us-east-1")) .http_client(http_client.clone()) + .with_test_defaults() .build(); - let client = Client::new(&sdk_config); + let client = Client::from_conf(config); let _ = client .list_objects_v2() .bucket("test-bucket") .prefix("prefix~") - .customize() - .request_time_for_tests(UNIX_EPOCH + Duration::from_secs(1624036048)) - .user_agent_for_tests() .send() .await; diff --git a/aws/sdk/integration-tests/s3control/Cargo.toml b/aws/sdk/integration-tests/s3control/Cargo.toml index 723f8c964a..bd1923c141 100644 --- a/aws/sdk/integration-tests/s3control/Cargo.toml +++ b/aws/sdk/integration-tests/s3control/Cargo.toml @@ -10,10 +10,14 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +default = ["test-util"] +test-util = [] + [dev-dependencies] aws-credential-types = { path = "../../build/aws-sdk/sdk/aws-credential-types", features = ["test-util"] } aws-http = { path = "../../build/aws-sdk/sdk/aws-http" } -aws-sdk-s3control = { path = "../../build/aws-sdk/sdk/s3control" } +aws-sdk-s3control = { path = "../../build/aws-sdk/sdk/s3control", features = ["test-util"] } aws-smithy-async = { path = "../../build/aws-sdk/sdk/aws-smithy-async" } aws-smithy-runtime = { path = "../../build/aws-sdk/sdk/aws-smithy-runtime", features = ["client", "test-util"] } aws-smithy-http = { path = "../../build/aws-sdk/sdk/aws-smithy-http" } diff --git a/aws/sdk/integration-tests/s3control/tests/signing-it.rs b/aws/sdk/integration-tests/s3control/tests/signing-it.rs index b94e397170..242f2f2d78 100644 --- a/aws/sdk/integration-tests/s3control/tests/signing-it.rs +++ b/aws/sdk/integration-tests/s3control/tests/signing-it.rs @@ -5,41 +5,36 @@ use aws_credential_types::provider::SharedCredentialsProvider; use aws_sdk_s3control::config::{Credentials, Region}; -use aws_sdk_s3control::Client; +use aws_sdk_s3control::{Client, Config}; use aws_smithy_http::body::SdkBody; use aws_smithy_runtime::client::http::test_util::{ReplayEvent, StaticReplayClient}; -use aws_types::SdkConfig; -use std::time::{Duration, UNIX_EPOCH}; #[tokio::test] async fn test_signer() { let http_client = StaticReplayClient::new(vec![ReplayEvent::new( http::Request::builder() .header("authorization", - "AWS4-HMAC-SHA256 Credential=ANOTREAL/20211112/us-east-1/s3/aws4_request, \ - SignedHeaders=host;x-amz-account-id;x-amz-content-sha256;x-amz-date;x-amz-security-token;x-amz-user-agent, \ - Signature=ac58c2246428af711ab7bca30c704a2b6a5fd7451cf83f3bceff177f1636e277") + "AWS4-HMAC-SHA256 Credential=ANOTREAL/20090213/us-east-1/s3/aws4_request, \ + SignedHeaders=host;x-amz-account-id;x-amz-content-sha256;x-amz-date;x-amz-user-agent, \ + Signature=0102a74cb220f8445c4efada17660572ff813e07b524032ec831e8c2514be903") .uri("https://test-bucket.s3-control.us-east-1.amazonaws.com/v20180820/accesspoint") .body(SdkBody::empty()) .unwrap(), http::Response::builder().status(200).body(SdkBody::empty()).unwrap(), )]); - let sdk_config = SdkConfig::builder() + let config = Config::builder() .credentials_provider(SharedCredentialsProvider::new( Credentials::for_tests_with_session_token(), )) .http_client(http_client.clone()) .region(Region::new("us-east-1")) + .with_test_defaults() .build(); - let client = Client::new(&sdk_config); + let client = Client::from_conf(config); let _ = client .list_access_points() .account_id("test-bucket") - .customize() - .request_time_for_tests(UNIX_EPOCH + Duration::from_secs(1636751225)) - .user_agent_for_tests() - .remove_invocation_id_for_tests() .send() .await .expect_err("empty response"); diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGenerator.kt index 455942df49..a6379bb4b4 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGenerator.kt @@ -401,7 +401,7 @@ class ServiceConfigGenerator( testUtilOnly.render(this) Attribute.AllowUnusedMut.render(this) docs("Apply test defaults to the builder") - rustBlock("pub fn set_test_defaults(&mut self) -> &mut Self") { + rustBlock("pub fn apply_test_defaults(&mut self) -> &mut Self") { customizations.forEach { it.section(ServiceConfig.DefaultForTests("self"))(this) } rust("self") } @@ -410,7 +410,7 @@ class ServiceConfigGenerator( Attribute.AllowUnusedMut.render(this) docs("Apply test defaults to the builder") rustBlock("pub fn with_test_defaults(mut self) -> Self") { - rust("self.set_test_defaults(); self") + rust("self.apply_test_defaults(); self") } docs("Builds a [`Config`].")