1 1 | /*
|
2 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
3 3 | * SPDX-License-Identifier: Apache-2.0
|
4 4 | */
|
5 5 |
|
6 - | use aws_config::Region;
|
6 + | use aws_sdk_s3::config::Region;
|
7 7 | use aws_sdk_s3::{Client, Config};
|
8 8 | use aws_smithy_http_client::test_util::capture_request;
|
9 9 |
|
10 10 | // S3 is one of the servies that relies on endpoint-based auth scheme resolution.
|
11 11 | // An auth scheme preference should not be overridden by other resolution methods.
|
12 12 |
|
13 13 | #[tracing_test::traced_test]
|
14 14 | #[tokio::test]
|
15 15 | async fn auth_scheme_preference_at_client_level_should_take_the_highest_priority() {
|
16 16 | let (http_client, _) = capture_request(None);
|
17 - | let config = aws_config::from_env()
|
17 + | let conf = Config::builder()
|
18 18 | .http_client(http_client)
|
19 19 | .region(Region::new("us-east-2"))
|
20 + | .with_test_defaults()
|
20 21 | // Explicitly set a preference that favors `sigv4`, otherwise `sigv4a`
|
21 22 | // would normally be resolved based on the endpoint authSchemes property.
|
22 23 | .auth_scheme_preference([aws_runtime::auth::sigv4::SCHEME_ID])
|
23 - | .load()
|
24 - | .await;
|
25 - |
|
26 - | let client = Client::new(&config);
|
24 + | .build();
|
25 + | let client = Client::from_conf(conf);
|
27 26 | let _ = client
|
28 27 | .get_object()
|
29 28 | .bucket("arn:aws:s3::123456789012:accesspoint/mfzwi23gnjvgw.mrap")
|
30 29 | .key("doesnotmatter")
|
31 30 | .send()
|
32 31 | .await;
|
33 32 |
|
34 33 | assert!(logs_contain(&format!(
|
35 34 | "resolving identity scheme_id=AuthSchemeId {{ scheme_id: \"{auth_scheme_id_str}\" }}",
|
36 35 | auth_scheme_id_str = aws_runtime::auth::sigv4::SCHEME_ID.inner(),
|
37 36 | )));
|
38 37 | }
|
39 38 |
|
40 39 | #[tracing_test::traced_test]
|
41 40 | #[tokio::test]
|
42 41 | async fn auth_scheme_preference_at_operation_level_should_take_the_highest_priority() {
|
43 42 | let (http_client, _) = capture_request(None);
|
44 - | let config = aws_config::from_env()
|
43 + | let conf = Config::builder()
|
45 44 | .http_client(http_client)
|
46 45 | .region(Region::new("us-east-2"))
|
47 - | .load()
|
48 - | .await;
|
49 - |
|
50 - | let client = Client::new(&config);
|
46 + | .with_test_defaults()
|
47 + | .build();
|
48 + | let client = Client::from_conf(conf);
|
51 49 | let _ = client
|
52 50 | .get_object()
|
53 51 | .bucket("arn:aws:s3::123456789012:accesspoint/mfzwi23gnjvgw.mrap")
|
54 52 | .key("doesnotmatter")
|
55 53 | .customize()
|
56 54 | .config_override(
|
57 55 | // Explicitly set a preference that favors `sigv4`, otherwise `sigv4a`
|
58 56 | // would normally be resolved based on the endpoint authSchemes property.
|
59 57 | Config::builder().auth_scheme_preference([aws_runtime::auth::sigv4::SCHEME_ID]),
|
60 58 | )
|