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

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


The following commit(s) were added to refs/heads/develop by this push:
     new b8d26b1  GEODE-6034 Protobuf clients should not access or modify 
internal regions
b8d26b1 is described below

commit b8d26b158cabf91983e40e72221ab135143a26e0
Author: Bruce Schuchardt <bschucha...@pivotal.io>
AuthorDate: Mon Nov 26 08:54:25 2018 -0800

    GEODE-6034 Protobuf clients should not access or modify internal regions
    
    The Protobuf API now disallows access to internal cache regions
---
 .../experimental/driver/AuthenticationTest.java    | 15 ++++-
 ...henticationTest.java => AuthorizationTest.java} | 65 ++++++++++++++--------
 .../protobuf/v1/AuthenticationIntegrationTest.java |  2 +-
 .../protobuf/v1/AuthorizationIntegrationTest.java  |  2 +-
 .../protobuf/v1/ServerMessageExecutionContext.java |  4 +-
 .../OutputCapturingServerConnectionTest.java       |  5 +-
 .../tier/sockets/ProtobufServerConnectionTest.java |  5 +-
 .../protobuf/ProtobufStreamProcessorTest.java      |  6 +-
 .../protobuf/security/SecureCacheImplTest.java     | 57 ++++++++++---------
 .../security/SecureFunctionServiceImplTest.java    |  5 +-
 ...ionOnGroupRequestOperationHandlerJUnitTest.java |  7 ++-
 ...onOnMemberRequestOperationHandlerJUnitTest.java |  7 ++-
 ...onOnRegionRequestOperationHandlerJUnitTest.java |  5 +-
 ...egionNamesRequestOperationHandlerJUnitTest.java |  5 +-
 .../GetSizeRequestOperationHandlerJUnitTest.java   |  5 +-
 .../v1/operations/OperationHandlerJUnitTest.java   |  5 +-
 16 files changed, 129 insertions(+), 71 deletions(-)

diff --git 
a/geode-experimental-driver/src/integrationTest/java/org/apache/geode/experimental/driver/AuthenticationTest.java
 
b/geode-experimental-driver/src/integrationTest/java/org/apache/geode/experimental/driver/AuthenticationTest.java
index bcf72e6..f4d11e9 100644
--- 
a/geode-experimental-driver/src/integrationTest/java/org/apache/geode/experimental/driver/AuthenticationTest.java
+++ 
b/geode-experimental-driver/src/integrationTest/java/org/apache/geode/experimental/driver/AuthenticationTest.java
@@ -15,6 +15,7 @@
 package org.apache.geode.experimental.driver;
 
 import static org.apache.geode.internal.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.io.IOException;
 import java.util.Properties;
@@ -39,7 +40,7 @@ public class AuthenticationTest {
   @Rule
   public RestoreSystemProperties restoreSystemProperties = new 
RestoreSystemProperties();
 
-  private static final String TEST_USERNAME = "cluster";
+  private static final String TEST_USERNAME = "";
   private static final String TEST_PASSWORD = TEST_USERNAME;
   private Locator locator;
   private Cache cache;
@@ -89,4 +90,16 @@ public class AuthenticationTest {
         .setPassword(TEST_PASSWORD).create();
     assertTrue(driver.isConnected());
   }
+
+  @Test
+  public void driverWithBadPasswordIsRejected() throws Exception {
+    CacheServer server = cache.addCacheServer();
+    server.setPort(0);
+    server.start();
+    DriverFactory factory =
+        new DriverFactory().addLocator("localhost", 
locatorPort).setUsername(TEST_USERNAME)
+            .setPassword("my my my");
+    assertThatThrownBy(() -> factory.create()).isInstanceOf(IOException.class);
+  }
+
 }
diff --git 
a/geode-experimental-driver/src/integrationTest/java/org/apache/geode/experimental/driver/AuthenticationTest.java
 
b/geode-experimental-driver/src/integrationTest/java/org/apache/geode/experimental/driver/AuthorizationTest.java
similarity index 50%
copy from 
geode-experimental-driver/src/integrationTest/java/org/apache/geode/experimental/driver/AuthenticationTest.java
copy to 
geode-experimental-driver/src/integrationTest/java/org/apache/geode/experimental/driver/AuthorizationTest.java
index bcf72e6..641c108 100644
--- 
a/geode-experimental-driver/src/integrationTest/java/org/apache/geode/experimental/driver/AuthenticationTest.java
+++ 
b/geode-experimental-driver/src/integrationTest/java/org/apache/geode/experimental/driver/AuthorizationTest.java
@@ -14,38 +14,42 @@
  */
 package org.apache.geode.experimental.driver;
 
-import static org.apache.geode.internal.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
 
 import java.io.IOException;
