Skip to content

Commit

Permalink
Catch and respond invalid index name exception when an index with inv…
Browse files Browse the repository at this point in the history
…alid name is mentioned (#865)

(cherry picked from commit 7c5dbb9)
  • Loading branch information
cliu123 authored and sujithvm committed Mar 18, 2021
1 parent b3ea671 commit 0d62a97
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ public void onFailure(Exception e) {
listener.onFailure(new ElasticsearchSecurityException("no permissions for " + pres.getMissingPrivileges()+ " and "+user, RestStatus.FORBIDDEN));
return;
}
} catch (ElasticsearchException e) {
if (task != null) {
log.debug("Failed to apply filter. Task id: {} ({}). Action: {}", task.getId(), task.getDescription(), action, e);
} else {
log.debug("Failed to apply filter. Action: {}", action, e);
}
listener.onFailure(e);
} catch (Throwable e) {
log.error("Unexpected exception "+e, e);
listener.onFailure(new ElasticsearchSecurityException("Unexpected exception " + action, RestStatus.INTERNAL_SERVER_ERROR));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

package com.amazon.opendistroforelasticsearch.security;

import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
Expand Down Expand Up @@ -456,6 +457,17 @@ public void testAliasResolution() throws Exception {
Assert.assertEquals(HttpStatus.SC_OK, rh.executeGetRequest(".ki*ana/_search?pretty", encodeBasicHeader("aliastest", "nagilum")).getStatusCode());
Assert.assertEquals(HttpStatus.SC_OK, rh.executeGetRequest(".kibana/_search?pretty", encodeBasicHeader("aliastest", "nagilum")).getStatusCode());
}

@Test
public void testIndexResolveInvalidIndexName() throws Exception {
setup();
final RestHelper rh = nonSslRestHelper();

// invalid_index_name_exception should be thrown and responded when invalid index name is mentioned in requests.
HttpResponse res = rh.executeGetRequest(URLEncoder.encode("_##pdt_data/_search", "UTF-8"), encodeBasicHeader("ccsresolv", "nagilum"));
Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, res.getStatusCode());
Assert.assertTrue(res.getBody().contains("invalid_index_name_exception"));
}

@Test
public void testCCSIndexResolve() throws Exception {
Expand Down

0 comments on commit 0d62a97

Please sign in to comment.