-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[smithy-rs] Move using-native-tls-instead-of-rustls to smithy-rs (#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 <zhessler@amazon.com> * Update aws/sdk/integration-tests/using-native-tls-instead-of-rustls/tests/no-rustls-in-dependency.rs Co-authored-by: Zelda Hessler <zhessler@amazon.com> * Update Cargo.toml This commit addresses smithy-lang/smithy-rs#2423 (comment) smithy-lang/smithy-rs#2423 (comment) --------- Co-authored-by: Yuki Saito <awsaito@amazon.com> Co-authored-by: Zelda Hessler <zhessler@amazon.com>
- Loading branch information
1 parent
2132228
commit a1b8e36
Showing
6 changed files
with
110 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. | ||
[package] | ||
name = "using-native-tls-instead-of-rustls" | ||
version = "0.1.0" | ||
authors = ["AWS Rust SDK Team <aws-sdk-rust@amazon.com>"] | ||
edition = "2021" | ||
[dev-dependencies.aws-config] | ||
path = "../../sdk/aws-config" | ||
default-features = false | ||
features = ["native-tls", "rt-tokio"] | ||
version = "0.0.0-smithy-rs-head" | ||
|
||
[dev-dependencies.aws-sdk-s3] | ||
path = "../../sdk/s3" | ||
default-features = false | ||
features = ["native-tls"] | ||
version = "0.25.0" | ||
|
||
[dev-dependencies.tokio] | ||
version = "1.20.1" | ||
features = ["rt", "macros"] |
52 changes: 52 additions & 0 deletions
52
tests/using-native-tls-instead-of-rustls/tests/no-rustls-in-dependency.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/// The SDK defaults to using RusTLS by default but you can also use [`native_tls`](https://github.com/sfackler/rust-native-tls) | ||
/// which will choose a TLS implementation appropriate for your platform. This test looks much like | ||
/// any other. Activating and deactivating `features` in your app's `Cargo.toml` is all that's needed. | ||
async fn list_buckets() -> Result<(), aws_sdk_s3::Error> { | ||
let sdk_config = aws_config::load_from_env().await; | ||
let client = aws_sdk_s3::Client::new(&sdk_config); | ||
|
||
let _resp = client.list_buckets().send().await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// You can run this test to ensure that it is only using `native-tls` and | ||
/// that nothing is pulling in `rustls` as a dependency | ||
#[test] | ||
#[should_panic = "error: package ID specification `rustls` did not match any packages"] | ||
fn test_rustls_is_not_in_dependency_tree() { | ||
let cargo_location = std::env::var("CARGO").unwrap(); | ||
let cargo_command = std::process::Command::new(&cargo_location) | ||
.arg("tree") | ||
.arg("--invert") | ||
.arg("rustls") | ||
.output() | ||
.expect("failed to run 'cargo tree'"); | ||
|
||
let stderr = String::from_utf8_lossy(&cargo_command.stderr); | ||
|
||
// We expect the call to `cargo tree` to error out. If it did, we panic with the resulting | ||
// message here. In the case that no error message is set, that's bad. | ||
if !stderr.is_empty() { | ||
panic!("{}", stderr); | ||
} | ||
|
||
// Uh oh. We expected an error message but got none, likely because `cargo tree` found | ||
// `rustls` in our dependencies. We'll print out the message we got to see what went wrong. | ||
let stdout = String::from_utf8_lossy(&cargo_command.stdout); | ||
|
||
println!("{}", stdout) | ||
} | ||
|
||
// NOTE: not currently run in CI, separate PR will set up a with-creds CI runner | ||
#[tokio::test] | ||
#[ignore] | ||
async fn needs_creds_native_tls_works() { | ||
list_buckets().await.expect("should succeed") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters