Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@
"overengineered",
"callfopen",
"throughs",
"msteiger",
"fseeki",
"ftelli",
// Json parser
"Jsonize",
"CJSON",
Expand Down
5 changes: 4 additions & 1 deletion src/aws-cpp-sdk-core/source/endpoint/BuiltInParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include <aws/core/endpoint/BuiltInParameters.h>
#include <aws/core/utils/DNS.h>
#include <aws/core/utils/logging/LogMacros.h>
#include <aws/core/config/EndpointResolver.h>

Expand Down Expand Up @@ -41,7 +42,9 @@ namespace Endpoint
if (!config.region.empty()) {
static const char* FIPS_PREFIX = "fips-";
static const char* FIPS_SUFFIX = "-fips";
if (config.region.rfind(FIPS_PREFIX, 0) == 0) {
if (!Aws::Utils::IsValidDnsLabel(config.region)) {
AWS_LOGSTREAM_ERROR(ENDPOINT_BUILTIN_LOG_TAG, "Invalid region name: " << config.region);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sanity check: logstream error causes the function to error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it just logs a failure, since the function returns void, and we have exceptions disabled we cannot return a real "error" from the function. the failure mode is that the region built in parameter region is not set. It fails in endpoint resolution because region is not set. Hypothetically if a endpoints rule set did not require region, resolution would still work.

} else if (config.region.rfind(FIPS_PREFIX, 0) == 0) {
// Backward compatibility layer for code hacking previous SDK version
Aws::String regionOverride = config.region.substr(strlen(FIPS_PREFIX));
forceFIPS = true;
Expand Down
96 changes: 92 additions & 4 deletions tests/aws-cpp-sdk-core-tests/endpoint/endpointParamTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <aws/core/utils/memory/stl/AWSArray.h>
#include <aws/testing/AwsCppSdkGTestSuite.h>

namespace EndpointParamTest{
namespace {
const size_t RulesBlobSize = 498;
using RulesBlobT = Aws::Array<const char, RulesBlobSize>;

Expand All @@ -31,21 +31,89 @@ static constexpr RulesBlobT RulesBlob = {{
's','e','t','"',',','"','t','y','p','e','"',':','"','e','r','r','o','r','"','}',']','}','\0'
}};

/**
We store endpoint rules json as a character array. This is the pretty print
of the following test rules set
{
"version": "1.0",
"parameters": {
"Region": {
"builtIn": "AWS::Region",
"required": false,
"documentation": "The AWS region used to dispatch the request.",
"type": "string"
}
},
"rules": [
{
"documentation": "Test region blob",
"conditions": [
{
"fn": "isSet",
"argv": [
{
"ref": "Region"
}
]
}
],
"endpoint": {
"url": "https://tartarus.{Region}.amazon.aws.com/"
},
"type": "endpoint"
},
{
"conditions": [],
"documentation": "error fallthrough",
"error": "no array values set",
"type": "error"
}
]
}
*/
const size_t RegionRulesBlobSize = 447;
using RegionRulesBlobT = Aws::Array<const char, RegionRulesBlobSize>;
static constexpr RegionRulesBlobT RegionRulesBlob = {
{'{', '"', 'v', 'e', 'r', 's', 'i', 'o', 'n', '"', ':', '"', '1', '.', '0', '"', ',', '"', 'p', 'a', 'r', 'a', 'm', 'e', 't', 'e', 'r',
's', '"', ':', '{', '"', 'R', 'e', 'g', 'i', 'o', 'n', '"', ':', '{', '"', 'b', 'u', 'i', 'l', 't', 'I', 'n', '"', ':', '"', 'A', 'W',
'S', ':', ':', 'R', 'e', 'g', 'i', 'o', 'n', '"', ',', '"', 'r', 'e', 'q', 'u', 'i', 'r', 'e', 'd', '"', ':', 'f', 'a', 'l', 's', 'e',
',', '"', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 'a', 't', 'i', 'o', 'n', '"', ':', '"', 'T', 'h', 'e', ' ', 'A', 'W', 'S', ' ', 'r',
'e', 'g', 'i', 'o', 'n', ' ', 'u', 's', 'e', 'd', ' ', 't', 'o', ' ', 'd', 'i', 's', 'p', 'a', 't', 'c', 'h', ' ', 't', 'h', 'e', ' ',
'r', 'e', 'q', 'u', 'e', 's', 't', '.', '"', ',', '"', 't', 'y', 'p', 'e', '"', ':', '"', 's', 't', 'r', 'i', 'n', 'g', '"', '}', '}',
',', '"', 'r', 'u', 'l', 'e', 's', '"', ':', '[', '{', '"', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 'a', 't', 'i', 'o', 'n', '"', ':',
'"', 'T', 'e', 's', 't', ' ', 'r', 'e', 'g', 'i', 'o', 'n', ' ', 'b', 'l', 'o', 'b', '"', ',', '"', 'c', 'o', 'n', 'd', 'i', 't', 'i',
'o', 'n', 's', '"', ':', '[', '{', '"', 'f', 'n', '"', ':', '"', 'i', 's', 'S', 'e', 't', '"', ',', '"', 'a', 'r', 'g', 'v', '"', ':',
'[', '{', '"', 'r', 'e', 'f', '"', ':', '"', 'R', 'e', 'g', 'i', 'o', 'n', '"', '}', ']', '}', ']', ',', '"', 'e', 'n', 'd', 'p', 'o',
'i', 'n', 't', '"', ':', '{', '"', 'u', 'r', 'l', '"', ':', '"', 'h', 't', 't', 'p', 's', ':', '/', '/', 't', 'a', 'r', 't', 'a', 'r',
'u', 's', '.', '{', 'R', 'e', 'g', 'i', 'o', 'n', '}', '.', 'a', 'm', 'a', 'z', 'o', 'n', '.', 'a', 'w', 's', '.', 'c', 'o', 'm', '/',
'"', '}', ',', '"', 't', 'y', 'p', 'e', '"', ':', '"', 'e', 'n', 'd', 'p', 'o', 'i', 'n', 't', '"', '}', ',', '{', '"', 'c', 'o', 'n',
'd', 'i', 't', 'i', 'o', 'n', 's', '"', ':', '[', ']', ',', '"', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 'a', 't', 'i', 'o', 'n', '"',
':', '"', 'e', 'r', 'r', 'o', 'r', ' ', 'f', 'a', 'l', 'l', 't', 'h', 'r', 'o', 'u', 'g', 'h', '"', ',', '"', 'e', 'r', 'r', 'o', 'r',
'"', ':', '"', 'n', 'o', ' ', 'a', 'r', 'r', 'a', 'y', ' ', 'v', 'a', 'l', 'u', 'e', 's', ' ', 's', 'e', 't', '"', ',', '"', 't', 'y',
'p', 'e', '"', ':', '"', 'e', 'r', 'r', 'o', 'r', '"', '}', ']', '}', '\0'}};

class RegionEndpointProviderTest : public Aws::Endpoint::DefaultEndpointProvider<> {
public:
using RegionEndpointResolveEndpointOutcome = Aws::Endpoint::ResolveEndpointOutcome;

RegionEndpointProviderTest() : Aws::Endpoint::DefaultEndpointProvider<>(RegionRulesBlob.data(), RegionRulesBlobSize) {}

~RegionEndpointProviderTest() override = default;
};

class TestServiceEndpointProviderTest : public Aws::Endpoint::DefaultEndpointProvider<>
{
class TestServiceEndpointProviderTest : public Aws::Endpoint::DefaultEndpointProvider<> {
public:
using TestServiceResolveEndpointOutcome = Aws::Endpoint::ResolveEndpointOutcome;

TestServiceEndpointProviderTest()
: Aws::Endpoint::DefaultEndpointProvider<>(EndpointParamTest::RulesBlob.data(), EndpointParamTest::RulesBlobSize)
: Aws::Endpoint::DefaultEndpointProvider<>(RulesBlob.data(), RulesBlobSize)
{}

~TestServiceEndpointProviderTest()
{
}
};
} // namespace

class EndpointTest : public Aws::Testing::AwsCppSdkGTestSuite {
protected:
Expand Down Expand Up @@ -82,3 +150,23 @@ TEST_F(EndpointTest, testStringArrayParamError) {

EXPECT_FALSE(res.IsSuccess());
}

TEST_F(EndpointTest, validRegionShouldBeUsed) {
RegionEndpointProviderTest regionEndpointProvider{};
Aws::Client::ClientConfiguration configuration{};
configuration.region = "us-east-1";
regionEndpointProvider.InitBuiltInParameters(configuration);
const auto result = regionEndpointProvider.ResolveEndpoint({});
EXPECT_TRUE(result.IsSuccess());
EXPECT_EQ(result.GetResult().GetURL(), "https://tartarus.us-east-1.amazon.aws.com");
}

TEST_F(EndpointTest, invalidRegionShouldNotBeUsed) {
RegionEndpointProviderTest regionEndpointProvider{};
Aws::Client::ClientConfiguration configuration{};
configuration.region = "i-am-thou-thou-art-i/";
regionEndpointProvider.InitBuiltInParameters(configuration);
const auto result = regionEndpointProvider.ResolveEndpoint({});
EXPECT_FALSE(result.IsSuccess());
EXPECT_EQ(result.GetError().GetErrorType(), Aws::Client::CoreErrors::INVALID_PARAMETER_COMBINATION);
}
Loading