Skip to content

Commit

Permalink
Fix unchecked cast in dynamic action map getter (opensearch-project#1…
Browse files Browse the repository at this point in the history
…5394)

Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis authored Aug 24, 2024
1 parent 2301adf commit 6152afe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix range aggregation optimization ignoring top level queries ([#15194](https://github.com/opensearch-project/OpenSearch/pull/15194))
- Fix incorrect parameter names in MinHash token filter configuration handling ([#15233](https://github.com/opensearch-project/OpenSearch/pull/15233))
- Fix split response processor not included in allowlist ([#15393](https://github.com/opensearch-project/OpenSearch/pull/15393))
- Fix unchecked cast in dynamic action map getter ([#15394](https://github.com/opensearch-project/OpenSearch/pull/15394))

### Security

Expand Down
7 changes: 5 additions & 2 deletions server/src/main/java/org/opensearch/action/ActionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -1200,9 +1200,12 @@ public void unregisterDynamicRoute(NamedRoute route) {
* @param route The {@link RestHandler.Route}.
* @return the corresponding {@link RestSendToExtensionAction} if it is registered, null otherwise.
*/
@SuppressWarnings("unchecked")
public RestSendToExtensionAction get(RestHandler.Route route) {
return routeRegistry.get(route);
if (route instanceof NamedRoute) {
return routeRegistry.get((NamedRoute) route);
}
// Only NamedRoutes are map keys so any other route is not in the map
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.opensearch.extensions.action.ExtensionTransportAction;
import org.opensearch.extensions.rest.RestSendToExtensionAction;
import org.opensearch.rest.NamedRoute;
import org.opensearch.rest.RestHandler;
import org.opensearch.rest.RestRequest;
import org.opensearch.tasks.Task;
import org.opensearch.tasks.TaskManager;
Expand Down Expand Up @@ -85,13 +86,17 @@ public void testDynamicActionRegistryWithNamedRoutes() {
RestSendToExtensionAction action2 = mock(RestSendToExtensionAction.class);
NamedRoute r1 = new NamedRoute.Builder().method(RestRequest.Method.GET).path("/foo").uniqueName("foo").build();
NamedRoute r2 = new NamedRoute.Builder().method(RestRequest.Method.PUT).path("/bar").uniqueName("bar").build();
RestHandler.Route r3 = new RestHandler.Route(RestRequest.Method.DELETE, "/foo");

DynamicActionRegistry registry = new DynamicActionRegistry();
registry.registerDynamicRoute(r1, action);
registry.registerDynamicRoute(r2, action2);

assertTrue(registry.isActionRegistered("foo"));
assertEquals(action, registry.get(r1));
assertTrue(registry.isActionRegistered("bar"));
assertEquals(action2, registry.get(r2));
assertNull(registry.get(r3));

registry.unregisterDynamicRoute(r2);

Expand Down

0 comments on commit 6152afe

Please sign in to comment.