Skip to content

Commit

Permalink
Merge branch 'awsdocs:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
AMZ-brandon authored Mar 14, 2024
2 parents 4573665 + 3d2905f commit baf7687
Show file tree
Hide file tree
Showing 47 changed files with 692 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@
<Marker>aW5ub2RiX2NoZWNrc3Vtcw==</Marker>
<Parameters>
<Parameter>
<AllowedValues>0,1</AllowedValues>
<ApplyType>static</ApplyType>
<DataType>boolean</DataType>
<Description>Controls whether user-defined functions that have only an xxx symbol for the main function
can be loaded
</Description>
<AllowedValues>1-65535</AllowedValues>
<ApplyType>dynamic</ApplyType>
<DataType>integer</DataType>
<Description>Description text</Description>
<ApplyMethod>pending-reboot</ApplyMethod>
<Source>engine-default</Source>
<ParameterName>allow-suspicious-udfs</ParameterName>
<IsModifiable>false</IsModifiable>
<SupportedEngineModes>
<member>provisioned</member>
</SupportedEngineModes>
<Source>user</Source>
<ParameterName>auto_increment_increment</ParameterName>
<IsModifiable>true</IsModifiable>
<ParameterValue>3</ParameterValue>
</Parameter>
<Parameter>
<AllowedValues>1-65535</AllowedValues>
<ApplyType>dynamic</ApplyType>
<DataType>integer</DataType>
<Description>Description text</Description>
<ApplyMethod>pending-reboot</ApplyMethod>
<Source>user</Source>
<ParameterName>auto_decrement_decrement</ParameterName>
<IsModifiable>true</IsModifiable>
<ParameterValue>3</ParameterValue>
</Parameter>
</Parameters>
</DescribeDBClusterParametersResult>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@
<DescribeDBClusterParametersResult>
<Parameters>
<Parameter>
<AllowedValues>0,1</AllowedValues>
<AllowedValues>1-65535</AllowedValues>
<ApplyType>dynamic</ApplyType>
<DataType>boolean</DataType>
<Description>Enables per-index compression-related statistics in the
INFORMATION_SCHEMA.INNODB_CMP_PER_INDEX table.
</Description>
<DataType>integer</DataType>
<Description>Description text</Description>
<ApplyMethod>pending-reboot</ApplyMethod>
<Source>engine-default</Source>
<ParameterName>innodb_cmp_per_index_enabled</ParameterName>
<Source>user</Source>
<ParameterName>auto_increment_increment</ParameterName>
<IsModifiable>true</IsModifiable>
<SupportedEngineModes>
<member>provisioned</member>
</SupportedEngineModes>
<ParameterValue>3</ParameterValue>
</Parameter>
<Parameter>
<AllowedValues>1-65535</AllowedValues>
<ApplyType>dynamic</ApplyType>
<DataType>integer</DataType>
<Description>Description text</Description>
<ApplyMethod>pending-reboot</ApplyMethod>
<Source>user</Source>
<ParameterName>auto_decrement_decrement</ParameterName>
<IsModifiable>true</IsModifiable>
<ParameterValue>3</ParameterValue>
</Parameter>
</Parameters>
</DescribeDBClusterParametersResult>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
<IsModifiable>true</IsModifiable>
<ParameterValue>3</ParameterValue>
</Parameter>
<Parameter>
<AllowedValues>1-65535</AllowedValues>
<ApplyType>dynamic</ApplyType>
<DataType>integer</DataType>
<Description>Description text</Description>
<ApplyMethod>pending-reboot</ApplyMethod>
<Source>user</Source>
<ParameterName>auto_decrement_decrement</ParameterName>
<IsModifiable>true</IsModifiable>
<ParameterValue>3</ParameterValue>
</Parameter>
</Parameters>
</DescribeDBClusterParametersResult>
</DescribeDBClusterParametersResponse>
Expand Down
1 change: 0 additions & 1 deletion cpp/example_code/autoscaling/tests/autoscaling_gtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class CustomMockHTTPClient : public MockHttpClient {
};

