Skip to content

Commit

Permalink
GEODE-9820: stopCQ should handle general exception same way as Execut…
Browse files Browse the repository at this point in the history
…eCQ61 (apache#7122)
  • Loading branch information
jinmeiliao authored Nov 22, 2021
1 parent 685ad9e commit f61e32f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
import org.apache.geode.cache.client.ClientRegionFactory;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.apache.geode.cache.client.ServerOperationException;
import org.apache.geode.cache.query.CqAttributesFactory;
import org.apache.geode.cache.query.CqQuery;
import org.apache.geode.cache.query.QueryService;
import org.apache.geode.cache.query.dunit.SecurityTestUtils.EventsCqListner;
import org.apache.geode.cache.query.dunit.SecurityTestUtils.KeysCacheListener;
import org.apache.geode.internal.cache.tier.sockets.CacheClientProxy;
Expand Down Expand Up @@ -387,6 +390,72 @@ public void cqOlderClientWithClientInteractionWillDeliverEventEventually() throw
});
}

@Test
public void createCQWillReAuth() throws Exception {
int serverPort = server.getPort();
clientVM = cluster.startClientVM(0, clientVersion,
c -> c.withProperty(SECURITY_CLIENT_AUTH_INIT, UpdatableUserAuthInitialize.class.getName())
.withPoolSubscription(true)
.withServerConnection(serverPort));

clientVM.invoke(() -> {
UpdatableUserAuthInitialize.setUser("user1");
Region<Object, Object> proxyRegion =
ClusterStartupRule.clientCacheRule.createProxyRegion("region");
proxyRegion.put("key1", "value1");
});

getSecurityManager().addExpiredUser("user1");

clientVM.invoke(() -> {
UpdatableUserAuthInitialize.setUser("user2");
QueryService queryService = ClusterStartupRule.getClientCache().getQueryService();
CqQuery cq =
queryService.newCq("CQ1", "select * from /region", new CqAttributesFactory().create());
cq.execute();
});

Map<String, List<String>> unAuthorizedOps = getSecurityManager().getUnAuthorizedOps();
Map<String, List<String>> authorizedOps = getSecurityManager().getAuthorizedOps();
assertThat(unAuthorizedOps.keySet()).containsExactly("user1");
assertThat(unAuthorizedOps.get("user1")).containsExactly("DATA:READ:region");
assertThat(authorizedOps.keySet()).containsExactly("user1", "user2");
assertThat(authorizedOps.get("user2")).containsExactly("DATA:READ:region");
}

@Test
public void stopCQ() throws Exception {
int serverPort = server.getPort();
clientVM = cluster.startClientVM(0, clientVersion,
c -> c.withProperty(SECURITY_CLIENT_AUTH_INIT, UpdatableUserAuthInitialize.class.getName())
.withPoolSubscription(true)
.withServerConnection(serverPort));

clientVM.invoke(() -> {
UpdatableUserAuthInitialize.setUser("user1");
QueryService queryService = ClusterStartupRule.getClientCache().getQueryService();
CqQuery cq =
queryService.newCq("CQ1", "select * from /region", new CqAttributesFactory().create());
cq.execute();
});

getSecurityManager().addExpiredUser("user1");

clientVM.invoke(() -> {
UpdatableUserAuthInitialize.setUser("user2");
QueryService queryService = ClusterStartupRule.getClientCache().getQueryService();
CqQuery cq = queryService.getCq("CQ1");
cq.stop();
});

Map<String, List<String>> unAuthorizedOps = getSecurityManager().getUnAuthorizedOps();
Map<String, List<String>> authorizedOps = getSecurityManager().getAuthorizedOps();
assertThat(unAuthorizedOps.keySet()).containsExactly("user1");
assertThat(unAuthorizedOps.get("user1")).containsExactly("CLUSTER:MANAGE:QUERY");
assertThat(authorizedOps.keySet()).containsExactly("user1", "user2");
assertThat(authorizedOps.get("user2")).containsExactly("CLUSTER:MANAGE:QUERY");
}

@Test
public void registeredInterestForDefaultInterestPolicy() throws Exception {
int serverPort = server.getPort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ public void cmdExecute(final Message clientMessage, final ServerConnection serve
serverConnection);
return;
} catch (Exception e) {
String err =
String.format("Exception while stopping CQ named %s :", cqName);
sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, err, clientMessage.getTransactionId(), e,
serverConnection);
writeChunkedException(clientMessage, e, serverConnection);
return;
}

Expand Down

0 comments on commit f61e32f

Please sign in to comment.