Skip to content

Commit 7ebfbcc

Browse files
ysaito1001Zelda Hessler
and
Zelda Hessler
authored
Move using-native-tls-instead-of-rustls to smithy-rs (smithy-lang#2423)
* Move using-native-tls-instead-of-rustls to smithy-rs This commit adds the test `using-native-tls-instead-of-rustls` to `smithy-rs` that was originally in the `aws-doc-sdk-examples`. The test is more useful to be in `smithy-rs` because it can catch a test failure early prior to cutting a release. * Fix Copyright header * Update aws/sdk/integration-tests/using-native-tls-instead-of-rustls/tests/no-rustls-in-dependency.rs Co-authored-by: Zelda Hessler <[email protected]> * Update aws/sdk/integration-tests/using-native-tls-instead-of-rustls/tests/no-rustls-in-dependency.rs Co-authored-by: Zelda Hessler <[email protected]> * Update Cargo.toml This commit addresses smithy-lang#2423 (comment) smithy-lang#2423 (comment) --------- Co-authored-by: Yuki Saito <[email protected]> Co-authored-by: Zelda Hessler <[email protected]>
1 parent 049287d commit 7ebfbcc

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

aws/sdk/integration-tests/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ members = [
1515
"s3control",
1616
"sts",
1717
"transcribestreaming",
18+
"using-native-tls-instead-of-rustls",
1819
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "using-native-tls-instead-of-rustls"
3+
version = "0.1.0"
4+
authors = ["AWS Rust SDK Team <[email protected]>"]
5+
edition = "2021"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dev-dependencies]
10+
# aws-config pulls in rustls and several other things by default. We have to disable defaults in order to use native-tls
11+
# and then manually bring the other defaults back
12+
aws-config = { path = "../../build/aws-sdk/sdk/aws-config", default-features = false, features = [
13+
"native-tls",
14+
"rt-tokio",
15+
] }
16+
# aws-sdk-s3 brings in rustls by default so we disable that in order to use native-tls only
17+
aws-sdk-s3 = { path = "../../build/aws-sdk/sdk/s3", default-features = false, features = [
18+
"native-tls",
19+
] }
20+
tokio = { version = "1.20.1", features = ["rt", "macros"] }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
/// The SDK defaults to using RusTLS by default but you can also use [`native_tls`](https://github.com/sfackler/rust-native-tls)
7+
/// which will choose a TLS implementation appropriate for your platform. This test looks much like
8+
/// any other. Activating and deactivating `features` in your app's `Cargo.toml` is all that's needed.
9+
10+
async fn list_buckets() -> Result<(), aws_sdk_s3::Error> {
11+
let sdk_config = aws_config::load_from_env().await;
12+
let client = aws_sdk_s3::Client::new(&sdk_config);
13+
14+
let _resp = client.list_buckets().send().await?;
15+
16+
Ok(())
17+
}
18+
19+
/// You can run this test to ensure that it is only using `native-tls` and
20+
/// that nothing is pulling in `rustls` as a dependency
21+
#[test]
22+
#[should_panic = "error: package ID specification `rustls` did not match any packages"]
23+
fn test_rustls_is_not_in_dependency_tree() {
24+
let cargo_location = std::env::var("CARGO").unwrap();
25+
let cargo_command = std::process::Command::new(&cargo_location)
26+
.arg("tree")
27+
.arg("--invert")
28+
.arg("rustls")
29+
.output()
30+
.expect("failed to run 'cargo tree'");
31+
32+
let stderr = String::from_utf8_lossy(&cargo_command.stderr);
33+
34+
// We expect the call to `cargo tree` to error out. If it did, we panic with the resulting
35+
// message here. In the case that no error message is set, that's bad.
36+
if !stderr.is_empty() {
37+
panic!("{}", stderr);
38+
}
39+
40+
// Uh oh. We expected an error message but got none, likely because `cargo tree` found
41+
// `rustls` in our dependencies. We'll print out the message we got to see what went wrong.
42+
let stdout = String::from_utf8_lossy(&cargo_command.stdout);
43+
44+
println!("{}", stdout)
45+
}
46+
47+
// NOTE: not currently run in CI, separate PR will set up a with-creds CI runner
48+
#[tokio::test]
49+
#[ignore]
50+
async fn needs_creds_native_tls_works() {
51+
list_buckets().await.expect("should succeed")
52+
}

0 commit comments

Comments
 (0)