Unverified Commit bbe9d52a authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Fix the error message for SSO credential providers (#2722)

## Motivation and Context
The current error if the SSO error message is not enabled is inscrutable
and doesn't point the customer towards the removed feature.

## Description
Fix the error message, add tests.

## Testing
tests

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent c0345a5b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -35,3 +35,9 @@ message = "Fix compiler errors in generated code when naming shapes after types
references = ["smithy-rs#2696"]
meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "client"}
author = "jdisanti"

[[aws-sdk-rust]]
message = "Fix error message when `credentials-sso` feature is not enabled on `aws-config`. NOTE: if you use `no-default-features`, you will need to manually able `credentials-sso` after 0.55.*"
references = ["smithy-rs#2722", "aws-sdk-rust#703"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "rcoh"
+16 −9
Original line number Diff line number Diff line
@@ -224,8 +224,8 @@ mod test {
    /// make_test!(live: test_name)
    /// ```
    macro_rules! make_test {
        ($name: ident) => {
            make_test!($name, execute);
        ($name: ident $(#[$m:meta])*) => {
            make_test!($name, execute, $(#[$m])*);
        };
        (update: $name:ident) => {
            make_test!($name, execute_and_update);
@@ -233,13 +233,14 @@ mod test {
        (live: $name:ident) => {
            make_test!($name, execute_from_live_traffic);
        };
        ($name: ident, $func: ident) => {
            make_test!($name, $func, std::convert::identity);
        ($name: ident, $func: ident, $(#[$m:meta])*) => {
            make_test!($name, $func, std::convert::identity $(, #[$m])*);
        };
        ($name: ident, $provider_config_builder: expr) => {
        ($name: ident, builder: $provider_config_builder: expr) => {
            make_test!($name, execute, $provider_config_builder);
        };
        ($name: ident, $func: ident, $provider_config_builder: expr) => {
        ($name: ident, $func: ident, $provider_config_builder: expr $(, #[$m:meta])*) => {
            $(#[$m])*
            #[tokio::test]
            async fn $name() {
                crate::test_case::TestEnvironment::from_dir(concat!(
@@ -274,19 +275,19 @@ mod test {

    make_test!(imds_no_iam_role);
    make_test!(imds_default_chain_error);
    make_test!(imds_default_chain_success, |config| {
    make_test!(imds_default_chain_success, builder: |config| {
        config.with_time_source(aws_credential_types::time_source::TimeSource::testing(
            &aws_credential_types::time_source::TestingTimeSource::new(std::time::UNIX_EPOCH),
        ))
    });
    make_test!(imds_assume_role);
    make_test!(imds_config_with_no_creds, |config| {
    make_test!(imds_config_with_no_creds, builder: |config| {
        config.with_time_source(aws_credential_types::time_source::TimeSource::testing(
            &aws_credential_types::time_source::TestingTimeSource::new(std::time::UNIX_EPOCH),
        ))
    });
    make_test!(imds_disabled);
    make_test!(imds_default_chain_retries, |config| {
    make_test!(imds_default_chain_retries, builder: |config| {
        config.with_time_source(aws_credential_types::time_source::TimeSource::testing(
            &aws_credential_types::time_source::TestingTimeSource::new(std::time::UNIX_EPOCH),
        ))
@@ -295,8 +296,14 @@ mod test {
    make_test!(ecs_credentials);
    make_test!(ecs_credentials_invalid_profile);

    #[cfg(not(feature = "credentials-sso"))]
    make_test!(sso_assume_role #[should_panic(expected = "This behavior requires following cargo feature(s) enabled: credentials-sso")]);
    #[cfg(not(feature = "credentials-sso"))]
    make_test!(sso_no_token_file #[should_panic(expected = "This behavior requires following cargo feature(s) enabled: credentials-sso")]);

    #[cfg(feature = "credentials-sso")]
    make_test!(sso_assume_role);

    #[cfg(feature = "credentials-sso")]
    make_test!(sso_no_token_file);

+13 −0
Original line number Diff line number Diff line
@@ -257,6 +257,13 @@ pub enum ProfileFileError {
        /// The name of the provider
        name: String,
    },

    /// Feature not enabled
    #[non_exhaustive]
    FeatureNotEnabled {
        /// The feature or comma delimited list of features that must be enabled
        feature: Cow<'static, str>,
    },
}

impl ProfileFileError {
@@ -309,6 +316,12 @@ impl Display for ProfileFileError {
                "profile `{}` did not contain credential information",
                profile
            ),
            ProfileFileError::FeatureNotEnabled { feature: message } => {
                write!(
                    f,
                    "This behavior requires following cargo feature(s) enabled: {message}",
                )
            }
        }
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -137,8 +137,8 @@ impl ProviderChain {
                }
                #[cfg(not(feature = "credentials-sso"))]
                {
                    Err(ProfileFileError::UnknownProvider {
                        name: "sso".to_string(),
                    Err(ProfileFileError::FeatureNotEnabled {
                        feature: "credentials-sso".into(),
                    })?
                }
            }
+1 −1
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@ where
                );
            }
            (Err(actual_error), GenericTestResult::Ok(expected_creds)) => panic!(
                "expected credentials ({:?}) but an error was returned: {}",
                "expected credentials ({:?}) but an error was returned: {:?}",
                expected_creds, actual_error
            ),
            (Ok(creds), GenericTestResult::ErrorContains(substr)) => panic!(