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 (opensearch-project#865) (opensearch-project#1081)

(cherry picked from commit 7c5dbb9)
  • Loading branch information
cliu123 authored Mar 18, 2021
1 parent 27c9970 commit e2e5c7d
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 @@ -336,6 +336,13 @@ public void onFailure(Exception e) {
log.debug("no permissions for {}", pres.getMissingPrivileges());
listener.onFailure(new ElasticsearchSecurityException("no permissions for " + pres.getMissingPrivileges()+ " and "+user, RestStatus.FORBIDDEN));
}
} 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 @@ -455,6 +456,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 e2e5c7d

Please sign in to comment.