Skip to content

Commit f1311ec

Browse files
committed
Updates integ tests to use environment varible for auth and resources
1 parent 7c37b57 commit f1311ec

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

aws-cpp-sdk-lambda-integration-tests/FunctionTest.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <aws/cognito-identity/CognitoIdentityClient.h>
4545
#include <aws/testing/TestingEnvironment.h>
4646
#include <aws/core/utils/UUID.h>
47+
#include <aws/core/platform/Environment.h>
4748

4849
using namespace Aws::Auth;
4950
using namespace Aws::Http;
@@ -63,6 +64,7 @@ static const char BASE_SIMPLE_FUNCTION[] = "TestSimple";
6364
static const char BASE_UNHANDLED_ERROR_FUNCTION[] = "TestUnhandledError";
6465
static const char SIMPLE_FUNCTION_CODE[] = RESOURCES_DIR "/succeed.zip";
6566
static const char UNHANDLED_ERROR_FUNCTION_CODE[] = RESOURCES_DIR "/unhandled.zip";
67+
static const char TEST_LAMBDA_CODE_PATH[] = "TEST_LAMBDA_CODE_PATH";
6668
static const char ALLOCATION_TAG[] = "FunctionTest";
6769
static const char BASE_IAM_ROLE_NAME[] = "AWSNativeSDKLambdaIntegrationTestRole";
6870

@@ -96,7 +98,8 @@ class FunctionTest : public ::testing::Test {
9698
void SetUp()
9799
{
98100
m_UUID = Aws::Utils::UUID::RandomUUID();
99-
CreateFunction(BuildResourceName(BASE_SIMPLE_FUNCTION), SIMPLE_FUNCTION_CODE);
101+
CreateFunction(BuildResourceName(BASE_SIMPLE_FUNCTION),
102+
getLambdaCodePathFromEnvIfExists(SIMPLE_FUNCTION_CODE, "/succeed.zip"));
100103
}
101104

102105
void TearDown()
@@ -255,6 +258,16 @@ class FunctionTest : public ::testing::Test {
255258

256259
WaitForFunctionStatus(functionName, Aws::Lambda::Model::State::Active);
257260
}
261+
262+
static Aws::String getLambdaCodePathFromEnvIfExists(const Aws::String& cmakePath, const Aws::String& filePath) {
263+
Aws::String functionCodePath(Aws::Environment::GetEnv(TEST_LAMBDA_CODE_PATH));
264+
if(functionCodePath.empty()) {
265+
functionCodePath = cmakePath;
266+
} else {
267+
functionCodePath.append(filePath);
268+
}
269+
return functionCodePath;
270+
}
258271
};
259272

260273
std::shared_ptr<LambdaClient> FunctionTest::m_client(nullptr);
@@ -406,7 +419,8 @@ TEST_F(FunctionTest, TestInvokeSync)
406419

407420
TEST_F(FunctionTest, TestInvokeSyncUnhandledFunctionError)
408421
{
409-
CreateFunction(BuildResourceName(BASE_UNHANDLED_ERROR_FUNCTION), UNHANDLED_ERROR_FUNCTION_CODE);
422+
CreateFunction(BuildResourceName(BASE_UNHANDLED_ERROR_FUNCTION),
423+
getLambdaCodePathFromEnvIfExists(UNHANDLED_ERROR_FUNCTION_CODE, "/unhandled.zip"));
410424

411425
InvokeRequest invokeRequest;
412426
invokeRequest.SetFunctionName(BuildResourceName(BASE_UNHANDLED_ERROR_FUNCTION));

aws-cpp-sdk-s3control-integration-tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_project(aws-cpp-sdk-s3control-integration-tests
55
aws-cpp-sdk-access-management
66
aws-cpp-sdk-iam
77
aws-cpp-sdk-cognito-identity
8+
aws-cpp-sdk-sts
89
testing-resources
910
aws-cpp-sdk-core)
1011

aws-cpp-sdk-s3control-integration-tests/S3ControlTest.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#include <aws/access-management/AccessManagementClient.h>
4141
#include <aws/iam/IAMClient.h>
4242
#include <aws/cognito-identity/CognitoIdentityClient.h>
43+
#include <aws/sts/STSClient.h>
44+
#include <aws/sts/model/AssumeRoleRequest.h>
4345

4446
using namespace Aws;
4547
using namespace Aws::Http;
@@ -80,7 +82,7 @@ namespace
8082
config.connectTimeoutMs = 30000;
8183
config.requestTimeoutMs = 30000;
8284
m_client = S3ControlClient(config);
83-
m_s3Client = S3::S3Client(config);
85+
m_s3Client = createS3Client(config);
8486
m_httpClient = Aws::Http::CreateHttpClient(config);
8587

8688
// IAM client has to use us-east-1 in its signer.
@@ -119,6 +121,24 @@ namespace
119121
return resourceUUID;
120122
}
121123

124+
static S3::S3Client createS3Client(const ClientConfiguration &configuration) {
125+
Aws::String testRoleArn(Aws::Environment::GetEnv("TEST_ASSUME_ROLE_ARN"));
126+
if (!testRoleArn.empty()) {
127+
STS::STSClient stsClient(configuration);
128+
STS::Model::AssumeRoleRequest assumeRoleRequest;
129+
assumeRoleRequest.SetRoleArn(testRoleArn);
130+
assumeRoleRequest.SetRoleSessionName("s3-control-cpp-integ-test");
131+
STS::Model::AssumeRoleOutcome outcome = stsClient.AssumeRole(assumeRoleRequest);
132+
STS::Model::Credentials creds = outcome.GetResult().GetCredentials();
133+
Auth::AWSCredentials awsCredentials(creds.GetAccessKeyId(),
134+
creds.GetSecretAccessKey(),
135+
creds.GetSessionToken(),
136+
creds.GetExpiration());
137+
return {awsCredentials, configuration};
138+
}
139+
return {configuration};
140+
}
141+
122142
static bool WaitForBucketToPropagate(const Aws::String& bucketName, const S3::S3Client& client)
123143
{
124144
unsigned timeoutCount = 0;
@@ -217,7 +237,7 @@ namespace
217237

218238
Aws::Client::ClientConfiguration config;
219239
config.region = region;
220-
Aws::S3::S3Client s3Client(config);
240+
Aws::S3::S3Client s3Client = createS3Client(config);
221241

222242
S3::Model::CreateBucketRequest createBucketRequest;
223243
S3::Model::CreateBucketConfiguration bucketConfiguration;
@@ -288,7 +308,7 @@ namespace
288308
{
289309
Aws::Client::ClientConfiguration config;
290310
config.region = region;
291-
Aws::S3::S3Client s3Client(config);
311+
Aws::S3::S3Client s3Client = createS3Client(config);
292312

293313
Aws::String regionalBucket = bucketName + "-" + region;
294314
S3::Model::DeleteBucketRequest deleteBucketRequest;
@@ -691,7 +711,7 @@ namespace
691711

692712
Aws::Client::ClientConfiguration config;
693713
config.region = Aws::Region::US_WEST_2;
694-
Aws::S3::S3Client s3Client(config);
714+
Aws::S3::S3Client s3Client = createS3Client(config);
695715

696716
Aws::Vector<Aws::String> objectKeys;
697717
objectKeys.push_back(TEST_OBJECT_KEY);

0 commit comments

Comments
 (0)