Skip to content

Commit

Permalink
Remove temporary test customizations (#3044)
Browse files Browse the repository at this point in the history
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
  • Loading branch information
jdisanti authored Oct 10, 2023
1 parent 38375a5 commit 547b631
Show file tree
Hide file tree
Showing 21 changed files with 165 additions and 313 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -158,6 +159,15 @@ class UserAgentDecorator : ClientCodegenDecorator {
)
}

is ServiceConfig.DefaultForTests -> writable {
rustTemplate(
"""
self.config.store_put(#{AwsUserAgent}::for_tests());
""",
*codegenScope,
)
}

else -> emptySection
}
}
Expand Down
6 changes: 5 additions & 1 deletion aws/sdk/integration-tests/kms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
20 changes: 8 additions & 12 deletions aws/sdk/integration-tests/kms/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,16 +44,16 @@ 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(
http::Request::builder()
.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/"))
Expand All @@ -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
Expand All @@ -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");
Expand Down Expand Up @@ -118,16 +116,16 @@ 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(
http::Request::builder()
.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/"))
Expand All @@ -147,16 +145,14 @@ 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);

let err = client
.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");
Expand Down
6 changes: 5 additions & 1 deletion aws/sdk/integration-tests/qldbsession/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
11 changes: 4 additions & 7 deletions aws/sdk/integration-tests/qldbsession/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ 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(
http::Request::builder()
.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(),
Expand All @@ -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);

Expand All @@ -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");
Expand Down
6 changes: 5 additions & 1 deletion aws/sdk/integration-tests/s3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
Loading

0 comments on commit 547b631

Please sign in to comment.