-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error messaging for auth scheme selection (#3277)
This patch adds a stack-allocated list of explored auth schemes and the reason each didn't work to the auth orchestrator so that its error message is much easier to decipher. ---- _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
Showing
5 changed files
with
323 additions
and
7 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
32 changes: 32 additions & 0 deletions
32
aws/sdk/integration-tests/dynamodb/tests/auth_scheme_error.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,32 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
use aws_sdk_dynamodb::config::Region; | ||
use aws_sdk_dynamodb::error::DisplayErrorContext; | ||
use aws_sdk_dynamodb::{Client, Config}; | ||
use aws_smithy_runtime::assert_str_contains; | ||
use aws_smithy_runtime::client::http::test_util::capture_request; | ||
|
||
#[tokio::test] | ||
async fn auth_scheme_error() { | ||
let (http_client, _) = capture_request(None); | ||
let config = Config::builder() | ||
.behavior_version_latest() | ||
.http_client(http_client) | ||
.region(Region::new("us-west-2")) | ||
// intentionally omitting credentials_provider | ||
.build(); | ||
let client = Client::from_conf(config); | ||
|
||
let err = client | ||
.list_tables() | ||
.send() | ||
.await | ||
.expect_err("there is no credential provider, so this must fail"); | ||
assert_str_contains!( | ||
DisplayErrorContext(&err).to_string(), | ||
"\"sigv4\" wasn't a valid option because there was no identity resolver for it. Be sure to set an identity" | ||
); | ||
} |
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 |
---|---|---|
|
@@ -5,3 +5,5 @@ | |
|
||
/// Utility for capturing and displaying logs during a unit test. | ||
pub mod capture_test_logs; | ||
|
||
mod assertions; |
57 changes: 57 additions & 0 deletions
57
rust-runtime/aws-smithy-runtime/src/test_util/assertions.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,57 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/// Asserts that a given string value `$str` contains a substring `$expected`. | ||
/// | ||
/// This macro can also take a custom panic message with formatting. | ||
#[macro_export] | ||
macro_rules! assert_str_contains { | ||
($str:expr, $expected:expr) => { | ||
assert_str_contains!($str, $expected, "") | ||
}; | ||
($str:expr, $expected:expr, $($fmt_args:tt)+) => {{ | ||
let s = $str; | ||
let expected = $expected; | ||
if !s.contains(&expected) { | ||
panic!( | ||
"assertion failed: `str.contains(expected)`\n{:>8}: {expected}\n{:>8}: {s}\n{}", | ||
"expected", | ||
"str", | ||
::std::fmt::format(::std::format_args!($($fmt_args)+)), | ||
); | ||
} | ||
}}; | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::panic::{catch_unwind, UnwindSafe}; | ||
|
||
fn expect_panic(f: impl FnOnce() -> () + UnwindSafe) -> String { | ||
*catch_unwind(f) | ||
.expect_err("it should fail") | ||
.downcast::<String>() | ||
.expect("it should be a string") | ||
} | ||
|
||
#[test] | ||
fn assert_str_contains() { | ||
assert_str_contains!("foobar", "bar"); | ||
assert_str_contains!("foobar", "o"); | ||
|
||
assert_eq!( | ||
"assertion failed: `str.contains(expected)`\nexpected: not-in-it\n str: foobar\n", | ||
expect_panic(|| assert_str_contains!("foobar", "not-in-it")) | ||
); | ||
assert_eq!( | ||
"assertion failed: `str.contains(expected)`\nexpected: not-in-it\n str: foobar\nsome custom message", | ||
expect_panic(|| assert_str_contains!("foobar", "not-in-it", "some custom message")) | ||
); | ||
assert_eq!( | ||
"assertion failed: `str.contains(expected)`\nexpected: not-in-it\n str: foobar\nsome custom message with formatting", | ||
expect_panic(|| assert_str_contains!("foobar", "not-in-it", "some custom message with {}", "formatting")) | ||
); | ||
} | ||
} |