void AwsDocTest::AutoScaling_GTests::SetUpTestSuite() {
s_options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Debug;
InitAPI(s_options);

// s_clientConfig must be a pointer because the client config must be initialized
Expand Down
1 change: 1 addition & 0 deletions cpp/example_code/iam/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ target_compile_definitions(
${CURRENT_TARGET}
PUBLIC
TESTING_BUILD
SRC_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
)

target_link_libraries(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,58 @@


namespace AwsDocTest {
// This test requires a user. It fails when running in an EC2 instance that assumes a role.
// Add the 'U' indicating it only runs in a user environment.
// NOLINTNEXTLINE(readability-named-parameter)
TEST_F(IAM_GTests, create_user_assume_role_scenario_2_) {
TEST_F(IAM_GTests, create_user_assume_role_scenario_2U_) {

auto result = AwsDoc::IAM::iamCreateUserAssumeRoleScenario(*s_clientConfig);
EXPECT_TRUE(result);
}

// NOLINTNEXTLINE(readability-named-parameter)
TEST_F(IAM_GTests, create_user_assume_role_scenario_3_) {
MockHTTP mockHttp;
bool result = mockHttp.addResponseWithBody("mock_input/1-CreateUser.xml");
ASSERT_TRUE(result) << preconditionError() << std::endl;

result = mockHttp.addResponseWithBody("mock_input/2-GetUser.xml");
ASSERT_TRUE(result) << preconditionError() << std::endl;

result = mockHttp.addResponseWithBody("mock_input/3-CreateRole.xml");
ASSERT_TRUE(result) << preconditionError() << std::endl;

result = mockHttp.addResponseWithBody("mock_input/4-CreatePolicy.xml");
ASSERT_TRUE(result) << preconditionError() << std::endl;

result = mockHttp.addResponseWithBody("mock_input/5-AssumeRole.xml", Aws::Http::HttpResponseCode::FORBIDDEN);
ASSERT_TRUE(result) << preconditionError() << std::endl;

result = mockHttp.addResponseWithBody("mock_input/10-AssumeRole.xml");
ASSERT_TRUE(result) << preconditionError() << std::endl;

result = mockHttp.addResponseWithBody("mock_input/ListBucketsFailed.xml", Aws::Http::HttpResponseCode::FORBIDDEN);
ASSERT_TRUE(result) << preconditionError() << std::endl;

result = mockHttp.addResponseWithBody("mock_input/11-AttachRolePolicy.xml");
ASSERT_TRUE(result) << preconditionError() << std::endl;

result = mockHttp.addResponseWithBody("mock_input/ListBuckets.xml");
ASSERT_TRUE(result) << preconditionError() << std::endl;

result = mockHttp.addResponseWithBody("mock_input/12-DetachRolePolicy.xml");
ASSERT_TRUE(result) << preconditionError() << std::endl;

result = mockHttp.addResponseWithBody("mock_input/13-DeletePolicy.xml");
ASSERT_TRUE(result) << preconditionError() << std::endl;

result = mockHttp.addResponseWithBody("mock_input/14-DeleteRole.xml");
ASSERT_TRUE(result) << preconditionError() << std::endl;

result = mockHttp.addResponseWithBody("mock_input/15-DeleteUser.xml");
ASSERT_TRUE(result) << preconditionError() << std::endl;

result = AwsDoc::IAM::iamCreateUserAssumeRoleScenario(*s_clientConfig);
EXPECT_TRUE(result);
}
} // namespace AwsDocTest
85 changes: 85 additions & 0 deletions cpp/example_code/iam/tests/iam_gtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,62 @@
#include <aws/iam/model/CreatePolicyRequest.h>
#include <aws/iam/model/CreateAccountAliasRequest.h>
#include <aws/core/utils/UUID.h>
#include <fstream>

Aws::SDKOptions AwsDocTest::IAM_GTests::s_options;
std::unique_ptr<Aws::Client::ClientConfiguration> AwsDocTest::IAM_GTests::s_clientConfig;
Aws::String AwsDocTest::IAM_GTests::s_accessKey;
Aws::String AwsDocTest::IAM_GTests::s_role;
Aws::String AwsDocTest::IAM_GTests::s_userName;
Aws::String AwsDocTest::IAM_GTests::s_policyArn;
static const char ALLOCATION_TAG[] = "IAM_GTEST";

/*
* Subclass MockHTTPCLient to respond to credential requests.
* Otherwise, the stored responses are returned for credential requests
* and not the service API calls.
*/
class CustomMockHTTPClient : public MockHttpClient {
public:
explicit CustomMockHTTPClient(
const std::shared_ptr<Aws::Http::HttpRequest> &requestTmp) {
std::shared_ptr<Aws::Http::Standard::StandardHttpResponse> goodResponse = Aws::MakeShared<Aws::Http::Standard::StandardHttpResponse>(
ALLOCATION_TAG, requestTmp);
goodResponse->AddHeader("Content-Type", "text/json");
goodResponse->SetResponseCode(Aws::Http::HttpResponseCode::OK);
Aws::Utils::DateTime expiration =
Aws::Utils::DateTime::Now() + std::chrono::milliseconds(60000);

goodResponse->GetResponseBody() << "{"
<< R"("RoleArn":"arn:aws:iam::123456789012:role/MockRole",)"
<< R"("AccessKeyId":"ABCDEFGHIJK",)"
<< R"("SecretAccessKey":"ABCDEFGHIJK",)"
<< R"(Token":"ABCDEFGHIJK==","Expiration":")" << expiration.ToGmtString(Aws::Utils::DateFormat::ISO_8601) << "\""
<< "}";
this->AddResponseToReturn(goodResponse);

mCredentialsResponse = MockHttpClient::MakeRequest(requestTmp);
}

std::shared_ptr<Aws::Http::HttpResponse>
MakeRequest(const std::shared_ptr<Aws::Http::HttpRequest> &request,
Aws::Utils::RateLimits::RateLimiterInterface *readLimiter,
Aws::Utils::RateLimits::RateLimiterInterface *writeLimiter) const override {

// Do not use stored responses for a credentials request.
if (request->GetURIString().find("/credentials/") != std::string::npos) {
std::cout << "CustomMockHTTPClient returning credentials request."
<< std::endl;
return mCredentialsResponse;
}
else {
return MockHttpClient::MakeRequest(request, readLimiter, writeLimiter);;
}
}

private:
std::shared_ptr<Aws::Http::HttpResponse> mCredentialsResponse;
};

void AwsDocTest::IAM_GTests::SetUpTestSuite() {
InitAPI(s_options);
Expand Down Expand Up @@ -380,5 +429,41 @@ bool AwsDocTest::IAM_GTests::suppressStdOut() {
return std::getenv("EXAMPLE_TESTS_LOG_ON") == nullptr;
}

AwsDocTest::MockHTTP::MockHTTP() {
requestTmp = CreateHttpRequest(Aws::Http::URI("https://test.com/"),
Aws::Http::HttpMethod::HTTP_GET,
Aws::Utils::Stream::DefaultResponseStreamFactoryMethod);
mockHttpClient = Aws::MakeShared<CustomMockHTTPClient>(
ALLOCATION_TAG, requestTmp);
mockHttpClientFactory = Aws::MakeShared<MockHttpClientFactory>(ALLOCATION_TAG);
mockHttpClientFactory->SetClient(mockHttpClient);
SetHttpClientFactory(mockHttpClientFactory);
}

AwsDocTest::MockHTTP::~MockHTTP() {
Aws::Http::CleanupHttp();
Aws::Http::InitHttp();
}

bool AwsDocTest::MockHTTP::addResponseWithBody(const std::string &fileName,
Aws::Http::HttpResponseCode httpResponseCode) {
std::string filePath = std::string(SRC_DIR) + "/" + fileName;

std::ifstream inStream(filePath);
if (inStream) {
std::shared_ptr<Aws::Http::Standard::StandardHttpResponse> goodResponse = Aws::MakeShared<Aws::Http::Standard::StandardHttpResponse>(
ALLOCATION_TAG, requestTmp);
goodResponse->AddHeader("Content-Type", "text/json");
goodResponse->SetResponseCode(httpResponseCode);
goodResponse->GetResponseBody() << inStream.rdbuf();
mockHttpClient->AddResponseToReturn(goodResponse);

return true;
}

std::cerr << "MockHTTP::addResponseWithBody open file error '" << filePath << "'."
<< std::endl;

return false;
}

24 changes: 21 additions & 3 deletions cpp/example_code/iam/tests/iam_gtests.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// SPDX-License-Identifier: Apache-2.0

#pragma once
#ifndef S3_EXAMPLES_S3_GTESTS_H
#define S3_EXAMPLES_S3_GTESTS_H
#ifndef IAM_EXAMPLES_IAM_GTESTS_H
#define IAM_EXAMPLES_IAM_GTESTS_H

#include <aws/core/Aws.h>
#include <memory>
#include <gtest/gtest.h>
#include <aws/testing/mocks/http/MockHttpClient.h>

namespace AwsDocTest {

Expand Down Expand Up @@ -88,6 +89,23 @@ namespace AwsDocTest {
static Aws::String s_userName;
static Aws::String s_policyArn;
};

class MockHTTP {
public:
MockHTTP();

virtual ~MockHTTP();

bool addResponseWithBody(const std::string &fileName,
Aws::Http::HttpResponseCode httpResponseCode = Aws::Http::HttpResponseCode::OK);

private:

std::shared_ptr<MockHttpClient> mockHttpClient;
std::shared_ptr<MockHttpClientFactory> mockHttpClientFactory;
std::shared_ptr<Aws::Http::HttpRequest> requestTmp;
}; // MockHTTP

} // AwsDocTest

#endif //S3_EXAMPLES_S3_GTESTS_H
#endif //IAM_EXAMPLES_IAM_GTESTS_H
14 changes: 14 additions & 0 deletions cpp/example_code/iam/tests/mock_input/1-CreateUser.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<CreateUserResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/"> <CreateUserResult>
<User>
<Path>/</Path>
<UserName>iam-demo-user</UserName>
<Arn>arn:aws:iam::1111111222222:user/iam-demo-user</Arn>
<UserId>AIDARZQKN6ARC25I5FZPP</UserId>
<CreateDate>2024-03-11T14:18:54Z</CreateDate>
</User>
</CreateUserResult>
<ResponseMetadata>
<RequestId>4c7cd91f-dace-4832-b892-cdfdf1f7c861</RequestId>
</ResponseMetadata>
</CreateUserResponse>

17 changes: 17 additions & 0 deletions cpp/example_code/iam/tests/mock_input/10-AssumeRole.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<AssumeRoleResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/"> <AssumeRoleResult>
<AssumedRoleUser>
<AssumedRoleId>AROARZQKN6ARBA3MU7HQ4:iam-demo-role-session-facb92a0-a797-44e1-8430-c79a5b067201</AssumedRoleId>
<Arn>arn:aws:sts::1111111222222:assumed-role/iam-demo-role/iam-demo-role-session-facb92a0-a797-44e1-8430-c79a5b067201</Arn>
</AssumedRoleUser>
<Credentials>
<AccessKeyId>AAABBBBBBBBB</AccessKeyId>
<SecretAccessKey>AAABBBBBBBBB</SecretAccessKey>
<SessionToken>AAABBBBBBBBB+USs</SessionToken>
<Expiration>2040-03-11T15:19:02Z</Expiration>
</Credentials>
</AssumeRoleResult>
<ResponseMetadata>
<RequestId>d52b113b-597f-41e6-99d6-ed6e53a915bf</RequestId>
</ResponseMetadata>
</AssumeRoleResponse>

5 changes: 5 additions & 0 deletions cpp/example_code/iam/tests/mock_input/11-AttachRolePolicy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<AttachRolePolicyResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/"> <ResponseMetadata>
<RequestId>0c6e3333-33ae-4269-8338-979a8bd0346d</RequestId>
</ResponseMetadata>
</AttachRolePolicyResponse>

5 changes: 5 additions & 0 deletions cpp/example_code/iam/tests/mock_input/12-DetachRolePolicy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<DetachRolePolicyResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/"> <ResponseMetadata>
<RequestId>61891e46-50ca-48d0-8b50-0d958d863fb4</RequestId>
</ResponseMetadata>
</DetachRolePolicyResponse>

5 changes: 5 additions & 0 deletions cpp/example_code/iam/tests/mock_input/13-DeletePolicy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<DeletePolicyResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/"> <ResponseMetadata>
<RequestId>37c90b6c-06de-4a4d-9b1c-f5cdc19e6ef1</RequestId>
</ResponseMetadata>
</DeletePolicyResponse>

5 changes: 5 additions & 0 deletions cpp/example_code/iam/tests/mock_input/14-DeleteRole.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<DeleteRoleResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/"> <ResponseMetadata>
<RequestId>0843a35e-a598-44a1-9eb1-f1adda10b162</RequestId>
</ResponseMetadata>
</DeleteRoleResponse>

5 changes: 5 additions & 0 deletions cpp/example_code/iam/tests/mock_input/15-DeleteUser.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<DeleteUserResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/"> <ResponseMetadata>
<RequestId>545004dc-b93c-4174-8b7e-8abd11577996</RequestId>
</ResponseMetadata>
</DeleteUserResponse>

15 changes: 15 additions & 0 deletions cpp/example_code/iam/tests/mock_input/2-GetUser.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<GetUserResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/"> <GetUserResult>
<User>
<Path>/</Path>
<PasswordLastUsed>2023-04-10T19:34:28Z</PasswordLastUsed>
<UserName>UnitTester</UserName>
<Arn>arn:aws:iam::1111111222222:user/UnitTester</Arn>
<UserId>AIDARZQKN6ARLXIC6YK7J</UserId>
<CreateDate>2022-08-10T13:38:30Z</CreateDate>
</User>
</GetUserResult>
<ResponseMetadata>
<RequestId>12edbe2c-76a6-416d-9470-4010556b1c59</RequestId>
</ResponseMetadata>
</GetUserResponse>

Loading

0 comments on commit baf7687

Please sign in to comment.