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 bcf72e6f09f5..f4d11e9471a6 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 void driverCanConnectWhenThereAreServers() throws Exception { .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/AuthorizationTest.java b/geode-experimental-driver/src/integrationTest/java/org/apache/geode/experimental/driver/AuthorizationTest.java new file mode 100644 index 000000000000..641c10882102 --- /dev/null +++ b/geode-experimental-driver/src/integrationTest/java/org/apache/geode/experimental/driver/AuthorizationTest.java @@ -0,0 +1,113 @@ +/* + * 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. + */ +package org.apache.geode.experimental.driver; + +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.Test; +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 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"); + + // Create a cache + CacheFactory cf = new CacheFactory(); + cf.set(ConfigurationProperties.MCAST_PORT, "0"); + cf.setSecurityManager(new SimpleTestSecurityManager()); + cache = cf.create(); + + // Start a locator + locator = Locator.startLocatorAndDS(0, null, new Properties()); + locatorPort = locator.getPort(); + + // do not start a cache server + } + + @After + public void cleanup() { + locator.stop(); + cache.close(); + } + + @Test + 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 attributes = + serverCache.getRegionAttributes(RegionShortcut.REPLICATE.toString()); + LocalRegion serverRegion = + (LocalRegion) serverCache.createVMRegion("internalRegion", attributes, + internalRegionArguments); + assertThat(serverRegion.isInternalRegion()).isTrue(); + + CacheServer server = cache.addCacheServer(); + server.setPort(0); + server.start(); + 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 d1be0cbe07a3..a18ac07a290e 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 Object authenticate(Properties credentials) throws AuthenticationFailedEx @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 2d378801dfa9..b98557e4efd5 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 Object authenticate(Properties credentials) throws AuthenticationFailedEx @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 df71e226e89d..6b00a380267b 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 0ed68a9141cb..2d5bac34e9f2 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.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 @@ private ProtobufServerConnection getServerConnection(Socket socketMock, 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 d365fad5473e..cdf7a2a3a67e 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.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 @@ private ProtobufServerConnection getServerConnection(Socket socketMock, 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 d889a833c718..4a1715fd0f53 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 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 void receiveMessage() throws Exception { 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 3318fb38d464..c582fc191270 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.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.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 void setUp() { } @Test - public void getAllSuccesses() throws Exception { + public void getAllSuccesses() { authorize(DATA, READ, REGION, "a"); authorize(DATA, READ, REGION, "b"); Map okValues = new HashMap<>(); @@ -97,7 +100,7 @@ public void getAllSuccesses() throws Exception { } @Test - public void getAllWithRegionLevelAuthorizationSucceeds() throws Exception { + public void getAllWithRegionLevelAuthorizationSucceeds() { authorize(DATA, READ, REGION, ALL); Map okValues = new HashMap<>(); Map exceptionValues = new HashMap<>(); @@ -113,7 +116,7 @@ public void getAllWithRegionLevelAuthorizationSucceeds() throws Exception { } @Test - public void getAllWithFailure() throws Exception { + public void getAllWithFailure() { authorize(DATA, READ, REGION, "b"); Map okValues = new HashMap<>(); Map exceptionValues = new HashMap<>(); @@ -131,7 +134,7 @@ public void getAllWithFailure() throws Exception { } @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 @@ private void authorize(ResourcePermission.Resource resource, } @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 void getIsPostProcessed() throws Exception { } @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 entries = new HashMap<>(); @@ -205,7 +208,7 @@ public void putAll() throws Exception { } @Test - public void putAllWithRegionLevelAuthorizationSucceeds() throws Exception { + public void putAllWithRegionLevelAuthorizationSucceeds() { authorize(DATA, WRITE, REGION, ALL); Map entries = new HashMap<>(); entries.put("a", "b"); @@ -221,7 +224,7 @@ public void putAllWithRegionLevelAuthorizationSucceeds() throws Exception { } @Test - public void putAllWithFailure() throws Exception { + public void putAllWithFailure() { authorize(DATA, WRITE, REGION, "a"); Map entries = new HashMap<>(); entries.put("a", "b"); @@ -239,20 +242,20 @@ public void putAllWithFailure() throws Exception { } @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 void removeIsPostProcessed() throws Exception { } @Test - public void getRegionNames() throws Exception { + public void getRegionNames() { authorize(DATA, READ, ALL, ALL); Set> regions = new HashSet<>(); regions.add(region); @@ -284,59 +287,59 @@ public void getRegionNames() throws Exception { } @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 void putIfAbsentIsPostProcessed() throws Exception { } @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 a36c114266ef..3b116ecdb56b 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.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.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 f2331f04b2fd..f2767ece6725 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.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 @@ FunctionContext getContext() { @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 1bb5fcfa47f8..d03b574fe499 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.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 @@ FunctionContext getContext() { @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 744c8a16f4c3..acc947e32496 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.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 @@ FunctionContext getContext() { @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 8db6cd594728..0182eb6d53bb 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 @@ 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.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 void processReturnsCacheRegions() throws Exception { @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>())); 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 845ced1fa487..8eea811a135c 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.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 void processReturnsCacheRegions() throws Exception { @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>())); 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 f6292953b604..10e00dc9eb2b 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(); } }