You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by dg...@apache.org on 2017/12/12 21:50:56 UTC

[geode-native] 03/03: GEODE-4066: Update security test to use stack allocated objects

This is an automated email from the ASF dual-hosted git repository.

dgkimura pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git

commit 5ffe8199a62a4a65b69d16fcc67cb74e80129e81
Author: David Kimura <dk...@pivotal.io>
AuthorDate: Mon Dec 11 19:09:45 2017 -0800

    GEODE-4066: Update security test to use stack allocated objects
---
 .../testThinClientSecurityMultiUserTest.cpp        |  30 ++----
 cppcache/test/CacheableStringTests.cpp             |   2 +-
 cppcache/test/DataOutputTest.cpp                   |   2 +-
 cppcache/test/PdxLocalReaderTest.cpp               | 114 ---------------------
 4 files changed, 11 insertions(+), 137 deletions(-)

diff --git a/cppcache/integration-test/testThinClientSecurityMultiUserTest.cpp b/cppcache/integration-test/testThinClientSecurityMultiUserTest.cpp
index a6f9baf..ea75333 100644
--- a/cppcache/integration-test/testThinClientSecurityMultiUserTest.cpp
+++ b/cppcache/integration-test/testThinClientSecurityMultiUserTest.cpp
@@ -26,9 +26,6 @@ using namespace apache::geode::client;
 #define CLIENT1 s1p1
 #define LOCATORSERVER s2p2
 
-std::shared_ptr<RegionService> user1_regionService;
-std::shared_ptr<RegionService> user2_regionService;
-
 DUNIT_TASK_DEFINITION(LOCATORSERVER, CreateLocator)
   {
     CacheHelper::initLocator(1, false, false, -1, 0, false, true);
@@ -38,54 +35,46 @@ END_TASK_DEFINITION
 
 DUNIT_TASK_DEFINITION(LOCATORSERVER, CreateServer)
   {
-    std::string args = "--J=-Dsecurity-manager=javaobject.SimpleSecurityManager";
-
     CacheHelper::initServer(
       1, "cacheserver_notify_subscription2.xml",
       CacheHelper::getLocatorHostPort(isLocator, isLocalServer, 1),
-      const_cast<char*>(args.c_str()), false, true, false, false, false, true);
+      "--J=-Dsecurity-manager=javaobject.SimpleSecurityManager",
+      false, true, false, false, false, true);
     LOG("Server started");
   }
 END_TASK_DEFINITION
 
 DUNIT_TASK_DEFINITION(CLIENT1, PerformSecureOperationsWithUserCredentials)
   {
-    auto cacheFactory = CacheFactory::createCacheFactory();
-    auto cache = std::shared_ptr<Cache>(new Cache(cacheFactory->create()));
-    auto poolFactory = cache->getPoolManager().createFactory();
+    auto cache = CacheFactory::createCacheFactory()->create();
+    auto poolFactory = cache.getPoolManager().createFactory();
     poolFactory->setMultiuserAuthentication(true);
     poolFactory->addLocator("localhost", CacheHelper::staticLocatorHostPort1);
     poolFactory->create("mypool");
 
-    auto regionFactory = cache->createRegionFactory(PROXY);
+    auto regionFactory = cache.createRegionFactory(PROXY);
     regionFactory.setPoolName("mypool");
     regionFactory.create("DistRegionAck");
 
     auto config1 = Properties::create();
     config1->insert("security-username", "root");
     config1->insert("security-password", "root-password");
-    user1_regionService = cache->createAuthenticatedView(config1, "mypool");
 
-    user1_regionService->getRegion("DistRegionAck")->put("akey", "avalue");
+    cache.createAuthenticatedView(config1, "mypool")->getRegion("DistRegionAck")
+                                                    ->put("akey", "avalue");
 
     auto config2 = Properties::create();
     config2->insert("security-username", "reader");
     config2->insert("security-password", "reader-password");
-    user2_regionService = cache->createAuthenticatedView(config2, "mypool");
 
     try {
-      user2_regionService->getRegion("DistRegionAck")->put("akey", "avalue");
+      cache.createAuthenticatedView(config2, "mypool")->getRegion("DistRegionAck")
+                                                      ->put("akey", "avalue");
       FAIL("Didn't throw expected AuthenticationFailedException.");
     } catch (const apache::geode::client::NotAuthorizedException& other) {
       LOG("Caught expected AuthenticationFailedException.");
     }
-
   }
-  LOG("PerformSecureOperations Completed");
-END_TASK_DEFINITION
-
-DUNIT_TASK_DEFINITION(CLIENT1, CloseCache)
-  { cleanProc(); }
 END_TASK_DEFINITION
 
 DUNIT_TASK_DEFINITION(LOCATORSERVER, CloseServer)
@@ -107,7 +96,6 @@ DUNIT_MAIN
   CALL_TASK(CreateLocator);
   CALL_TASK(CreateServer);
   CALL_TASK(PerformSecureOperationsWithUserCredentials);
-  CALL_TASK(CloseCache);
   CALL_TASK(CloseServer);
   CALL_TASK(CloseLocator);
   }
