Skip to content

Commit 6f44279

Browse files
authored
Merge branch 'main' into merge-smithy-rs-release-1.x.y-to-main
2 parents 3124d1a + 85d2621 commit 6f44279

File tree

8 files changed

+366
-12
lines changed

8 files changed

+366
-12
lines changed

CHANGELOG.next.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,32 @@ result of the compilation."""
3232
references = ["aws-sdk-rust#975", "smithy-rs#3269"]
3333
meta = { "breaking" = false, "tada" = true, "bug" = false }
3434
author = "jdisanti"
35+
36+
[[aws-sdk-rust]]
37+
message = """Add `test_credentials` to `ConfigLoader` in `aws_config`. This allows the following pattern during tests:
38+
39+
```rust
40+
async fn main() {
41+
let conf = aws_config::defaults(BehaviorVersion::latest())
42+
.test_credentials()
43+
.await;
44+
}
45+
```
46+
47+
This is designed for unit tests and using local mocks like DynamoDB Local and LocalStack with the SDK.
48+
"""
49+
meta = { "breaking" = false, "tada" = true, "bug" = false }
50+
author = "rcoh"
51+
references = ["smithy-rs#3279", "aws-sdk-rust#971"]
52+
53+
[[aws-sdk-rust]]
54+
message = "Improve the error messages for when auth fails to select an auth scheme for a request."
55+
references = ["aws-sdk-rust#979", "smithy-rs#3277"]
56+
meta = { "breaking" = false, "tada" = false, "bug" = false }
57+
author = "jdisanti"
58+
59+
[[smithy-rs]]
60+
message = "Improve the error messages for when auth fails to select an auth scheme for a request."
61+
references = ["smithy-rs#3277"]
62+
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client" }
63+
author = "jdisanti"

aws/rust-runtime/aws-config/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ repository = "https://github.com/smithy-lang/smithy-rs"
1212
behavior-version-latest = []
1313
client-hyper = ["aws-smithy-runtime/connector-hyper-0-14-x"]
1414
rustls = ["aws-smithy-runtime/tls-rustls", "client-hyper"]
15-
allow-compilation = [] # our tests use `cargo test --all-features` and native-tls breaks CI
1615
rt-tokio = ["aws-smithy-async/rt-tokio", "aws-smithy-runtime/rt-tokio", "tokio/rt"]
1716
sso = ["dep:aws-sdk-sso", "dep:aws-sdk-ssooidc", "dep:ring", "dep:hex", "dep:zeroize", "aws-smithy-runtime-api/http-auth"]
1817
credentials-process = ["tokio/process"]
1918

2019
default = ["client-hyper", "rustls", "rt-tokio", "credentials-process", "sso"]
2120

21+
# deprecated: this feature does nothing
22+
allow-compilation = []
23+
2224
[dependencies]
23-
aws-credential-types = { path = "../../sdk/build/aws-sdk/sdk/aws-credential-types" }
25+
aws-credential-types = { path = "../../sdk/build/aws-sdk/sdk/aws-credential-types", features = ["test-util"] }
2426
aws-http = { path = "../../sdk/build/aws-sdk/sdk/aws-http" }
2527
aws-sdk-sts = { path = "../../sdk/build/aws-sdk/sdk/sts", default-features = false }
2628
aws-smithy-async = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-async" }
@@ -52,7 +54,6 @@ zeroize = { version = "1", optional = true }
5254
aws-sdk-ssooidc = { path = "../../sdk/build/aws-sdk/sdk/ssooidc", default-features = false, optional = true }
5355

5456
[dev-dependencies]
55-
aws-credential-types = { path = "../../sdk/build/aws-sdk/sdk/aws-credential-types", features = ["test-util"] }
5657
aws-smithy-runtime = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-runtime", features = ["client", "connector-hyper-0-14-x", "test-util"] }
5758
aws-smithy-runtime-api = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-runtime-api", features = ["test-util"] }
5859
futures-util = { version = "0.3.16", default-features = false }

aws/rust-runtime/aws-config/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ mod loader {
212212
use crate::profile::profile_file::ProfileFiles;
213213
use crate::provider_config::ProviderConfig;
214214
use aws_credential_types::provider::{ProvideCredentials, SharedCredentialsProvider};
215+
use aws_credential_types::Credentials;
215216
use aws_smithy_async::rt::sleep::{default_async_sleep, AsyncSleep, SharedAsyncSleep};
216217
use aws_smithy_async::time::{SharedTimeSource, TimeSource};
217218
use aws_smithy_runtime_api::client::behavior_version::BehaviorVersion;
@@ -458,6 +459,10 @@ mod loader {
458459
/// anonymous auth for S3, calling operations in STS that don't require a signature,
459460
/// or using token-based auth.
460461
///
462+
/// **Note**: For tests, e.g. with a service like DynamoDB Local, this is **not** what you
463+
/// want. If credentials are disabled, requests cannot be signed. For these use cases, use
464+
/// [`test_credentials`](Self::test_credentials).
465+
///
461466
/// # Examples
462467
///
463468
/// Turn off credentials in order to call a service without signing:
@@ -474,6 +479,11 @@ mod loader {
474479
self
475480
}
476481

482+
/// Set test credentials for use when signing requests
483+
pub fn test_credentials(self) -> Self {
484+
self.credentials_provider(Credentials::for_tests())
485+
}
486+
477487
/// Override the name of the app used to build [`SdkConfig`](aws_types::SdkConfig).
478488
///
479489
/// This _optional_ name is used to identify the application in the user agent that
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
use aws_sdk_dynamodb::config::Region;
7+
use aws_sdk_dynamodb::error::DisplayErrorContext;
8+
use aws_sdk_dynamodb::{Client, Config};
9+
use aws_smithy_runtime::assert_str_contains;
10+
use aws_smithy_runtime::client::http::test_util::capture_request;
11+
12+
#[tokio::test]
13+
async fn auth_scheme_error() {
14+
let (http_client, _) = capture_request(None);
15+
let config = Config::builder()
16+
.behavior_version_latest()
17+
.http_client(http_client)
18+
.region(Region::new("us-west-2"))
19+
// intentionally omitting credentials_provider
20+
.build();
21+
let client = Client::from_conf(config);
22+
23+
let err = client
24+
.list_tables()
25+
.send()
26+
.await
27+
.expect_err("there is no credential provider, so this must fail");
28+
assert_str_contains!(
29+
DisplayErrorContext(&err).to_string(),
30+
"\"sigv4\" wasn't a valid option because there was no identity resolver for it. Be sure to set an identity"
31+
);
32+
}

0 commit comments

Comments
 (0)