@@ -1162,3 +1162,42 @@ TEST_F(AWSCachedCredentialsTest, ShouldCacheCredenitalAsync)
11621162 ASSERT_TRUE (containCredentials (creds, {" and" , " no" , " surprises" }));
11631163 ASSERT_FALSE (containCredentials (creds, {" a" , " quiet" , " life" }));
11641164}
1165+
1166+ class STSCredentialsProviderTest : public Aws ::Testing::AwsCppSdkGTestSuite {
1167+ public:
1168+ void SetUp () {
1169+ mockHttpClient = Aws::MakeShared<MockHttpClient>(AllocationTag);
1170+ mockHttpClientFactory = Aws::MakeShared<MockHttpClientFactory>(AllocationTag);
1171+ mockHttpClientFactory->SetClient (mockHttpClient);
1172+ SetHttpClientFactory (mockHttpClientFactory);
1173+ }
1174+
1175+ void TearDown () {
1176+ mockHttpClient = nullptr ;
1177+ mockHttpClientFactory = nullptr ;
1178+ CleanupHttp ();
1179+ InitHttp ();
1180+ }
1181+
1182+ std::shared_ptr<MockHttpClient> mockHttpClient;
1183+ std::shared_ptr<MockHttpClientFactory> mockHttpClientFactory;
1184+ };
1185+
1186+ TEST_F (STSCredentialsProviderTest, TestInvalidRegionCredentials) {
1187+ Aws::Client::ClientConfiguration::CredentialProviderConfiguration config;
1188+ config.region = " @amazon.com#" ;
1189+
1190+ config.stsCredentialsProviderConfig .roleArn = " arn:aws:iam::123456789012:role/TestRole" ;
1191+ config.stsCredentialsProviderConfig .sessionName = " test-session" ;
1192+ config.stsCredentialsProviderConfig .tokenFilePath = " /tmp/token" ;
1193+
1194+ STSAssumeRoleWebIdentityCredentialsProvider provider (config);
1195+
1196+ auto creds = provider.GetAWSCredentials ();
1197+ ASSERT_TRUE (creds.IsEmpty ());
1198+
1199+ if (!mockHttpClient ->GetAllRequestsMade ().empty ()) {
1200+ auto httpRequest = mockHttpClient->GetMostRecentHttpRequest ();
1201+ ASSERT_TRUE (httpRequest.GetURIString ().find (" @amazon.com#" ) != std::string::npos);
1202+ }
1203+ }
0 commit comments