Skip to content

Commit 2b534e6

Browse files
committed
pending tests
1 parent 87e263d commit 2b534e6

File tree

5 files changed

+274
-0
lines changed

5 files changed

+274
-0
lines changed

cmake/sdksCommon.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ list(APPEND HIGH_LEVEL_SDK_LIST "text-to-speech")
8787
set(SDK_TEST_PROJECT_LIST "")
8888
list(APPEND SDK_TEST_PROJECT_LIST "cloudfront:tests/aws-cpp-sdk-cloudfront-integration-tests")
8989
list(APPEND SDK_TEST_PROJECT_LIST "cognito-identity:tests/aws-cpp-sdk-cognitoidentity-integration-tests")
90+
list(APPEND SDK_TEST_PROJECT_LIST "cognito-idp:tests/aws-cpp-sdk-cognitoidentityprovider-integration-tests")
9091
list(APPEND SDK_TEST_PROJECT_LIST "core:tests/aws-cpp-sdk-core-tests")
9192
list(APPEND SDK_TEST_PROJECT_LIST "dynamodb:tests/aws-cpp-sdk-dynamodb-integration-tests")
9293
list(APPEND SDK_TEST_PROJECT_LIST "dynamodb:tests/aws-cpp-sdk-dynamodb-unit-tests")

