You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by mm...@apache.org on 2021/07/06 19:37:07 UTC
[geode-native] branch develop updated: GEODE-9405: Remove broken
security tests (#826)
This is an automated email from the ASF dual-hosted git repository.
mmartell pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git
The following commit(s) were added to refs/heads/develop by this push:
new 76337f0 GEODE-9405: Remove broken security tests (#826)
76337f0 is described below
commit 76337f0130f67a941ccde4a6b00325bb52817455
Author: Michael Martell <mm...@pivotal.io>
AuthorDate: Tue Jul 6 12:35:25 2021 -0700
GEODE-9405: Remove broken security tests (#826)
* GEODE-9401: Remove broken security tests
---
cppcache/integration-test/CMakeLists.txt | 10 -
.../integration-test/ThinClientSecurityHelper.hpp | 10 -
.../testThinClientSecurityAuthentication.cpp | 501 -----------
.../testThinClientSecurityAuthenticationMU.cpp | 552 ------------
...ientSecurityAuthenticationSetAuthInitialize.cpp | 21 +-
.../testThinClientSecurityAuthorization.cpp | 707 ---------------
.../testThinClientSecurityAuthorizationMU.cpp | 971 ---------------------
.../testThinClientSecurityCQAuthorizationMU.cpp | 515 -----------
...tThinClientSecurityDurableCQAuthorizationMU.cpp | 650 --------------
.../integration-test/testThinClientTicket303.cpp | 122 ---
.../integration-test/testThinClientTicket304.cpp | 209 -----
.../integration-test/testThinClientTracking.cpp | 270 ------
.../testThinClientWriterException.cpp | 261 ------
13 files changed, 1 insertion(+), 4798 deletions(-)
diff --git a/cppcache/integration-test/CMakeLists.txt b/cppcache/integration-test/CMakeLists.txt
index 3284569..10eb886 100644
--- a/cppcache/integration-test/CMakeLists.txt
+++ b/cppcache/integration-test/CMakeLists.txt
@@ -197,7 +197,6 @@ set_tests_properties(
testThinClientPdxTests
testThinClientPutAll
testThinClientPutAllWithCallBackArgWithoutConcurrency
- testThinClientSecurityCQAuthorizationMU
testThinClientTXFailover
# broken
testThinClientCqDurable
@@ -205,16 +204,7 @@ set_tests_properties(
testThinClientPoolAttrTest
testThinClientPoolLocator
testThinClientPoolRedundancy
- testThinClientSecurityAuthentication
- testThinClientSecurityAuthenticationMU
- testThinClientSecurityAuthorization
- testThinClientSecurityAuthorizationMU
- testThinClientSecurityDurableCQAuthorizationMU
testThinClientSecurityPostAuthorization
- testThinClientTicket303
- testThinClientTicket304
- testThinClientTracking
- testThinClientWriterException
PROPERTIES
DISABLED TRUE
)
diff --git a/cppcache/integration-test/ThinClientSecurityHelper.hpp b/cppcache/integration-test/ThinClientSecurityHelper.hpp
index 62d3e88..ff5cb56 100644
--- a/cppcache/integration-test/ThinClientSecurityHelper.hpp
+++ b/cppcache/integration-test/ThinClientSecurityHelper.hpp
@@ -58,16 +58,6 @@ const std::string locHostPort =
const char* regionNamesAuth[] = {"DistRegionAck"};
std::shared_ptr<CredentialGenerator> credentialGeneratorHandler;
-std::string getXmlPath() {
- char xmlPath[1000] = {'\0'};
- const char* path = std::getenv("TESTSRC");
- ASSERT(path != nullptr,
- "Environment variable TESTSRC for test source directory is not set.");
- strncpy(xmlPath, path, strlen(path) - strlen("cppcache"));
- strncat(xmlPath, "xml/Security/", sizeof(xmlPath) - strlen(xmlPath) - 1);
- return std::string(xmlPath);
-}
-
void initCredentialGenerator() {
static int loopNum = 1;
diff --git a/cppcache/integration-test/testThinClientSecurityAuthentication.cpp b/cppcache/integration-test/testThinClientSecurityAuthentication.cpp
deleted file mode 100644
index 9da1d77..0000000
--- a/cppcache/integration-test/testThinClientSecurityAuthentication.cpp
+++ /dev/null
@@ -1,501 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "fw_dunit.hpp"
-#include "ThinClientHelper.hpp"
-#include <ace/OS.h>
-#include <ace/High_Res_Timer.h>
-
-#include "ThinClientSecurity.hpp"
-#include <geode/CacheTransactionManager.hpp>
-
-#define CORRECT_CREDENTIALS 'C'
-#define INCORRECT_CREDENTIALS 'I'
-#define NOT_PROVIDED_CREDENTIALS 'N'
-
-using apache::geode::client::testframework::security::CredentialGenerator;
-
-const std::string locHostPort =
- CacheHelper::getLocatorHostPort(isLocator, isLocalServer, 1);
-const char *regionNamesAuth[] = {"DistRegionAck", "DistRegionNoAck"};
-std::shared_ptr<CredentialGenerator> credentialGeneratorHandler;
-
-std::string getXmlPath() {
- char xmlPath[1000] = {'\0'};
- const char *path = std::getenv("TESTSRC");
- ASSERT(path != nullptr,
- "Environment variable TESTSRC for test source directory is not set.");
- strncpy(xmlPath, path, strlen(path) - strlen("cppcache"));
- strncat(xmlPath, "xml/Security/", sizeof(xmlPath) - strlen(xmlPath) - 1);
- return std::string(xmlPath);
-}
-
-void initCredentialGenerator() {
- static int loopNum = 1;
-
- switch (loopNum) {
- case 1: {
- credentialGeneratorHandler = CredentialGenerator::create("DUMMY");
- break;
- }
- case 2: {
- credentialGeneratorHandler = CredentialGenerator::create("LDAP");
- break;
- }
- default:
- case 3: {
- credentialGeneratorHandler = CredentialGenerator::create("PKCS");
- break;
- }
- }
-
- if (credentialGeneratorHandler == nullptr) {
- FAIL("credentialGeneratorHandler is nullptr");
- }
-
- loopNum++;
- if (loopNum > 3) loopNum = 1;
-}
-
-void initClientAuth(char credentialsType) {
- auto config = Properties::create();
- if (credentialGeneratorHandler == nullptr) {
- FAIL("credentialGeneratorHandler is nullptr");
- }
- bool insertAuthInit = true;
- switch (credentialsType) {
- case 'C':
- credentialGeneratorHandler->getValidCredentials(config);
- config->insert("security-password",
- config->find("security-username")->value().c_str());
- printf("Username is %s and Password is %s ",
- config->find("security-username")->value().c_str(),
- config->find("security-password")->value().c_str());
- break;
- case 'I':
- credentialGeneratorHandler->getInvalidCredentials(config);
- config->insert("security-password", "junk");
- printf("Username is %s and Password is %s ",
- config->find("security-username")->value().c_str(),
- config->find("security-password")->value().c_str());
- break;
- case 'N':
- default:
- insertAuthInit = false;
- break;
- }
- if (insertAuthInit) {
- // config->insert(
- // "security-client-auth-factory","createUserPasswordAuthInitInstance" );
- // config->insert( "security-client-auth-library","authinitImpl" );
- credentialGeneratorHandler->getAuthInit(config);
- }
-
- try {
- initClient(true, config);
- } catch (...) {
- throw;
- }
-}
-
-#define CLIENT1 s1p1
-#define CLIENT2 s1p2
-#define CLIENT3 s2p1
-#define LOCATORSERVER s2p2
-
-DUNIT_TASK_DEFINITION(LOCATORSERVER, CreateLocator)
- {
- if (isLocator) CacheHelper::initLocator(1);
- LOG("Locator1 started");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(LOCATORSERVER, CreateServer1)
- {
- initCredentialGenerator();
- std::string cmdServerAuthenticator;
- if (credentialGeneratorHandler == nullptr) {
- FAIL("credentialGeneratorHandler is nullptr");
- }
-
- try {
- if (isLocalServer) {
- cmdServerAuthenticator = credentialGeneratorHandler->getServerCmdParams(
- "authenticator", getXmlPath());
- printf("Input to server cmd is --> %s",
- cmdServerAuthenticator.c_str());
- CacheHelper::initServer(
- 1, nullptr, locHostPort,
- const_cast<char *>(cmdServerAuthenticator.c_str()));
- LOG("Server1 started");
- }
- } catch (...) {
- printf("this is some exception");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(LOCATORSERVER, CreateServer2)
- {
- std::string cmdServerAuthenticator2;
- cmdServerAuthenticator2 = credentialGeneratorHandler->getServerCmdParams(
- "authenticator", getXmlPath());
- printf("Input to server cmd is --> %s", cmdServerAuthenticator2.c_str());
- CacheHelper::initServer(
- 2, "cacheserver_notify_subscription2.xml", locHostPort,
- const_cast<char *>(cmdServerAuthenticator2.c_str()));
- LOG("Server2 started");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, StepOne)
- {
- initCredentialGenerator();
- try {
- initClientAuth(INCORRECT_CREDENTIALS);
- } catch (
- const apache::geode::client::AuthenticationFailedException &other) {
- LOG(other.getStackTrace());
- LOG(other.what());
- }
-
- try {
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, true);
- FAIL("Should have thrown AuthenticationFailedException.");
- } catch (
- const apache::geode::client::AuthenticationFailedException &other) {
- LOG(other.getStackTrace());
- LOG(other.what());
- } catch (const apache::geode::client::Exception &other) {
- LOG(other.getStackTrace());
- LOG(other.what());
- FAIL("Only AuthenticationFailedException is expected");
- }
- LOG("StepOne Completed");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, StepTwo)
- {
- initClientAuth(CORRECT_CREDENTIALS);
- try {
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, true);
- createEntry(regionNamesAuth[0], keys[0], vals[0]);
- updateEntry(regionNamesAuth[0], keys[0], nvals[0]);
- auto regPtr0 = getHelper()->getRegion(regionNamesAuth[0]);
- regPtr0->containsKeyOnServer(
- apache::geode::client::CacheableKey::create(keys[0]));
- } catch (const apache::geode::client::Exception &other) {
- LOG(other.getStackTrace());
- FAIL(other.what());
- }
- LOG("Handshake and Authentication successfully completed");
- LOG("StepTwo Completed");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT2, StepThree)
- {
- initCredentialGenerator();
- initClientAuth(CORRECT_CREDENTIALS);
- try {
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, true);
- } catch (const apache::geode::client::Exception &other) {
- LOG(other.getStackTrace());
- FAIL(other.what());
- }
- LOG("Handshake and Authentication successfully completed");
- }
- LOG("StepThree Completed");
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT3, StepFour)
- {
- initCredentialGenerator();
- try {
- initClientAuth(NOT_PROVIDED_CREDENTIALS);
- } catch (
- const apache::geode::client::AuthenticationRequiredException &other) {
- LOG(other.getStackTrace());
- FAIL(other.what());
- }
-
- try {
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, true);
- FAIL("Should have thrown AuthenticationRequiredException.");
- } catch (
- const apache::geode::client::AuthenticationRequiredException &other) {
- LOG(other.getStackTrace());
- LOG(other.what());
- } catch (const apache::geode::client::Exception &other) {
- LOG(other.getStackTrace());
- LOG(other.what());
- FAIL("Only AuthenticationRequiredException is expected");
- }
- LOG("StepFour Completed");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT2, StepFive)
- {
- SLEEP(80);
- try {
- createRegionForSecurity(regionNamesAuth[1], USE_ACK, true);
- auto regPtr0 = getHelper()->getRegion(regionNamesAuth[0]);
- auto keyPtr = CacheableKey::create(keys[0]);
- auto checkPtr =
- std::dynamic_pointer_cast<CacheableString>(regPtr0->get(keyPtr));
- if (checkPtr != nullptr && !strcmp(nvals[0], checkPtr->value().c_str())) {
- LOG("checkPtr is not null");
- char buf[1024];
- sprintf(buf, "In net search, get returned %s for key %s",
- checkPtr->value().c_str(), keys[0]);
- LOG(buf);
- } else {
- LOG("checkPtr is nullptr");
- }
- } catch (const apache::geode::client::Exception &other) {
- LOG(other.getStackTrace());
- FAIL(other.what());
- }
- LOG("Handshake and Authentication successfully completed after FailOver");
- LOG("StepFive Completed");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, StepSix)
- {
- initClientAuth(CORRECT_CREDENTIALS);
- try {
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, true);
- createEntry(regionNamesAuth[0], keys[0], vals[0]);
- updateEntry(regionNamesAuth[0], keys[0], nvals[0]);
- } catch (const apache::geode::client::Exception &other) {
- LOG(other.getStackTrace());
- FAIL(other.what());
- }
- LOG("Handshake and Authentication successfully completed");
- LOG("StepSix Completed");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT2, StepSeven)
- {
- try {
- initClientAuth(INCORRECT_CREDENTIALS);
- } catch (
- const apache::geode::client::AuthenticationFailedException &other) {
- LOG(other.getStackTrace());
- LOG(other.what());
- }
- LOG("Setting JavaConnectionPoolSize to 0 ");
- CacheHelper::setJavaConnectionPoolSize(0);
- SLEEP(500);
- try {
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, true, nullptr, true,
- 0);
- FAIL("Should have thrown AuthenticationFailedException.");
- } catch (
- const apache::geode::client::AuthenticationFailedException &other) {
- LOG(other.getStackTrace());
- LOG(other.what());
- } catch (const apache::geode::client::Exception &other) {
- LOG(other.getStackTrace());
- LOG(other.what());
- FAIL("Only AuthenticationFailedException is expected");
- }
- LOG("StepSeven Completed");
- }
-END_TASK_DEFINITION
-
-void createEntryTx(const char *name, const char *key, const char *value) {
- LOG("createEntry() entered.");
- fprintf(stdout, "Creating entry -- key: %s value: %s in region %s\n", key,
- value, name);
- fflush(stdout);
- // Create entry, verify entry is correct
- auto keyPtr = CacheableKey::create(key);
- auto valPtr = CacheableString::create(value);
-
- auto regPtr = getHelper()->getRegion(name);
- ASSERT(regPtr != nullptr, "Region not found.");
-
- // ASSERT( !regPtr->containsKey( keyPtr ), "Key should not have been found in
- // region." );
- // ASSERT( !regPtr->containsValueForKey( keyPtr ), "Value should not have been
- // found in region." );
-
- // regPtr->create( keyPtr, valPtr );
- regPtr->put(keyPtr, valPtr);
- LOG("Created entry.");
-
- // verifyEntry( name, key, value );
- LOG("Entry created.");
-}
-
-void updateEntryTx(const char *name, const char *key, const char *value) {
- LOG("updateEntry() entered.");
- fprintf(stdout, "Updating entry -- key: %s value: %s in region %s\n", key,
- value, name);
- fflush(stdout);
- // Update entry, verify entry is correct
- auto keyPtr = CacheableKey::create(key);
- auto valPtr = CacheableString::create(value);
-
- auto regPtr = getHelper()->getRegion(name);
- ASSERT(regPtr != nullptr, "Region not found.");
-
- ASSERT(regPtr->containsKey(keyPtr), "Key should have been found in region.");
- ASSERT(regPtr->containsValueForKey(keyPtr),
- "Value should have been found in region.");
-
- regPtr->put(keyPtr, valPtr);
- LOG("Put entry.");
-
- verifyEntry(name, key, value);
- LOG("Entry updated.");
-}
-
-DUNIT_TASK_DEFINITION(CLIENT1, StepEight)
- {
- initClientAuth(CORRECT_CREDENTIALS);
- try {
- createRegionForSecurity(regionNamesAuth[1], USE_ACK, true);
- auto regPtr0 = getHelper()->getRegion(regionNamesAuth[1]);
- auto txManager = getHelper()->getCache()->getCacheTransactionManager();
- LOG("txManager got");
- txManager->begin();
- LOG("txManager begin done");
- createEntryTx(regionNamesAuth[1], "TxKey", "TxValue");
- LOG("createEntryTx done");
- txManager->commit();
- LOG("txManager commit done");
-
- auto keyPtr = CacheableKey::create("TxKey");
- auto checkPtr =
- std::dynamic_pointer_cast<CacheableString>(regPtr0->get(keyPtr));
- ASSERT(checkPtr != nullptr, "Value not found.");
- LOGINFO("checkPtr->value().c_str() = %s ", checkPtr->value().c_str());
- ASSERT(strcmp("TxValue", checkPtr->value().c_str()) == 0,
- "Value not correct.");
- if (checkPtr != nullptr &&
- !strcmp("TxValue", checkPtr->value().c_str())) {
- LOG("checkPtr is not null");
- char buf[1024];
- sprintf(buf, "In net search, get returned %s for key %s",
- checkPtr->value().c_str(), "TxKey");
- LOG(buf);
- } else {
- LOG("checkPtr is nullptr");
- }
-
- txManager->begin();
- LOG("txManager begin done");
- createEntryTx(regionNamesAuth[1], "TxKey", "TxNewValue");
- LOG("createEntryTx done");
- txManager->rollback();
- LOG("txManager rollback done");
-
- checkPtr =
- std::dynamic_pointer_cast<CacheableString>(regPtr0->get(keyPtr));
- ASSERT(checkPtr != nullptr, "Value not found.");
- ASSERT(strcmp("TxValue", checkPtr->value().c_str()) == 0,
- "Value not correct.");
- if (checkPtr != nullptr &&
- !strcmp("TxValue", checkPtr->value().c_str())) {
- LOG("checkPtr is not null");
- char buf[1024];
- sprintf(buf, "In net search, get returned %s for key %s",
- checkPtr->value().c_str(), "TxKey");
- LOG(buf);
- } else {
- LOG("checkPtr is nullptr");
- }
-
- } catch (const apache::geode::client::Exception &other) {
- LOG(other.getStackTrace());
- FAIL(other.what());
- }
-
- LOG("StepEight Completed");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, CloseCache1)
- { cleanProc(); }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT2, CloseCache2)
- { cleanProc(); }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT3, CloseCache3)
- { cleanProc(); }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(LOCATORSERVER, CloseServer1)
- {
- if (isLocalServer) {
- CacheHelper::closeServer(1);
- LOG("SERVER1 stopped");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(LOCATORSERVER, CloseServer2)
- {
- if (isLocalServer) {
- CacheHelper::closeServer(2);
- LOG("SERVER2 stopped");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(LOCATORSERVER, CloseLocator)
- {
- if (isLocator) {
- CacheHelper::closeLocator(1);
- LOG("Locator1 stopped");
- }
- }
-END_TASK_DEFINITION
-
-void doThinClientSecurityAuthentication() {
- CALL_TASK(CreateLocator);
- CALL_TASK(CreateServer1);
- CALL_TASK(StepOne);
- CALL_TASK(CreateServer2);
- CALL_TASK(CloseCache1);
- CALL_TASK(StepTwo);
- CALL_TASK(StepThree);
- CALL_TASK(StepFour);
- CALL_TASK(CloseServer1);
- CALL_TASK(StepFive);
- CALL_TASK(CloseCache1);
- CALL_TASK(CloseCache2);
- CALL_TASK(StepSix);
- CALL_TASK(StepSeven);
- CALL_TASK(StepEight);
- CALL_TASK(CloseCache1);
- CALL_TASK(CloseCache2);
- CALL_TASK(CloseCache3);
- CALL_TASK(CloseServer2);
- CALL_TASK(CloseLocator);
-}
-
-DUNIT_MAIN
- { doThinClientSecurityAuthentication(); }
-END_MAIN
diff --git a/cppcache/integration-test/testThinClientSecurityAuthenticationMU.cpp b/cppcache/integration-test/testThinClientSecurityAuthenticationMU.cpp
deleted file mode 100644
index a920a53..0000000
--- a/cppcache/integration-test/testThinClientSecurityAuthenticationMU.cpp
+++ /dev/null
@@ -1,552 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define ROOT_NAME "testThinClientSecurityAuthenticationMU"
-
-#include "fw_dunit.hpp"
-#include "ThinClientHelper.hpp"
-#include <ace/OS.h>
-#include <ace/High_Res_Timer.h>
-
-#include "ThinClientSecurity.hpp"
-#include <geode/CacheTransactionManager.hpp>
-
-#define CORRECT_CREDENTIALS 'C'
-#define INCORRECT_CREDENTIALS 'I'
-#define NOT_PROVIDED_CREDENTIALS 'N'
-
-using apache::geode::client::testframework::security::CredentialGenerator;
-
-const std::string locHostPort =
- CacheHelper::getLocatorHostPort(isLocator, isLocalServer, 1);
-const char *regionNamesAuth[] = {"DistRegionAck", "DistRegionNoAck"};
-std::shared_ptr<CredentialGenerator> credentialGeneratorHandler;
-
-std::string getXmlPath() {
- char xmlPath[1000] = {'\0'};
- const char *path = std::getenv("TESTSRC");
- ASSERT(path != nullptr,
- "Environment variable TESTSRC for test source directory is not set.");
- strncpy(xmlPath, path, strlen(path) - strlen("cppcache"));
- strncat(xmlPath, "xml/Security/", sizeof(xmlPath) - strlen(xmlPath) - 1);
- return std::string(xmlPath);
-}
-
-void initCredentialGenerator() {
- static int loopNum = 1;
-
- switch (loopNum) {
- case 1: {
- credentialGeneratorHandler = CredentialGenerator::create("DUMMY");
- break;
- }
- case 2: {
- credentialGeneratorHandler = CredentialGenerator::create("LDAP");
- break;
- }
- default:
- case 3: {
- credentialGeneratorHandler = CredentialGenerator::create("PKCS");
- break;
- }
- }
-
- if (credentialGeneratorHandler == nullptr) {
- FAIL("credentialGeneratorHandler is nullptr");
- }
-
- loopNum++;
- if (loopNum > 2) loopNum = 1;
-}
-std::shared_ptr<Properties> userCreds;
-void initClientAuth(char credentialsType) {
- printf(" in initclientAuth 0 = %c ", credentialsType);
- userCreds = Properties::create();
- auto config = Properties::create();
- if (credentialGeneratorHandler == nullptr) {
- FAIL("credentialGeneratorHandler is nullptr");
- }
- bool insertAuthInit = true;
- switch (credentialsType) {
- case 'C':
- LOG(" in initclientAuth0.00");
- credentialGeneratorHandler->getValidCredentials(userCreds);
- // config->insert("security-password" ,
- // config->find("security-username")->value().c_str() );
- // printf("Username is %s and Password is %s
- // ",userCreds->find("security-username")->value().c_str(),userCreds->find("security-password")->value().c_str());
- break;
- case 'I':
- LOG(" in initclientAuth0.0");
- credentialGeneratorHandler->getInvalidCredentials(userCreds);
- // config->insert("security-password" , "junk");
- // printf("Username is %s and Password is %s
- // ",userCreds->find("security-username")->value().c_str(),userCreds->find("security-password")->value().c_str());
- break;
- case 'N':
- default:
- insertAuthInit = false;
- break;
- }
- if (insertAuthInit) {
- // config->insert(
- // "security-client-auth-factory","createUserPasswordAuthInitInstance" );
- // config->insert( "security-client-auth-library","authinitImpl" );
- credentialGeneratorHandler->getAuthInit(config);
- }
-
- try {
- LOG(" in initclientAuth");
- initClient(true, config);
- LOG(" in initclientAuth 2");
- } catch (...) {
- throw;
- }
-}
-
-#define CLIENT1 s1p1
-#define CLIENT2 s1p2
-#define CLIENT3 s2p1
-#define LOCATORSERVER s2p2
-
-DUNIT_TASK_DEFINITION(LOCATORSERVER, CreateLocator)
- {
- if (isLocator) CacheHelper::initLocator(1);
- LOG("Locator1 started");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(LOCATORSERVER, CreateServer1)
- {
- initCredentialGenerator();
- std::string cmdServerAuthenticator;
- if (credentialGeneratorHandler == nullptr) {
- FAIL("credentialGeneratorHandler is nullptr");
- }
-
- try {
- if (isLocalServer) {
- cmdServerAuthenticator = credentialGeneratorHandler->getServerCmdParams(
- "authenticator", getXmlPath());
- printf("Input to server cmd is --> %s",
- cmdServerAuthenticator.c_str());
- CacheHelper::initServer(
- 1, nullptr, locHostPort,
- const_cast<char *>(cmdServerAuthenticator.c_str()));
- LOG("Server1 started");
- }
- } catch (...) {
- printf("this is some exception");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(LOCATORSERVER, CreateServer2)
- {
- std::string cmdServerAuthenticator2;
- cmdServerAuthenticator2 = credentialGeneratorHandler->getServerCmdParams(
- "authenticator", getXmlPath());
- printf("Input to server cmd is --> %s", cmdServerAuthenticator2.c_str());
- CacheHelper::initServer(
- 2, "cacheserver_notify_subscription2.xml", locHostPort,
- const_cast<char *>(cmdServerAuthenticator2.c_str()));
- LOG("Server2 started");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, StepOne)
- {
- LOG(" 1");
- initCredentialGenerator();
- LOG(" 2");
- try {
- initClientAuth(INCORRECT_CREDENTIALS);
- LOG(" 3");
- } catch (
- const apache::geode::client::AuthenticationFailedException &other) {
- LOG(other.getStackTrace().c_str());
- LOG(other.what());
- }
-
- try {
- LOG(" 4");
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, false, nullptr,
- false, -1, true, 0);
- LOG(" 5");
- // need to insure pool name
- auto pool = getPool(regionNamesAuth[0]);
- LOG(" 6");
- if (pool != nullptr) {
- LOG(" 7");
- auto virtualCache = getVirtualCache(userCreds, pool);
- LOG(" 8");
- virtualCache.getRegion(regionNamesAuth[0])->put(keys[0], vals[0]);
- LOG("Operation allowed, something is wrong.");
- } else {
- LOG("Pool is nullptr");
- }
- FAIL("Should have thrown AuthenticationFailedException.");
- } catch (
- const apache::geode::client::AuthenticationFailedException &other) {
- LOG(other.getStackTrace().c_str());
- LOG(other.what());
- } catch (const apache::geode::client::Exception &other) {
- LOG(other.getStackTrace().c_str());
- LOG(other.what());
- FAIL("Only AuthenticationFailedException is expected");
- }
- LOG("StepOne Completed");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, StepTwo)
- {
- initClientAuth(CORRECT_CREDENTIALS);
- try {
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, false, nullptr,
- false, -1, true, 0);
- char buff[128] = {'\0'};
- sprintf(buff, "%s_0", regionNamesAuth[0]);
- auto pool = getPool(regionNamesAuth[0]);
- if (pool != nullptr) {
- auto virtualCache = getVirtualCache(userCreds, pool);
- auto virtualRegion = virtualCache.getRegion(regionNamesAuth[0]);
- virtualRegion->create(keys[0], vals[0]);
- virtualRegion->put(keys[0], nvals[0]);
- virtualRegion->containsKeyOnServer(
- apache::geode::client::CacheableKey::create(keys[0]));
- LOG("Operation allowed.");
- } else {
- LOG("Pool is nullptr");
- }
- } catch (const apache::geode::client::Exception &other) {
- LOG(other.getStackTrace().c_str());
- FAIL(other.what());
- }
- LOG("Handshake and Authentication successfully completed");
- LOG("StepTwo Completed");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT2, StepThree)
- {
- initCredentialGenerator();
- initClientAuth(CORRECT_CREDENTIALS);
- try {
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, false, nullptr,
- false, -1, true, 0);
- // need to insure pool name
- auto pool = getPool(regionNamesAuth[0]);
- if (pool != nullptr) {
- auto virtualCache = getVirtualCache(userCreds, pool);
- virtualCache.getRegion(regionNamesAuth[0])->put(keys[0], vals[0]);
- } else {
- LOG("Pool is nullptr");
- }
- } catch (const apache::geode::client::Exception &other) {
- LOG(other.getStackTrace().c_str());
- FAIL(other.what());
- }
- LOG("Handshake and Authentication successfully completed");
- }
- LOG("StepThree Completed");
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT3, StepFour)
- {
- initCredentialGenerator();
- try {
- initClientAuth(NOT_PROVIDED_CREDENTIALS);
- } catch (
- const apache::geode::client::AuthenticationRequiredException &other) {
- LOG(other.getStackTrace().c_str());
- FAIL(other.what());
- }
-
- try {
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, false, nullptr,
- false, -1, true, 0);
- // need to insure pool name
- auto pool = getPool(regionNamesAuth[0]);
- if (pool != nullptr) {
- auto virtualCache = getVirtualCache(userCreds, pool);
- virtualCache.getRegion(regionNamesAuth[0])->put(keys[0], vals[0]);
- } else {
- LOG("Pool is nullptr");
- }
- FAIL("Should have thrown AuthenticationRequiredException.");
- } catch (
- const apache::geode::client::AuthenticationRequiredException &other) {
- LOG(other.getStackTrace().c_str());
- LOG(other.what());
- } catch (
- const apache::geode::client::AuthenticationFailedException &other) {
- LOG(other.getStackTrace().c_str());
- LOG(other.what());
- } catch (const apache::geode::client::Exception &other) {
- LOG(other.getStackTrace().c_str());
- LOG(other.what());
- FAIL("Only AuthenticationRequiredException is expected");
- }
- LOG("StepFour Completed");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT2, StepFive)
- {
- SLEEP(80);
- try {
- createRegionForSecurity(regionNamesAuth[1], USE_ACK, false, nullptr,
- false, -1, true, 0);
- // need to insure pool name
- auto pool = getPool(regionNamesAuth[1]);
-
- std::shared_ptr<Region> virtualRegion;
- if (pool != nullptr) {
- auto virtualCache = getVirtualCache(userCreds, pool);
- virtualRegion = virtualCache.getRegion(regionNamesAuth[1]);
- } else {
- LOG("Pool is nullptr");
- }
- auto keyPtr = CacheableKey::create(keys[0]);
- LOG("before get");
- auto checkPtr = std::dynamic_pointer_cast<CacheableString>(
- virtualRegion->get(keyPtr));
- if (checkPtr != nullptr && !strcmp(nvals[0], checkPtr->value().c_str())) {
- LOG("checkPtr is not null");
- char buf[1024];
- sprintf(buf, "In net search, get returned %s for key %s",
- checkPtr->value().c_str(), keys[0]);
- LOG(buf);
- } else {
- LOG("checkPtr is nullptr");
- }
- } catch (const apache::geode::client::Exception &other) {
- LOG(other.getStackTrace().c_str());
- FAIL(other.what());
- }
- LOG("Handshake and Authentication successfully completed after FailOver");
- LOG("StepFive Completed");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, StepSix)
- {
- initClientAuth(CORRECT_CREDENTIALS);
- try {
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, false, nullptr,
- false, -1, true, 0);
- char buff[128] = {'\0'};
- sprintf(buff, "%s_1", regionNamesAuth[0]);
- auto pool = getPool(regionNamesAuth[0]);
- if (pool != nullptr) {
- auto virtualCache = getVirtualCache(userCreds, pool);
- auto virtualRegion = virtualCache.getRegion(regionNamesAuth[0]);
- virtualRegion->create(keys[0], vals[0]);
- virtualRegion->put(keys[0], nvals[0]);
- LOG("Operation allowed, something is wrong.");
- } else {
- LOG("Pool is nullptr");
- }
- } catch (const apache::geode::client::Exception &other) {
- LOG(other.getStackTrace().c_str());
- FAIL(other.what());
- }
- LOG("Handshake and Authentication successfully completed");
- LOG("StepSix Completed");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT2, StepSeven)
- {
- try {
- initClientAuth(INCORRECT_CREDENTIALS);
- } catch (
- const apache::geode::client::AuthenticationFailedException &other) {
- LOG(other.getStackTrace().c_str());
- LOG(other.what());
- }
- LOG("Setting JavaConnectionPoolSize to 0 ");
- CacheHelper::setJavaConnectionPoolSize(0);
- SLEEP(500);
- try {
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, false, nullptr,
- false, -1, true, 0);
- char buff[128] = {'\0'};
- sprintf(buff, "%s_0", regionNamesAuth[0]);
- auto pool = getPool(regionNamesAuth[0]);
- if (pool != nullptr) {
- auto virtualCache = getVirtualCache(userCreds, pool);
- auto virtualRegion = virtualCache.getRegion(regionNamesAuth[0]);
- virtualRegion->create(keys[0], vals[0]);
- virtualRegion->put(keys[0], nvals[0]);
- LOG("Operation allowed, something is wrong.");
- } else {
- LOG("Pool is nullptr");
- }
- FAIL("Should have thrown AuthenticationFailedException.");
- } catch (
- const apache::geode::client::AuthenticationFailedException &other) {
- LOG(other.getStackTrace().c_str());
- LOG(other.what());
- } catch (const apache::geode::client::Exception &other) {
- LOG(other.getStackTrace().c_str());
- LOG(other.what());
- FAIL("Only AuthenticationFailedException is expected");
- }
- LOG("StepSeven Completed");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, StepEight)
- {
- initClientAuth(CORRECT_CREDENTIALS);
- try {
- createRegionForSecurity(regionNamesAuth[1], USE_ACK, false, nullptr,
- false, -1, true, 0);
- // need to insure pool name
- auto pool = getPool(regionNamesAuth[1]);
-
- std::shared_ptr<Region> virtualRegion;
- if (pool != nullptr) {
- auto virtualCache = getVirtualCache(userCreds, pool);
- virtualRegion = virtualCache.getRegion(regionNamesAuth[1]);
- } else {
- LOG("Pool is nullptr");
- }
-
- auto txManager = getHelper()->getCache()->getCacheTransactionManager();
- LOG("txManager got");
- txManager->begin();
- LOG("txManager begin done");
- virtualRegion->put("TxKey", "TxValue");
- LOG("createEntryTx done");
- txManager->commit();
- LOG("txManager commit done");
-
- auto checkPtr = std::dynamic_pointer_cast<CacheableString>(
- virtualRegion->get("TxKey"));
- ASSERT(checkPtr != nullptr, "Value not found.");
- LOGINFO("checkPtr->value().c_str() = %s ", checkPtr->value().c_str());
- ASSERT(strcmp("TxValue", checkPtr->value().c_str()) == 0,
- "Value not correct.");
- if (checkPtr != nullptr &&
- !strcmp("TxValue", checkPtr->value().c_str())) {
- LOG("checkPtr is not null");
- char buf[1024];
- sprintf(buf, "In net search, get returned %s for key %s",
- checkPtr->value().c_str(), "TxKey");
- LOG(buf);
- } else {
- LOG("checkPtr is nullptr");
- }
-
- txManager->begin();
- LOG("txManager begin done");
- virtualRegion->put("TxKey", "TxNewValue");
- LOG("createEntryTx done");
- txManager->rollback();
- LOG("txManager rollback done");
-
- checkPtr = std::dynamic_pointer_cast<CacheableString>(
- virtualRegion->get("TxKey"));
- ASSERT(checkPtr != nullptr, "Value not found.");
- ASSERT(strcmp("TxValue", checkPtr->value().c_str()) == 0,
- "Value not correct.");
- if (checkPtr != nullptr &&
- !strcmp("TxValue", checkPtr->value().c_str())) {
- LOG("checkPtr is not null");
- char buf[1024];
- sprintf(buf, "In net search, get returned %s for key %s",
- checkPtr->value().c_str(), "TxKey");
- LOG(buf);
- } else {
- LOG("checkPtr is nullptr");
- }
- } catch (const apache::geode::client::Exception &other) {
- LOG(other.getStackTrace().c_str());
- FAIL(other.what());
- }
- LOG("StepEight Completed");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, CloseCache1)
- { cleanProc(); }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT2, CloseCache2)
- { cleanProc(); }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT3, CloseCache3)
- { cleanProc(); }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(LOCATORSERVER, CloseServer1)
- {
- if (isLocalServer) {
- CacheHelper::closeServer(1);
- LOG("SERVER1 stopped");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(LOCATORSERVER, CloseServer2)
- {
- if (isLocalServer) {
- CacheHelper::closeServer(2);
- LOG("SERVER2 stopped");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(LOCATORSERVER, CloseLocator)
- {
- if (isLocator) {
- CacheHelper::closeLocator(1);
- LOG("Locator1 stopped");
- }
- }
-END_TASK_DEFINITION
-
-void doThinClientSecurityAuthentication() {
- CALL_TASK(CreateLocator);
- CALL_TASK(CreateServer1);
- CALL_TASK(StepOne);
- CALL_TASK(CreateServer2);
- CALL_TASK(CloseCache1);
- CALL_TASK(StepTwo);
- CALL_TASK(StepThree);
- CALL_TASK(StepFour);
- CALL_TASK(CloseServer1);
- CALL_TASK(StepFive);
- CALL_TASK(CloseCache1);
- CALL_TASK(CloseCache2);
- CALL_TASK(StepSix);
- CALL_TASK(StepSeven);
- CALL_TASK(StepEight);
- CALL_TASK(CloseCache1);
- CALL_TASK(CloseCache2);
- CALL_TASK(CloseCache3);
- CALL_TASK(CloseServer2);
- CALL_TASK(CloseLocator);
-}
-
-DUNIT_MAIN
- { doThinClientSecurityAuthentication(); }
-END_MAIN
diff --git a/cppcache/integration-test/testThinClientSecurityAuthenticationSetAuthInitialize.cpp b/cppcache/integration-test/testThinClientSecurityAuthenticationSetAuthInitialize.cpp
index d6e0ff8..031c1fe 100644
--- a/cppcache/integration-test/testThinClientSecurityAuthenticationSetAuthInitialize.cpp
+++ b/cppcache/integration-test/testThinClientSecurityAuthenticationSetAuthInitialize.cpp
@@ -34,16 +34,6 @@ const std::string locHostPort =
const char *regionNamesAuth[] = {"DistRegionAck", "DistRegionNoAck"};
std::shared_ptr<CredentialGenerator> credentialGeneratorHandler;
-std::string getXmlPath() {
- char xmlPath[1000] = {'\0'};
- const char *path = std::getenv("TESTSRC");
- ASSERT(path != NULL,
- "Environment variable TESTSRC for test source directory is not set.");
- strncpy(xmlPath, path, strlen(path) - strlen("cppcache"));
- strncat(xmlPath, "xml/Security/", sizeof(xmlPath) - strlen(xmlPath) - 1);
- return std::string(xmlPath);
-}
-
#define SECURITY_USERNAME "security-username"
#define SECURITY_PASSWORD "security-password"
class UserPasswordAuthInit : public AuthInitialize {
@@ -112,16 +102,7 @@ DUNIT_TASK_DEFINITION(LOCATORSERVER, CreateServer1)
try {
if (isLocalServer) {
- cmdServerAuthenticator +=
- " --J=-Dgemfire.security-authz-xml-uri=" + getXmlPath() +
- "authz-dummy.xml "
- "--J=-Dgemfire.security-client-authenticator=javaobject."
- "DummyAuthenticator.create";
- printf("Input to server cmd is --> %s",
- cmdServerAuthenticator.c_str());
- CacheHelper::initServer(
- 1, {}, locHostPort,
- const_cast<char *>(cmdServerAuthenticator.c_str()));
+ CacheHelper::initServer(1, {}, locHostPort);
LOG("Server1 started");
}
} catch (...) {
diff --git a/cppcache/integration-test/testThinClientSecurityAuthorization.cpp b/cppcache/integration-test/testThinClientSecurityAuthorization.cpp
deleted file mode 100644
index 9072576..0000000
--- a/cppcache/integration-test/testThinClientSecurityAuthorization.cpp
+++ /dev/null
@@ -1,707 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "fw_dunit.hpp"
-#include <geode/FunctionService.hpp>
-#include <geode/CqAttributesFactory.hpp>
-
-#define ROOT_NAME "testThinClientSecurityAuthentication"
-#define ROOT_SCOPE DISTRIBUTED_ACK
-
-#include "CacheHelper.hpp"
-#include "ThinClientHelper.hpp"
-#include <ace/Process.h>
-
-#include "ThinClientSecurity.hpp"
-
-using apache::geode::client::CqAttributesFactory;
-using apache::geode::client::FunctionService;
-using apache::geode::client::HashMapOfCacheable;
-using apache::geode::client::QueryService;
-using apache::geode::client::testframework::security::CredentialGenerator;
-using apache::geode::client::testframework::security::OP_CONTAINS_KEY;
-using apache::geode::client::testframework::security::OP_CREATE;
-using apache::geode::client::testframework::security::OP_DESTROY;
-using apache::geode::client::testframework::security::OP_EXECUTE_FUNCTION;
-using apache::geode::client::testframework::security::OP_GET;
-using apache::geode::client::testframework::security::OP_GETALL;
-using apache::geode::client::testframework::security::OP_INVALIDATE;
-using apache::geode::client::testframework::security::OP_KEY_SET;
-using apache::geode::client::testframework::security::OP_PUTALL;
-using apache::geode::client::testframework::security::OP_QUERY;
-using apache::geode::client::testframework::security::OP_REGION_CLEAR;
-using apache::geode::client::testframework::security::OP_REGISTER_CQ;
-using apache::geode::client::testframework::security::OP_REGISTER_INTEREST;
-using apache::geode::client::testframework::security::OP_UNREGISTER_INTEREST;
-using apache::geode::client::testframework::security::OP_UPDATE;
-using apache::geode::client::testframework::security::opCodeList;
-
-const std::string locHostPort =
- CacheHelper::getLocatorHostPort(isLocator, isLocalServer, 1);
-std::shared_ptr<CredentialGenerator> credentialGeneratorHandler;
-
-std::string getXmlPath() {
- char xmlPath[1000] = {'\0'};
- const char *path = std::getenv("TESTSRC");
- ASSERT(path != nullptr,
- "Environment variable TESTSRC for test source directory is not set.");
- strncpy(xmlPath, path, strlen(path) - strlen("cppcache"));
- strncat(xmlPath, "xml/Security/", sizeof(xmlPath) - strlen(xmlPath) - 1);
- return std::string(xmlPath);
-}
-
-void initCredentialGenerator() {
- static int loopNum = 1;
-
- switch (loopNum) {
- case 1: {
- credentialGeneratorHandler = CredentialGenerator::create("DUMMY");
- break;
- }
- case 2: {
- credentialGeneratorHandler = CredentialGenerator::create("LDAP");
- break;
- }
- default:
- case 3: {
- credentialGeneratorHandler = CredentialGenerator::create("PKCS");
- break;
- }
- }
-
- if (credentialGeneratorHandler == nullptr) {
- FAIL("credentialGeneratorHandler is nullptr");
- }
-
- loopNum++;
- if (loopNum > 3) loopNum = 1;
-}
-
-opCodeList::value_type tmpRArr[] = {
- OP_GET, OP_GETALL, OP_REGISTER_INTEREST, OP_UNREGISTER_INTEREST,
- OP_KEY_SET, OP_CONTAINS_KEY};
-
-opCodeList::value_type tmpWArr[] = {OP_CREATE, OP_UPDATE, OP_PUTALL,
- OP_DESTROY, OP_INVALIDATE, OP_REGION_CLEAR};
-
-opCodeList::value_type tmpAArr[] = {OP_CREATE, OP_UPDATE,
- OP_DESTROY, OP_INVALIDATE,
- OP_REGION_CLEAR, OP_REGISTER_INTEREST,
- OP_GET, OP_QUERY,
- OP_REGISTER_CQ, OP_EXECUTE_FUNCTION};
-
-#define HANDLE_NO_NOT_AUTHORIZED_EXCEPTION \
- catch (const apache::geode::client::NotAuthorizedException &) { \
- LOG("NotAuthorizedException Caught"); \
- FAIL("should not have caught NotAuthorizedException"); \
- } \
- catch (const apache::geode::client::Exception &other) { \
- LOG("Got apache::geode::client::Exception& other "); \
- LOG(other.getStackTrace()); \
- FAIL(other.what()); \
- }
-
-#define HANDLE_NOT_AUTHORIZED_EXCEPTION \
- catch (const apache::geode::client::NotAuthorizedException &) { \
- LOG("NotAuthorizedException Caught"); \
- LOG("Success"); \
- } \
- catch (const apache::geode::client::Exception &other) { \
- LOG(other.getStackTrace()); \
- FAIL(other.what()); \
- }
-
-#define ADMIN_CLIENT s1p1
-#define WRITER_CLIENT s1p2
-#define READER_CLIENT s2p1
-
-const char *regionNamesAuth[] = {"DistRegionAck"};
-
-void initClientAuth(char UserType) {
- auto config = Properties::create();
- opCodeList wr(tmpWArr, tmpWArr + sizeof tmpWArr / sizeof *tmpWArr);
- opCodeList rt(tmpRArr, tmpRArr + sizeof tmpRArr / sizeof *tmpRArr);
- opCodeList ad(tmpAArr, tmpAArr + sizeof tmpAArr / sizeof *tmpAArr);
- credentialGeneratorHandler->getAuthInit(config);
- switch (UserType) {
- case 'W':
- credentialGeneratorHandler->getAllowedCredentialsForOps(wr, config,
- nullptr);
- break;
- case 'R':
- credentialGeneratorHandler->getAllowedCredentialsForOps(rt, config,
- nullptr);
- break;
- case 'A':
- credentialGeneratorHandler->getAllowedCredentialsForOps(ad, config,
- nullptr);
- break;
- default:
- break;
- }
-
- auto alias = config->find("security-alias");
- auto uname = config->find("security-username");
- auto passwd = config->find("security-password");
-
- char msgAlias[100];
- char msgUname[100];
- char msgPasswd[100];
-
- sprintf(msgAlias, "PKCS alias is %s",
- alias == nullptr ? "null" : alias->value().c_str());
- sprintf(msgUname, "username is %s",
- uname == nullptr ? "null" : uname->value().c_str());
- sprintf(msgPasswd, "password is %s",
- passwd == nullptr ? "null" : passwd->value().c_str());
-
- LOG(msgAlias);
- LOG(msgUname);
- LOG(msgPasswd);
-
- try {
- initClient(true, config);
- } catch (...) {
- throw;
- }
-}
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, StartServer1)
- {
- initCredentialGenerator();
- std::string cmdServerAuthenticator;
-
- if (isLocalServer) {
- cmdServerAuthenticator = credentialGeneratorHandler->getServerCmdParams(
- "authenticator:authorizer", getXmlPath());
- printf("string %s", cmdServerAuthenticator.c_str());
- CacheHelper::initServer(
- 1, "cacheserver_notify_subscription.xml", locHostPort,
- const_cast<char *>(cmdServerAuthenticator.c_str()));
- LOG("Server1 started");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, StartServer2)
- {
- std::string cmdServerAuthenticator;
-
- if (isLocalServer) {
- cmdServerAuthenticator = credentialGeneratorHandler->getServerCmdParams(
- "authenticator:authorizer", getXmlPath());
- printf("string %s", cmdServerAuthenticator.c_str());
- CacheHelper::initServer(
- 2, "cacheserver_notify_subscription2.xml", locHostPort,
- const_cast<char *>(cmdServerAuthenticator.c_str()));
- LOG("Server2 started");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, StartLocator)
- {
- if (isLocator) {
- CacheHelper::initLocator(1);
- LOG("Locator1 started");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, StepOne)
- {
- initClientAuth('A');
- try {
- LOG("Tying Region creation");
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, true);
-
- auto regPtr = getHelper()->getRegion(regionNamesAuth[0]);
-
- LOG("Region created successfully");
- //---------------------for region clear tests-----
- regPtr->put(1, 1);
- regPtr->clear();
-
- auto getVal = regPtr->get(1);
- if (getVal == nullptr) {
- LOG("Get completed after region.clear successfully");
- } else {
- FAIL("Get did not complete successfully");
- }
-
- //---------------------------------------------------
- LOG("Tying Entry creation");
- createEntry(regionNamesAuth[0], keys[0], vals[0]);
- LOG("Entry created successfully");
- updateEntry(regionNamesAuth[0], keys[0], nvals[0]);
- LOG("Entry updated successfully");
- HashMapOfCacheable entrymap;
- entrymap.clear();
- for (int i = 0; i < 5; i++) {
- entrymap.emplace(CacheableKey::create(i), CacheableInt32::create(i));
- }
-
- regPtr->putAll(entrymap);
- LOG("PutAll completed successfully");
- for (int i = 0; i < 5; i++) {
- regPtr->invalidate(CacheableKey::create(i));
- }
- std::vector<std::shared_ptr<CacheableKey>> entrykeys;
- for (int i = 0; i < 5; i++) {
- entrykeys.push_back(CacheableKey::create(i));
- }
- const auto valuesMap = regPtr->getAll(entrykeys);
- if (valuesMap.size() > 0) {
- LOG("GetAll completed successfully");
- } else {
- FAIL("GetAll did not complete successfully");
- }
-
- LOG("GetServerKeys check started for ADMIN");
- auto keysvec = regPtr->serverKeys();
- LOG("GetServerKeys check passed for ADMIN");
-
- regPtr->query("1=1");
- LOG("Query completed successfully");
- auto pool =
- getHelper()->getCache()->getPoolManager().find(regionNamesAuth[0]);
- std::shared_ptr<QueryService> qs;
- if (pool != nullptr) {
- // Using region name as pool name
- qs = pool->getQueryService();
- } else {
- qs = getHelper()->cachePtr->getQueryService();
- }
- char queryString[100];
- sprintf(queryString, "select * from /%s", regionNamesAuth[0]);
- CqAttributesFactory cqFac;
- auto cqAttrs = cqFac.create();
- auto qry = qs->newCq("cq_security", queryString, cqAttrs);
- qs->executeCqs();
- qs->closeCqs();
- LOG("CQ completed successfully");
- if (pool != nullptr) {
- // TODO:
- FunctionService::onServer(pool).execute("securityTest")->getResult();
- LOG("Function execution completed successfully");
- FunctionService::onServers(pool).execute("securityTest")->getResult();
- LOG("Function execution completed successfully");
- FunctionService::onRegion(regPtr).execute("securityTest")->getResult();
- LOG("Function execution completed successfully");
- FunctionService::onRegion(regPtr).execute("FireNForget");
- LOG("Function execution with no result completed successfully");
- } else {
- LOG("Skipping function execution for non pool case");
- }
- invalidateEntry(regionNamesAuth[0], keys[0]);
- LOG("Entry invalidated successfully");
- verifyInvalid(regionNamesAuth[0], keys[0]);
- LOG("Entry invalidate-verified successfully");
- destroyEntry(regionNamesAuth[0], keys[0]);
- LOG("Entry destroyed successfully");
- verifyDestroyed(regionNamesAuth[0], keys[0]);
- LOG("Entry destroy-verified successfully");
- destroyRegion(regionNamesAuth[0]);
- LOG("Region destroy successfully");
- LOG("Tying Region creation");
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, true);
- LOG("Region created successfully");
- createEntry(regionNamesAuth[0], keys[2], vals[2]);
- LOG("Entry created successfully");
- auto regPtr0 = getHelper()->getRegion(regionNamesAuth[0]);
- if (regPtr0 != nullptr) {
- LOG("Going to do registerAllKeys");
- regPtr0->registerAllKeys();
- LOG("Going to do unregisterAllKeys");
- regPtr0->unregisterAllKeys();
- }
- }
- HANDLE_NO_NOT_AUTHORIZED_EXCEPTION
- LOG("StepOne complete.");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(WRITER_CLIENT, StepTwo)
- {
- initCredentialGenerator();
- initClientAuth('W');
- try {
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, true);
- LOG("Region created successfully");
- createEntry(regionNamesAuth[0], keys[0], vals[0]);
- LOG("Entry created successfully");
- updateEntry(regionNamesAuth[0], keys[0], nvals[0]);
- LOG("Entry updated successfully");
- HashMapOfCacheable entrymap;
- entrymap.clear();
- for (int i = 0; i < 5; i++) {
- entrymap.emplace(CacheableKey::create(i), CacheableInt32::create(i));
- }
- auto regPtr = getHelper()->getRegion(regionNamesAuth[0]);
- regPtr->putAll(entrymap);
- LOG("PutAll completed successfully");
- invalidateEntry(regionNamesAuth[0], keys[0]);
- LOG("Entry invalidated successfully");
- verifyInvalid(regionNamesAuth[0], keys[0]);
- LOG("Entry invalidate-verified successfully");
- destroyEntry(regionNamesAuth[0], keys[0]);
- LOG("Entry destroyed successfully");
- verifyDestroyed(regionNamesAuth[0], keys[0]);
- LOG("Entry destroy-verified successfully");
- createEntry(regionNamesAuth[0], keys[0], vals[0]);
- LOG("Entry created successfully");
- updateEntry(regionNamesAuth[0], keys[0], nvals[0]);
- LOG("Entry updated successfully");
- verifyEntry(regionNamesAuth[0], keys[0], nvals[0]);
- LOG("Entry updation-verified successfully");
- }
- HANDLE_NO_NOT_AUTHORIZED_EXCEPTION
- try {
- auto regPtr = getHelper()->getRegion(regionNamesAuth[0]);
- LOG("containsKeyOnServer");
- regPtr->containsKeyOnServer(
- apache::geode::client::CacheableKey::create(keys[2]));
- FAIL("containsKeyOnServer should hav failed for writer");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- auto regPtr0 = getHelper()->getRegion(regionNamesAuth[0]);
- auto keyPtr = CacheableKey::create(keys[2]);
- auto checkPtr =
- std::dynamic_pointer_cast<CacheableString>(regPtr0->get(keyPtr));
- if (checkPtr != nullptr) {
- char buf[1024];
- sprintf(buf, "In net search, get returned %s for key %s",
- checkPtr->value().c_str(), keys[2]);
- LOG(buf);
- FAIL("Should not get the value");
- } else {
- LOG("checkPtr is nullptr");
- }
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
- auto regPtr0 = getHelper()->getRegion(regionNamesAuth[0]);
- try {
- LOG("Going to do registerAllKeys");
- regPtr0->registerAllKeys();
- FAIL("Should not be able to do Register Interest");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- for (int i = 0; i < 5; i++) {
- regPtr0->invalidate(CacheableKey::create(i));
- }
- std::vector<std::shared_ptr<CacheableKey>> entrykeys;
- for (int i = 0; i < 5; i++) {
- entrykeys.push_back(CacheableKey::create(i));
- }
- const auto valuesMap = regPtr0->getAll(entrykeys);
- if (valuesMap.size() > 0) {
- FAIL("GetAll should not have completed successfully");
- }
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- regPtr0->query("1=1");
- FAIL("Query should not have completed successfully");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- auto pool =
- getHelper()->getCache()->getPoolManager().find(regionNamesAuth[0]);
-
- try {
- std::shared_ptr<QueryService> qs;
- if (pool != nullptr) {
- // Using region name as pool name
- qs = pool->getQueryService();
- } else {
- qs = getHelper()->cachePtr->getQueryService();
- }
- char queryString[100];
- sprintf(queryString, "select * from /%s", regionNamesAuth[0]);
- CqAttributesFactory cqFac;
- auto cqAttrs = cqFac.create();
- auto qry = qs->newCq("cq_security", queryString, cqAttrs);
- qs->executeCqs();
- FAIL("CQ should not have completed successfully");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- LOG("GetServerKeys check started for WRITER");
- auto keysvec = regPtr0->serverKeys();
- LOG("GetServerKeys check passed for WRITER");
- FAIL("GetServerKeys should not have completed successfully for WRITER");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- createEntry(regionNamesAuth[0], keys[2], vals[2]);
- LOG("Entry created successfully");
-
- LOG("StepTwo complete.");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(READER_CLIENT, StepThree)
- {
- initCredentialGenerator();
- initClientAuth('R');
- std::shared_ptr<Region> rptr;
- char buf[100];
- int value = 102;
-
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, true);
-
- rptr = getHelper()->getRegion(regionNamesAuth[0]);
- sprintf(buf, "%s: %d", rptr->getName().c_str(), value);
- auto key = CacheableKey::create(buf);
- sprintf(buf, "testUpdate::%s: value of %d", rptr->getName().c_str(), value);
- auto valuePtr = buf;
- try {
- LOG("Trying put Operation");
- rptr->put(key, valuePtr);
- LOG(" Put Operation Successful");
- FAIL("Should have got NotAuthorizedException during put");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- LOG("Trying createEntry");
- createEntry(regionNamesAuth[0], keys[2], vals[2]);
- FAIL("Should have got NotAuthorizedException during createEntry");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- ASSERT(!rptr->containsKey(keys[2]),
- "Key should not have been found in the region");
- try {
- LOG("containsKeyOnServer");
- rptr->containsKeyOnServer(
- apache::geode::client::CacheableKey::create(keys[2]));
- }
- HANDLE_NO_NOT_AUTHORIZED_EXCEPTION
-
- try {
- LOG("Trying updateEntry");
- updateEntry(regionNamesAuth[0], keys[2], nvals[2], false, false);
- FAIL("Should have got NotAuthorizedException during updateEntry");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- ASSERT(!rptr->containsKey(keys[2]),
- "Key should not have been found in the region");
-
- try {
- auto regPtr0 = getHelper()->getRegion(regionNamesAuth[0]);
- auto keyPtr = CacheableKey::create(keys[2]);
- auto checkPtr =
- std::dynamic_pointer_cast<CacheableString>(regPtr0->get(keyPtr));
- if (checkPtr != nullptr) {
- LOG("In net search, get returned " + checkPtr->value() + " for key " +
- keys[2]);
- } else {
- LOG("checkPtr is nullptr");
- }
- }
- HANDLE_NO_NOT_AUTHORIZED_EXCEPTION
-
- try {
- LOG("Trying region clear..");
- auto regPtr0 = getHelper()->getRegion(regionNamesAuth[0]);
- regPtr0->clear();
- FAIL("Should have got NotAuthorizedException for region.clear ops");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- auto regPtr0 = getHelper()->getRegion(regionNamesAuth[0]);
- if (regPtr0 != nullptr) {
- try {
- LOG("Going to do registerAllKeys");
- regPtr0->registerAllKeys();
- LOG("Going to do unregisterAllKeys");
- regPtr0->unregisterAllKeys();
- }
- HANDLE_NO_NOT_AUTHORIZED_EXCEPTION
- }
-
- try {
- HashMapOfCacheable entrymap;
- entrymap.clear();
- for (int i = 0; i < 5; i++) {
- entrymap.emplace(CacheableKey::create(i), CacheableInt32::create(i));
- }
- regPtr0->putAll(entrymap);
- FAIL("PutAll should not have completed successfully");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- LOG("GetServerKeys check started for READER");
- auto keysvec = regPtr0->serverKeys();
- LOG("GetServerKeys check passed for READER");
- }
- HANDLE_NO_NOT_AUTHORIZED_EXCEPTION
-
- try {
- std::vector<std::shared_ptr<CacheableKey>> entrykeys;
- for (int i = 0; i < 5; i++) {
- entrykeys.push_back(CacheableKey::create(i));
- }
- const auto valuesMap = regPtr0->getAll(entrykeys);
- if (valuesMap.size() > 0) {
- LOG("GetAll completed successfully");
- } else {
- FAIL("GetAll did not complete successfully");
- }
- }
- HANDLE_NO_NOT_AUTHORIZED_EXCEPTION
-
- try {
- regPtr0->query("1=1");
- FAIL("Query should not have completed successfully");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- auto pool =
- getHelper()->getCache()->getPoolManager().find(regionNamesAuth[0]);
-
- try {
- std::shared_ptr<QueryService> qs;
- if (pool != nullptr) {
- // Using region name as pool name
- qs = pool->getQueryService();
- } else {
- qs = getHelper()->cachePtr->getQueryService();
- }
- char queryString[100];
- sprintf(queryString, "select * from /%s", regionNamesAuth[0]);
- CqAttributesFactory cqFac;
- auto cqAttrs = cqFac.create();
- auto qry = qs->newCq("cq_security", queryString, cqAttrs);
- qs->executeCqs();
- // FAIL("CQ should not have completed successfully");
- }
- HANDLE_NO_NOT_AUTHORIZED_EXCEPTION
-
- pool = getHelper()->getCache()->getPoolManager().find(regionNamesAuth[0]);
-
- try {
- if (pool != nullptr) {
- FunctionService::onServer(pool).execute("securityTest")->getResult();
- FAIL("Function execution should not have completed successfully");
- } else {
- LOG("Skipping function execution for non pool case");
- }
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- if (pool != nullptr) {
- FunctionService::onServer(pool).execute("securityTest")->getResult();
- FAIL("Function execution should not have completed successfully");
- } else {
- LOG("Skipping function execution for non pool case");
- }
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- if (pool != nullptr) {
- FunctionService::onServers(pool).execute("securityTest")->getResult();
- FAIL("Function execution should not have completed successfully");
- } else {
- LOG("Skipping function execution for non pool case");
- }
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- if (pool != nullptr) {
- regPtr0 = getHelper()->getRegion(regionNamesAuth[0]);
- FunctionService::onRegion(regPtr0).execute("securityTest")->getResult();
- FAIL("Function execution should not have completed successfully");
- } else {
- LOG("Skipping function execution for non pool case");
- }
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- LOG("StepThree complete.");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, CloseServer1)
- {
- SLEEP(9000);
- if (isLocalServer) {
- CacheHelper::closeServer(1);
- LOG("SERVER1 stopped");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, CloseServer2)
- {
- if (isLocalServer) {
- CacheHelper::closeServer(2);
- LOG("SERVER2 stopped");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, CloseLocator)
- {
- if (isLocator) {
- CacheHelper::closeLocator(1);
- LOG("Locator1 stopped");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, CloseCacheAdmin)
- { cleanProc(); }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(WRITER_CLIENT, CloseCacheWriter)
- { cleanProc(); }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(READER_CLIENT, CloseCacheReader)
- { cleanProc(); }
-END_TASK_DEFINITION
-
-void doThinClientSecurityAuthorization() {
- CALL_TASK(StartLocator);
- CALL_TASK(StartServer1);
- CALL_TASK(StepOne);
- CALL_TASK(StepTwo);
- CALL_TASK(StartServer2);
- CALL_TASK(CloseServer1);
- CALL_TASK(StepThree);
- CALL_TASK(CloseCacheReader);
- CALL_TASK(CloseCacheWriter);
- CALL_TASK(CloseCacheAdmin);
- CALL_TASK(CloseServer2);
- CALL_TASK(CloseLocator);
-}
-
-DUNIT_MAIN
- { doThinClientSecurityAuthorization(); }
-END_MAIN
diff --git a/cppcache/integration-test/testThinClientSecurityAuthorizationMU.cpp b/cppcache/integration-test/testThinClientSecurityAuthorizationMU.cpp
deleted file mode 100644
index f91f47e..0000000
--- a/cppcache/integration-test/testThinClientSecurityAuthorizationMU.cpp
+++ /dev/null
@@ -1,971 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "fw_dunit.hpp"
-#include <geode/FunctionService.hpp>
-#include <geode/Execution.hpp>
-#include <geode/UserFunctionExecutionException.hpp>
-#include <geode/RegionAttributesFactory.hpp>
-#include <geode/CqAttributesFactory.hpp>
-
-#define ROOT_NAME "testThinClientSecurityAuthenticationMU"
-#define ROOT_SCOPE DISTRIBUTED_ACK
-
-#include "CacheHelper.hpp"
-#include "ThinClientHelper.hpp"
-#include <ace/Process.h>
-
-#include "ThinClientSecurity.hpp"
-
-using apache::geode::client::CacheableArrayList;
-using apache::geode::client::CacheableBoolean;
-using apache::geode::client::CacheableVector;
-using apache::geode::client::ClassCastException;
-using apache::geode::client::CqAttributesFactory;
-using apache::geode::client::FunctionService;
-using apache::geode::client::HashMapOfCacheable;
-using apache::geode::client::QueryService;
-using apache::geode::client::UserFunctionExecutionException;
-using apache::geode::client::testframework::security::CredentialGenerator;
-using apache::geode::client::testframework::security::OP_CONTAINS_KEY;
-using apache::geode::client::testframework::security::OP_CREATE;
-using apache::geode::client::testframework::security::OP_DESTROY;
-using apache::geode::client::testframework::security::OP_EXECUTE_FUNCTION;
-using apache::geode::client::testframework::security::OP_GET;
-using apache::geode::client::testframework::security::OP_GETALL;
-using apache::geode::client::testframework::security::OP_INVALIDATE;
-using apache::geode::client::testframework::security::OP_KEY_SET;
-using apache::geode::client::testframework::security::OP_PUTALL;
-using apache::geode::client::testframework::security::OP_QUERY;
-using apache::geode::client::testframework::security::OP_REGION_CLEAR;
-using apache::geode::client::testframework::security::OP_REGISTER_CQ;
-using apache::geode::client::testframework::security::OP_REGISTER_INTEREST;
-using apache::geode::client::testframework::security::OP_UNREGISTER_INTEREST;
-using apache::geode::client::testframework::security::OP_UPDATE;
-using apache::geode::client::testframework::security::opCodeList;
-
-const std::string locHostPort =
- CacheHelper::getLocatorHostPort(isLocator, isLocalServer, 1);
-
-std::shared_ptr<CredentialGenerator> credentialGeneratorHandler;
-
-const char *exFuncNameSendException = "executeFunction_SendException";
-
-std::string getXmlPath() {
- char xmlPath[1000] = {'\0'};
- const char *path = std::getenv("TESTSRC");
- ASSERT(path != nullptr,
- "Environment variable TESTSRC for test source directory is not set.");
- strncpy(xmlPath, path, strlen(path) - strlen("cppcache"));
- strncat(xmlPath, "xml/Security/", sizeof(xmlPath) - strlen(xmlPath) - 1);
- return std::string(xmlPath);
-}
-
-void initCredentialGenerator() {
- static int loopNum = 1;
-
- switch (loopNum) {
- case 1: {
- credentialGeneratorHandler = CredentialGenerator::create("DUMMY");
- break;
- }
- case 2: {
- credentialGeneratorHandler = CredentialGenerator::create("LDAP");
- break;
- }
- default:
- case 3: {
- credentialGeneratorHandler = CredentialGenerator::create("PKCS");
- break;
- }
- }
-
- if (credentialGeneratorHandler == nullptr) {
- FAIL("credentialGeneratorHandler is nullptr");
- }
-
- loopNum++;
- if (loopNum > 2) loopNum = 1;
-}
-
-opCodeList::value_type tmpRArr[] = {
- OP_GET, OP_GETALL, OP_REGISTER_INTEREST, OP_UNREGISTER_INTEREST,
- OP_KEY_SET, OP_CONTAINS_KEY};
-
-opCodeList::value_type tmpWArr[] = {OP_CREATE, OP_UPDATE, OP_PUTALL,
- OP_DESTROY, OP_INVALIDATE, OP_REGION_CLEAR};
-
-opCodeList::value_type tmpAArr[] = {OP_CREATE, OP_UPDATE,
- OP_DESTROY, OP_INVALIDATE,
- OP_REGION_CLEAR, OP_REGISTER_INTEREST,
- OP_GET, OP_QUERY,
- OP_REGISTER_CQ, OP_EXECUTE_FUNCTION};
-
-#define HANDLE_NO_NOT_AUTHORIZED_EXCEPTION \
- catch (const apache::geode::client::NotAuthorizedException &) { \
- LOG("NotAuthorizedException Caught"); \
- FAIL("should not have caught NotAuthorizedException"); \
- } \
- catch (const apache::geode::client::Exception &other) { \
- LOG("Got apache::geode::client::Exception& other "); \
- LOG(other.getStackTrace().c_str()); \
- FAIL(other.what()); \
- }
-
-#define HANDLE_NOT_AUTHORIZED_EXCEPTION \
- catch (const apache::geode::client::NotAuthorizedException &) { \
- LOG("NotAuthorizedException Caught"); \
- LOG("Success"); \
- } \
- catch (const apache::geode::client::Exception &other) { \
- LOG(other.getStackTrace().c_str()); \
- FAIL(other.what()); \
- }
-
-#define ADMIN_CLIENT s1p1
-#define WRITER_CLIENT s1p2
-#define READER_CLIENT s2p1
-
-const std::string regionNamesAuth[] = {"DistRegionAck"};
-std::shared_ptr<Properties> userCreds;
-void initClientAuth(char UserType) {
- userCreds = Properties::create();
- auto config = Properties::create();
- opCodeList wr(tmpWArr, tmpWArr + sizeof tmpWArr / sizeof *tmpWArr);
- opCodeList rt(tmpRArr, tmpRArr + sizeof tmpRArr / sizeof *tmpRArr);
- opCodeList ad(tmpAArr, tmpAArr + sizeof tmpAArr / sizeof *tmpAArr);
- credentialGeneratorHandler->getAuthInit(config);
- switch (UserType) {
- case 'W':
- credentialGeneratorHandler->getAllowedCredentialsForOps(wr, userCreds,
- nullptr);
- break;
- case 'R':
- credentialGeneratorHandler->getAllowedCredentialsForOps(rt, userCreds,
- nullptr);
- break;
- case 'A':
- credentialGeneratorHandler->getAllowedCredentialsForOps(ad, userCreds,
- nullptr);
- break;
- default:
- break;
- }
-
- auto alias = userCreds->find("security-alias");
- auto uname = userCreds->find("security-username");
- auto passwd = userCreds->find("security-password");
-
- char msgAlias[100];
- char msgUname[100];
- char msgPasswd[100];
-
- sprintf(msgAlias, "PKCS alias is %s",
- alias == nullptr ? "null" : alias->value().c_str());
- sprintf(msgUname, "username is %s",
- uname == nullptr ? "null" : uname->value().c_str());
- sprintf(msgPasswd, "password is %s",
- passwd == nullptr ? "null" : passwd->value().c_str());
-
- LOG(msgAlias);
- LOG(msgUname);
- LOG(msgPasswd);
-
- try {
- initClient(true, config);
- } catch (...) {
- throw;
- }
-}
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, StartServer1)
- {
- initCredentialGenerator();
- std::string cmdServerAuthenticator;
-
- if (isLocalServer) {
- cmdServerAuthenticator = credentialGeneratorHandler->getServerCmdParams(
- "authenticator:authorizer", getXmlPath());
- printf("string %s", cmdServerAuthenticator.c_str());
- CacheHelper::initServer(
- 1, "cacheserver_notify_subscription.xml", locHostPort,
- const_cast<char *>(cmdServerAuthenticator.c_str()));
- LOG("Server1 started");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, StartServer2)
- {
- std::string cmdServerAuthenticator;
-
- if (isLocalServer) {
- cmdServerAuthenticator = credentialGeneratorHandler->getServerCmdParams(
- "authenticator:authorizer", getXmlPath());
- printf("string %s", cmdServerAuthenticator.c_str());
- CacheHelper::initServer(
- 2, "cacheserver_notify_subscription2.xml", locHostPort,
- const_cast<char *>(cmdServerAuthenticator.c_str()));
- LOG("Server2 started");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, StartLocator)
- {
- if (isLocator) {
- CacheHelper::initLocator(1);
- LOG("Locator1 started");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, StepOne)
- {
- initClientAuth('A');
- try {
- LOG("Tying Region creation");
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, true, nullptr, false,
- -1, true, 0);
- LOG("Region created successfully");
- LOG("Tying Entry creation");
-
- auto pool = getPool(regionNamesAuth[0]);
- LOG(" 6");
-
- if (pool == nullptr) {
- FAIL("Pool is nullptr");
- }
-
- LOG(" 7");
- auto virtualCache = getVirtualCache(userCreds, pool);
- LOG(" 8");
- auto regionPtr = virtualCache.getRegion(regionNamesAuth[0]);
-
- LOG("Operation allowed, something is wrong.");
-
- //---------------------for region clear tests-----
- regionPtr->put(1, 1);
- regionPtr->clear();
-
- auto getVal = regionPtr->get(1);
- if (getVal == nullptr) {
- LOG("Get completed after region.clear successfully");
- } else {
- FAIL("Get did not complete successfully");
- }
-
- //---------------------------------------------------
- regionPtr->create(keys[0], vals[0]);
- LOG("Entry created successfully");
- regionPtr->put(keys[0], nvals[0]);
- LOG("Entry updated successfully");
- HashMapOfCacheable entrymap;
- entrymap.clear();
- for (int i = 0; i < 5; i++) {
- entrymap.emplace(CacheableKey::create(i), CacheableInt32::create(i));
- }
- regionPtr->putAll(entrymap);
- LOG("PutAll completed successfully");
-
- LOG("GetServerKeys check started for ADMIN");
- auto keysvec = regionPtr->serverKeys();
- LOG("GetServerKeys check passed for ADMIN");
-
- std::vector<std::shared_ptr<CacheableKey>> entrykeys;
- for (int i = 0; i < 5; i++) {
- entrykeys.push_back(CacheableKey::create(i));
- }
-
- const auto valuesMap = regionPtr->getAll(entrykeys);
- if (valuesMap.size() > 0) {
- LOG("GetAll completed successfully");
- } else {
- FAIL("GetAll did not complete successfully");
- }
- regionPtr->query("1=1");
- LOG("Query completed successfully");
-
- std::shared_ptr<QueryService> qs;
- // Using region name as pool name
- try {
- qs = pool->getQueryService();
- FAIL("Pool should not return queryservice in multiusermode");
- } catch (const apache::geode::client::UnsupportedOperationException &) {
- LOG("UnsupportedOperationException Caught for pool.getQuerySerice in "
- "multiusermode");
- LOG("Success");
- } catch (const apache::geode::client::Exception &other) {
- LOG(other.getStackTrace().c_str());
- FAIL(other.what());
- }
-
- qs = virtualCache.getQueryService();
-
- auto queryString = "select * from /" + regionNamesAuth[0];
-
- auto &&qry = qs->newQuery(queryString);
- printf(" before query executing\n");
- auto &&results = qry->execute(std::chrono::seconds(850));
- LOG("Query completed successfully");
-
- auto &&cqAttrs = CqAttributesFactory{}.create();
- auto &&cqQry = qs->newCq("cq_security", queryString, cqAttrs);
- cqQry->execute();
- cqQry->close();
- LOG("CQ completed successfully");
-
- if (pool) {
- FunctionService::onServer(virtualCache)
- .execute("securityTest")
- ->getResult();
- LOG("onServer executed successfully.");
- FunctionService::onServers(virtualCache)
- .execute("securityTest")
- ->getResult();
- LOG("onServerS executed successfully.");
- FunctionService::onRegion(regionPtr)
- .execute("securityTest")
- ->getResult();
- LOG("FunctionService::onRegion executed successfully.");
- FunctionService::onRegion(regionPtr).execute("FireNForget");
- LOG("Function execution with no result completed successfully");
-
- //-----------------------Test with
- // sendException-------------------------------//
- LOG("Function execution with sendException");
- char buf[128];
- for (int i = 1; i <= 200; i++) {
- auto value = CacheableInt32::create(i);
-
- sprintf(buf, "execKey-%d", i);
- auto key = CacheableKey::create(buf);
- regionPtr->put(key, value);
- }
- LOG("Put for execKey's on region complete.");
-
- LOG("Adding filter");
- auto arrList = CacheableArrayList::create();
- for (int i = 100; i < 120; i++) {
- sprintf(buf, "execKey-%d", i);
- auto key = CacheableKey::create(buf);
- arrList->push_back(key);
- }
-
- auto filter = CacheableVector::create();
- for (int i = 100; i < 120; i++) {
- sprintf(buf, "execKey-%d", i);
- auto key = CacheableKey::create(buf);
- filter->push_back(key);
- }
- LOG("Adding filter done.");
-
- auto args = CacheableBoolean::create(1);
-
- auto funcExec = FunctionService::onRegion(regionPtr);
-
- auto collector = funcExec.withArgs(args).withFilter(filter).execute(
- exFuncNameSendException, std::chrono::seconds(15));
-
- auto result = collector->getResult();
-
- if (result == nullptr) {
- ASSERT(false, "echo String : result is nullptr");
- } else {
- try {
- for (size_t i = 0; i < result->size(); i++) {
- auto uFEPtr =
- std::dynamic_pointer_cast<UserFunctionExecutionException>(
- result->operator[](i));
- ASSERT(uFEPtr != nullptr, "uFEPtr exception is nullptr");
- LOGINFO("Done casting to uFEPtr");
- LOGINFO("Read expected uFEPtr exception %s ",
- uFEPtr->getMessage().c_str());
- }
- } catch (ClassCastException &ex) {
- std::string logmsg = "";
- logmsg += ex.getName();
- logmsg += ": ";
- logmsg += ex.what();
- LOG(logmsg.c_str());
- LOG(ex.getStackTrace().c_str());
- FAIL(
- "exFuncNameSendException casting to string for bool arguement "
- "exception.");
- } catch (...) {
- FAIL(
- "exFuncNameSendException casting to string for bool arguement "
- "Unknown exception.");
- }
- }
-
- LOG("exFuncNameSendException done for bool arguement.");
-
- collector = funcExec.withArgs(arrList).withFilter(filter).execute(
- exFuncNameSendException, std::chrono::seconds(15));
-
- result = collector->getResult();
- ASSERT(result->size() == arrList->size() + 1,
- "region get: resultList count is not as arrayList count + "
- "exception");
-
- for (size_t i = 0; i < result->size(); i++) {
- try {
- auto intValue = std::dynamic_pointer_cast<CacheableInt32>(
- result->operator[](i));
- ASSERT(intValue != nullptr, "int value is nullptr");
- LOGINFO("intValue is %d ", intValue->value());
- } catch (ClassCastException &ex) {
- LOG("exFuncNameSendException casting to int for arrayList "
- "arguement "
- "exception.");
- std::string logmsg = "";
- logmsg += ex.getName();
- logmsg += ": ";
- logmsg += ex.what();
- LOG(logmsg.c_str());
- LOG(ex.getStackTrace().c_str());
- auto uFEPtr =
- std::dynamic_pointer_cast<UserFunctionExecutionException>(
- result->operator[](i));
- ASSERT(uFEPtr != nullptr, "uFEPtr exception is nullptr");
- LOGINFO("Done casting to uFEPtr");
- LOGINFO("Read expected uFEPtr exception %s ",
- uFEPtr->getMessage().c_str());
- } catch (...) {
- FAIL(
- "exFuncNameSendException casting to string for bool arguement "
- "Unknown exception.");
- }
- }
-
- LOG("exFuncNameSendException done for arrayList arguement.");
-
- LOG("Function execution with sendException successfull");
- //----------------------------------------------------------------------------------------------//
-
- LOG("Function execution completed successfully");
- } else {
- LOG("Skipping function execution for non pool case");
- }
- regionPtr->destroy(keys[0]);
- LOG("Entry destroyed successfully");
- destroyRegion(regionNamesAuth[0]);
- LOG("Region destroy successfully");
- LOG("Tying Region creation");
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, false, nullptr,
- false, -1, true, 0);
- char buf[100] = {'\0'};
- static int indexForPool = 0;
- sprintf(buf, "%s_%d", regionNamesAuth[0].c_str(), indexForPool++);
- pool = getPool(buf);
- LOG(" 6");
- if (pool != nullptr) {
- LOG(" 7");
- virtualCache = getVirtualCache(userCreds, pool);
- LOG(" 8");
- regionPtr = virtualCache.getRegion(regionNamesAuth[0]);
- LOG("Operation allowed, something is wrong.");
- } else {
- LOG("Pool is nullptr");
- }
-
- LOG("Region created successfully");
- regionPtr->create(keys[2], vals[2]);
- LOG("Entry created successfully");
- virtualCache.close();
- LOG("Cache close successfully");
- }
- HANDLE_NO_NOT_AUTHORIZED_EXCEPTION
-
- try {
- LOG("Trying operation using real region in multiusersecure mode");
- auto regPtr = getHelper()->getRegion(regionNamesAuth[0]);
- regPtr->put("key", "val");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- LOG("StepOne complete.");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(WRITER_CLIENT, StepTwo)
- {
- initCredentialGenerator();
- initClientAuth('W');
- try {
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, true, nullptr, false,
- -1, true, 0);
- LOG("Region created successfully");
-
- auto pool = getPool(regionNamesAuth[0]);
- LOG(" 6");
-
- if (pool == nullptr) {
- FAIL("Pool is nullptr");
- }
-
- LOG(" 7");
- auto virtualCache = getVirtualCache(userCreds, pool);
- LOG(" 8");
- auto regionPtr = virtualCache.getRegion(regionNamesAuth[0]);
- LOG("Operation allowed, something is wrong.");
-
- regionPtr->create(keys[0], vals[0]);
- LOG("Entry created successfully");
- regionPtr->put(keys[0], nvals[0]);
- LOG("Entry updated successfully");
- HashMapOfCacheable entrymap;
- entrymap.clear();
- for (int i = 0; i < 5; i++) {
- entrymap.emplace(CacheableKey::create(i), CacheableInt32::create(i));
- }
- regionPtr->putAll(entrymap);
- LOG("PutAll completed successfully");
- regionPtr->destroy(keys[0]);
- LOG("Entry destroyed successfully");
- regionPtr->create(keys[0], vals[0]);
- LOG("Entry created successfully");
- regionPtr->put(keys[0], nvals[0]);
- LOG("Entry updated successfully");
- }
- HANDLE_NO_NOT_AUTHORIZED_EXCEPTION
-
- try {
- std::shared_ptr<Region> regionPtr;
- auto pool = getPool(regionNamesAuth[0]);
- if (pool != nullptr) {
- auto virtualCache = getVirtualCache(userCreds, pool);
- regionPtr = virtualCache.getRegion(regionNamesAuth[0]);
- } else {
- LOG("Pool is nullptr");
- }
- LOG("GetServerKeys check started for WRITER");
- auto keysvec = regionPtr->serverKeys();
- LOG("GetServerKeys check passed for WRITER");
- FAIL("GetServerKeys should not have completed successfully for WRITER");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- auto pool = getPool(regionNamesAuth[0]);
- LOG(" 6");
- if (pool == nullptr) {
- LOG("Pool is nullptr");
- }
- LOG(" 7");
- auto virtualCache = getVirtualCache(userCreds, pool);
- LOG(" 8");
- auto regionPtr = virtualCache.getRegion(regionNamesAuth[0]);
- LOG("Operation allowed, something is wrong.");
- auto keyPtr = CacheableKey::create(keys[2]);
- auto checkPtr =
- std::dynamic_pointer_cast<CacheableString>(regionPtr->get(keyPtr));
- if (checkPtr != nullptr) {
- char buf[1024];
- sprintf(buf, "In net search, get returned %s for key %s",
- checkPtr->value().c_str(), keys[2]);
- LOG(buf);
- FAIL("Should not get the value");
- } else {
- LOG("checkPtr is nullptr");
- }
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- LOG("Going to do registerAllKeys");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- auto pool = getPool(regionNamesAuth[0]);
- LOG(" 6");
- if (pool == nullptr) {
- LOG("Pool is nullptr");
- }
- LOG(" 7");
- auto virtualCache = getVirtualCache(userCreds, pool);
- LOG(" 8");
- auto regionPtr = virtualCache.getRegion(regionNamesAuth[0]);
- LOG("Operation allowed, something is wrong.");
-
- std::vector<std::shared_ptr<CacheableKey>> entrykeys;
- for (int i = 0; i < 5; i++) {
- entrykeys.push_back(CacheableKey::create(i));
- }
-
- const auto valuesMap = regionPtr->getAll(entrykeys);
- if (valuesMap.size() > 0) {
- FAIL("GetAll should not have completed successfully");
- }
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- std::shared_ptr<Region> regionPtr;
- auto pool = getPool(regionNamesAuth[0]);
- LOG(" 6");
- if (pool != nullptr) {
- LOG(" 7");
- auto virtualCache = getVirtualCache(userCreds, pool);
- LOG(" 8");
- regionPtr = virtualCache.getRegion(regionNamesAuth[0]);
- LOG("Operation allowed, something is wrong.");
- } else {
- LOG("Pool is nullptr");
- }
- regionPtr->query("1=1");
- FAIL("Query should not have completed successfully");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- auto pool = getPool(regionNamesAuth[0]);
- auto virtualCache = getVirtualCache(userCreds, pool);
- auto queryService = virtualCache.getQueryService();
-
- auto queryString = "select * from /" + regionNamesAuth[0];
-
- auto cqAttrs = CqAttributesFactory{}.create();
- auto qry = queryService->newCq("cq_security", queryString, cqAttrs);
- queryService->executeCqs();
- FAIL("CQ should not have completed successfully");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- auto pool = getPool(regionNamesAuth[0]);
- auto virtualCache = getVirtualCache(userCreds, pool);
-
- FunctionService::onServer(virtualCache)
- .execute("securityTest")
- ->getResult();
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- auto pool = getPool(regionNamesAuth[0]);
- auto virtualCache = getVirtualCache(userCreds, pool);
-
- FunctionService::onServers(virtualCache)
- .execute("securityTest")
- ->getResult();
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- auto pool = getPool(regionNamesAuth[0]);
- auto virtualCache = getVirtualCache(userCreds, pool);
- std::shared_ptr<Region> regionPtr;
- regionPtr = virtualCache.getRegion(regionNamesAuth[0]);
-
- //-----------------------Test with
- // sendException-------------------------------//
- LOG("Function execution with sendException with expected Authorization "
- "exception");
- char buf[128];
- for (int i = 1; i <= 200; i++) {
- auto value = CacheableInt32::create(i);
-
- sprintf(buf, "execKey-%d", i);
- auto key = CacheableKey::create(buf);
- regionPtr->put(key, value);
- }
- LOG("Put for execKey's on region complete.");
-
- LOG("Adding filter");
- auto arrList = CacheableArrayList::create();
- for (int i = 100; i < 120; i++) {
- sprintf(buf, "execKey-%d", i);
- auto key = CacheableKey::create(buf);
- arrList->push_back(key);
- }
-
- auto filter = CacheableVector::create();
- for (int i = 100; i < 120; i++) {
- sprintf(buf, "execKey-%d", i);
- auto key = CacheableKey::create(buf);
- filter->push_back(key);
- }
- LOG("Adding filter done.");
-
- auto args = CacheableBoolean::create(1);
-
- LOG("OnServers with sendException");
-
- auto funcExec = FunctionService::onServers(virtualCache);
-
- auto collector = funcExec.withArgs(args).execute(
- exFuncNameSendException, std::chrono::seconds(15));
-
- //----------------------------------------------------------------------------------------------//
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- auto pool = getPool(regionNamesAuth[0]);
- auto virtualCache = getVirtualCache(userCreds, pool);
- std::shared_ptr<Region> regionPtr;
- regionPtr = virtualCache.getRegion(regionNamesAuth[0]);
-
- FunctionService::onRegion(regionPtr).execute("securityTest")->getResult();
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- auto pool = getPool(regionNamesAuth[0]);
- auto virtualCache = getVirtualCache(userCreds, pool);
- std::shared_ptr<Region> regionPtr;
- regionPtr = virtualCache.getRegion(regionNamesAuth[0]);
-
- //-----------------------Test with
- // sendException-------------------------------//
- LOG("Function execution with sendException with expected Authorization "
- "exception with onRegion");
- char buf[128];
- for (int i = 1; i <= 200; i++) {
- auto value = CacheableInt32::create(i);
-
- sprintf(buf, "execKey-%d", i);
- auto key = CacheableKey::create(buf);
- regionPtr->put(key, value);
- }
- LOG("Put for execKey's on region complete.");
-
- LOG("Adding filter");
- auto arrList = CacheableArrayList::create();
- for (int i = 100; i < 120; i++) {
- sprintf(buf, "execKey-%d", i);
- auto key = CacheableKey::create(buf);
- arrList->push_back(key);
- }
-
- auto filter = CacheableVector::create();
- for (int i = 100; i < 120; i++) {
- sprintf(buf, "execKey-%d", i);
- auto key = CacheableKey::create(buf);
- filter->push_back(key);
- }
- LOG("Adding filter done.");
-
- auto args = CacheableBoolean::create(1);
-
- LOG("OnServers with sendException");
-
- auto funcExec = FunctionService::onRegion(regionPtr);
-
- auto collector = funcExec.withArgs(args).withFilter(filter).execute(
- exFuncNameSendException, std::chrono::seconds(15));
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- std::shared_ptr<Region> regionPtr;
- auto pool = getPool(regionNamesAuth[0]);
- LOG(" 6");
- if (pool != nullptr) {
- LOG(" 7");
- auto virtualCache = getVirtualCache(userCreds, pool);
- LOG(" 8");
- regionPtr = virtualCache.getRegion(regionNamesAuth[0]);
- LOG("Operation allowed, something is wrong.");
- } else {
- LOG("Pool is nullptr");
- }
-
- regionPtr->create(keys[2], vals[2]);
- LOG("Entry created successfully");
-
- LOG("StepTwo complete.");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(READER_CLIENT, StepThree)
- {
- initCredentialGenerator();
- initClientAuth('R');
- char buf[100];
- int value = 102;
-
- createRegionForSecurity(regionNamesAuth[0], USE_ACK, false, nullptr, false,
- -1, true, 0);
- std::shared_ptr<Region> rptr;
- auto pool = getPool(regionNamesAuth[0]);
- LOG(" 6");
- if (pool != nullptr) {
- LOG("Pool is nullptr");
- }
- LOG(" 7");
- auto virtualCache = getVirtualCache(userCreds, pool);
- LOG(" 8");
- rptr = virtualCache.getRegion(regionNamesAuth[0]);
- LOG("Operation allowed, something is wrong.");
-
- sprintf(buf, "%s: %d", rptr->getName().c_str(), value);
- auto key = CacheableKey::create(buf);
- sprintf(buf, "testUpdate::%s: value of %d", rptr->getName().c_str(), value);
- auto valuePtr = buf;
- try {
- LOG("Trying put Operation");
- rptr->put(key, valuePtr);
- LOG(" Put Operation Successful");
- FAIL("Should have got NotAuthorizedException during put");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- LOG("Trying createEntry");
- createEntry(regionNamesAuth[0], keys[2], vals[2]);
- rptr->create(keys[2], vals[2]);
- FAIL("Should have got NotAuthorizedException during createEntry");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- LOG("Trying region clear..");
- rptr->clear();
- FAIL("Should have got NotAuthorizedException for region.clear ops");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- LOG("Trying updateEntry");
- rptr->put(keys[2], nvals[2]);
- FAIL("Should have got NotAuthorizedException during updateEntry");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- auto keyPtr = CacheableKey::create(keys[2]);
- auto checkPtr =
- std::dynamic_pointer_cast<CacheableString>(rptr->get(keyPtr));
- if (checkPtr != nullptr) {
- LOG("In net search, get returned " + checkPtr->value() + " for key " +
- keys[2]);
- } else {
- LOG("checkPtr is nullptr");
- }
- }
- HANDLE_NO_NOT_AUTHORIZED_EXCEPTION
-
- try {
- HashMapOfCacheable entrymap;
- entrymap.clear();
- for (int i = 0; i < 5; i++) {
- entrymap.emplace(CacheableKey::create(i), CacheableInt32::create(i));
- }
- rptr->putAll(entrymap);
- FAIL("PutAll should not have completed successfully");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- LOG("GetServerKeys check started for READER");
- auto keysvec = rptr->serverKeys();
- LOG("GetServerKeys check passed for READER");
- }
- HANDLE_NO_NOT_AUTHORIZED_EXCEPTION
-
- try {
- std::vector<std::shared_ptr<CacheableKey>> entrykeys;
- for (int i = 0; i < 5; i++) {
- entrykeys.push_back(CacheableKey::create(i));
- }
- const auto valuesMap = rptr->getAll(entrykeys);
- if (valuesMap.size() > 0) {
- LOG("GetAll completed successfully");
- } else {
- FAIL("GetAll did not complete successfully");
- }
- }
- HANDLE_NO_NOT_AUTHORIZED_EXCEPTION
-
- try {
- rptr->query("1=1");
-
- FAIL("Query should not have completed successfully");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- try {
- FunctionService::onServer(virtualCache)
- .execute("securityTest")
- ->getResult();
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
-
- LOG("StepThree complete.");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, CloseServer1)
- {
- SLEEP(9000);
- if (isLocalServer) {
- CacheHelper::closeServer(1);
- LOG("SERVER1 stopped");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, CloseServer2)
- {
- if (isLocalServer) {
- CacheHelper::closeServer(2);
- LOG("SERVER2 stopped");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, CloseLocator)
- {
- if (isLocator) {
- CacheHelper::closeLocator(1);
- LOG("Locator1 stopped");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, CloseCacheAdmin)
- { cleanProc(); }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(WRITER_CLIENT, CloseCacheWriter)
- { cleanProc(); }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(READER_CLIENT, CloseCacheReader)
- { cleanProc(); }
-END_TASK_DEFINITION
-
-void doThinClientSecurityAuthorization() {
- CALL_TASK(StartLocator);
- CALL_TASK(StartServer1);
- CALL_TASK(StepOne);
- CALL_TASK(StepTwo);
- CALL_TASK(StartServer2);
- CALL_TASK(CloseServer1);
- CALL_TASK(StepThree);
- CALL_TASK(CloseCacheReader);
- CALL_TASK(CloseCacheWriter);
- CALL_TASK(CloseCacheAdmin);
- CALL_TASK(CloseServer2);
- CALL_TASK(CloseLocator);
-}
-
-DUNIT_MAIN
- { doThinClientSecurityAuthorization(); }
-END_MAIN
diff --git a/cppcache/integration-test/testThinClientSecurityCQAuthorizationMU.cpp b/cppcache/integration-test/testThinClientSecurityCQAuthorizationMU.cpp
deleted file mode 100644
index 78ba57d..0000000
--- a/cppcache/integration-test/testThinClientSecurityCQAuthorizationMU.cpp
+++ /dev/null
@@ -1,515 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "fw_dunit.hpp"
-#include <geode/CqAttributesFactory.hpp>
-#include <geode/CqAttributes.hpp>
-#include <geode/CqListener.hpp>
-#include <geode/CqQuery.hpp>
-#include <geode/CqServiceStatistics.hpp>
-#include <geode/AuthenticatedView.hpp>
-#include <ace/OS.h>
-#include <ace/High_Res_Timer.h>
-#include <string>
-
-#define ROOT_NAME "testThinClientSecurityCQAuthorizationMU"
-#define ROOT_SCOPE DISTRIBUTED_ACK
-
-#include "CacheHelper.hpp"
-
-#include "QueryStrings.hpp"
-#include "QueryHelper.hpp"
-
-#include <geode/Query.hpp>
-#include <geode/QueryService.hpp>
-
-#include "ThinClientCQ.hpp"
-
-#include "CacheHelper.hpp"
-#include "ThinClientHelper.hpp"
-#include <ace/Process.h>
-
-using apache::geode::client::testframework::security::CredentialGenerator;
-
-using apache::geode::client::AuthenticatedView;
-using apache::geode::client::CqAttributesFactory;
-using apache::geode::client::CqEvent;
-using apache::geode::client::CqListener;
-using apache::geode::client::CqOperation;
-using apache::geode::client::Exception;
-using apache::geode::client::IllegalStateException;
-using apache::geode::client::QueryService;
-
-const std::string locHostPort =
- CacheHelper::getLocatorHostPort(isLocator, isLocalServer, 1);
-std::shared_ptr<CredentialGenerator> credentialGeneratorHandler;
-#define CLIENT1 s1p1
-#define SERVER1 s2p1
-#define CLIENT2 s1p2
-
-#define MAX_LISTNER 8
-
-const char *cqNames[MAX_LISTNER] = {"MyCq_0", "MyCq_1", "MyCq_2", "MyCq_3",
- "MyCq_4", "MyCq_5", "MyCq_6", "MyCq_7"};
-
-const char *queryStrings[MAX_LISTNER] = {
- "select * from /Portfolios p where p.ID < 1",
- "select * from /Portfolios p where p.ID < 2",
- "select * from /Portfolios p where p.ID = 2",
- "select * from /Portfolios p where p.ID >= 3",
- "select * from /Portfolios p where p.ID = 4",
- "select * from /Portfolios p where p.ID = 5",
- "select * from /Portfolios p where p.ID = 6",
- "select * from /Portfolios p where p.ID = 7"};
-
-const char *regionNamesCq[] = {"Portfolios", "Positions", "Portfolios2",
- "Portfolios3"};
-
-class MyCqListener : public CqListener {
- uint8_t m_id;
- uint32_t m_numInserts;
- uint32_t m_numUpdates;
- uint32_t m_numDeletes;
- uint32_t m_numEvents;
-
- public:
- uint8_t getId() { return m_id; }
- uint32_t getNumInserts() { return m_numInserts; }
- uint32_t getNumUpdates() { return m_numUpdates; }
- uint32_t getNumDeletes() { return m_numDeletes; }
- uint32_t getNumEvents() { return m_numEvents; }
- explicit MyCqListener(uint8_t id)
- : m_id(id),
- m_numInserts(0),
- m_numUpdates(0),
- m_numDeletes(0),
- m_numEvents(0) {}
- ~MyCqListener() noexcept override = default;
- inline void updateCount(const CqEvent &cqEvent) {
- printf(" in cqEvent.getQueryOperation() %d id = %d\n",
- static_cast<int>(cqEvent.getQueryOperation()), m_id);
- printf(" in update key = %s \n",
- (dynamic_cast<CacheableString *>(cqEvent.getKey().get()))
- ->value()
- .c_str());
- m_numEvents++;
- switch (cqEvent.getQueryOperation()) {
- case CqOperation::OP_TYPE_CREATE:
- m_numInserts++;
- break;
- case CqOperation::OP_TYPE_UPDATE:
- m_numUpdates++;
- break;
- case CqOperation::OP_TYPE_DESTROY:
- m_numDeletes++;
- break;
- case CqOperation::OP_TYPE_INVALID:
- case CqOperation::OP_TYPE_INVALIDATE:
- case CqOperation::OP_TYPE_REGION_CLEAR:
- case CqOperation::OP_TYPE_MARKER:
- break;
- }
- printf(" in create = %d, update = %d , delete = %d ", m_numInserts,
- m_numUpdates, m_numDeletes);
- }
-
- void onEvent(const CqEvent &cqe) override {
- LOG("MyCqListener::OnEvent called");
- updateCount(cqe);
- }
- void onError(const CqEvent &cqe) override {
- updateCount(cqe);
- LOG("MyCqListener::OnError called");
- }
- void close() override { LOG("MyCqListener::close called"); }
-};
-
-std::string getXmlPath() {
- char xmlPath[1000] = {'\0'};
- const char *path = std::getenv("TESTSRC");
- ASSERT(path != nullptr,
- "Environment variable TESTSRC for test source directory is not set.");
- strncpy(xmlPath, path, strlen(path) - strlen("cppcache"));
- strncat(xmlPath, "xml/Security/", sizeof(xmlPath) - strlen(xmlPath) - 1);
- return std::string(xmlPath);
-}
-
-void initCredentialGenerator() {
- credentialGeneratorHandler = CredentialGenerator::create("DUMMY3");
-
- if (credentialGeneratorHandler == nullptr) {
- FAIL("credentialGeneratorHandler is nullptr");
- }
-}
-std::shared_ptr<Properties> userCreds;
-void initClientCq(const bool isthinClient) {
- userCreds = Properties::create();
- auto config = Properties::create();
- // credentialGeneratorHandler->getAuthInit(config);
- credentialGeneratorHandler->getValidCredentials(userCreds);
-
- if (cacheHelper == nullptr) {
- cacheHelper = new CacheHelper(isthinClient, config);
- }
- ASSERT(cacheHelper, "Failed to create a CacheHelper client instance.");
- try {
- auto serializationRegistry =
- CacheRegionHelper::getCacheImpl(cacheHelper->getCache().get())
- ->getSerializationRegistry();
- serializationRegistry->addDataSerializableType(
- Position::createDeserializable, 2);
- serializationRegistry->addDataSerializableType(
- Portfolio::createDeserializable, 3);
- } catch (const IllegalStateException &) {
- // ignore exception
- }
-}
-
-DUNIT_TASK_DEFINITION(CLIENT1, CreateServer1)
- {
- initCredentialGenerator();
- std::string cmdServerAuthenticator;
-
- if (isLocalServer) {
- cmdServerAuthenticator = credentialGeneratorHandler->getServerCmdParams(
- "authenticator:authorizer:authorizerPP", getXmlPath());
- printf("string %s", cmdServerAuthenticator.c_str());
- CacheHelper::initServer(
- 1, "remotequery.xml", {},
- const_cast<char *>(cmdServerAuthenticator.c_str()));
- LOG("Server1 started");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, CreateServer2)
- {
- std::string cmdServerAuthenticator;
-
- if (isLocalServer) {
- cmdServerAuthenticator = credentialGeneratorHandler->getServerCmdParams(
- "authenticator:authorizer:authorizerPP", getXmlPath());
- printf("string %s", cmdServerAuthenticator.c_str());
- CacheHelper::initServer(
- 2, "remotequery2.xml", nullptr,
- const_cast<char *>(cmdServerAuthenticator.c_str()));
- LOG("Server2 started");
- }
- SLEEP(20000);
- }
-END_TASK_DEFINITION
-
-void stepOne() {
- LOG("StepOne1 complete. 1");
- initClientCq(true);
- LOG("StepOne1 complete. 2");
- createRegionForCQMU(regionNamesCq[0], USE_ACK, false);
- LOG("StepOne1 complete. 3");
- auto regptr = getHelper()->getRegion(regionNamesCq[0]);
- LOG("StepOne1 complete. 4");
- LOG("StepOne1 complete. 5");
- auto subregPtr =
- regptr->createSubregion(regionNamesCq[1], regptr->getAttributes());
-
- LOG("StepOne complete.");
-}
-
-void stepOne2() {
- LOG("StepOne2 complete. 1");
- initClientCq(true);
- LOG("StepOne2 complete. 2");
- createRegionForCQMU(regionNamesCq[0], USE_ACK, false);
- LOG("StepOne2 complete. 3");
- auto regptr = getHelper()->getRegion(regionNamesCq[0]);
- LOG("StepOne2 complete. 4");
- LOG("StepOne2 complete. 5");
- auto subregPtr =
- regptr->createSubregion(regionNamesCq[1], regptr->getAttributes());
-
- LOG("StepOne2 complete.");
-}
-
-DUNIT_TASK_DEFINITION(CLIENT1, StepOne_PoolEP)
- { stepOne(); }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT2, StepOne2_PoolEP)
- {
- initCredentialGenerator();
- stepOne2();
- }
-END_TASK_DEFINITION
-std::shared_ptr<Pool> getPool(const char *name) {
- return getHelper()->getCache()->getPoolManager().find(name);
-}
-
-static std::shared_ptr<QueryService> userQueryService;
-
-AuthenticatedView setUpAuthenticatedView(const int userId) {
- auto creds = Properties::create();
- char tmp[25] = {'\0'};
- sprintf(tmp, "user%d", userId);
-
- creds->insert("security-username", tmp);
- creds->insert("security-password", tmp);
- return getHelper()->getCache()->createAuthenticatedView(creds,
- regionNamesCq[0]);
-}
-
-DUNIT_TASK_DEFINITION(CLIENT1, StepTwo)
- {
- auto authenticatedView = setUpAuthenticatedView(4);
-
- auto regPtr0 = authenticatedView.getRegion(regionNamesCq[0]);
- auto subregPtr0 = regPtr0->getSubregion(regionNamesCq[1]);
-
- authenticatedView.close();
- LOG("StepTwo complete.");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, StepThree)
- {
- uint8_t i = 0;
- // QueryHelper * qh = &QueryHelper::getHelper();
- // userCache = getVirtualCache(userCreds, regionNamesCq[0]);
- auto authenticatedView = setUpAuthenticatedView(4);
- userQueryService = authenticatedView.getQueryService();
- std::shared_ptr<QueryService> qs;
-
- qs = userQueryService;
-
- try {
- for (i = 0; i < MAX_LISTNER; i++) {
- auto cqLstner = std::make_shared<MyCqListener>(i);
- CqAttributesFactory cqFac;
- cqFac.addCqListener(cqLstner);
- auto cqAttr = cqFac.create();
-
- auto qry = qs->newCq(cqNames[i], queryStrings[i], cqAttr);
- qry->execute();
- }
-
- LOG("EXECUTE 1 START");
-
- // qs->executeCqs();
-
- LOG("EXECUTE 1 STOP");
- } catch (const Exception &excp) {
- std::string logmsg = "";
- logmsg += excp.getName();
- logmsg += ": ";
- logmsg += excp.what();
- LOG(logmsg.c_str());
- LOG(excp.getStackTrace());
- }
-
- authenticatedView.close();
- LOG("StepThree complete.");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT2, StepTwo2)
- {
- auto authenticatedView = setUpAuthenticatedView(3);
- auto regPtr0 = authenticatedView.getRegion(regionNamesCq[0]);
- auto subregPtr0 = regPtr0->getSubregion(regionNamesCq[1]);
-
- QueryHelper *qh = &QueryHelper::getHelper();
-
- qh->populatePortfolioData(regPtr0, 3, 2, 1);
- qh->populatePositionData(subregPtr0, 3, 2);
- for (int i = 1; i <= 4; i++) {
- auto port = std::make_shared<Portfolio>(i, 2);
-
- char tmp[25] = {'\0'};
- sprintf(tmp, "port1-%d", i);
- auto keyport = CacheableKey::create(tmp);
- regPtr0->put(keyport, port);
- SLEEP(10); // sleep a while to allow server query to complete
- }
-
- LOG("StepTwo2 complete. Sleeping .25 min for server query to complete...");
- SLEEP(15000); // sleep .25 min to allow server query to complete
- authenticatedView.close();
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, StepFour)
- {
- // auto userCache = getVirtualCache(userCreds, regionNamesCq[0]);
- std::shared_ptr<QueryService> qs;
-
- qs = userQueryService;
-
- char buf[1024];
-
- uint8_t i = 0;
-
- CqAttributesFactory cqFac;
- for (i = 0; i < MAX_LISTNER; i++) {
- sprintf(buf, "get info for cq[%s]:", cqNames[i]);
- LOG(buf);
- auto cqy = qs->getCq(cqNames[i]);
- // auto cqStats = cqy->getStatistics();
- }
-
- // if key port1-4 then only query 3 and 4 will satisfied
- auto cqy = qs->getCq(cqNames[3]);
- auto cqAttr = cqy->getCqAttributes();
- auto vl = cqAttr->getCqListeners();
-
- auto cqListener_3 = static_cast<MyCqListener *>(vl[0].get());
- printf(" cqListener_3 should have one create event = %d \n",
- cqListener_3->getNumInserts());
- ASSERT(cqListener_3->getNumInserts() == 1,
- "incorrect number of events got listener 3");
-
- cqy = qs->getCq(cqNames[4]);
- cqAttr = cqy->getCqAttributes();
- vl = cqAttr->getCqListeners();
-
- auto cqListener_4 = static_cast<MyCqListener *>(vl[0].get());
- printf(" cqListener_4 should have one create event = %d \n",
- cqListener_4->getNumInserts());
- ASSERT(cqListener_4->getNumInserts() == 1,
- "incorrect number of events got listener 4");
-
- /*for(i=0; i < MAX_LISTNER; i++)
- {
- sprintf(buf, "get info for cq[%s]:", cqNames[i]);
- LOG(buf);
- auto cqy = qs->getCq(cqNames[i]);
- cqy->stop();
- cqy->close();
- //auto cqStats = cqy->getStatistics();
- }*/
-
- // userCache->close();
- LOG("StepFour complete.");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, StepFour2)
- {
- auto qs = userQueryService;
-
- char buf[1024];
-
- uint8_t i = 0;
-
- for (i = 0; i < MAX_LISTNER; i++) {
- sprintf(buf, "get info for cq[%s]:", cqNames[i]);
- LOG(buf);
- auto cqy = qs->getCq(cqNames[i]);
- // auto cqStats = cqy->getStatistics();
- }
-
- // if key port1-4 then only query 3 and 4 will satisfied
- auto cqy = qs->getCq(cqNames[3]);
- auto cqAttr = cqy->getCqAttributes();
- auto vl = cqAttr->getCqListeners();
-
- MyCqListener *cqListener_3 = static_cast<MyCqListener *>(vl[0].get());
- printf(" cqListener_3 should have one update event = %d \n",
- cqListener_3->getNumUpdates());
- ASSERT(cqListener_3->getNumUpdates() == 1,
- "incorrect number of events got listener 3");
-
- cqy = qs->getCq(cqNames[4]);
- cqAttr = cqy->getCqAttributes();
- vl = cqAttr->getCqListeners();
-
- auto cqListener_4 = static_cast<MyCqListener *>(vl[0].get());
- printf(" cqListener_4 should have one update event = %d \n",
- cqListener_4->getNumUpdates());
- ASSERT(cqListener_4->getNumUpdates() == 1,
- "incorrect number of events got listener 4");
-
- /*for(i=0; i < MAX_LISTNER; i++)
- {
- sprintf(buf, "get info for cq[%s]:", cqNames[i]);
- LOG(buf);
- auto cqy = qs->getCq(cqNames[i]);
- cqy->stop();
- cqy->close();
- //auto cqStats = cqy->getStatistics();
- }*/
-
- LOG("StepFour2 complete.");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, CloseCache1)
- {
- LOG("cleanProc 1...");
- cleanProc();
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT2, CloseCache2)
- {
- LOG("cleanProc 2...");
- cleanProc();
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(SERVER1, CloseServer1)
- {
- LOG("closing Server1...");
- if (isLocalServer) {
- CacheHelper::closeServer(1);
- LOG("SERVER1 stopped");
- }
- SLEEP(5000);
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(SERVER1, CloseServer2)
- {
- LOG("closing Server2...");
- if (isLocalServer) {
- CacheHelper::closeServer(2);
- LOG("SERVER2 stopped");
- }
- }
-END_TASK_DEFINITION
-
-void doThinClientCq() {
- // CALL_TASK(CreateLocator);
- // CALL_TASK(CreateServer1_Locator);
- //
- // CALL_TASK(StepOne_PoolLocator);
- // CALL_TASK(StepOne2_PoolLocator);
-
- CALL_TASK(StepTwo);
- CALL_TASK(StepThree);
- CALL_TASK(StepTwo2);
- CALL_TASK(StepFour); // validates listener events
- CALL_TASK(CreateServer2);
- CALL_TASK(CloseServer1);
- CALL_TASK(StepTwo2); // again put data
- CALL_TASK(StepFour2);
- CALL_TASK(CloseCache1);
- CALL_TASK(CloseCache2);
- CALL_TASK(CloseServer2);
-
- // CALL_TASK(CloseLocator);
-}
-
-DUNIT_MAIN
- { doThinClientCq(); }
-END_MAIN
diff --git a/cppcache/integration-test/testThinClientSecurityDurableCQAuthorizationMU.cpp b/cppcache/integration-test/testThinClientSecurityDurableCQAuthorizationMU.cpp
deleted file mode 100644
index 6e530e1..0000000
--- a/cppcache/integration-test/testThinClientSecurityDurableCQAuthorizationMU.cpp
+++ /dev/null
@@ -1,650 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "fw_dunit.hpp"
-#include <geode/CqAttributesFactory.hpp>
-#include <geode/CqAttributes.hpp>
-#include <geode/CqListener.hpp>
-#include <geode/CqQuery.hpp>
-#include <geode/CqServiceStatistics.hpp>
-#include <geode/AuthenticatedView.hpp>
-#include <ace/OS.h>
-#include <ace/High_Res_Timer.h>
-#include <string>
-
-#define ROOT_NAME "testThinClientSecurityDurableCQAuthorizationMU"
-#define ROOT_SCOPE DISTRIBUTED_ACK
-
-#include "CacheHelper.hpp"
-
-#include "QueryStrings.hpp"
-#include "QueryHelper.hpp"
-
-#include <geode/Query.hpp>
-#include <geode/QueryService.hpp>
-
-#include "ThinClientCQ.hpp"
-
-#include "CacheHelper.hpp"
-#include "ThinClientHelper.hpp"
-#include <ace/Process.h>
-
-using apache::geode::client::AuthenticatedView;
-using apache::geode::client::CqAttributesFactory;
-using apache::geode::client::CqEvent;
-using apache::geode::client::CqListener;
-using apache::geode::client::CqOperation;
-using apache::geode::client::Exception;
-using apache::geode::client::IllegalStateException;
-using apache::geode::client::QueryService;
-using apache::geode::client::testframework::security::CredentialGenerator;
-
-const std::string locHostPort =
- CacheHelper::getLocatorHostPort(isLocator, isLocalServer, 1);
-
-std::shared_ptr<CredentialGenerator> credentialGeneratorHandler;
-
-#define CLIENT1 s1p1
-#define SERVER1 s2p1
-#define CLIENT2 s1p2
-
-#define MAX_LISTNER 8
-
-const char *cqNames[MAX_LISTNER] = {"MyCq_0", "MyCq_1", "MyCq_2", "MyCq_3",
- "MyCq_4", "MyCq_5", "MyCq_6", "MyCq_7"};
-
-const char *queryStrings[MAX_LISTNER] = {
- "select * from /Portfolios p where p.ID < 1",
- "select * from /Portfolios p where p.ID < 2",
- "select * from /Portfolios p where p.ID = 2",
- "select * from /Portfolios p where p.ID >= 3",
- "select * from /Portfolios p where p.ID = 4",
- "select * from /Portfolios p where p.ID = 5",
- "select * from /Portfolios p where p.ID = 6",
- "select * from /Portfolios p where p.ID = 7"};
-
-const char *regionNamesCq[] = {"Portfolios", "Positions", "Portfolios2",
- "Portfolios3"};
-
-class MyCqListener : public CqListener {
- uint8_t m_id;
- uint32_t m_numInserts;
- uint32_t m_numUpdates;
- uint32_t m_numDeletes;
- uint32_t m_numEvents;
-
- public:
- uint8_t getId() { return m_id; }
- uint32_t getNumInserts() { return m_numInserts; }
- uint32_t getNumUpdates() { return m_numUpdates; }
- uint32_t getNumDeletes() { return m_numDeletes; }
- uint32_t getNumEvents() { return m_numEvents; }
- explicit MyCqListener(uint8_t id)
- : m_id(id),
- m_numInserts(0),
- m_numUpdates(0),
- m_numDeletes(0),
- m_numEvents(0) {}
- ~MyCqListener() noexcept override = default;
- inline void updateCount(const CqEvent &cqEvent) {
- printf(" in cqEvent.getQueryOperation() %d id = %d\n",
- static_cast<int>(cqEvent.getQueryOperation()), m_id);
- printf(" in update key = %s \n",
- (dynamic_cast<CacheableString *>(cqEvent.getKey().get()))
- ->value()
- .c_str());
- m_numEvents++;
- switch (cqEvent.getQueryOperation()) {
- case CqOperation::OP_TYPE_CREATE:
- m_numInserts++;
- break;
- case CqOperation::OP_TYPE_UPDATE:
- m_numUpdates++;
- break;
- case CqOperation::OP_TYPE_DESTROY:
- m_numDeletes++;
- break;
- case CqOperation::OP_TYPE_INVALID:
- case CqOperation::OP_TYPE_INVALIDATE:
- case CqOperation::OP_TYPE_REGION_CLEAR:
- case CqOperation::OP_TYPE_MARKER:
- break;
- }
- printf(" in create = %d, update = %d , delete = %d ", m_numInserts,
- m_numUpdates, m_numDeletes);
- }
-
- void onEvent(const CqEvent &cqe) override {
- LOG("MyCqListener::OnEvent called");
- updateCount(cqe);
- }
- void onError(const CqEvent &cqe) override {
- updateCount(cqe);
- LOG("MyCqListener::OnError called");
- }
- void close() override { LOG("MyCqListener::close called"); }
-};
-
-std::string getXmlPath() {
- char xmlPath[1000] = {'\0'};
- const char *path = std::getenv("TESTSRC");
- ASSERT(path != nullptr,
- "Environment variable TESTSRC for test source directory is not set.");
- strncpy(xmlPath, path, strlen(path) - strlen("cppcache"));
- strncat(xmlPath, "xml/Security/", sizeof(xmlPath) - strlen(xmlPath) - 1);
- return std::string(xmlPath);
-}
-
-void initCredentialGenerator() {
- credentialGeneratorHandler = CredentialGenerator::create("DUMMY3");
-
- if (credentialGeneratorHandler == nullptr) {
- FAIL("credentialGeneratorHandler is nullptr");
- }
-}
-std::shared_ptr<Properties> userCreds;
-const char *durableIds[] = {"DurableId1", "DurableId2"};
-void initClientCq(const bool isthinClient, int clientIdx) {
- userCreds = Properties::create();
- auto config = Properties::create();
- // credentialGeneratorHandler->getAuthInit(config);
- credentialGeneratorHandler->getValidCredentials(userCreds);
-
- config->insert("durable-client-id", durableIds[clientIdx]);
- config->insert("durable-timeout", std::chrono::seconds(60));
- config->insert("notify-ack-interval", std::chrono::seconds(1));
-
- if (cacheHelper == nullptr) {
- cacheHelper = new CacheHelper(isthinClient, config);
- }
- ASSERT(cacheHelper, "Failed to create a CacheHelper client instance.");
- try {
- CacheImpl *cacheImpl =
- CacheRegionHelper::getCacheImpl(cacheHelper->getCache().get());
- cacheImpl->getSerializationRegistry()->addDataSerializableType(
- Position::createDeserializable, 2);
- cacheImpl->getSerializationRegistry()->addDataSerializableType(
- Portfolio::createDeserializable, 3);
- } catch (const IllegalStateException &) {
- // ignore exception
- }
-}
-
-bool closeLogicalCache = false;
-bool logicalCacheKeepAlive = false;
-bool durableCq = false;
-
-DUNIT_TASK_DEFINITION(CLIENT1, CreateServer1)
- {
- initCredentialGenerator();
- std::string cmdServerAuthenticator;
-
- if (isLocalServer) {
- cmdServerAuthenticator = credentialGeneratorHandler->getServerCmdParams(
- "authenticator:authorizerPP", getXmlPath());
- printf("string %s", cmdServerAuthenticator.c_str());
- CacheHelper::initServer(
- 1, "remotequery.xml", nullptr,
- const_cast<char *>(cmdServerAuthenticator.c_str()));
- LOG("Server1 started");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, CreateServer2)
- {
- std::string cmdServerAuthenticator;
-
- if (isLocalServer) {
- cmdServerAuthenticator = credentialGeneratorHandler->getServerCmdParams(
- "authenticator:authorizerPP", getXmlPath());
- printf("string %s", cmdServerAuthenticator.c_str());
- CacheHelper::initServer(
- 2, "remotequery2.xml", nullptr,
- const_cast<char *>(cmdServerAuthenticator.c_str()));
- LOG("Server2 started");
- }
- SLEEP(20000);
- }
-END_TASK_DEFINITION
-
-void stepOne() {
- LOG("StepOne1 complete. 1");
- initClientCq(true, 0);
- LOG("StepOne1 complete. 2");
- createRegionForCQMU(regionNamesCq[0], USE_ACK, false);
- LOG("StepOne1 complete. 3");
- auto regptr = getHelper()->getRegion(regionNamesCq[0]);
- LOG("StepOne1 complete. 4");
- auto subregPtr =
- regptr->createSubregion(regionNamesCq[1], regptr->getAttributes());
-
- LOG("StepOne complete.");
-}
-
-void readyForEvents() {
- try {
- getHelper()->cachePtr->readyForEvents();
- LOG("StepOne readyForevents Complete");
- } catch (...) {
- LOG("Exception occured while sending readyForEvents");
- }
-}
-
-void stepOne2() {
- LOG("StepOne2 complete. 1");
- initClientCq(true, 1);
- LOG("StepOne2 complete. 2");
- createRegionForCQMU(regionNamesCq[0], USE_ACK, false);
- LOG("StepOne2 complete. 3");
- auto regptr = getHelper()->getRegion(regionNamesCq[0]);
- LOG("StepOne2 complete. 4");
- auto subregPtr =
- regptr->createSubregion(regionNamesCq[1], regptr->getAttributes());
-
- LOG("StepOne2 complete.");
-}
-
-DUNIT_TASK_DEFINITION(CLIENT1, StepOne_PoolEP)
- { stepOne(); }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT2, StepOne2_PoolEP)
- {
- initCredentialGenerator();
- stepOne2();
- }
-END_TASK_DEFINITION
-
-std::shared_ptr<Pool> getPool(const char *name) {
- return getHelper()->getCache()->getPoolManager().find(name);
-}
-
-AuthenticatedView setUpAuthenticatedView(const int userId) {
- auto creds = Properties::create();
- char tmp[25] = {'\0'};
- sprintf(tmp, "user%d", userId);
-
- creds->insert("security-username", tmp);
- creds->insert("security-password", tmp);
- return getHelper()->getCache()->createAuthenticatedView(creds,
- regionNamesCq[0]);
-}
-
-static std::shared_ptr<QueryService> userQueryService;
-
-DUNIT_TASK_DEFINITION(CLIENT1, StepTwo)
- {
- auto authenticatedView = setUpAuthenticatedView(4);
- auto regPtr0 = authenticatedView.getRegion(regionNamesCq[0]);
- auto subregPtr0 = regPtr0->getSubregion(regionNamesCq[1]);
-
- // QueryHelper * qh = &QueryHelper::getHelper();
-
- // qh->populatePortfolioData(regPtr0 , 2, 1, 1);
- // qh->populatePositionData(subregPtr0, 2, 1);
-
- if (closeLogicalCache) {
- authenticatedView.close();
- }
-
- LOG("StepTwo complete.");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, ReadyForEvents)
- { readyForEvents(); }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, StepThree)
- {
- uint8_t i = 0;
- // QueryHelper * qh = &QueryHelper::getHelper();
- // userCache = getVirtualCache(userCreds, regionNamesCq[0]);
-
- auto authenticatedView = setUpAuthenticatedView(4);
- userQueryService = authenticatedView.getQueryService();
-
- std::shared_ptr<QueryService> qs;
-
- qs = userQueryService;
-
- try {
- for (i = 0; i < MAX_LISTNER; i++) {
- auto cqLstner = std::make_shared<MyCqListener>(i);
- CqAttributesFactory cqFac;
- cqFac.addCqListener(cqLstner);
- auto cqAttr = cqFac.create();
- printf("adding new cq = %s , %d", cqNames[i], durableCq);
- auto qry = qs->newCq(cqNames[i], queryStrings[i], cqAttr, durableCq);
- qry->execute();
- }
-
- LOG("EXECUTE 1 START");
-
- // qs->executeCqs();
-
- LOG("EXECUTE 1 STOP");
- } catch (const Exception &excp) {
- std::string logmsg = "";
- logmsg += excp.getName();
- logmsg += ": ";
- logmsg += excp.what();
- LOG(logmsg.c_str());
- LOG(excp.getStackTrace().c_str());
- }
-
- if (closeLogicalCache) {
- authenticatedView.close();
- }
-
- LOG("StepThree complete.");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, CloseCache1Down)
- {
- getHelper()->disconnect(true);
- cleanProc();
- LOG("Clnt1Down complete: Keepalive = True");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT2, StepTwo2)
- {
- auto authenticatedView = setUpAuthenticatedView(3);
- auto regPtr0 = authenticatedView.getRegion(regionNamesCq[0]);
- auto subregPtr0 = regPtr0->getSubregion(regionNamesCq[1]);
-
- QueryHelper *qh = &QueryHelper::getHelper();
-
- qh->populatePortfolioData(regPtr0, 3, 2, 1);
- qh->populatePositionData(subregPtr0, 3, 2);
- for (int i = 1; i <= 4; i++) {
- auto port = std::make_shared<Portfolio>(i, 2);
-
- char tmp[25] = {'\0'};
- sprintf(tmp, "port1-%d", i);
- auto keyport = CacheableKey::create(tmp);
- regPtr0->put(keyport, port);
- SLEEP(10); // sleep a while to allow server query to complete
- }
-
- LOG("StepTwo2 complete. Sleeping .25 min for server query to complete...");
- SLEEP(15000); // sleep .25 min to allow server query to complete
-
- if (closeLogicalCache) {
- authenticatedView.close();
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, StepFour)
- {
- // auto userCache = getVirtualCache(userCreds, regionNamesCq[0]);
- auto qs = userQueryService;
-
- char buf[1024];
-
- uint8_t i = 0;
-
- for (i = 0; i < MAX_LISTNER; i++) {
- sprintf(buf, "get info for cq[%s]:", cqNames[i]);
- LOG(buf);
- auto cqy = qs->getCq(cqNames[i]);
- // auto cqStats = cqy->getStatistics();
- }
-
- // if key port1-4 then only query 3 and 4 will satisfied
- auto cqy = qs->getCq(cqNames[3]);
- auto cqAttr = cqy->getCqAttributes();
- auto vl = cqAttr->getCqListeners();
-
- auto cqListener_3 = static_cast<MyCqListener *>(vl[0].get());
- printf(" cqListener_3 should have one create event = %d \n",
- cqListener_3->getNumInserts());
- ASSERT(cqListener_3->getNumInserts() == 1,
- "incorrect number of events got listener 3");
-
- cqy = qs->getCq(cqNames[4]);
- cqAttr = cqy->getCqAttributes();
- vl = cqAttr->getCqListeners();
-
- auto cqListener_4 = static_cast<MyCqListener *>(vl[0].get());
- printf(" cqListener_4 should have one create event = %d \n",
- cqListener_4->getNumInserts());
- ASSERT(cqListener_4->getNumInserts() == 1,
- "incorrect number of events got listener 4");
-
- LOG("StepFour complete.");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, StepFour2)
- {
- SLEEP(15000); // sleep .25 min
- // auto userCache = getVirtualCache(userCreds, regionNamesCq[0]);
-
- auto authenticatedView = setUpAuthenticatedView(4);
- userQueryService = authenticatedView.getQueryService();
- auto qs = userQueryService;
-
- char buf[1024];
-
- uint8_t i = 0;
-
- for (i = 0; i < MAX_LISTNER; i++) {
- sprintf(buf, "get info for cq[%s]:", cqNames[i]);
- LOG(buf);
- auto cqy = qs->getCq(cqNames[i]);
- // auto cqStats = cqy->getStatistics();
- }
-
- if ((durableCq && !logicalCacheKeepAlive && !closeLogicalCache) ||
- (durableCq && logicalCacheKeepAlive && closeLogicalCache)) {
- // if key port1-4 then only query 3 and 4 will satisfied
- auto cqy = qs->getCq(cqNames[3]);
- auto cqAttr = cqy->getCqAttributes();
- auto vl = cqAttr->getCqListeners();
-
- auto cqListener_3 = static_cast<MyCqListener *>(vl[0].get());
- printf(" cqListener_3 should have one update event = %d \n",
- cqListener_3->getNumUpdates());
- ASSERT(cqListener_3->getNumUpdates() == 1,
- "incorrect number of events got listener 3");
-
- cqy = qs->getCq(cqNames[4]);
- cqAttr = cqy->getCqAttributes();
- vl = cqAttr->getCqListeners();
-
- MyCqListener *cqListener_4 = static_cast<MyCqListener *>(vl[0].get());
- printf(" cqListener_4 should have one update event = %d \n",
- cqListener_4->getNumUpdates());
- ASSERT(cqListener_4->getNumUpdates() == 1,
- "incorrect number of events got listener 4");
- }
-
- if ((!durableCq && !logicalCacheKeepAlive && !closeLogicalCache) ||
- (durableCq && !logicalCacheKeepAlive && closeLogicalCache)) {
- // if key port1-4 then only query 3 and 4 will satisfied
- auto cqy = qs->getCq(cqNames[3]);
- auto cqAttr = cqy->getCqAttributes();
- auto vl = cqAttr->getCqListeners();
-
- auto cqListener_3 = static_cast<MyCqListener *>(vl[0].get());
- printf(" cqListener_3 should have zero update event = %d \n",
- cqListener_3->getNumUpdates());
- ASSERT(cqListener_3->getNumUpdates() == 0,
- "incorrect number of events got listener 3");
-
- cqy = qs->getCq(cqNames[4]);
- cqAttr = cqy->getCqAttributes();
- vl = cqAttr->getCqListeners();
-
- auto cqListener_4 = static_cast<MyCqListener *>(vl[0].get());
- printf(" cqListener_4 should have zero update event = %d \n",
- cqListener_4->getNumUpdates());
- ASSERT(cqListener_4->getNumUpdates() == 0,
- "incorrect number of events got listener 4");
- }
-
- /*for(i=0; i < MAX_LISTNER; i++)
- {
- sprintf(buf, "get info for cq[%s]:", cqNames[i]);
- LOG(buf);
- auto cqy = qs->getCq(cqNames[i]);
- cqy->stop();
- cqy->close();
- //auto cqStats = cqy->getStatistics();
- }*/
-
- if (closeLogicalCache) {
- authenticatedView.close();
- }
- LOG("StepFour2 complete.");
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, CloseCache1)
- {
- LOG("cleanProc 1...");
- cleanProc();
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT2, CloseCache2)
- {
- LOG("cleanProc 2...");
- cleanProc();
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(SERVER1, CloseServer1)
- {
- LOG("closing Server1...");
- if (isLocalServer) {
- CacheHelper::closeServer(1);
- LOG("SERVER1 stopped");
- }
- SLEEP(5000);
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(SERVER1, CloseServer2)
- {
- LOG("closing Server2...");
- if (isLocalServer) {
- CacheHelper::closeServer(2);
- LOG("SERVER2 stopped");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, durableCQ)
- {
- closeLogicalCache = false;
- logicalCacheKeepAlive = false;
- durableCq = true;
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, NodurableCQ)
- {
- closeLogicalCache = false;
- logicalCacheKeepAlive = false;
- durableCq = false;
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, LogicalCacheTrueAnddurableCQ)
- {
- closeLogicalCache = true;
- logicalCacheKeepAlive = true;
- durableCq = true;
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, LogicalCacheFalseAnddurableCQ)
- {
- closeLogicalCache = true;
- logicalCacheKeepAlive = false;
- durableCq = true;
- }
-END_TASK_DEFINITION
-
-void doThinClientCq(bool poolConfig = false, bool poolLocators = false) {
- for (int i = 0; i < 4; i++) {
- if (i == 0) // realCache.close(true)
- {
- CALL_TASK(durableCQ); // this should get events
- } else if (i == 1) // no durable CQ
- {
- CALL_TASK(NodurableCQ); // this should not get events
- } else if (i == 2) // AuthenticatedView.close(true)
- {
- CALL_TASK(LogicalCacheTrueAnddurableCQ); // this should get events
- } else if (i == 3) // AuthenticatedView.close(false)
- {
- CALL_TASK(LogicalCacheFalseAnddurableCQ); // this should not get events
- }
-
- if (poolConfig && poolLocators) {
- // CALL_TASK(CreateLocator);
- // CALL_TASK(CreateServer1_Locator);
- } else {
- CALL_TASK(CreateServer1);
- }
- if (poolConfig) {
- if (poolLocators) {
- // CALL_TASK(StepOne_PoolLocator);
- // CALL_TASK(StepOne2_PoolLocator);
- } else {
- CALL_TASK(StepOne_PoolEP);
- CALL_TASK(StepOne2_PoolEP);
- }
- }
- CALL_TASK(ReadyForEvents);
- CALL_TASK(StepTwo);
- CALL_TASK(StepThree);
- CALL_TASK(StepTwo2); // another client put data
- CALL_TASK(StepFour); // validates listener events
- // CALL_TASK(CreateServer2);
- CALL_TASK(CloseCache1Down);
- CALL_TASK(StepTwo2); // again put data
- CALL_TASK(StepOne_PoolEP);
- CALL_TASK(StepTwo);
- CALL_TASK(StepThree);
- CALL_TASK(ReadyForEvents);
- CALL_TASK(StepFour2); // validates listener events After client become up
- CALL_TASK(CloseCache1);
- CALL_TASK(CloseCache2);
- CALL_TASK(CloseServer1);
-
- if (poolConfig && poolLocators) {
- // CALL_TASK(CloseLocator);
- }
- }
-}
-
-DUNIT_MAIN
- {
- doThinClientCq(
- true); // pool-with-endpoints case: pool == true, locators == false
-
- // doThinClientCq(true, true); // pool-with-locator case: pool == true,
- // locators == true
- }
-END_MAIN
diff --git a/cppcache/integration-test/testThinClientTicket303.cpp b/cppcache/integration-test/testThinClientTicket303.cpp
deleted file mode 100644
index b156db6..0000000
--- a/cppcache/integration-test/testThinClientTicket303.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define ROOT_NAME "testThinClientTicket303"
-
-#include "ThinClientSecurityHelper.hpp"
-
-#define SERVER s1p1
-#define CLIENT1 s1p2
-
-// Test for Rollback mechanism for put. Ticket #303
-
-void createAuthzRegion() {
- initCredentialGenerator();
- initClientAuth('A');
- auto regPtr = createOverflowRegion(regionNamesAuth[0], false, 1);
- ASSERT(regPtr != nullptr, "Failed to create region.");
- LOG("Region created.");
-}
-DUNIT_TASK_DEFINITION(SERVER, StartServer1)
- {
- initCredentialGenerator();
- std::string cmdServerAuthenticator;
-
- if (isLocalServer) {
- cmdServerAuthenticator = credentialGeneratorHandler->getServerCmdParams(
- "authenticator:dummy", getXmlPath());
- printf("string %s", cmdServerAuthenticator.c_str());
- CacheHelper::initServer(
- 1, "cacheserver_notify_subscription.xml", locHostPort,
- const_cast<char*>(cmdServerAuthenticator.c_str()));
- LOG("Server1 started");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(SERVER, StartLocator)
- {
- if (isLocator) {
- CacheHelper::initLocator(1);
- LOG("Locator1 started");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, StartClient1)
- {
- createAuthzRegion();
- LOG("CLIENT1 started");
- }
-END_TASK_DEFINITION
-// check that tracking work correctly with put.
-DUNIT_TASK_DEFINITION(CLIENT1, PutAndVerification)
- {
- auto rptr = getHelper()->getRegion(regionNamesAuth[0]);
- rptr->put("key-1", "client1-value1");
- rptr->put("key-2", "client1-value2");
- rptr->put("key-3", "client1-value3");
- try {
- rptr->put("invalidkey-1", "client1-Invalidvalue1");
- LOG(" Put Operation Successful");
- FAIL("Should have got NotAuthorizedException during put");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
- ASSERT(rptr->containsKey("invalidkey-1") == false,
- "Key should not be found in region.");
- ASSERT(rptr->containsKey("key-1") == true,
- "Key key-1 should be found in region.");
- ASSERT(rptr->containsKey("key-2") == true,
- "Key key-2 should be found in region.");
- ASSERT(rptr->containsKey("key-3") == true,
- "Key key-3 should be found in region.");
- LOG("PutAndVerification completed");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(SERVER, CloseServer1)
- {
- SLEEP(2000);
- if (isLocalServer) {
- CacheHelper::closeServer(1);
- LOG("SERVER1 stopped");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(SERVER, CloseLocator)
- {
- if (isLocator) {
- CacheHelper::closeLocator(1);
- LOG("Locator1 stopped");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, CloseClient1)
- { cleanProc(); }
-END_TASK_DEFINITION
-DUNIT_MAIN
- {
- CALL_TASK(StartLocator);
- CALL_TASK(StartServer1);
- CALL_TASK(StartClient1);
- CALL_TASK(PutAndVerification);
- CALL_TASK(CloseClient1);
- CALL_TASK(CloseServer1);
- CALL_TASK(CloseLocator);
- }
-END_MAIN
diff --git a/cppcache/integration-test/testThinClientTicket304.cpp b/cppcache/integration-test/testThinClientTicket304.cpp
deleted file mode 100644
index 14370f2..0000000
--- a/cppcache/integration-test/testThinClientTicket304.cpp
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define ROOT_NAME "testThinClientTicket304"
-
-#include "ThinClientSecurityHelper.hpp"
-
-#define SERVER s1p1
-#define CLIENT1 s1p2
-#define CLIENT2 s2p1
-
-// This is the test for tracking work. bug#304
-
-putThread *thread1 = nullptr;
-
-void createAuthzRegion() {
- initCredentialGenerator();
- initClientAuth('A');
- createRegion(regionNamesAuth[0], false, true);
-}
-DUNIT_TASK_DEFINITION(SERVER, StartServer1)
- {
- initCredentialGenerator();
- std::string cmdServerAuthenticator;
-
- if (isLocalServer) {
- cmdServerAuthenticator = credentialGeneratorHandler->getServerCmdParams(
- "authenticator", getXmlPath());
- printf("string %s", cmdServerAuthenticator.c_str());
- cmdServerAuthenticator += std::string(
- " --J=-Dgemfire.security-client-accessor-pp=javaobject."
- "DummyAuthorization.create");
- CacheHelper::initServer(
- 1, "cacheserver_notify_subscription.xml", locHostPort,
- const_cast<char *>(cmdServerAuthenticator.c_str()));
- LOG("Server1 started");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(SERVER, StartLocator)
- {
- if (isLocator) {
- CacheHelper::initLocator(1);
- LOG("Locator1 started");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, StartClient1)
- {
- createAuthzRegion();
- LOG("CLIENT1 started");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT2, StartClient2)
- {
- createAuthzRegion();
- LOG("CLIENT2 started");
- }
-END_TASK_DEFINITION
-// check that tracking works correctly with put.
-DUNIT_TASK_DEFINITION(CLIENT1, PutOnClient1)
- {
- auto rptr = getHelper()->getRegion(regionNamesAuth[0]);
- rptr->put("key-1", "client1-value1");
- rptr->put("key-2", "client1-value2");
- rptr->put("key-3", "client1-value3");
- LOG("PutOnClient1 completed");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT2, RegisterInterestAllOnClient2)
- {
- auto rptr = getHelper()->getRegion(regionNamesAuth[0]);
- thread1 = new putThread(rptr, true);
- thread1->start();
- LOG("RegisterInterest started on client 2");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT1, DestroyEntryOnClient1)
- {
- auto rptr = getHelper()->getRegion(regionNamesAuth[0]);
- rptr->destroy("key-3");
- LOG("DestroyEntryOnClient1 completed");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT1, VerifyOnClient1)
- {
- verifyEntry(regionNamesAuth[0], "key-1", "client1-value1");
- verifyEntry(regionNamesAuth[0], "key-2", "client1-value2");
- verifyDestroyed(regionNamesAuth[0], "key-3");
- LOG("VerifyOnClient1 completed");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT2, VerifyOnClient2)
- {
- thread1->stop();
- delete thread1;
- SLEEP(5000);
- verifyEntry(regionNamesAuth[0], "key-1", "client1-value1");
- verifyEntry(regionNamesAuth[0], "key-2", "client1-value2");
- verifyDestroyed(regionNamesAuth[0], "key-3");
- auto rptr = getHelper()->getRegion(regionNamesAuth[0]);
- rptr->localDestroyRegion();
- LOG("VerifyOnClient2 completed");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT2, RegisterInterestKeysOnClient2)
- {
- auto rptr = getHelper()->getRegion(regionNamesAuth[0]);
- thread1 = new putThread(rptr);
- thread1->setParams(5, 3, 1);
- thread1->start();
- LOG("RegisterInterestKeys started on client 2");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT2, RegisterRegexClient2)
- {
- auto rptr = getHelper()->getRegion(regionNamesAuth[0]);
- thread1 = new putThread(rptr);
- thread1->setParams(6, 3, 1);
- thread1->start();
- LOG("RegisterRegex started on client 2");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT1, CreateRegionOnClient1)
- {
- auto rptr = getHelper()->getRegion(regionNamesAuth[0]);
- rptr->localDestroyRegion();
- SLEEP(10000);
- createRegion(regionNamesAuth[0], false, true);
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT2, CreateRegionOnClient2)
- {
- SLEEP(10000);
- createRegion(regionNamesAuth[0], false, true);
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(SERVER, CloseServer1)
- {
- SLEEP(2000);
- if (isLocalServer) {
- CacheHelper::closeServer(1);
- LOG("SERVER1 stopped");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(SERVER, CloseLocator)
- {
- if (isLocator) {
- CacheHelper::closeLocator(1);
- LOG("Locator1 stopped");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, CloseClient1)
- { cleanProc(); }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT2, CloseClient2)
- { cleanProc(); }
-END_TASK_DEFINITION
-DUNIT_MAIN
- {
- CALL_TASK(StartLocator);
- CALL_TASK(StartServer1);
- CALL_TASK(StartClient1);
- CALL_TASK(StartClient2);
- CALL_TASK(PutOnClient1);
- CALL_TASK(RegisterInterestAllOnClient2);
- CALL_TASK(DestroyEntryOnClient1);
- CALL_TASK(VerifyOnClient1);
- CALL_TASK(VerifyOnClient2);
- CALL_TASK(CreateRegionOnClient1);
- CALL_TASK(CreateRegionOnClient2);
- CALL_TASK(PutOnClient1);
- CALL_TASK(RegisterInterestKeysOnClient2);
- CALL_TASK(DestroyEntryOnClient1);
- CALL_TASK(VerifyOnClient1);
- CALL_TASK(VerifyOnClient2);
- CALL_TASK(CreateRegionOnClient1);
- CALL_TASK(CreateRegionOnClient2);
- CALL_TASK(PutOnClient1);
- CALL_TASK(RegisterRegexClient2);
- CALL_TASK(DestroyEntryOnClient1);
- CALL_TASK(VerifyOnClient1);
- CALL_TASK(VerifyOnClient2);
- CALL_TASK(CloseClient1);
- CALL_TASK(CloseClient2);
- CALL_TASK(CloseServer1);
- CALL_TASK(CloseLocator);
- }
-END_MAIN
diff --git a/cppcache/integration-test/testThinClientTracking.cpp b/cppcache/integration-test/testThinClientTracking.cpp
deleted file mode 100644
index 0bd61fd..0000000
--- a/cppcache/integration-test/testThinClientTracking.cpp
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define ROOT_NAME "testThinClientTracking"
-
-#include "ThinClientSecurityHelper.hpp"
-
-#define SERVER s1p1
-#define CLIENT1 s1p2
-#define CLIENT2 s2p1
-
-// This is the test for tracking work.
-
-putThread *thread1 = nullptr;
-putThread *thread2 = nullptr;
-
-void createAuthzRegion() {
- initCredentialGenerator();
- initClientAuth('A');
- std::shared_ptr<Region> rptr;
- createRegion(regionNamesAuth[0], false, true);
- rptr = getHelper()->getRegion(regionNamesAuth[0]);
- rptr->registerAllKeys();
-}
-void verifyEntry(const char *value) {
- auto rptr = getHelper()->getRegion(regionNamesAuth[0]);
- auto entry = rptr->getEntry("key-1");
- ASSERT(entry != nullptr, "Key should have been found in region.");
- auto valuePtr = std::dynamic_pointer_cast<CacheableString>(entry->getValue());
- char buf1[1024];
-
- if (valuePtr == nullptr) {
- FAIL("Value was null.");
- }
- sprintf(buf1, "value for key-1 is %s", valuePtr->value().c_str());
- LOG(buf1);
- ASSERT(strcmp(valuePtr->value().c_str(), value) == 0,
- "Updated value not found in region.");
-}
-DUNIT_TASK_DEFINITION(SERVER, StartServer1)
- {
- initCredentialGenerator();
- std::string cmdServerAuthenticator;
-
- if (isLocalServer) {
- cmdServerAuthenticator = credentialGeneratorHandler->getServerCmdParams(
- "authenticator:dummy", getXmlPath());
- printf("string %s", cmdServerAuthenticator.c_str());
- CacheHelper::initServer(
- 1, "cacheserver_notify_subscription.xml", locHostPort,
- const_cast<char *>(cmdServerAuthenticator.c_str()));
- LOG("Server1 started");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(SERVER, StartLocator)
- {
- if (isLocator) {
- CacheHelper::initLocator(1);
- LOG("Locator1 started");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, StartClient1)
- {
- createAuthzRegion();
- LOG("CLIENT1 started");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT2, StartClient2)
- {
- createAuthzRegion();
- LOG("CLIENT2 started");
- }
-END_TASK_DEFINITION
-// check that tracking work correctly with put.
-DUNIT_TASK_DEFINITION(CLIENT1, PutOnClient1)
- {
- auto rptr = getHelper()->getRegion(regionNamesAuth[0]);
- thread1 = new putThread(rptr);
- thread1->setParams(0, 1, 1, true);
- thread1->start();
- LOG("PutOnClient1 completed");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT2, PutOnClient2)
- {
- auto rptr = getHelper()->getRegion(regionNamesAuth[0]);
- thread2 = new putThread(rptr);
- thread2->setParams(0, 1, 1);
- thread2->start();
- thread2->stop();
- delete thread2;
- LOG("PutOnClient2 completed");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT1, VerifyOnClient1)
- {
- verifyEntry("client2-value1");
- LOG("VerifyOnClient1 completed");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT2, VerifyOnClient2)
- {
- SLEEP(5000);
- verifyEntry("client2-value1");
- LOG("VerifyOnClient2 completed");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT1, VerifyOnClient12)
- {
- thread1->stop();
- delete thread1;
- verifyEntry("client2-value1");
-
- LOG("VerifyOnClient12 completed");
- }
-END_TASK_DEFINITION
-// check that tracking work correctly with destroy.
-DUNIT_TASK_DEFINITION(CLIENT1, DestroyOnClient1)
- {
- auto rptr = getHelper()->getRegion(regionNamesAuth[0]);
- thread1 = new putThread(rptr);
- thread1->setParams(0, 1, 1, true);
- thread1->start();
- LOG("DestroyOnClient1 completed");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT2, DestroyOnClient2)
- {
- auto rptr = getHelper()->getRegion(regionNamesAuth[0]);
- thread2 = new putThread(rptr);
- thread2->setParams(2, 1, 1);
- thread2->start();
- thread2->stop();
- delete thread2;
- LOG("DestroyOnClient2 completed");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT1, VerifyDestroyOnClient1)
- {
- verifyDestroyed(regionNamesAuth[0], "key-1");
- LOG("VerifyDestroyOnClient1 completed");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT2, VerifyDestroyOnClient2)
- {
- SLEEP(5000);
- verifyDestroyed(regionNamesAuth[0], "key-1");
- LOG("VerifyDestroyOnClient2 completed");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT1, VerifyDestroyOnClient12)
- {
- thread1->stop();
- delete thread1;
- verifyDestroyed(regionNamesAuth[0], "key-1");
- LOG("VerifyDestroyOnClient12 completed");
- }
-END_TASK_DEFINITION
-// check that Conversion from Tracked Map Entry and back work correctly
-DUNIT_TASK_DEFINITION(CLIENT1, PutTrackedMapOnClient1)
- {
- auto rptr = getHelper()->getRegion(regionNamesAuth[0]);
- thread1 = new putThread(rptr);
- thread1->setParams(0, 1, 1, true);
- thread1->start();
- LOG("PutTrackedMapOnClient1 completed");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT2, PutTrackedMapOnClient2)
- {
- auto rptr = getHelper()->getRegion(regionNamesAuth[0]);
- thread2 = new putThread(rptr);
- thread2->setParams(0, 10, 1, false, true);
- thread2->start();
- thread2->stop();
- delete thread2;
- verifyEntry("client2-value10");
- LOG("PutTrackedMapOnClient2 completed");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT1, VerifyTrackedMapOnClient1)
- {
- verifyEntry("client2-value10");
- LOG("VerifyTrackedMapOnClient1 completed");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT2, VerifyTrackedMapOnClient2)
- {
- verifyEntry("client2-value10");
- LOG("VerifyTrackedMapOnClient2 completed");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT1, VerifyTrackedMapOnClient12)
- {
- thread1->stop();
- delete thread1;
- verifyEntry("client2-value10");
- LOG("VerifyTrackedMapOnClient12 completed");
- }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(SERVER, CloseServer1)
- {
- SLEEP(2000);
- if (isLocalServer) {
- CacheHelper::closeServer(1);
- LOG("SERVER1 stopped");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(SERVER, CloseLocator)
- {
- if (isLocator) {
- CacheHelper::closeLocator(1);
- LOG("Locator1 stopped");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, CloseClient1)
- { cleanProc(); }
-END_TASK_DEFINITION
-DUNIT_TASK_DEFINITION(CLIENT2, CloseClient2)
- { cleanProc(); }
-END_TASK_DEFINITION
-DUNIT_MAIN
- {
- CALL_TASK(StartLocator);
- CALL_TASK(StartServer1);
- CALL_TASK(StartClient1);
- CALL_TASK(StartClient2);
- CALL_TASK(PutOnClient1);
- CALL_TASK(PutOnClient2);
- CALL_TASK(VerifyOnClient1);
- CALL_TASK(VerifyOnClient2);
- CALL_TASK(VerifyOnClient12);
- CALL_TASK(DestroyOnClient1);
- CALL_TASK(DestroyOnClient2);
- CALL_TASK(VerifyDestroyOnClient1);
- CALL_TASK(VerifyDestroyOnClient2);
- CALL_TASK(VerifyDestroyOnClient12);
- CALL_TASK(PutTrackedMapOnClient1);
- CALL_TASK(PutTrackedMapOnClient2);
- CALL_TASK(VerifyTrackedMapOnClient1);
- CALL_TASK(VerifyTrackedMapOnClient2);
- CALL_TASK(VerifyTrackedMapOnClient12);
- CALL_TASK(CloseClient1);
- CALL_TASK(CloseClient2);
- CALL_TASK(CloseServer1);
- CALL_TASK(CloseLocator);
- }
-END_MAIN
diff --git a/cppcache/integration-test/testThinClientWriterException.cpp b/cppcache/integration-test/testThinClientWriterException.cpp
deleted file mode 100644
index 4eaf055..0000000
--- a/cppcache/integration-test/testThinClientWriterException.cpp
+++ /dev/null
@@ -1,261 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "fw_dunit.hpp"
-#include "ThinClientHelper.hpp"
-#include <ace/Process.h>
-#include "TallyListener.hpp"
-#include "TallyWriter.hpp"
-
-#include "ThinClientSecurity.hpp"
-
-/*
- 1. Using client with security enable.
- 2. Check that writer is invoked and listener is not invoked on the client and
- no data in local region after the failure.
- 3. Check if writer fails for any key the cache writer exception is beimg
- thrown and no data in local region.
- 4. test also check the localput operation.
-*/
-
-using apache::geode::client::testframework::security::CredentialGenerator;
-using apache::geode::client::testframework::security::OP_CONTAINS_KEY;
-using apache::geode::client::testframework::security::OP_GET;
-using apache::geode::client::testframework::security::OP_KEY_SET;
-using apache::geode::client::testframework::security::OP_REGISTER_INTEREST;
-using apache::geode::client::testframework::security::OP_UNREGISTER_INTEREST;
-using apache::geode::client::testframework::security::opCodeList;
-
-using apache::geode::client::testing::TallyListener;
-using apache::geode::client::testing::TallyWriter;
-
-std::shared_ptr<TallyListener> regListener;
-std::shared_ptr<TallyWriter> regWriter;
-
-const std::string locHostPort =
- CacheHelper::getLocatorHostPort(isLocator, isLocalServer, 1);
-
-const char *regionNamesAuth[] = {"DistRegionAck"};
-std::shared_ptr<CredentialGenerator> credentialGeneratorHandler;
-
-std::string getXmlPath() {
- char xmlPath[1000] = {'\0'};
- const char *path = std::getenv("TESTSRC");
- ASSERT(path != nullptr,
- "Environment variable TESTSRC for test source directory is not set.");
- strncpy(xmlPath, path, strlen(path) - strlen("cppcache"));
- strncat(xmlPath, "xml/Security/", sizeof(xmlPath) - strlen(xmlPath) - 1);
- return std::string(xmlPath);
-}
-
-void initCredentialGenerator() {
- static int loopNum = 1;
-
- switch (loopNum) {
- case 1: {
- credentialGeneratorHandler = CredentialGenerator::create("DUMMY");
- break;
- }
- case 2: {
- credentialGeneratorHandler = CredentialGenerator::create("LDAP");
- break;
- }
- default:
- case 3: {
- credentialGeneratorHandler = CredentialGenerator::create("PKCS");
- break;
- }
- }
-
- if (credentialGeneratorHandler == nullptr) {
- FAIL("credentialGeneratorHandler is nullptr");
- }
-
- loopNum++;
- if (loopNum > 2) loopNum = 1;
-}
-
-opCodeList::value_type tmpRArr[] = {OP_GET, OP_REGISTER_INTEREST,
- OP_UNREGISTER_INTEREST, OP_KEY_SET,
- OP_CONTAINS_KEY};
-
-#define HANDLE_NOT_AUTHORIZED_EXCEPTION \
- catch (const apache::geode::client::NotAuthorizedException &) { \
- LOG("NotAuthorizedException Caught"); \
- LOG("Success"); \
- } \
- catch (const apache::geode::client::Exception &other) { \
- LOG(other.getStackTrace()); \
- FAIL(other.what()); \
- }
-
-#define HANDLE_CACHEWRITER_EXCEPTION \
- catch (const apache::geode::client::CacheWriterException &) { \
- LOG("CacheWriterException Caught"); \
- LOG("Success"); \
- }
-
-#define ADMIN_CLIENT s1p1
-#define READER_CLIENT s2p1
-
-void initClientAuth() {
- auto config = Properties::create();
- opCodeList rt(tmpRArr, tmpRArr + sizeof tmpRArr / sizeof *tmpRArr);
- credentialGeneratorHandler->getAuthInit(config);
- credentialGeneratorHandler->getAllowedCredentialsForOps(rt, config, nullptr);
- printf("User is %s Pass is %s ",
- config->find("security-username")->value().c_str(),
- (config->find("security-password") != nullptr
- ? config->find("security-password")->value().c_str()
- : " not set"));
- try {
- initClient(true, config);
- } catch (...) {
- throw;
- }
-}
-
-void setCacheWriter(const char *regName,
- std::shared_ptr<TallyWriter> tallyWriter) {
- auto reg = getHelper()->getRegion(regName);
- auto attrMutator = reg->getAttributesMutator();
- attrMutator->setCacheWriter(tallyWriter);
-}
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, StartServer1)
- {
- initCredentialGenerator();
- std::string cmdServerAuthenticator;
-
- if (isLocalServer) {
- cmdServerAuthenticator = credentialGeneratorHandler->getServerCmdParams(
- "authenticator:authorizer", getXmlPath());
- printf("string %s", cmdServerAuthenticator.c_str());
- CacheHelper::initServer(
- 1, "cacheserver_notify_subscription.xml", locHostPort,
- const_cast<char *>(cmdServerAuthenticator.c_str()));
- LOG("Server1 started");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, StartLocator)
- {
- if (isLocator) {
- CacheHelper::initLocator(1);
- LOG("Locator1 started");
- }
- }
-END_TASK_DEFINITION
-
-void startClient() {
- initCredentialGenerator();
- initClientAuth();
- std::shared_ptr<Region> rptr;
- char buf[100];
- int i = 102;
- LOG("Creating region in READER_CLIENT , no-ack, no-cache, with-listener and "
- "writer");
- regListener = std::make_shared<TallyListener>();
- createRegionForSecurity(regionNamesAuth[0], false, true, regListener);
- regWriter = std::make_shared<TallyWriter>();
- setCacheWriter(regionNamesAuth[0], regWriter);
- rptr = getHelper()->getRegion(regionNamesAuth[0]);
- rptr->registerAllKeys();
- sprintf(buf, "%s: %d", rptr->getName().c_str(), i);
- auto key = CacheableKey::create(buf);
- sprintf(buf, "testUpdate::%s: value of %d", rptr->getName().c_str(), i);
- auto valuePtr = buf;
- try {
- LOG("Trying put Operation");
- rptr->put(key, valuePtr);
- LOG(" Put Operation Successful");
- FAIL("Should have got NotAuthorizedException during put");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
- ASSERT(regWriter->isWriterInvoked() == true, "Writer Should be invoked");
- ASSERT(regListener->isListenerInvoked() == false,
- "Listener Should not be invoked");
- ASSERT(!rptr->containsKey(key),
- "Key should not have been found in the region");
- rptr->localPut(keys[2], vals[2]);
- ASSERT(rptr->containsKey(keys[2]),
- "Key should have been found in the region");
- ASSERT(regWriter->isWriterInvoked() == true, "Writer Should be invoked");
- ASSERT(regListener->isListenerInvoked() == true,
- "Listener Should be invoked");
- try {
- LOG("Trying updateEntry");
- regListener->resetListnerInvokation();
- updateEntry(regionNamesAuth[0], keys[2], nvals[2], false, false);
- FAIL("Should have got NotAuthorizedException during updateEntry");
- }
- HANDLE_NOT_AUTHORIZED_EXCEPTION
- ASSERT(regWriter->isWriterInvoked() == true, "Writer Should be invoked");
- ASSERT(regListener->isListenerInvoked() == false,
- "Listener Should not be invoked");
- ASSERT(rptr->containsKey(keys[2]),
- "Key should have been found in the region");
- verifyEntry(regionNamesAuth[0], keys[2], vals[2]);
- regWriter->setWriterFailed();
- try {
- LOG("Testing CacheWriterException");
- updateEntry(regionNamesAuth[0], keys[2], nvals[2], false, false);
- FAIL("Should have got NotAuthorizedException during updateEntry");
- }
- HANDLE_CACHEWRITER_EXCEPTION
- LOG("StepThree complete.");
-}
-
-DUNIT_TASK_DEFINITION(READER_CLIENT, StartClientPoolLocator)
- { startClient(); }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, CloseServer1)
- {
- SLEEP(9000);
- if (isLocalServer) {
- CacheHelper::closeServer(1);
- LOG("SERVER1 stopped");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(ADMIN_CLIENT, CloseLocator)
- {
- if (isLocator) {
- CacheHelper::closeLocator(1);
- LOG("Locator1 stopped");
- }
- }
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(READER_CLIENT, CloseCacheReader)
- { cleanProc(); }
-END_TASK_DEFINITION
-
-void doThinClientWriterException() {
- CALL_TASK(StartLocator);
- CALL_TASK(StartServer1);
- CALL_TASK(StartClientPoolLocator);
- CALL_TASK(CloseCacheReader);
- CALL_TASK(CloseServer1);
- CALL_TASK(CloseLocator);
-}
-
-DUNIT_MAIN
- { doThinClientWriterException(); }
-END_MAIN