void URI::ExtractAndSetPath(const Aws::String& uri) { size_t authorityStart = uri.find(SEPARATOR); if (authorityStart == Aws::String::npos) { authorityStart = 0; } else { authorityStart += 3; } size_t pathEnd = uri.find('?'); if (pathEnd == Aws::String::npos) { pathEnd = uri.length(); } Aws::String authorityAndPath = uri.substr(authorityStart, pathEnd - authorityStart); size_t pathStart = authorityAndPath.find('/'); if (pathStart != Aws::String::npos) { SetPath(authorityAndPath.substr(pathStart, pathEnd - pathStart), false); } else { SetPath("/"); } }
QueryStringParameterCollection URI::GetQueryStringParameters(bool decode) const { Aws::String queryString = GetQueryString(); QueryStringParameterCollection parameterCollection; //if we actually have a query string if (queryString.size() > 0) { size_t currentPos = 1, locationOfNextDelimiter = 1; //while we have params left to parse while (currentPos < queryString.size()) { //find next key/value pair locationOfNextDelimiter = queryString.find('&', currentPos); Aws::String keyValuePair; //if this isn't the last parameter if (locationOfNextDelimiter != Aws::String::npos) { keyValuePair = queryString.substr(currentPos, locationOfNextDelimiter - currentPos); } //if it is the last parameter else { keyValuePair = queryString.substr(currentPos); } //split on = size_t locationOfEquals = keyValuePair.find('='); Aws::String key = keyValuePair.substr(0, locationOfEquals); Aws::String value = keyValuePair.substr(locationOfEquals + 1); if(decode) { parameterCollection[StringUtils::URLDecode(key.c_str())] = StringUtils::URLDecode(value.c_str()); } else { parameterCollection[key] = value; } currentPos += keyValuePair.size() + 1; } } return parameterCollection; }
TEST_F(QueueOperationTest, TestQueueAttributes) { CreateQueueRequest createQueueRequest; createQueueRequest.SetQueueName(BuildResourceName(BASE_ATTRIBUTES_QUEUE_NAME)); createQueueRequest.AddAttributes(QueueAttributeName::DelaySeconds, "45"); CreateQueueOutcome createQueueOutcome = sqsClient->CreateQueue(createQueueRequest); ASSERT_TRUE(createQueueOutcome.IsSuccess()); Aws::String queueUrl = createQueueOutcome.GetResult().GetQueueUrl(); ASSERT_TRUE(queueUrl.find(createQueueRequest.GetQueueName()) != Aws::String::npos); GetQueueAttributesRequest queueAttributesRequest; queueAttributesRequest.AddAttributeNames(QueueAttributeName::DelaySeconds).WithQueueUrl(queueUrl); GetQueueAttributesOutcome queueAttributesOutcome = sqsClient->GetQueueAttributes(queueAttributesRequest); ASSERT_TRUE(queueAttributesOutcome.IsSuccess()); EXPECT_EQ("45", queueAttributesOutcome.GetResult().GetAttributes().find(QueueAttributeName::DelaySeconds)->second); SetQueueAttributesRequest setQueueAttributesRequest; setQueueAttributesRequest.AddAttributes(QueueAttributeName::VisibilityTimeout, "42").WithQueueUrl(queueUrl); SetQueueAttributesOutcome setQueueAttributesOutcome = sqsClient->SetQueueAttributes(setQueueAttributesRequest); ASSERT_TRUE(setQueueAttributesOutcome.IsSuccess()); queueAttributesRequest.AddAttributeNames(QueueAttributeName::VisibilityTimeout).WithQueueUrl(queueUrl); queueAttributesOutcome = sqsClient->GetQueueAttributes(queueAttributesRequest); ASSERT_TRUE(queueAttributesOutcome.IsSuccess()); EXPECT_EQ("45", queueAttributesOutcome.GetResult().GetAttributes().find(QueueAttributeName::DelaySeconds)->second); EXPECT_EQ("42", queueAttributesOutcome.GetResult().GetAttributes().find(QueueAttributeName::VisibilityTimeout)->second); DeleteQueueRequest deleteQueueRequest; deleteQueueRequest.WithQueueUrl(queueUrl); DeleteQueueOutcome deleteQueueOutcome = sqsClient->DeleteQueue(deleteQueueRequest); ASSERT_TRUE(deleteQueueOutcome.IsSuccess()); }
TEST_F(QueueOperationTest, TestCreateAndDeleteQueue) { CreateQueueRequest createQueueRequest; createQueueRequest.SetQueueName(BuildResourceName(BASE_SIMPLE_QUEUE_NAME)); CreateQueueOutcome createQueueOutcome; bool shouldContinue = true; while (shouldContinue) { createQueueOutcome = sqsClient->CreateQueue(createQueueRequest); if (createQueueOutcome.IsSuccess()) break; if (createQueueOutcome.GetError().GetErrorType() == SQSErrors::QUEUE_DELETED_RECENTLY) { std::this_thread::sleep_for(std::chrono::seconds(10)); } else { FAIL() << "Unexpected error response: " << createQueueOutcome.GetError().GetMessage(); } } Aws::String queueUrl = createQueueOutcome.GetResult().GetQueueUrl(); ASSERT_TRUE(queueUrl.find(createQueueRequest.GetQueueName()) != Aws::String::npos); createQueueRequest.AddAttributes(QueueAttributeName::VisibilityTimeout, "50"); createQueueOutcome = sqsClient->CreateQueue(createQueueRequest); ASSERT_FALSE(createQueueOutcome.IsSuccess()); SQSErrors error = createQueueOutcome.GetError().GetErrorType(); EXPECT_TRUE(SQSErrors::QUEUE_NAME_EXISTS == error || SQSErrors::QUEUE_DELETED_RECENTLY == error); // This call in eventually consistent (sometimes over 1 min), so try it a few times for (int attempt = 0; ; attempt++) { ListQueuesRequest listQueueRequest; listQueueRequest.WithQueueNamePrefix(BuildResourcePrefix()); ListQueuesOutcome listQueuesOutcome = sqsClient->ListQueues(listQueueRequest); if (listQueuesOutcome.IsSuccess()) { ListQueuesResult listQueuesResult = listQueuesOutcome.GetResult(); if (listQueuesResult.GetQueueUrls().size() == 1) { EXPECT_EQ(queueUrl, listQueuesResult.GetQueueUrls()[0]); EXPECT_TRUE(listQueuesResult.GetResponseMetadata().GetRequestId().length() > 0); break; // success! } } if (attempt >= 10) FAIL(); std::this_thread::sleep_for(std::chrono::seconds(10)); } DeleteQueueRequest deleteQueueRequest; deleteQueueRequest.WithQueueUrl(queueUrl); DeleteQueueOutcome deleteQueueOutcome = sqsClient->DeleteQueue(deleteQueueRequest); ASSERT_TRUE(deleteQueueOutcome.IsSuccess()); }
static void InvalidRegistrationFail(const PlayFabError& error, void* customData) { bool foundEmailMsg, foundPasswordMsg; Aws::String expectedEmailMsg = "Email address is not valid."; Aws::String expectedPasswordMsg = "Password must be between"; Aws::String errorConcat; for (auto it = error.ErrorDetails.begin(); it != error.ErrorDetails.end(); ++it) errorConcat += it->second; foundEmailMsg = (errorConcat.find(expectedEmailMsg) != -1); foundPasswordMsg = (errorConcat.find(expectedPasswordMsg) != -1); PfTestContext* testContext = reinterpret_cast<PfTestContext*>(customData); if (foundEmailMsg && foundPasswordMsg) EndTest(*testContext, PASSED, ""); else EndTest(*testContext, FAILED, "All error details: " + errorConcat); }
void URI::ExtractAndSetQueryString(const Aws::String& uri) { size_t queryStart = uri.find('?'); if (queryStart != Aws::String::npos) { queryString = uri.substr(queryStart); } }
void URI::ExtractAndSetPort(const Aws::String& uri) { size_t authorityStart = uri.find(SEPARATOR); if(authorityStart == Aws::String::npos) { authorityStart = 0; } else { authorityStart += 3; } size_t positionOfPortDelimiter = uri.find(':', authorityStart); bool hasPort = positionOfPortDelimiter != Aws::String::npos; if ((uri.find('/', authorityStart) < positionOfPortDelimiter) || (uri.find('?', authorityStart) < positionOfPortDelimiter)) { hasPort = false; } if (hasPort) { Aws::String strPort; size_t i = positionOfPortDelimiter + 1; char currentDigit = uri[i]; while (std::isdigit(currentDigit)) { strPort += currentDigit; currentDigit = uri[++i]; } SetPort(static_cast<uint16_t>(atoi(strPort.c_str()))); } }
void URI::ExtractAndSetScheme(const Aws::String& uri) { size_t posOfSeparator = uri.find(SEPARATOR); if (posOfSeparator != Aws::String::npos) { Aws::String schemePortion = uri.substr(0, posOfSeparator); SetScheme(SchemeMapper::FromString(schemePortion.c_str())); } else { SetScheme(Scheme::HTTP); } }
TEST(VersionTest, TestCompilerVersionString) { Aws::String compiler = GetCompilerVersionString(); #if defined(_MSC_VER) const auto expected = "MSVC"; #elif defined(__clang__) const auto expected = "Clang"; #elif defined(__GNUC__) const auto expected = "GCC"; #else const auto expected = "Unknown"; #endif ASSERT_EQ(0u, compiler.find(expected)); }
void URI::ExtractAndSetAuthority(const Aws::String& uri) { size_t authorityStart = uri.find(SEPARATOR); if (authorityStart == Aws::String::npos) { authorityStart = 0; } else { authorityStart += 3; } size_t posOfEndOfAuthorityPort = uri.find(':', authorityStart); size_t posOfEndOfAuthoritySlash = uri.find('/', authorityStart); size_t posOfEndOfAuthorityQuery = uri.find('?', authorityStart); size_t posEndOfAuthority = std::min({posOfEndOfAuthorityPort, posOfEndOfAuthoritySlash, posOfEndOfAuthorityQuery}); if (posEndOfAuthority == Aws::String::npos) { posEndOfAuthority = uri.length(); } SetAuthority(uri.substr(authorityStart, posEndOfAuthority - authorityStart)); }
TEST_F(QueueOperationTest, TestPermissions) { Aws::String queueName = BuildResourceName(BASE_PERMISSIONS_QUEUE_NAME); Aws::String queueUrl = CreateDefaultQueue(queueName); ASSERT_TRUE(queueUrl.find(queueName) != Aws::String::npos); AddPermissionRequest addPermissionRequest; addPermissionRequest.AddAWSAccountIds(m_accountId).AddActions("ReceiveMessage").WithLabel("Test").WithQueueUrl( queueUrl); AddPermissionOutcome permissionOutcome = sqsClient->AddPermission(addPermissionRequest); ASSERT_TRUE(permissionOutcome.IsSuccess()); GetQueueAttributesRequest queueAttributesRequest; queueAttributesRequest.AddAttributeNames(QueueAttributeName::Policy).WithQueueUrl(queueUrl); GetQueueAttributesOutcome queueAttributesOutcome = sqsClient->GetQueueAttributes(queueAttributesRequest); ASSERT_TRUE(queueAttributesOutcome.IsSuccess()); Aws::String policyString = queueAttributesOutcome.GetResult().GetAttributes().find(QueueAttributeName::Policy)->second; EXPECT_TRUE(policyString.length() > 0); JsonValue policy(policyString); EXPECT_EQ(addPermissionRequest.GetLabel(), policy.GetArray("Statement")[0].GetString("Sid")); Aws::StringStream expectedValue; expectedValue << "arn:aws:iam::" << m_accountId << ":root"; EXPECT_EQ(expectedValue.str(), policy.GetArray("Statement")[0].GetObject("Principal").GetString("AWS")); EXPECT_EQ("SQS:ReceiveMessage", policy.GetArray("Statement")[0].GetString("Action")); RemovePermissionRequest removePermissionRequest; removePermissionRequest.WithLabel("Test").WithQueueUrl(queueUrl); RemovePermissionOutcome removePermissionOutcome = sqsClient->RemovePermission(removePermissionRequest); ASSERT_TRUE(removePermissionOutcome.IsSuccess()); queueAttributesOutcome = sqsClient->GetQueueAttributes(queueAttributesRequest); ASSERT_TRUE(queueAttributesOutcome.IsSuccess()); EXPECT_TRUE(queueAttributesOutcome.GetResult().GetAttributes().find(QueueAttributeName::Policy) == queueAttributesOutcome.GetResult().GetAttributes().end()); DeleteQueueRequest deleteQueueRequest; deleteQueueRequest.WithQueueUrl(queueUrl); DeleteQueueOutcome deleteQueueOutcome = sqsClient->DeleteQueue(deleteQueueRequest); ASSERT_TRUE(deleteQueueOutcome.IsSuccess()); }
void StringUtils::Replace(Aws::String &s, const char* search, const char* replace) { if(!search || !replace) { return; } size_t replaceLength = strlen(replace); size_t searchLength = strlen(search); for (std::size_t pos = 0;; pos += replaceLength) { pos = s.find(search, pos); if (pos == Aws::String::npos) break; s.erase(pos, searchLength); s.insert(pos, replace); } }
TEST_F(QueueOperationTest, TestSendReceiveDelete) { Aws::String queueName = BuildResourceName(BASE_SEND_RECEIVE_QUEUE_NAME); Aws::String queueUrl = CreateDefaultQueue(queueName); ASSERT_TRUE(queueUrl.find(queueName) != Aws::String::npos); SendMessageRequest sendMessageRequest; sendMessageRequest.SetMessageBody("TestMessageBody"); MessageAttributeValue stringAttributeValue; stringAttributeValue.SetStringValue("TestString"); stringAttributeValue.SetDataType("String"); sendMessageRequest.AddMessageAttributes("TestStringAttribute", stringAttributeValue); MessageAttributeValue binaryAttributeValue; Aws::Utils::ByteBuffer byteBuffer(10); for(unsigned i = 0; i < 10; ++i) { byteBuffer[i] = (unsigned char)i; } binaryAttributeValue.SetBinaryValue(byteBuffer); binaryAttributeValue.SetDataType("Binary"); sendMessageRequest.AddMessageAttributes("TestBinaryAttribute", binaryAttributeValue); sendMessageRequest.SetQueueUrl(queueUrl); SendMessageOutcome sendMessageOutcome = sqsClient->SendMessage(sendMessageRequest); ASSERT_TRUE(sendMessageOutcome.IsSuccess()); EXPECT_TRUE(sendMessageOutcome.GetResult().GetMessageId().length() > 0); ReceiveMessageRequest receiveMessageRequest; receiveMessageRequest.SetMaxNumberOfMessages(1); receiveMessageRequest.SetQueueUrl(queueUrl); receiveMessageRequest.AddMessageAttributeNames("All"); ReceiveMessageOutcome receiveMessageOutcome = sqsClient->ReceiveMessage(receiveMessageRequest); ASSERT_TRUE(receiveMessageOutcome.IsSuccess()); ReceiveMessageResult receiveMessageResult = receiveMessageOutcome.GetResult(); ASSERT_EQ(1uL, receiveMessageResult.GetMessages().size()); EXPECT_EQ("TestMessageBody", receiveMessageResult.GetMessages()[0].GetBody()); Aws::Map<Aws::String, MessageAttributeValue> messageAttributes = receiveMessageResult.GetMessages()[0].GetMessageAttributes(); ASSERT_TRUE(messageAttributes.find("TestStringAttribute") != messageAttributes.end()); EXPECT_EQ(stringAttributeValue.GetStringValue(), messageAttributes["TestStringAttribute"].GetStringValue()); ASSERT_TRUE(messageAttributes.find("TestBinaryAttribute") != messageAttributes.end()); EXPECT_EQ(byteBuffer, messageAttributes["TestBinaryAttribute"].GetBinaryValue()); DeleteMessageRequest deleteMessageRequest; deleteMessageRequest.SetQueueUrl(queueUrl); deleteMessageRequest.SetReceiptHandle(receiveMessageResult.GetMessages()[0].GetReceiptHandle()); DeleteMessageOutcome deleteMessageOutcome = sqsClient->DeleteMessage(deleteMessageRequest); ASSERT_TRUE(deleteMessageOutcome.IsSuccess()); receiveMessageOutcome = sqsClient->ReceiveMessage(receiveMessageRequest); EXPECT_EQ(0uL, receiveMessageOutcome.GetResult().GetMessages().size()); DeleteQueueRequest deleteQueueRequest; deleteQueueRequest.WithQueueUrl(queueUrl); DeleteQueueOutcome deleteQueueOutcome = sqsClient->DeleteQueue(deleteQueueRequest); ASSERT_TRUE(deleteQueueOutcome.IsSuccess()); }