tests/android-unified-tests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ file(GLOB SQS_SRC "${AWS_NATIVE_SDK_ROOT}/aws-cpp-sdk-sqs-integration-tests/Queu
1919
file(GLOB S3_SRC "${AWS_NATIVE_SDK_ROOT}/aws-cpp-sdk-s3-integration-tests/BucketAndObjectOperationTest.cpp")
2020
file(GLOB LAMBDA_SRC "${AWS_NATIVE_SDK_ROOT}/aws-cpp-sdk-lambda-integration-tests/FunctionTest.cpp")
2121
file(GLOB COGNITO_IDENTITY_IDENTITY_POOL_SRC "${AWS_NATIVE_SDK_ROOT}/aws-cpp-sdk-cognitoidentity-integration-tests/IdentityPoolOperationTest.cpp")
22+
file(GLOB COGNITO_IDENTITY_IDENTITY_POOL_SRC "${AWS_NATIVE_SDK_ROOT}/aws-cpp-sdk-cognitoidentityprovider-integration-tests/OperationTest.cpp")
2223
file(GLOB TRANSFER_SRC "${AWS_NATIVE_SDK_ROOT}/aws-cpp-sdk-transfer-tests/TransferTests.cpp")
2324
file(GLOB IDENTITY_MANAGEMENT_SRC "${AWS_NATIVE_SDK_ROOT}/aws-cpp-sdk-identity-management-tests/auth/*.cpp")
2425
file(GLOB ENCRYPTION_TESTS_SRC "${AWS_NATIVE_SDK_ROOT}/aws-cpp-sdk-s3-encryption-tests/CryptoModulesTest.cpp"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
add_project(aws-cpp-sdk-cognitoidentityprovider-integration-tests
2+
"Tests for the AWS Cognito Identity C++ SDK"
3+
#aws-cpp-sdk-access-management
4+
aws-cpp-sdk-cognito-idp
5+
#aws-cpp-sdk-iam
6+
testing-resources
7+
aws-cpp-sdk-core
8+
)
9+
10+
# Headers are included in the source so that they show up in Visual Studio.
11+
# They are included elsewhere for consistency.
12+
13+
file(GLOB AWS_COGNITO_SRC
14+
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
15+
)
16+
17+
file(GLOB AWS_COGNITO_INTEGRATION_TESTS_SRC
18+
${AWS_COGNITO_SRC}
19+
)
20+
21+
if(MSVC AND BUILD_SHARED_LIBS)
22+
add_definitions(-DGTEST_LINKED_AS_SHARED_LIBRARY=1)
23+
endif()
24+
25+
enable_testing()
26+
27+
if(PLATFORM_ANDROID AND BUILD_SHARED_LIBS)
28+
add_library(${PROJECT_NAME} ${AWS_COGNITO_INTEGRATION_TESTS_SRC})
29+
else()
30+
add_executable(${PROJECT_NAME} ${AWS_COGNITO_INTEGRATION_TESTS_SRC})
31+
endif()
32+
33+
set_compiler_flags(${PROJECT_NAME})
34+
set_compiler_warnings(${PROJECT_NAME})
35+
36+
find_package(OpenSSL REQUIRED)
37+
# Include directories for OpenSSL headers
38+
include_directories(${OPENSSL_INCLUDE_DIR})
39+
40+
target_link_libraries(${PROJECT_NAME} ${PROJECT_LIBS})
41+
42+
43+
44+
if(MSVC AND BUILD_SHARED_LIBS)
45+
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS
46+
"/DELAYLOAD:aws-cpp-sdk-access-management.dll /DELAYLOAD:aws-cpp-sdk-cognito-idp /DELAYLOAD:aws-cpp-sdk-iam /DELAYLOAD:aws-cpp-sdk-core.dll")
47+
target_link_libraries(${PROJECT_NAME} delayimp.lib)
48+
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
#include <gtest/gtest.h>
7+
#include <aws/testing/AwsTestHelpers.h>
8+
#include <aws/testing/MemoryTesting.h>
9+
#include <algorithm>
10+
#include <thread>
11+
12+
#include <aws/cognito-idp/CognitoIdentityProviderClient.h>
13+
#include <aws/cognito-idp/CognitoIdentityProviderErrors.h>
14+
#include <aws/cognito-idp/model/AuthFlowType.h>
15+
#include <aws/cognito-idp/model/ExplicitAuthFlowsType.h>
16+
#include <aws/cognito-idp/model/InitiateAuthRequest.h>
17+
#include <aws/cognito-idp/model/CreateUserPoolClientRequest.h>
18+
#include <aws/cognito-idp/model/SignUpRequest.h>
19+
#include <aws/cognito-idp/model/DeleteUserPoolClientRequest.h>
20+
21+
#include <aws/core/client/CoreErrors.h>
22+
#include <aws/core/utils/json/JsonSerializer.h>
23+
#include <aws/core/utils/Outcome.h>
24+
#include <aws/testing/TestingEnvironment.h>
25+
#include <aws/core/platform/Environment.h>
26+
#include <openssl/srp.h>
27+
using namespace Aws::CognitoIdentityProvider;
28+
using namespace Aws::CognitoIdentityProvider::Model;
29+
using namespace Aws::Client;
30+
using namespace Aws::Region;
31+
32+
#define TEST_POOL_PREFIX "IntegrationTest_"
33+
34+
namespace
35+
{
36+
static const char* ALLOCATION_TAG = "IdentityProviderOperationTest";
37+
38+
39+
class IdentityProviderOperationTest : public ::testing::Test
40+
{
41+
public:
42+
IdentityProviderOperationTest() :
43+
client(nullptr)
44+
{}
45+
46+
std::shared_ptr<Aws::CognitoIdentityProvider::CognitoIdentityProviderClient> client;
47+
Aws::String testTrace;
48+
49+
protected:
50+
51+
const Aws::String m_clientName{"testClient"};
52+
53+
void SetUp()
54+
{
55+
Aws::Client::ClientConfiguration config;
56+
config.region = AWS_TEST_REGION;
57+
58+
//TODO: move this over to profile config file.
59+
client = Aws::MakeShared<Aws::CognitoIdentityProvider::CognitoIdentityProviderClient>(ALLOCATION_TAG, config);
60+
}
61+
62+
void TearDown()
63+
{
64+
client = nullptr;
65+
if (::testing::Test::HasFailure())
66+
{
67+
std::cout << "Test traces: " << testTrace << "\n";
68+
}
69+
testTrace.erase();
70+
}
71+
72+
73+
void registerUser(const Aws::String& username, const Aws::String& password)
74+
{
75+
// Set up the request for creating a new User Pool Client
76+
Aws::CognitoIdentityProvider::Model::SignUpRequest request;
77+
request.SetClientId(m_clientName);
78+
request.SetUsername(username);
79+
request.SetPassword(password);
80+
81+
auto outcome = client->SignUp(request);
82+
ASSERT_TRUE(outcome.IsSuccess());
83+
if (outcome.IsSuccess())
84+
{
85+
std::cout << "User registered successfully." << std::endl;
86+
std::cout << "User confirmed: " << (outcome.GetResult().GetUserConfirmed() ? "Yes" : "No") << std::endl;
87+
std::cout << "User sub: " << outcome.GetResult().GetUserSub() << std::endl;
88+
89+
90+
}
91+
}
92+
93+
CreateUserPoolClientOutcome createPoolClient()
94+
{
95+
// Set up the request for creating a new User Pool Client
96+
Aws::CognitoIdentityProvider::Model::CreateUserPoolClientRequest request;
97+
request.SetUserPoolId("test-pool-id");
98+
request.SetClientName("testClient");
99+
100+
request.SetGenerateSecret(true); // If you need a secret for your client
101+
Aws::Vector<Aws::CognitoIdentityProvider::Model::ExplicitAuthFlowsType> authFlows{Aws::CognitoIdentityProvider::Model::ExplicitAuthFlowsType::ALLOW_USER_SRP_AUTH};
102+
request.SetExplicitAuthFlows(authFlows);
103+
104+
// Make the call to create the user pool client
105+
auto outcome = client->CreateUserPoolClient(request);
106+
ASSERT_TRUE(outcome.IsSuccess());
107+
if (outcome.IsSuccess())
108+
{
109+
std::cout << "User Pool Client created successfully." << std::endl;
110+
std::cout << "Client ID: " << outcome.GetResult().GetUserPoolClient().GetClientId() << std::endl;
111+
if (request.GetGenerateSecret())
112+
{
113+
std::cout << "Client Secret: " << outcome.GetResult().GetUserPoolClient().GetClientSecret() << std::endl;
114+
}
115+
}
116+
return outcome;
117+
}
118+
119+
void deletePoolClient()
120+
{
121+
// Set up the request for deleting the User Pool Client
122+
Aws::CognitoIdentityProvider::Model::DeleteUserPoolClientRequest request;
123+
request.SetUserPoolId("test-pool-id");
124+
request.SetClientId("testClient");
125+
126+
// Make the call to delete the user pool client
127+
auto outcome = client->DeleteUserPoolClient(request);
128+
ASSERT_TRUE(outcome.IsSuccess());
129+
if (outcome.IsSuccess())
130+
{
131+
std::cout << "User Pool Client deleted successfully." << std::endl;
132+
}
133+
}
134+
135+
136+
};
137+
138+
139+
140+
141+
142+
143+
TEST_F(IdentityProviderOperationTest, testSecret)
144+
{
145+
auto outcome = createPoolClient();
146+
147+
148+
Aws::String ComputeSecretHash(const Aws::String &userPoolClientId, const Aws::String &userPoolClientSecret, const Aws::String &userName)
149+
{
150+
const auto secret = userPoolClientSecret;
151+
const auto message = userName + userPoolClientId;
152+
153+
unsigned char * digest = HMAC(EVP_sha256(),
154+
secret.c_str(), static_cast<int>(secret.length()),
155+
reinterpret_cast<const unsigned char*>(message.c_str()),
156+
static_cast<int>(message.length()),
157+
NULL, NULL);
158+
159+
char mdString[SHA256_DIGEST_LENGTH * 2 + 1];
160+
for (int i = 0; i < SHA256_DIGEST_LENGTH; ++i)
161+
sprintf(&mdString[i*2], "%02x", (unsigned int)digest[i]);
162+
163+
mdString[64] = '\0'; // null-terminate the string
164+
165+
return Aws::String(mdString);
166+
}
167+
168+
169+
Aws::Map<Aws::String, Aws::String> authParameters;
170+
authParameters["USERNAME"] = "dummyuser"; // Replace with actual username
171+
172+
// Compute SECRET_HASH if the client has a secret
173+
const Aws::String clientId = outcome.GetResult().GetUserPoolClient().GetClientId(); // Client ID from previous step
174+
const Aws::String clientSecret = outcome.GetResult().GetUserPoolClient().GetClientSecret(); // Client Secret if generated
175+
authParameters["SECRET_HASH"] = ComputeSecretHash(clientId, clientSecret, "dummyuser");
176+
177+
// Note: SRP_A is part of the SRP protocol, you need to implement or use a library for SRP
178+
// This is a placeholder for a correct SRP implementation:
179+
authParameters["SRP_A"] = "dummy"; // Replace with actual SRP_A value
180+
181+
Aws::CognitoIdentityProvider::Model::InitiateAuthRequest authRequest;
182+
authRequest.SetClientId(clientId); // Client ID from when you created the client
183+
authRequest.SetAuthFlow(Aws::CognitoIdentityProvider::Model::AuthFlowType::USER_SRP_AUTH);
184+
authRequest.SetAuthParameters(authParameters);
185+
186+
Aws::CognitoIdentityProvider::Model::InitiateAuthOutcome authResult = client->InitiateAuth( authRequest );
187+
188+
EXPECT_TRUE(authResult.IsSuccess());
189+
190+
191+
deletePoolClient();
192+
}
193+
194+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
#include <gtest/gtest.h>
7+
#include <aws/core/Aws.h>
8+
#include <aws/testing/platform/PlatformTesting.h>
9+
#include <aws/testing/TestingEnvironment.h>
10+
#include <aws/testing/MemoryTesting.h>
11+
12+
int main(int argc, char** argv)
13+
{
14+
Aws::Testing::SetDefaultSigPipeHandler();
15+
Aws::SDKOptions options;
16+
options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Debug;
17+
AWS_BEGIN_MEMORY_TEST_EX(options, 1024, 128);
18+
19+
Aws::Testing::InitPlatformTest(options);
20+
Aws::Testing::ParseArgs(argc, argv);
21+
22+
Aws::InitAPI(options);
23+
::testing::InitGoogleTest(&argc, argv);
24+
int exitCode = RUN_ALL_TESTS();
25+
26+
Aws::ShutdownAPI(options);
27+
AWS_END_MEMORY_TEST_EX;
28+
Aws::Testing::ShutdownPlatformTest(options);
29+
return exitCode;
30+
}

0 commit comments

Comments
 (0)