+import java.util.Collections;
 import java.util.Properties;
 
+import org.assertj.core.api.ThrowableAssert;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.contrib.java.lang.system.RestoreSystemProperties;
 import org.junit.experimental.categories.Category;
 
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.RegionAttributes;
+import org.apache.geode.cache.RegionShortcut;
 import org.apache.geode.cache.server.CacheServer;
 import org.apache.geode.distributed.ConfigurationProperties;
 import org.apache.geode.distributed.Locator;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.internal.cache.InternalRegionArguments;
+import org.apache.geode.internal.cache.LocalRegion;
 import org.apache.geode.security.SimpleTestSecurityManager;
 import org.apache.geode.test.junit.categories.ClientServerTest;
 
 @Category({ClientServerTest.class})
-public class AuthenticationTest {
-  @Rule
-  public RestoreSystemProperties restoreSystemProperties = new 
RestoreSystemProperties();
-
-  private static final String TEST_USERNAME = "cluster";
+public class AuthorizationTest {
+  private static final String TEST_USERNAME = "";
   private static final String TEST_PASSWORD = TEST_USERNAME;
   private Locator locator;
   private Cache cache;
   private Driver driver;
   private int locatorPort;
 
+
   @Before
   public void createServer() throws Exception {
     System.setProperty("geode.feature-protobuf-protocol", "true");
@@ -70,23 +74,40 @@ public class AuthenticationTest {
   }
 
   @Test
-  public void driverFailsToConnectWhenThereAreNoServers() throws Exception {
-    try {
-      driver = new DriverFactory().addLocator("localhost", 
locatorPort).create();
-    } catch (IOException e) {
-      // success
-      return;
-    }
-    throw new AssertionError("expected an IOException");
-  }
+  public void performOperationsOnInternalRegion() throws Exception {
+    // we need to use internal APIs to create an "internal" region
+    GemFireCacheImpl serverCache = (GemFireCacheImpl) cache;
+    InternalRegionArguments internalRegionArguments = new 
InternalRegionArguments();
+    internalRegionArguments.setIsUsedForPartitionedRegionAdmin(true);
+    RegionAttributes<String, String> attributes =
+        serverCache.getRegionAttributes(RegionShortcut.REPLICATE.toString());
+    LocalRegion serverRegion =
+        (LocalRegion) serverCache.createVMRegion("internalRegion", attributes,
+            internalRegionArguments);
+    assertThat(serverRegion.isInternalRegion()).isTrue();
 
-  @Test
-  public void driverCanConnectWhenThereAreServers() throws Exception {
     CacheServer server = cache.addCacheServer();
     server.setPort(0);
     server.start();
-    driver = new DriverFactory().addLocator("localhost", 
locatorPort).setUsername(TEST_USERNAME)
-        .setPassword(TEST_PASSWORD).create();
-    assertTrue(driver.isConnected());
+    Driver driver =
+        new DriverFactory().addLocator("localhost", 
locatorPort).setUsername(TEST_USERNAME)
+            .setPassword(TEST_PASSWORD).create();
+    Region region = driver.getRegion("internalRegion");
+    assertThat(region).isNotNull();
+    assertFailure(() -> region.clear());
+    assertFailure(() -> region.get("some key"));
+    assertFailure(() -> region.getAll(Collections.singleton("some key")));
+    assertFailure(() -> region.keySet());
+    assertFailure(() -> region.put("some key", "some value"));
+    assertFailure(() -> region.putAll(Collections.singletonMap("some key", 
"some value")));
+    assertFailure(() -> region.putIfAbsent("some key", "some value"));
+    assertFailure(() -> region.remove("some key"));
+    assertFailure(() -> region.size());
+  }
+
+  private void assertFailure(final ThrowableAssert.ThrowingCallable callable) {
+    assertThatExceptionOfType(IOException.class).isThrownBy(callable)
+        .withMessageContaining(
+            "Not authorized");
   }
 }
diff --git 
a/geode-protobuf/src/integrationTest/java/org/apache/geode/internal/protocol/protobuf/v1/AuthenticationIntegrationTest.java
 
b/geode-protobuf/src/integrationTest/java/org/apache/geode/internal/protocol/protobuf/v1/AuthenticationIntegrationTest.java
index d1be0cb..a18ac07 100644
--- 
a/geode-protobuf/src/integrationTest/java/org/apache/geode/internal/protocol/protobuf/v1/AuthenticationIntegrationTest.java
+++ 
b/geode-protobuf/src/integrationTest/java/org/apache/geode/internal/protocol/protobuf/v1/AuthenticationIntegrationTest.java
@@ -112,7 +112,7 @@ public class AuthenticationIntegrationTest {
 
     @Override
     public boolean authorize(Object principal, ResourcePermission permission) {
-      return principal == authorizedPrincipal;
+      return principal.equals(authorizedPrincipal);
     }
   }
 
diff --git 
a/geode-protobuf/src/integrationTest/java/org/apache/geode/internal/protocol/protobuf/v1/AuthorizationIntegrationTest.java
 
b/geode-protobuf/src/integrationTest/java/org/apache/geode/internal/protocol/protobuf/v1/AuthorizationIntegrationTest.java
index 2d37880..b98557e 100644
--- 
a/geode-protobuf/src/integrationTest/java/org/apache/geode/internal/protocol/protobuf/v1/AuthorizationIntegrationTest.java
+++ 
b/geode-protobuf/src/integrationTest/java/org/apache/geode/internal/protocol/protobuf/v1/AuthorizationIntegrationTest.java
@@ -100,7 +100,7 @@ public class AuthorizationIntegrationTest {
     @Override
     public boolean authorize(Object principal, ResourcePermission permission) {
       // Only allow data operations and only from the expected principal
-      if (principal != securityPrincipal
+      if (!principal.equals(securityPrincipal)
           || permission.getResource() != ResourcePermission.Resource.DATA) {
         return false;
       }
diff --git 
a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/ServerMessageExecutionContext.java
 
b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/ServerMessageExecutionContext.java
index df71e22..6b00a38 100644
--- 
a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/ServerMessageExecutionContext.java
+++ 
b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/ServerMessageExecutionContext.java
@@ -41,10 +41,10 @@ public class ServerMessageExecutionContext extends 
MessageExecutionContext {
   public ServerMessageExecutionContext(InternalCache cache, ClientStatistics 
statistics,
       SecurityService securityService) {
     super(statistics, securityService);
-    this.cache = cache;
+    this.cache = cache.getCacheForProcessingClientRequests();
     Security security =
         securityService.isIntegratedSecurity() ? new NotLoggedInSecurity() : 
new NoSecurity();
-    this.secureCache = new SecureCacheImpl(cache, security);
+    this.secureCache = new SecureCacheImpl(this.cache, security);
   }
 
   @Override
diff --git 
a/geode-protobuf/src/test/java/org/apache/geode/internal/cache/tier/sockets/OutputCapturingServerConnectionTest.java
 
b/geode-protobuf/src/test/java/org/apache/geode/internal/cache/tier/sockets/OutputCapturingServerConnectionTest.java
index 0ed68a9..2d5bac3 100644
--- 
a/geode-protobuf/src/test/java/org/apache/geode/internal/cache/tier/sockets/OutputCapturingServerConnectionTest.java
+++ 
b/geode-protobuf/src/test/java/org/apache/geode/internal/cache/tier/sockets/OutputCapturingServerConnectionTest.java
@@ -33,7 +33,7 @@ import org.junit.contrib.java.lang.system.SystemOutRule;
 import org.junit.experimental.categories.Category;
 
 import org.apache.geode.cache.IncompatibleVersionException;
-import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.InternalCacheForClientAccess;
 import org.apache.geode.internal.cache.client.protocol.ClientProtocolProcessor;
 import org.apache.geode.internal.cache.tier.CachedRegionHelper;
 import org.apache.geode.internal.cache.tier.CommunicationMode;
@@ -87,7 +87,8 @@ public class OutputCapturingServerConnectionTest {
     
when(socketMock.getRemoteSocketAddress()).thenReturn(inetSocketAddressStub);
     when(socketMock.getInetAddress()).thenReturn(inetAddressStub);
 
-    InternalCache cache = mock(InternalCache.class);
+    InternalCacheForClientAccess cache = 
mock(InternalCacheForClientAccess.class);
+    when(cache.getCacheForProcessingClientRequests()).thenReturn(cache);
     CachedRegionHelper cachedRegionHelper = mock(CachedRegionHelper.class);
     when(cachedRegionHelper.getCache()).thenReturn(cache);
     return new ProtobufServerConnection(socketMock, cache, cachedRegionHelper,
diff --git 
a/geode-protobuf/src/test/java/org/apache/geode/internal/cache/tier/sockets/ProtobufServerConnectionTest.java
 
b/geode-protobuf/src/test/java/org/apache/geode/internal/cache/tier/sockets/ProtobufServerConnectionTest.java
index d365fad..cdf7a2a 100644
--- 
a/geode-protobuf/src/test/java/org/apache/geode/internal/cache/tier/sockets/ProtobufServerConnectionTest.java
+++ 
b/geode-protobuf/src/test/java/org/apache/geode/internal/cache/tier/sockets/ProtobufServerConnectionTest.java
@@ -35,7 +35,7 @@ import org.mockito.Mockito;
 
 import org.apache.geode.cache.IncompatibleVersionException;
 import org.apache.geode.internal.Assert;
-import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.InternalCacheForClientAccess;
 import org.apache.geode.internal.cache.client.protocol.ClientProtocolProcessor;
 import org.apache.geode.internal.cache.tier.CachedRegionHelper;
 import org.apache.geode.internal.cache.tier.CommunicationMode;
@@ -126,7 +126,8 @@ public class ProtobufServerConnectionTest {
     
when(socketMock.getRemoteSocketAddress()).thenReturn(inetSocketAddressStub);
     when(socketMock.getInetAddress()).thenReturn(inetAddressStub);
 
-    InternalCache cache = mock(InternalCache.class);
+    InternalCacheForClientAccess cache = 
mock(InternalCacheForClientAccess.class);
+    when(cache.getCacheForProcessingClientRequests()).thenReturn(cache);
     CachedRegionHelper cachedRegionHelper = mock(CachedRegionHelper.class);
     when(cachedRegionHelper.getCache()).thenReturn(cache);
     return new ProtobufServerConnection(socketMock, cache, cachedRegionHelper,
diff --git 
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/ProtobufStreamProcessorTest.java
 
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/ProtobufStreamProcessorTest.java
index d889a83..4a1715f 100644
--- 
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/ProtobufStreamProcessorTest.java
+++ 
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/ProtobufStreamProcessorTest.java
@@ -15,6 +15,7 @@
 package org.apache.geode.internal.protocol.protobuf;
 
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -25,7 +26,7 @@ import java.io.OutputStream;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.InternalCacheForClientAccess;
 import org.apache.geode.internal.protocol.TestExecutionContext;
 import org.apache.geode.internal.protocol.protobuf.v1.ProtobufStreamProcessor;
 import org.apache.geode.test.junit.categories.ClientServerTest;
@@ -38,7 +39,8 @@ public class ProtobufStreamProcessorTest {
     OutputStream outputStream = new ByteArrayOutputStream(2);
 
     ProtobufStreamProcessor protobufStreamProcessor = new 
ProtobufStreamProcessor();
-    InternalCache mockInternalCache = mock(InternalCache.class);
+    InternalCacheForClientAccess mockInternalCache = 
mock(InternalCacheForClientAccess.class);
+    
when(mockInternalCache.getCacheForProcessingClientRequests()).thenReturn(mockInternalCache);
     protobufStreamProcessor.receiveMessage(inputStream, outputStream,
         
TestExecutionContext.getNoAuthCacheExecutionContext(mockInternalCache));
   }
diff --git 
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/security/SecureCacheImplTest.java
 
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/security/SecureCacheImplTest.java
index 3318fb3..c582fc1 100644
--- 
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/security/SecureCacheImplTest.java
+++ 
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/security/SecureCacheImplTest.java
@@ -24,6 +24,7 @@ import static org.assertj.core.data.MapEntry.entry;
 import static org.junit.Assert.assertEquals;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -53,6 +54,7 @@ import org.apache.geode.cache.query.internal.StructImpl;
 import org.apache.geode.cache.query.internal.types.ObjectTypeImpl;
 import org.apache.geode.cache.query.internal.types.StructTypeImpl;
 import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.InternalCacheForClientAccess;
 import org.apache.geode.security.NotAuthorizedException;
 import org.apache.geode.security.ResourcePermission;
 import org.apache.geode.test.junit.categories.ClientServerTest;
@@ -68,7 +70,8 @@ public class SecureCacheImplTest {
 
   @Before
   public void setUp() {
-    cache = mock(InternalCache.class);
+    cache = mock(InternalCacheForClientAccess.class);
+    doReturn(cache).when(cache).getCacheForProcessingClientRequests();
     region = mock(Region.class);
     when(cache.getRegion(REGION)).thenReturn(region);
     security = mock(Security.class);
@@ -80,7 +83,7 @@ public class SecureCacheImplTest {
   }
 
   @Test
-  public void getAllSuccesses() throws Exception {
+  public void getAllSuccesses() {
     authorize(DATA, READ, REGION, "a");
     authorize(DATA, READ, REGION, "b");
     Map<Object, Object> okValues = new HashMap<>();
@@ -97,7 +100,7 @@ public class SecureCacheImplTest {
   }
 
   @Test
-  public void getAllWithRegionLevelAuthorizationSucceeds() throws Exception {
+  public void getAllWithRegionLevelAuthorizationSucceeds() {
     authorize(DATA, READ, REGION, ALL);
     Map<Object, Object> okValues = new HashMap<>();
     Map<Object, Exception> exceptionValues = new HashMap<>();
@@ -113,7 +116,7 @@ public class SecureCacheImplTest {
   }
 
   @Test
-  public void getAllWithFailure() throws Exception {
+  public void getAllWithFailure() {
     authorize(DATA, READ, REGION, "b");
     Map<Object, Object> okValues = new HashMap<>();
     Map<Object, Exception> exceptionValues = new HashMap<>();
@@ -131,7 +134,7 @@ public class SecureCacheImplTest {
   }
 
   @Test
-  public void getAllIsPostProcessed() throws Exception {
+  public void getAllIsPostProcessed() {
     authorize(DATA, READ, REGION, "a");
     authorize(DATA, READ, REGION, "b");
     when(security.postProcess(any(), any(), any())).thenReturn("spam");
@@ -154,20 +157,20 @@ public class SecureCacheImplTest {
   }
 
   @Test
-  public void get() throws Exception {
+  public void get() {
     authorize(DATA, READ, REGION, "a");
     when(region.get("a")).thenReturn("value");
     assertEquals("value", authorizingCache.get(REGION, "a"));
   }
 
   @Test
-  public void getWithFailure() throws Exception {
+  public void getWithFailure() {
     assertThatThrownBy(() -> authorizingCache.get(REGION, "a"))
         .isInstanceOf(NotAuthorizedException.class);
   }
 
   @Test
-  public void getIsPostProcessed() throws Exception {
+  public void getIsPostProcessed() {
     authorize(DATA, READ, REGION, "a");
     when(security.postProcess(REGION, "a", "value")).thenReturn("spam");
     when(region.get("a")).thenReturn("value");
@@ -175,20 +178,20 @@ public class SecureCacheImplTest {
   }
 
   @Test
-  public void put() throws Exception {
+  public void put() {
     authorize(DATA, WRITE, REGION, "a");
     authorizingCache.put(REGION, "a", "value");
     verify(region).put("a", "value");
   }
 
   @Test
-  public void putWithFailure() throws Exception {
+  public void putWithFailure() {
     assertThatThrownBy(() -> authorizingCache.put(REGION, "a", "value"))
         .isInstanceOf(NotAuthorizedException.class);
   }
 
   @Test
-  public void putAll() throws Exception {
+  public void putAll() {
     authorize(DATA, WRITE, REGION, "a");
     authorize(DATA, WRITE, REGION, "c");
     Map<Object, Object> entries = new HashMap<>();
@@ -205,7 +208,7 @@ public class SecureCacheImplTest {
   }
 
   @Test
-  public void putAllWithRegionLevelAuthorizationSucceeds() throws Exception {
+  public void putAllWithRegionLevelAuthorizationSucceeds() {
     authorize(DATA, WRITE, REGION, ALL);
     Map<Object, Object> entries = new HashMap<>();
     entries.put("a", "b");
@@ -221,7 +224,7 @@ public class SecureCacheImplTest {
   }
 
   @Test
-  public void putAllWithFailure() throws Exception {
+  public void putAllWithFailure() {
     authorize(DATA, WRITE, REGION, "a");
     Map<Object, Object> entries = new HashMap<>();
     entries.put("a", "b");
@@ -239,20 +242,20 @@ public class SecureCacheImplTest {
   }
 
   @Test
-  public void remove() throws Exception {
+  public void remove() {
     authorize(DATA, WRITE, REGION, "a");
     authorizingCache.remove(REGION, "a");
     verify(region).remove("a");
   }
 
   @Test
-  public void removeWithoutAuthorization() throws Exception {
+  public void removeWithoutAuthorization() {
     assertThatThrownBy(() -> authorizingCache.remove(REGION, "a"))
         .isInstanceOf(NotAuthorizedException.class);
   }
 
   @Test
-  public void removeIsPostProcessed() throws Exception {
+  public void removeIsPostProcessed() {
     authorize(DATA, WRITE, REGION, "a");
     when(region.remove("a")).thenReturn("value");
     when(security.postProcess(REGION, "a", "value")).thenReturn("spam");
@@ -262,7 +265,7 @@ public class SecureCacheImplTest {
   }
 
   @Test
-  public void getRegionNames() throws Exception {
+  public void getRegionNames() {
     authorize(DATA, READ, ALL, ALL);
     Set<Region<?, ?>> regions = new HashSet<>();
     regions.add(region);
@@ -284,59 +287,59 @@ public class SecureCacheImplTest {
   }
 
   @Test
-  public void getRegionNamesWithoutAuthorization() throws Exception {
+  public void getRegionNamesWithoutAuthorization() {
     assertThatThrownBy(() -> authorizingCache.getRegionNames())
         .isInstanceOf(NotAuthorizedException.class);
   }
 
   @Test
-  public void getSize() throws Exception {
+  public void getSize() {
     authorize(DATA, READ, REGION, ALL);
     authorizingCache.getSize(REGION);
     verify(region).size();
   }
 
   @Test
-  public void getSizeWithoutAuthorization() throws Exception {
+  public void getSizeWithoutAuthorization() {
     assertThatThrownBy(() -> authorizingCache.getSize(REGION))
         .isInstanceOf(NotAuthorizedException.class);
   }
 
   @Test
-  public void keySet() throws Exception {
+  public void keySet() {
     authorize(DATA, READ, REGION, ALL);
     authorizingCache.keySet(REGION);
     verify(region).keySet();
   }
 
   @Test
-  public void keySetWithoutAuthorization() throws Exception {
+  public void keySetWithoutAuthorization() {
     assertThatThrownBy(() -> authorizingCache.keySet(REGION))
         .isInstanceOf(NotAuthorizedException.class);
   }
 
   @Test
-  public void clear() throws Exception {
+  public void clear() {
     authorize(DATA, WRITE, REGION, ALL);
     authorizingCache.clear(REGION);
     verify(region).clear();
   }
 
   @Test
-  public void clearWithoutAuthorization() throws Exception {
+  public void clearWithoutAuthorization() {
     assertThatThrownBy(() -> authorizingCache.clear(REGION))
         .isInstanceOf(NotAuthorizedException.class);
   }
 
   @Test
-  public void putIfAbsent() throws Exception {
+  public void putIfAbsent() {
     authorize(DATA, WRITE, REGION, "a");
     String oldValue = authorizingCache.putIfAbsent(REGION, "a", "b");
     verify(region).putIfAbsent("a", "b");
   }
 
   @Test
-  public void putIfAbsentIsPostProcessed() throws Exception {
+  public void putIfAbsentIsPostProcessed() {
     authorize(DATA, WRITE, REGION, "a");
     when(region.putIfAbsent(any(), any())).thenReturn("value");
     when(security.postProcess(REGION, "a", "value")).thenReturn("spam");
@@ -346,7 +349,7 @@ public class SecureCacheImplTest {
   }
 
   @Test
-  public void putIfAbsentWithoutAuthorization() throws Exception {
+  public void putIfAbsentWithoutAuthorization() {
     assertThatThrownBy(() -> authorizingCache.putIfAbsent(REGION, "a", "b"))
         .isInstanceOf(NotAuthorizedException.class);
   }
diff --git 
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/security/SecureFunctionServiceImplTest.java
 
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/security/SecureFunctionServiceImplTest.java
index a36c114..3b116ec 100644
--- 
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/security/SecureFunctionServiceImplTest.java
+++ 
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/security/SecureFunctionServiceImplTest.java
@@ -20,6 +20,7 @@ import static 
org.apache.geode.security.ResourcePermission.Resource.CLUSTER;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -36,6 +37,7 @@ import org.apache.geode.cache.Region;
 import org.apache.geode.cache.execute.Function;
 import org.apache.geode.cache.execute.FunctionService;
 import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.InternalCacheForClientAccess;
 import org.apache.geode.security.NotAuthorizedException;
 import org.apache.geode.security.ResourcePermission;
 import org.apache.geode.test.junit.categories.ClientServerTest;
@@ -52,7 +54,8 @@ public class SecureFunctionServiceImplTest {
 
   @Before
   public void setUp() {
-    cache = mock(InternalCache.class);
+    cache = mock(InternalCacheForClientAccess.class);
+    doReturn(cache).when(cache).getCacheForProcessingClientRequests();
     region = mock(Region.class);
     when(cache.getRegion(REGION)).thenReturn(region);
     security = mock(Security.class);
diff --git 
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/ExecuteFunctionOnGroupRequestOperationHandlerJUnitTest.java
 
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/ExecuteFunctionOnGroupRequestOperationHandlerJUnitTest.java
index f2331f0..f2767ec 100644
--- 
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/ExecuteFunctionOnGroupRequestOperationHandlerJUnitTest.java
+++ 
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/ExecuteFunctionOnGroupRequestOperationHandlerJUnitTest.java
@@ -39,7 +39,7 @@ import 
org.apache.geode.distributed.DistributedSystemDisconnectedException;
 import org.apache.geode.distributed.internal.DistributionManager;
 import org.apache.geode.distributed.internal.InternalDistributedSystem;
 import 
org.apache.geode.distributed.internal.membership.InternalDistributedMember;
-import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.InternalCacheForClientAccess;
 import 
org.apache.geode.internal.protocol.protobuf.statistics.ProtobufClientStatistics;
 import org.apache.geode.internal.protocol.protobuf.v1.FunctionAPI;
 import 
org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
@@ -56,7 +56,7 @@ public class 
ExecuteFunctionOnGroupRequestOperationHandlerJUnitTest {
   private static final String TEST_GROUP2 = "group2";
   private static final String TEST_FUNCTION_ID = "testFunction";
   public static final String NOT_A_GROUP = "notAGroup";
-  private InternalCache cacheStub;
+  private InternalCacheForClientAccess cacheStub;
   private DistributionManager distributionManager;
   private ExecuteFunctionOnGroupRequestOperationHandler operationHandler;
   private ProtobufSerializationService serializationService;
@@ -88,7 +88,8 @@ public class 
ExecuteFunctionOnGroupRequestOperationHandlerJUnitTest {
 
   @Before
   public void setUp() throws Exception {
-    cacheStub = mock(InternalCache.class);
+    cacheStub = mock(InternalCacheForClientAccess.class);
+    
when(cacheStub.getCacheForProcessingClientRequests()).thenReturn(cacheStub);
     serializationService = new ProtobufSerializationService();
     
when(cacheStub.getSecurityService()).thenReturn(mock(SecurityService.class));
 
diff --git 
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/ExecuteFunctionOnMemberRequestOperationHandlerJUnitTest.java
 
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/ExecuteFunctionOnMemberRequestOperationHandlerJUnitTest.java
index 1bb5fcf..d03b574 100644
--- 
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/ExecuteFunctionOnMemberRequestOperationHandlerJUnitTest.java
+++ 
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/ExecuteFunctionOnMemberRequestOperationHandlerJUnitTest.java
@@ -35,7 +35,7 @@ import org.apache.geode.cache.execute.FunctionService;
 import org.apache.geode.distributed.DistributedSystemDisconnectedException;
 import org.apache.geode.distributed.internal.DistributionManager;
 import 
org.apache.geode.distributed.internal.membership.InternalDistributedMember;
-import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.InternalCacheForClientAccess;
 import 
org.apache.geode.internal.protocol.protobuf.statistics.ProtobufClientStatistics;
 import org.apache.geode.internal.protocol.protobuf.v1.FunctionAPI;
 import 
org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
@@ -52,7 +52,7 @@ public class 
ExecuteFunctionOnMemberRequestOperationHandlerJUnitTest {
   private static final String TEST_MEMBER2 = "member2";
   private static final String TEST_FUNCTION_ID = "testFunction";
   public static final String NOT_A_MEMBER = "notAMember";
-  private InternalCache cacheStub;
+  private InternalCacheForClientAccess cacheStub;
   private DistributionManager distributionManager;
   private ExecuteFunctionOnMemberRequestOperationHandler operationHandler;
   private ProtobufSerializationService serializationService;
@@ -83,7 +83,8 @@ public class 
ExecuteFunctionOnMemberRequestOperationHandlerJUnitTest {
 
   @Before
   public void setUp() throws Exception {
-    cacheStub = mock(InternalCache.class);
+    cacheStub = mock(InternalCacheForClientAccess.class);
+    
when(cacheStub.getCacheForProcessingClientRequests()).thenReturn(cacheStub);
     serializationService = new ProtobufSerializationService();
     
when(cacheStub.getSecurityService()).thenReturn(mock(SecurityService.class));
 
diff --git 
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/ExecuteFunctionOnRegionRequestOperationHandlerJUnitTest.java
 
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/ExecuteFunctionOnRegionRequestOperationHandlerJUnitTest.java
index 744c8a1..acc947e 100644
--- 
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/ExecuteFunctionOnRegionRequestOperationHandlerJUnitTest.java
+++ 
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/ExecuteFunctionOnRegionRequestOperationHandlerJUnitTest.java
@@ -15,6 +15,7 @@
 package org.apache.geode.internal.protocol.protobuf.v1.operations;
 
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -35,6 +36,7 @@ import org.apache.geode.cache.execute.Function;
 import org.apache.geode.cache.execute.FunctionContext;
 import org.apache.geode.cache.execute.FunctionService;
 import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.InternalCacheForClientAccess;
 import org.apache.geode.internal.cache.LocalRegion;
 import 
org.apache.geode.internal.protocol.protobuf.statistics.ProtobufClientStatistics;
 import org.apache.geode.internal.protocol.protobuf.v1.FunctionAPI;
@@ -87,7 +89,8 @@ public class 
ExecuteFunctionOnRegionRequestOperationHandlerJUnitTest {
   @Before
   public void setUp() {
     regionStub = mock(LocalRegion.class);
-    cacheStub = mock(InternalCache.class);
+    cacheStub = mock(InternalCacheForClientAccess.class);
+    doReturn(cacheStub).when(cacheStub).getCacheForProcessingClientRequests();
     serializationService = new ProtobufSerializationService();
 
     when(cacheStub.getRegion(TEST_REGION)).thenReturn(regionStub);
diff --git 
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionNamesRequestOperationHandlerJUnitTest.java
 
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionNamesRequestOperationHandlerJUnitTest.java
index 8db6cd5..0182eb6 100644
--- 
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionNamesRequestOperationHandlerJUnitTest.java
+++ 
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionNamesRequestOperationHandlerJUnitTest.java
@@ -16,6 +16,7 @@ package 
org.apache.geode.internal.protocol.protobuf.v1.operations;
 
 import static org.apache.geode.internal.Assert.assertTrue;
 import static 
org.apache.geode.internal.protocol.TestExecutionContext.getNoAuthCacheExecutionContext;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -31,6 +32,7 @@ import org.junit.experimental.categories.Category;
 
 import org.apache.geode.cache.Region;
 import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.InternalCacheForClientAccess;
 import org.apache.geode.internal.protocol.protobuf.v1.ProtobufRequestUtilities;
 import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI;
 import org.apache.geode.internal.protocol.protobuf.v1.Result;
@@ -86,7 +88,8 @@ public class GetRegionNamesRequestOperationHandlerJUnitTest 
extends OperationHan
 
   @Test
   public void processReturnsNoCacheRegions() throws Exception {
-    InternalCache emptyCache = mock(InternalCache.class);
+    InternalCache emptyCache = mock(InternalCacheForClientAccess.class);
+    
doReturn(emptyCache).when(emptyCache).getCacheForProcessingClientRequests();
     when(emptyCache.rootRegions())
         .thenReturn(Collections.unmodifiableSet(new HashSet<Region<String, 
String>>()));
     Result result = operationHandler.process(serializationService,
diff --git 
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetSizeRequestOperationHandlerJUnitTest.java
 
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetSizeRequestOperationHandlerJUnitTest.java
index 845ced1..8eea811 100644
--- 
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetSizeRequestOperationHandlerJUnitTest.java
+++ 
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetSizeRequestOperationHandlerJUnitTest.java
@@ -15,6 +15,7 @@
 package org.apache.geode.internal.protocol.protobuf.v1.operations;
 
 import static 
org.apache.geode.internal.protocol.TestExecutionContext.getNoAuthCacheExecutionContext;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -34,6 +35,7 @@ import org.apache.geode.cache.RegionAttributes;
 import org.apache.geode.cache.RegionDestroyedException;
 import org.apache.geode.cache.Scope;
 import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.InternalCacheForClientAccess;
 import org.apache.geode.internal.protocol.protobuf.v1.MessageUtil;
 import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI;
 import org.apache.geode.internal.protocol.protobuf.v1.Result;
@@ -77,7 +79,8 @@ public class GetSizeRequestOperationHandlerJUnitTest extends 
OperationHandlerJUn
 
   @Test
   public void processReturnsNoCacheRegions() throws Exception {
-    InternalCache emptyCache = mock(InternalCache.class);
+    InternalCache emptyCache = mock(InternalCacheForClientAccess.class);
+    
doReturn(emptyCache).when(emptyCache).getCacheForProcessingClientRequests();
     when(emptyCache.rootRegions())
         .thenReturn(Collections.unmodifiableSet(new HashSet<Region<String, 
String>>()));
     String unknownRegionName = "UNKNOWN_REGION";
diff --git 
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/OperationHandlerJUnitTest.java
 
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/OperationHandlerJUnitTest.java
index f629295..10e00dc 100644
--- 
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/OperationHandlerJUnitTest.java
+++ 
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/OperationHandlerJUnitTest.java
@@ -14,12 +14,14 @@
  */
 package org.apache.geode.internal.protocol.protobuf.v1.operations;
 
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 
 import org.junit.Before;
 import org.junit.experimental.categories.Category;
 
 import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.InternalCacheForClientAccess;
 import org.apache.geode.internal.protocol.operations.ProtobufOperationHandler;
 import 
org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
 import org.apache.geode.test.junit.categories.ClientServerTest;
@@ -33,7 +35,8 @@ public class OperationHandlerJUnitTest {
   // if we name this setUp, then our children override, which is all kinds of 
annoying.
   @Before
   public void setUpForChildJUnitTests() throws Exception {
-    cacheStub = mock(InternalCache.class);
+    cacheStub = mock(InternalCacheForClientAccess.class);
+    doReturn(cacheStub).when(cacheStub).getCacheForProcessingClientRequests();
     serializationService = new ProtobufSerializationService();
   }
 }

Reply via email to