diff --git a/cppcache/test/CacheableStringTests.cpp b/cppcache/test/CacheableStringTests.cpp
index 6c5182a..13fe1d9 100644
--- a/cppcache/test/CacheableStringTests.cpp
+++ b/cppcache/test/CacheableStringTests.cpp
@@ -43,7 +43,7 @@ class TestDataOutput : public DataOutputInternal {
   }
 
   TestDataOutput(Cache* cache)
-      : DataOutputInternal(cache),
+      : DataOutputInternal(nullptr),
         m_byteArray(nullptr),
         m_serializationRegistry() {
     // NOP
diff --git a/cppcache/test/DataOutputTest.cpp b/cppcache/test/DataOutputTest.cpp
index a0094e9..f7a39aa 100644
--- a/cppcache/test/DataOutputTest.cpp
+++ b/cppcache/test/DataOutputTest.cpp
@@ -37,7 +37,7 @@ using namespace apache::geode::client;
 class TestDataOutput : public DataOutputInternal {
  public:
   TestDataOutput(Cache* cache)
-      : DataOutputInternal(cache),
+      : DataOutputInternal(nullptr),
         m_byteArray(nullptr),
         m_serializationRegistry() {
     // NOP
diff --git a/cppcache/test/PdxLocalReaderTest.cpp b/cppcache/test/PdxLocalReaderTest.cpp
deleted file mode 100644
index 5d40775..0000000
--- a/cppcache/test/PdxLocalReaderTest.cpp
+++ /dev/null
@@ -1,114 +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 <gtest/gtest.h>
-
-#include <geode/CacheFactory.hpp>
-#include <PdxType.hpp>
-#include <PdxLocalReader.hpp>
-#include <PdxLocalWriter.hpp>
-#include <PdxTypeRegistry.hpp>
-#include "CacheRegionHelper.hpp"
-#include "DataInputInternal.hpp"
-#include "DataOutputInternal.hpp"
-
-using namespace apache::geode::client;
-
-class MyPdxClass : public PdxSerializable {
- public:
-  MyPdxClass();
-  ~MyPdxClass();
-  virtual void toData(std::shared_ptr<PdxWriter> output) const override;
-  virtual void fromData(std::shared_ptr<PdxReader> input) override;
-  virtual void setAString(std::string a_string);
-  virtual std::string getAString();
-  virtual const std::string &getClassName() const override;
-
-  static PdxSerializable *CreateDeserializable();
-
- private:
-  std::string _a_string;
-};
-
-MyPdxClass::MyPdxClass() { _a_string = ""; }
-
-void MyPdxClass::setAString(std::string a_string) { _a_string = a_string; }
-
-std::string MyPdxClass::getAString() { return _a_string; }
-
-MyPdxClass::~MyPdxClass() {}
-
-void MyPdxClass::toData(std::shared_ptr<PdxWriter> output) const {
-  output->writeString("name", _a_string.c_str());
-}
-
-void MyPdxClass::fromData(std::shared_ptr<PdxReader> input) {
-  _a_string = input->readString("name");
-}
-const std::string &MyPdxClass::getClassName() const {
-  static std::string name = "MyPdxClass";
-  return name;
-}
-
-PdxSerializable *MyPdxClass::CreateDeserializable() { return new MyPdxClass(); }
-
-class DISABLED_PdxLocalReaderTest : public ::testing::Test {
- public:
-  void SetUp() {
-    auto factory = CacheFactory::createCacheFactory();
-    cache = std::make_shared<Cache>(factory->create());
-  }
-
- protected:
-  std::shared_ptr<Cache> cache;
-};
-
-TEST_F(DISABLED_PdxLocalReaderTest, testSerializationOfPdxType) {
-  MyPdxClass expected, actual;
-  DataOutputInternal stream(cache.get());
-  int length = 0;
-
-  expected.setAString("the_expected_string");
-
-  // TODO: Refactor static singleton patterns in PdxTypeRegistry so that
-  // tests will not interfere with each other.
-
-  auto pdxTypeRegistry =
-      CacheRegionHelper::getCacheImpl(cache.get())->getPdxTypeRegistry();
-
-  // C++ Client does not require pdxDomainClassName as it is only needed
-  // for reflection purposes, which we do not support in C++. We pass in
-  // getClassName() for consistency reasons only.
-  auto pdx_type_ptr = std::make_shared<PdxType>(pdxTypeRegistry,
-                                                expected.getClassName(), false);
-
-  // Here we construct a serialized stream of bytes representing MyPdxClass.
-  // The stream is later deserialization and validated for consistency.
-  auto writer =
-      std::make_shared<PdxLocalWriter>(stream, pdx_type_ptr, pdxTypeRegistry);
-  expected.toData(writer);
-  writer->endObjectWriting();
-  uint8_t *raw_stream = writer->getPdxStream(length);
-
-  DataInputInternal input(raw_stream, length, cache.get());
-  auto reader = std::make_shared<PdxLocalReader>(input, pdx_type_ptr, length,
-                                                 pdxTypeRegistry);
-
-  actual.fromData(reader);
-
-  EXPECT_EQ(actual.getAString(), "the_expected_string");
-}

-- 
To stop receiving notification emails like this one, please contact
"commits@geode.apache.org" <co...@geode.apache.org>.