Skip to content

Commit 1378a29

Browse files
authored
Fixed rest status for the replication action failure with DLS/FLS and (#1677)
updated test cases to capture status code Signed-off-by: Sai Kumar <[email protected]>
1 parent 920701e commit 1378a29

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/main/java/org/opensearch/security/configuration/DlsFlsValveImpl.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.opensearch.common.util.concurrent.ThreadContext;
5050
import org.opensearch.common.xcontent.NamedXContentRegistry;
5151
import org.opensearch.index.query.ParsedQuery;
52+
import org.opensearch.rest.RestStatus;
5253
import org.opensearch.search.DocValueFormat;
5354
import org.opensearch.search.aggregations.AggregationBuilder;
5455
import org.opensearch.search.aggregations.BucketOrder;
@@ -255,7 +256,8 @@ public boolean invoke(String action, ActionRequest request, final ActionListener
255256
}
256257

257258
if(action.contains("plugins/replication")) {
258-
listener.onFailure(new OpenSearchSecurityException("Cross Cluster Replication is not supported when FLS or DLS or Fieldmasking is activated"));
259+
listener.onFailure(new OpenSearchSecurityException("Cross Cluster Replication is not supported when FLS or DLS or Fieldmasking is activated",
260+
RestStatus.FORBIDDEN));
259261
return false;
260262
}
261263

src/test/java/org/opensearch/security/dlic/dlsfls/CCReplicationTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import org.opensearch.plugins.ActionPlugin;
6060
import org.opensearch.plugins.Plugin;
6161
import org.opensearch.repositories.RepositoriesService;
62+
import org.opensearch.rest.RestStatus;
6263
import org.opensearch.script.ScriptService;
6364
import org.opensearch.security.OpenSearchSecurityPlugin;
6465
import org.opensearch.security.support.ConfigConstants;
@@ -221,6 +222,7 @@ public void testReplication() throws Exception {
221222
log.warn(ex.getMessage());
222223
Assert.assertNotNull(ex);
223224
Assert.assertTrue(ex.getMessage().contains("Cross Cluster Replication is not supported when FLS or DLS or Fieldmasking is activated"));
225+
Assert.assertEquals(ex.status(), RestStatus.FORBIDDEN);
224226
}
225227

226228
try (Node node = new PluginAwareNode(false, tcSettings, Netty4Plugin.class, OpenSearchSecurityPlugin.class, MockReplicationPlugin.class).start()) {
@@ -230,6 +232,7 @@ public void testReplication() throws Exception {
230232
log.warn(ex.getMessage());
231233
Assert.assertNotNull(ex);
232234
Assert.assertTrue(ex.getMessage().contains("Cross Cluster Replication is not supported when FLS or DLS or Fieldmasking is activated"));
235+
Assert.assertEquals(ex.status(), RestStatus.FORBIDDEN);
233236
}
234237

235238
try (Node node = new PluginAwareNode(false, tcSettings, Netty4Plugin.class, OpenSearchSecurityPlugin.class, MockReplicationPlugin.class).start()) {
@@ -239,6 +242,7 @@ public void testReplication() throws Exception {
239242
log.warn(ex.getMessage());
240243
Assert.assertNotNull(ex);
241244
Assert.assertTrue(ex.getMessage().contains("Cross Cluster Replication is not supported when FLS or DLS or Fieldmasking is activated"));
245+
Assert.assertEquals(ex.status(), RestStatus.FORBIDDEN);
242246
}
243247

244248
try (Node node = new PluginAwareNode(false, tcSettings, Netty4Plugin.class, OpenSearchSecurityPlugin.class, MockReplicationPlugin.class).start()) {

0 commit comments

Comments
 (0)