diff --git a/x-pack/plugin/eql/qa/common/src/main/java/org/elasticsearch/test/eql/EqlRestValidationTestCase.java b/x-pack/plugin/eql/qa/common/src/main/java/org/elasticsearch/test/eql/EqlRestValidationTestCase.java index a011231729f37..207cc23f0f9bd 100644 --- a/x-pack/plugin/eql/qa/common/src/main/java/org/elasticsearch/test/eql/EqlRestValidationTestCase.java +++ b/x-pack/plugin/eql/qa/common/src/main/java/org/elasticsearch/test/eql/EqlRestValidationTestCase.java @@ -52,13 +52,59 @@ public void prepareIndices() throws IOException { assertOK(provisioningAdminClient().performRequest(new Request("POST", "/" + indexName + "/_refresh"))); } - protected abstract String getInexistentIndexErrorMessage(); + protected abstract boolean isSecurityEnabled(); + + protected String getInexistentIndexErrorMessage() { + if (isSecurityEnabled()) { + return "\"root_cause\":[{\"type\":\"verification_exception\",\"reason\":\"Found 1 problem\\nline -1:-1: Unknown index "; + } else { + return "\"root_cause\":[{\"type\":\"verification_exception\",\"reason\":\"Found 1 problem\\nline -1:-1: Unknown index "; + } + } protected String getInexistentWildcardErrorMessage() { - return getInexistentIndexErrorMessage(); + if (isSecurityEnabled()) { + return """ + "root_cause":[{"type":"verification_exception","reason":"Found 1 problem\\nline -1:-1: Unknown index [*,-*]"}],\ + "type":"index_not_found_exception","reason":"no such index\s"""; + } else { + return getInexistentIndexErrorMessage(); + } } - protected abstract void assertErrorMessageWhenAllowNoIndicesIsFalse(String reqParameter) throws IOException; + protected void assertErrorMessageWhenAllowNoIndicesIsFalse(String reqParameter) throws IOException { + if (isSecurityEnabled()) { + assertErrorMessage("inexistent1*", reqParameter, """ + "root_cause":[{"type":"index_not_found_exception","reason":"no such index [inexistent1*]\""""); + assertErrorMessage("inexistent1*,inexistent2*", reqParameter, """ + "root_cause":[{"type":"index_not_found_exception","reason":"no such index [inexistent1*]\""""); + assertErrorMessage("test_eql,inexistent*", reqParameter, """ + "root_cause":[{"type":"index_not_found_exception","reason":"no such index [inexistent*]\""""); + // TODO: revisit the next two tests when https://github.com/elastic/elasticsearch/issues/64190 is closed + assertErrorMessage("inexistent", reqParameter, """ + "root_cause":[{"type":"index_not_found_exception","reason":"no such index [inexistent]\""""); + assertErrorMessage("inexistent1,inexistent2", reqParameter, """ + "root_cause":[{"type":"index_not_found_exception","reason":"no such index [null]\""""); + } else { + assertErrorMessage("inexistent1*", reqParameter, """ + "root_cause":[{"type":"index_not_found_exception","reason":"no such index [inexistent1*]\""""); + assertErrorMessage("inexistent1*,inexistent2*", reqParameter, """ + "root_cause":[{"type":"index_not_found_exception","reason":"no such index [inexistent1*]\""""); + assertErrorMessage("test_eql,inexistent*", reqParameter, """ + "root_cause":[{"type":"index_not_found_exception","reason":"no such index [inexistent*]\""""); + assertErrorMessage("inexistent", reqParameter, """ + "root_cause":[{"type":"index_not_found_exception","reason":"no such index [inexistent]\""""); + // TODO: revisit after + // https://github.com/elastic/elasticsearch/issues/64197 + // is closed + assertErrorMessage( + "inexistent1,inexistent2", + reqParameter, + "\"root_cause\":[{\"type\":\"index_not_found_exception\",\"reason\":\"no such index [null]\"," + + "\"resource.type\":\"index_expression\",\"resource.id\":[\"inexistent1\",\"inexistent2\"]}]" + ); + } + } public void testDefaultIndicesOptions() throws IOException { assertErrorMessages(inexistentIndexNameWithWildcard, EMPTY, getInexistentWildcardErrorMessage()); diff --git a/x-pack/plugin/eql/qa/common/src/main/java/org/elasticsearch/test/eql/RemoteClusterAwareEqlRestTestCase.java b/x-pack/plugin/eql/qa/common/src/main/java/org/elasticsearch/test/eql/RemoteClusterAwareEqlRestTestCase.java index 739f3fc83cd1e..04182bbeb3d7f 100644 --- a/x-pack/plugin/eql/qa/common/src/main/java/org/elasticsearch/test/eql/RemoteClusterAwareEqlRestTestCase.java +++ b/x-pack/plugin/eql/qa/common/src/main/java/org/elasticsearch/test/eql/RemoteClusterAwareEqlRestTestCase.java @@ -119,7 +119,7 @@ protected static void deleteIndexWithProvisioningClient(String name) throws IOEx @Override protected Settings restClientSettings() { - return secureRemoteClientSettings(); + return Settings.builder().put(super.restClientSettings()).put(secureRemoteClientSettings()).build(); } protected static Settings secureRemoteClientSettings() { diff --git a/x-pack/plugin/eql/qa/common/src/main/java/org/elasticsearch/test/eql/stats/EqlUsageRestTestCase.java b/x-pack/plugin/eql/qa/common/src/main/java/org/elasticsearch/test/eql/stats/EqlUsageRestTestCase.java index 7c1804f2a5a32..b7a9bb2919a71 100644 --- a/x-pack/plugin/eql/qa/common/src/main/java/org/elasticsearch/test/eql/stats/EqlUsageRestTestCase.java +++ b/x-pack/plugin/eql/qa/common/src/main/java/org/elasticsearch/test/eql/stats/EqlUsageRestTestCase.java @@ -9,9 +9,6 @@ import org.elasticsearch.client.Request; import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.common.settings.SecureString; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.test.eql.DataLoader; import org.elasticsearch.test.rest.ESRestTestCase; @@ -390,9 +387,4 @@ private RestHighLevelClient highLevelClient() { return highLevelClient; } - @Override - protected Settings restClientSettings() { - String token = basicAuthHeaderValue("admin", new SecureString("admin-password".toCharArray())); - return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build(); - } } diff --git a/x-pack/plugin/eql/qa/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/eql/EqlRestValidationIT.java b/x-pack/plugin/eql/qa/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/eql/EqlRestValidationIT.java index a9f1d22ce0969..fd52776f65f00 100644 --- a/x-pack/plugin/eql/qa/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/eql/EqlRestValidationIT.java +++ b/x-pack/plugin/eql/qa/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/eql/EqlRestValidationIT.java @@ -20,6 +20,11 @@ protected String getInexistentIndexErrorMessage() { return "\"root_cause\":[{\"type\":\"index_not_found_exception\",\"reason\":\"no such index "; } + @Override + protected boolean isSecurityEnabled() { + return true; + } + protected void assertErrorMessageWhenAllowNoIndicesIsFalse(String reqParameter) throws IOException { assertErrorMessage("inexistent1*", reqParameter, getInexistentIndexErrorMessage() + "[" + indexPattern("inexistent1*") + "]\""); assertErrorMessage( diff --git a/x-pack/plugin/eql/qa/rest/src/javaRestTest/java/org/elasticsearch/xpack/eql/EqlRestIT.java b/x-pack/plugin/eql/qa/rest/src/javaRestTest/java/org/elasticsearch/xpack/eql/EqlRestIT.java index ed019f5cb1317..0343f41dd4147 100644 --- a/x-pack/plugin/eql/qa/rest/src/javaRestTest/java/org/elasticsearch/xpack/eql/EqlRestIT.java +++ b/x-pack/plugin/eql/qa/rest/src/javaRestTest/java/org/elasticsearch/xpack/eql/EqlRestIT.java @@ -7,9 +7,6 @@ package org.elasticsearch.xpack.eql; -import org.elasticsearch.common.settings.SecureString; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.test.eql.EqlRestTestCase; import org.junit.ClassRule; @@ -24,9 +21,4 @@ protected String getTestRestCluster() { return cluster.getHttpAddresses(); } - @Override - protected Settings restClientSettings() { - String token = basicAuthHeaderValue("admin", new SecureString("admin-password".toCharArray())); - return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build(); - } } diff --git a/x-pack/plugin/eql/qa/rest/src/javaRestTest/java/org/elasticsearch/xpack/eql/EqlRestValidationIT.java b/x-pack/plugin/eql/qa/rest/src/javaRestTest/java/org/elasticsearch/xpack/eql/EqlRestValidationIT.java index 46fd25d2f163c..009842b2bbe79 100644 --- a/x-pack/plugin/eql/qa/rest/src/javaRestTest/java/org/elasticsearch/xpack/eql/EqlRestValidationIT.java +++ b/x-pack/plugin/eql/qa/rest/src/javaRestTest/java/org/elasticsearch/xpack/eql/EqlRestValidationIT.java @@ -11,8 +11,6 @@ import org.elasticsearch.test.eql.EqlRestValidationTestCase; import org.junit.ClassRule; -import java.io.IOException; - public class EqlRestValidationIT extends EqlRestValidationTestCase { @ClassRule @@ -24,27 +22,7 @@ protected String getTestRestCluster() { } @Override - protected String getInexistentIndexErrorMessage() { - return "\"root_cause\":[{\"type\":\"verification_exception\",\"reason\":\"Found 1 problem\\nline -1:-1: Unknown index "; - } - - protected void assertErrorMessageWhenAllowNoIndicesIsFalse(String reqParameter) throws IOException { - assertErrorMessage("inexistent1*", reqParameter, """ - "root_cause":[{"type":"index_not_found_exception","reason":"no such index [inexistent1*]\""""); - assertErrorMessage("inexistent1*,inexistent2*", reqParameter, """ - "root_cause":[{"type":"index_not_found_exception","reason":"no such index [inexistent1*]\""""); - assertErrorMessage("test_eql,inexistent*", reqParameter, """ - "root_cause":[{"type":"index_not_found_exception","reason":"no such index [inexistent*]\""""); - assertErrorMessage("inexistent", reqParameter, """ - "root_cause":[{"type":"index_not_found_exception","reason":"no such index [inexistent]\""""); - // TODO: revisit after - // https://github.com/elastic/elasticsearch/issues/64197 - // is closed - assertErrorMessage( - "inexistent1,inexistent2", - reqParameter, - "\"root_cause\":[{\"type\":\"index_not_found_exception\",\"reason\":\"no such index [null]\"," - + "\"resource.type\":\"index_expression\",\"resource.id\":[\"inexistent1\",\"inexistent2\"]}]" - ); + protected boolean isSecurityEnabled() { + return cluster.isSecurityEnabled(); } } diff --git a/x-pack/plugin/eql/qa/security/src/javaRestTest/java/org/elasticsearch/xpack/eql/EqlRestValidationIT.java b/x-pack/plugin/eql/qa/security/src/javaRestTest/java/org/elasticsearch/xpack/eql/EqlRestValidationIT.java index 8887536379c3b..0689f9913ddb2 100644 --- a/x-pack/plugin/eql/qa/security/src/javaRestTest/java/org/elasticsearch/xpack/eql/EqlRestValidationIT.java +++ b/x-pack/plugin/eql/qa/security/src/javaRestTest/java/org/elasticsearch/xpack/eql/EqlRestValidationIT.java @@ -12,8 +12,6 @@ import org.elasticsearch.test.eql.EqlRestValidationTestCase; import org.junit.ClassRule; -import java.io.IOException; - import static org.elasticsearch.xpack.eql.SecurityUtils.secureClientSettings; public class EqlRestValidationIT extends EqlRestValidationTestCase { @@ -31,30 +29,7 @@ protected Settings restClientSettings() { } @Override - protected String getInexistentIndexErrorMessage() { - return "\"root_cause\":[{\"type\":\"verification_exception\",\"reason\":\"Found 1 problem\\nline -1:-1: Unknown index "; - } - - @Override - protected String getInexistentWildcardErrorMessage() { - return """ - "root_cause":[{"type":"verification_exception","reason":"Found 1 problem\\nline -1:-1: Unknown index [*,-*]"}],\ - "type":"index_not_found_exception","reason":"no such index\s"""; + protected boolean isSecurityEnabled() { + return true; } - - @Override - protected void assertErrorMessageWhenAllowNoIndicesIsFalse(String reqParameter) throws IOException { - assertErrorMessage("inexistent1*", reqParameter, """ - "root_cause":[{"type":"index_not_found_exception","reason":"no such index [inexistent1*]\""""); - assertErrorMessage("inexistent1*,inexistent2*", reqParameter, """ - "root_cause":[{"type":"index_not_found_exception","reason":"no such index [inexistent1*]\""""); - assertErrorMessage("test_eql,inexistent*", reqParameter, """ - "root_cause":[{"type":"index_not_found_exception","reason":"no such index [inexistent*]\""""); - // TODO: revisit the next two tests when https://github.com/elastic/elasticsearch/issues/64190 is closed - assertErrorMessage("inexistent", reqParameter, """ - "root_cause":[{"type":"index_not_found_exception","reason":"no such index [inexistent]\""""); - assertErrorMessage("inexistent1,inexistent2", reqParameter, """ - "root_cause":[{"type":"index_not_found_exception","reason":"no such index [null]\""""); - } - }