Skip to content

Commit de12417

Browse files
committed
testing
1 parent 5a0cd86 commit de12417

File tree

3 files changed

+48
-82
lines changed

3 files changed

+48
-82
lines changed

src/aws-cpp-sdk-core/source/internal/AWSHttpResourceClient.cpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ namespace Aws
119119
}
120120
std::shared_ptr<HttpRequest> request(CreateHttpRequest(ss.str(), HttpMethod::HTTP_GET,
121121
Aws::Utils::Stream::DefaultResponseStreamFactoryMethod));
122-
123122
request->SetUserAgent(m_userAgent);
124123

125124
if (authToken)
@@ -133,6 +132,12 @@ namespace Aws
133132
AmazonWebServiceResult<Aws::String> AWSHttpResourceClient::GetResourceWithAWSWebServiceResult(const std::shared_ptr<HttpRequest> &httpRequest) const
134133
{
135134
AWS_LOGSTREAM_TRACE(m_logtag.c_str(), "Retrieving credentials from " << httpRequest->GetURIString());
135+
Aws::Http::URI uri(httpRequest->GetURIString());
136+
if (!Aws::Utils::IsValidHost(uri.GetHost())) {
137+
AWS_LOGSTREAM_FATAL(m_logtag.c_str(), "Invalid endpoint host constructed: "<< uri.GetHost());
138+
return {{}, {}, HttpResponseCode::REQUEST_NOT_MADE};
139+
}
140+
136141
if (!m_httpClient)
137142
{
138143
AWS_LOGSTREAM_FATAL(m_logtag.c_str(), "Unable to get a response: missing http client!");
@@ -552,15 +557,6 @@ namespace Aws
552557
ss << ".cn";
553558
}
554559

555-
Aws::Http::URI uri(ss.str());
556-
if (!Aws::Utils::IsValidHost(uri.GetHost()))
557-
{
558-
AWS_LOGSTREAM_ERROR(STS_RESOURCE_CLIENT_LOG_TAG,
559-
"Invalid endpoint host constructed: " << uri.GetHost());
560-
m_endpoint.clear();
561-
return;
562-
}
563-
564560
m_endpoint = ss.str();
565561

566562
AWS_LOGSTREAM_INFO(STS_RESOURCE_CLIENT_LOG_TAG, "Creating STS ResourceClient with endpoint: " << m_endpoint);
@@ -696,15 +692,6 @@ namespace Aws
696692
{
697693
ss << ".cn";
698694
}
699-
ss.str();
700-
701-
Aws::Http::URI uri(ss.str());
702-
if (!Aws::Utils::IsValidHost(uri.GetHost()))
703-
{
704-
AWS_LOGSTREAM_ERROR(SSO_RESOURCE_CLIENT_LOG_TAG,
705-
"Invalid endpoint host constructed: " << uri.GetHost());
706-
return {};
707-
}
708695

709696
return ss.str();
710697
}

tests/aws-cpp-sdk-core-tests/aws/auth/AWSCredentialsProviderTest.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,48 @@ sso_start_url = https://d-92671207e4.awsapps.com/start
956956
ASSERT_TRUE(mockHttpClient->GetAllRequestsMade().empty());
957957
}
958958

959+
TEST_F(SSOCredentialsProviderTest, TestInvalidRegionCredentials)
960+
{
961+
AWS_LOGSTREAM_DEBUG("TEST_SSO", "Preparing Test Token file in: " << m_ssoTokenFileName);
962+
Aws::OFStream tokenFile(m_ssoTokenFileName.c_str(), Aws::OFStream::out | Aws::OFStream::trunc);
963+
tokenFile << R"({
964+
"accessToken": "base64string",
965+
"expiresAt": ")";
966+
tokenFile << DateTime::Now().GetYear() + 1;
967+
tokenFile << R"(-01-02T00:00:00Z",
968+
"region": "us-west-2",
969+
"startUrl": "https://d-92671207e4.awsapps.com/start"
970+
})";
971+
tokenFile.close();
972+
973+
Aws::OFStream configFile(m_configFileName.c_str(), Aws::OFStream::out | Aws::OFStream::trunc);
974+
configFile << R"([default]
975+
sso_account_id = 012345678901
976+
sso_region = @amazon.com#
977+
sso_role_name = SampleRole
978+
sso_start_url = https://d-92671207e4.awsapps.com/start
979+
)";
980+
configFile.close();
981+
982+
// Mock DNS/connection failure for invalid region
983+
std::shared_ptr<HttpRequest> requestTmp = CreateHttpRequest(URI("https://[email protected]#.amazonaws.com/federation/credentials"), HttpMethod::HTTP_GET, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod);
984+
std::shared_ptr<StandardHttpResponse> dnsFailureResponse = Aws::MakeShared<StandardHttpResponse>(AllocationTag, requestTmp);
985+
dnsFailureResponse->SetResponseCode(HttpResponseCode::REQUEST_NOT_MADE);
986+
mockHttpClient->AddResponseToReturn(dnsFailureResponse);
987+
988+
Aws::Config::ReloadCachedConfigFile();
989+
SSOCredentialsProvider provider;
990+
991+
auto creds = provider.GetAWSCredentials();
992+
ASSERT_TRUE(creds.IsEmpty());
993+
994+
// Check if any requests were made before calling GetMostRecentHttpRequest
995+
if (!mockHttpClient->GetAllRequestsMade().empty()) {
996+
auto request = mockHttpClient->GetMostRecentHttpRequest();
997+
ASSERT_TRUE(request.GetURIString().find("@amazon.com#") != std::string::npos);
998+
}
999+
}
1000+
9591001
class AWSCredentialsTest : public Aws::Testing::AwsCppSdkGTestSuite
9601002
{
9611003
};

tests/aws-cpp-sdk-core-tests/aws/auth/SSRFValidationTest.cpp

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)