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

[fix] Sleep not passed to ECS provider (#998)



* [fix] Sleep not passed to ECS provider

When constructing an ECS credential provider, sleep_impl was not properly passed along from the provider config. This adds a test that asserts that retries will be made, and fixes the bug.

* Fix clippy lint

* Update changelog

Co-authored-by: default avatarZelda Hessler <zhessler@amazon.com>
parent 9f1ef3d4
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -22,7 +22,13 @@ meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "jdisanti"

[[aws-sdk-rust]]
message = "Debug implementation of Credentials will print `expiry` in a human readable way"
message = "Debug implementation of Credentials will print `expiry` in a human readable way."
meta = { "breaking" = false, "tada" = false, "bug" = false }
references = ["smithy-rs#973"]
author = "rcoh"

[[aws-sdk-rust]]
message = "Fix bug where ECS credential provider could not perform retries."
meta = { "breaking" = false, "tada" = false, "bug" = true }
references = ["smithy-rs#998", "aws-sdk-rust#359"]
author = "rcoh"
+28 −1
Original line number Diff line number Diff line
@@ -451,6 +451,7 @@ mod test {
    use aws_types::os_shim_internal::Env;
    use aws_types::Credentials;

    use aws_smithy_async::rt::sleep::TokioSleep;
    use aws_smithy_client::erase::DynConnector;
    use aws_smithy_client::test_connection::TestConnection;
    use aws_smithy_http::body::SdkBody;
@@ -467,7 +468,8 @@ mod test {
    fn provider(env: Env, connector: DynConnector) -> EcsCredentialsProvider {
        let provider_config = ProviderConfig::empty()
            .with_env(env)
            .with_http_connector(connector);
            .with_http_connector(connector)
            .with_sleep(TokioSleep::new());
        Builder::default().configure(&provider_config).build()
    }

@@ -625,6 +627,31 @@ mod test {
        connector.assert_requests_match(&[]);
    }

    #[tokio::test]
    async fn retry_5xx() {
        let env = Env::from_slice(&[("AWS_CONTAINER_CREDENTIALS_RELATIVE_URI", "/credentials")]);
        let connector = TestConnection::new(vec![
            (
                creds_request("http://169.254.170.2/credentials", None),
                http::Response::builder()
                    .status(500)
                    .body(SdkBody::empty())
                    .unwrap(),
            ),
            (
                creds_request("http://169.254.170.2/credentials", None),
                ok_creds_response(),
            ),
        ]);
        tokio::time::pause();
        let provider = provider(env, DynConnector::new(connector.clone()));
        let creds = provider
            .provide_credentials()
            .await
            .expect("valid credentials");
        assert_correct(creds);
    }

    #[tokio::test]
    async fn load_valid_creds_no_auth() {
        let env = Env::from_slice(&[("AWS_CONTAINER_CREDENTIALS_RELATIVE_URI", "/credentials")]);
+7 −0
Original line number Diff line number Diff line
@@ -112,6 +112,7 @@ impl Builder {
        let connector = expect_connector(provider_config.connector(&http_settings));
        let client = aws_smithy_client::Builder::new()
            .connector(connector)
            .sleep_impl(provider_config.sleep())
            .build();
        HttpCredentialProvider {
            uri,
@@ -129,6 +130,12 @@ impl ParseStrictResponse for CredentialsResponseParser {
    type Output = credentials::Result;

    fn parse(&self, response: &Response<Bytes>) -> Self::Output {
        if !response.status().is_success() {
            return Err(CredentialsError::provider_error(format!(
                "Non-success status from HTTP credential provider: {:?}",
                response.status()
            )));
        }
        let str_resp =
            std::str::from_utf8(response.body().as_ref()).map_err(CredentialsError::unhandled)?;
        let json_creds = parse_json_credentials(str_resp).map_err(CredentialsError::unhandled)?;