diff --git a/integ-test/build.gradle b/integ-test/build.gradle index f188a2e773..ea80847f8f 100644 --- a/integ-test/build.gradle +++ b/integ-test/build.gradle @@ -392,7 +392,6 @@ task integTestWithSecurity(type: RestIntegTestTask) { configureSecurityPlugin(cluster) } - useJUnitPlatform() dependsOn ':opensearch-sql-plugin:bundlePlugin' testLogging { events "passed", "skipped", "failed" @@ -433,11 +432,8 @@ task integTestWithSecurity(type: RestIntegTestTask) { jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005' } - // NOTE: this IT config discovers only junit5 (jupiter) tests. - // https://github.com/opensearch-project/sql/issues/1974 filter { - includeTestsMatching 'org.opensearch.sql.security.CrossClusterSearchIT' - includeTestsMatching 'org.opensearch.sql.security.PPLPermissionsIT' + includeTestsMatching 'org.opensearch.sql.security.*' } } diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/OpenSearchSQLRestTestCase.java b/integ-test/src/test/java/org/opensearch/sql/legacy/OpenSearchSQLRestTestCase.java index ce118031e1..6f13890fd5 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/OpenSearchSQLRestTestCase.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/OpenSearchSQLRestTestCase.java @@ -272,7 +272,9 @@ protected static void configureHttpsClient(RestClientBuilder builder, Settings s * cluster. */ public void configureMultiClusters(String remote) throws IOException { - initRemoteClient(remote); + if (remoteClient == null) { + initRemoteClient(remote); + } Request connectionRequest = new Request("PUT", "_cluster/settings"); String connectionSetting = diff --git a/integ-test/src/test/java/org/opensearch/sql/security/CalciteCrossClusterSearchIT.java b/integ-test/src/test/java/org/opensearch/sql/security/CalciteCrossClusterSearchIT.java index 4ce012b11c..b89574a4fd 100644 --- a/integ-test/src/test/java/org/opensearch/sql/security/CalciteCrossClusterSearchIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/security/CalciteCrossClusterSearchIT.java @@ -5,9 +5,6 @@ package org.opensearch.sql.security; -import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ACCOUNT; -import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK; -import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DOG; import static org.opensearch.sql.util.MatcherUtils.columnName; import static org.opensearch.sql.util.MatcherUtils.rows; import static org.opensearch.sql.util.MatcherUtils.schema; @@ -16,51 +13,21 @@ import static org.opensearch.sql.util.MatcherUtils.verifySchema; import java.io.IOException; -import lombok.SneakyThrows; import org.json.JSONObject; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.opensearch.sql.ppl.PPLIntegTestCase; +import org.junit.Test; /** Cross Cluster Search tests with Calcite enabled for enhanced fields features. */ -public class CalciteCrossClusterSearchIT extends PPLIntegTestCase { - - static { - String[] clusterNames = System.getProperty("cluster.names").split(","); - var remote = "remoteCluster"; - for (var cluster : clusterNames) { - if (cluster.startsWith("remote")) { - remote = cluster; - break; - } - } - REMOTE_CLUSTER = remote; - } - - public static final String REMOTE_CLUSTER; - private static final String TEST_INDEX_ACCOUNT_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_ACCOUNT; - private static final String TEST_INDEX_DOG_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_DOG; - private static final String TEST_INDEX_BANK_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_BANK; - private static boolean initialized = false; - - @SneakyThrows - @BeforeEach - public void initialize() { - if (!initialized) { - setUpIndices(); - initialized = true; - } - } +public class CalciteCrossClusterSearchIT extends CrossClusterTestBase { @Override protected void init() throws Exception { - configureMultiClusters(REMOTE_CLUSTER); + super.init(); loadIndex(Index.BANK); loadIndex(Index.BANK, remoteClient()); - loadIndex(Index.ACCOUNT); - loadIndex(Index.ACCOUNT, remoteClient()); loadIndex(Index.DOG); loadIndex(Index.DOG, remoteClient()); + loadIndex(Index.ACCOUNT); + loadIndex(Index.ACCOUNT, remoteClient()); loadIndex(Index.TIME_TEST_DATA); loadIndex(Index.TIME_TEST_DATA, remoteClient()); enableCalcite(); @@ -87,8 +54,8 @@ public void testCrossClusterFieldsWildcardPrefix() throws IOException { public void testCrossClusterFieldsWildcardSuffix() throws IOException { JSONObject result = executeQuery(String.format("search source=%s | fields *Name", TEST_INDEX_DOG_REMOTE)); - verifyColumn(result, columnName("dog_name"), columnName("holdersName")); - verifySchema(result, schema("dog_name", "string"), schema("holdersName", "string")); + verifyColumn(result, columnName("holdersName")); + verifySchema(result, schema("holdersName", "string")); } @Test @@ -165,7 +132,7 @@ public void testDefaultBinCrossCluster() throws IOException { TEST_INDEX_ACCOUNT_REMOTE)); verifySchema(result, schema("count()", null, "bigint"), schema("age", null, "string")); - verifyDataRows(result, rows(451L, "20-30"), rows(504L, "30-40"), rows(45L, "40-50")); + verifyDataRows(result, rows(451, "20.0-30.0"), rows(504L, "30.0-40.0"), rows(45L, "40.0-50.0")); } @Test @@ -218,7 +185,7 @@ public void testRangeBinCrossCluster() throws IOException { TEST_INDEX_ACCOUNT_REMOTE)); verifySchema(result, schema("count()", null, "bigint"), schema("age", null, "string")); - verifyDataRows(result, rows(1000L, "0-100")); + verifyDataRows(result, rows(451, "20-30"), rows(504L, "30-40"), rows(45L, "40-50")); } @Test @@ -226,10 +193,10 @@ public void testTimeBinCrossCluster() throws IOException { // Time-based binning with span JSONObject result = executeQuery( - REMOTE_CLUSTER - + ":opensearch-sql_test_index_time_data" - + " | bin @timestamp span=1h" - + " | fields `@timestamp`, value | sort `@timestamp` | head 3"); + String.format( + "source=%s | bin @timestamp span=1h | fields `@timestamp`, value | sort" + + " `@timestamp` | head 3", + TEST_INDEX_TIME_DATA_REMOTE)); verifySchema(result, schema("@timestamp", null, "timestamp"), schema("value", null, "int")); // With 1-hour spans @@ -285,12 +252,27 @@ public void testCrossClusterRenameFullWildcard() throws IOException { JSONObject result = executeQuery(String.format("search source=%s | rename * as old_*", TEST_INDEX_DOG_REMOTE)); verifyColumn( - result, columnName("old_dog_name"), columnName("old_holdersName"), columnName("old_age")); + result, + columnName("old_dog_name"), + columnName("old_holdersName"), + columnName("old_age"), + columnName("old__id"), + columnName("old__index"), + columnName("old__score"), + columnName("old__maxscore"), + columnName("old__sort"), + columnName("old__routing")); verifySchema( result, schema("old_dog_name", "string"), schema("old_holdersName", "string"), - schema("old_age", "bigint")); + schema("old_age", "bigint"), + schema("old__id", "string"), + schema("old__index", "string"), + schema("old__score", "float"), + schema("old__maxscore", "float"), + schema("old__sort", "bigint"), + schema("old__routing", "string")); } @Test diff --git a/integ-test/src/test/java/org/opensearch/sql/security/CrossClusterCoalesceIT.java b/integ-test/src/test/java/org/opensearch/sql/security/CrossClusterCoalesceIT.java index 530dccd528..74d6be236d 100644 --- a/integ-test/src/test/java/org/opensearch/sql/security/CrossClusterCoalesceIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/security/CrossClusterCoalesceIT.java @@ -5,50 +5,21 @@ package org.opensearch.sql.security; -import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DOG; import static org.opensearch.sql.util.MatcherUtils.columnName; import static org.opensearch.sql.util.MatcherUtils.verifyColumn; import java.io.IOException; -import lombok.SneakyThrows; import org.json.JSONObject; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.opensearch.sql.ppl.PPLIntegTestCase; +import org.junit.Test; -public class CrossClusterCoalesceIT extends PPLIntegTestCase { - - static { - String[] clusterNames = System.getProperty("cluster.names").split(","); - var remote = "remoteCluster"; - for (var cluster : clusterNames) { - if (cluster.startsWith("remote")) { - remote = cluster; - break; - } - } - REMOTE_CLUSTER = remote; - } - - public static final String REMOTE_CLUSTER; - private static final String TEST_INDEX_DOG_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_DOG; - private static boolean initialized = false; - - @SneakyThrows - @BeforeEach - public void initialize() { - if (!initialized) { - setUpIndices(); - initialized = true; - } - } +public class CrossClusterCoalesceIT extends CrossClusterTestBase { @Override protected void init() throws Exception { - enableCalcite(); - configureMultiClusters(REMOTE_CLUSTER); + super.init(); loadIndex(Index.DOG); loadIndex(Index.DOG, remoteClient()); + enableCalcite(); } @Test diff --git a/integ-test/src/test/java/org/opensearch/sql/security/CrossClusterSearchIT.java b/integ-test/src/test/java/org/opensearch/sql/security/CrossClusterSearchIT.java index af1c08e861..abdbb616e2 100644 --- a/integ-test/src/test/java/org/opensearch/sql/security/CrossClusterSearchIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/security/CrossClusterSearchIT.java @@ -5,60 +5,23 @@ package org.opensearch.sql.security; -import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ACCOUNT; import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK; -import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DOG; import static org.opensearch.sql.util.MatcherUtils.columnName; import static org.opensearch.sql.util.MatcherUtils.rows; import static org.opensearch.sql.util.MatcherUtils.verifyColumn; import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; import java.io.IOException; -import lombok.SneakyThrows; import org.json.JSONObject; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.Test; import org.opensearch.client.ResponseException; -import org.opensearch.sql.ppl.PPLIntegTestCase; /** Cross Cluster Search tests to be executed with security plugin. */ -public class CrossClusterSearchIT extends PPLIntegTestCase { - - static { - // find a remote cluster - String[] clusterNames = System.getProperty("cluster.names").split(","); - var remote = "remoteCluster"; - for (var cluster : clusterNames) { - if (cluster.startsWith("remote")) { - remote = cluster; - break; - } - } - REMOTE_CLUSTER = remote; - } - - public static final String REMOTE_CLUSTER; - - private static final String TEST_INDEX_BANK_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_BANK; - private static final String TEST_INDEX_DOG_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_DOG; - private static final String TEST_INDEX_DOG_MATCH_ALL_REMOTE = - MATCH_ALL_REMOTE_CLUSTER + ":" + TEST_INDEX_DOG; - private static final String TEST_INDEX_ACCOUNT_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_ACCOUNT; - - private static boolean initialized = false; - - @SneakyThrows - @BeforeEach - public void initialize() { - if (!initialized) { - setUpIndices(); - initialized = true; - } - } +public class CrossClusterSearchIT extends CrossClusterTestBase { @Override protected void init() throws Exception { - configureMultiClusters(REMOTE_CLUSTER); + super.init(); loadIndex(Index.BANK); loadIndex(Index.BANK, remoteClient()); loadIndex(Index.DOG); diff --git a/integ-test/src/test/java/org/opensearch/sql/security/CrossClusterTestBase.java b/integ-test/src/test/java/org/opensearch/sql/security/CrossClusterTestBase.java new file mode 100644 index 0000000000..d9de95c663 --- /dev/null +++ b/integ-test/src/test/java/org/opensearch/sql/security/CrossClusterTestBase.java @@ -0,0 +1,45 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.sql.security; + +import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ACCOUNT; +import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK; +import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DOG; +import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_TIME_DATA; + +import org.opensearch.sql.ppl.PPLIntegTestCase; + +public class CrossClusterTestBase extends PPLIntegTestCase { + static { + // find a remote cluster + String[] clusterNames = System.getProperty("cluster.names").split(","); + var remote = "remoteCluster"; + for (var cluster : clusterNames) { + if (cluster.startsWith("remote")) { + remote = cluster; + break; + } + } + REMOTE_CLUSTER = remote; + } + + public static final String REMOTE_CLUSTER; + + protected static final String TEST_INDEX_BANK_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_BANK; + protected static final String TEST_INDEX_DOG_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_DOG; + protected static final String TEST_INDEX_DOG_MATCH_ALL_REMOTE = + MATCH_ALL_REMOTE_CLUSTER + ":" + TEST_INDEX_DOG; + protected static final String TEST_INDEX_ACCOUNT_REMOTE = + REMOTE_CLUSTER + ":" + TEST_INDEX_ACCOUNT; + protected static final String TEST_INDEX_TIME_DATA_REMOTE = + REMOTE_CLUSTER + ":" + TEST_INDEX_TIME_DATA; + + @Override + protected void init() throws Exception { + super.init(); + configureMultiClusters(REMOTE_CLUSTER); + } +} diff --git a/integ-test/src/test/java/org/opensearch/sql/security/PPLPermissionsIT.java b/integ-test/src/test/java/org/opensearch/sql/security/PPLPermissionsIT.java index f6b6347808..243e07c5a3 100644 --- a/integ-test/src/test/java/org/opensearch/sql/security/PPLPermissionsIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/security/PPLPermissionsIT.java @@ -14,10 +14,8 @@ import java.io.IOException; import java.util.Locale; -import lombok.SneakyThrows; import org.json.JSONObject; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.Test; import org.opensearch.client.Request; import org.opensearch.client.RequestOptions; import org.opensearch.client.Response; @@ -59,21 +57,12 @@ public class PPLPermissionsIT extends PPLIntegTestCase { private static final String NO_PIT_USER = "no_pit_user"; private static final String NO_PIT_ROLE = "no_pit_role"; - private static boolean initialized = false; - - @SneakyThrows - @BeforeEach - public void initialize() { - if (!initialized) { - setUpIndices(); - createSecurityRolesAndUsers(); - initialized = true; - } - } + private boolean initialized = false; @Override protected void init() throws Exception { super.init(); + createSecurityRolesAndUsers(); loadIndex(Index.BANK); loadIndex(Index.DOG); // Enable Calcite engine to test PIT behavior with Calcite @@ -87,24 +76,27 @@ protected void init() throws Exception { * access to their specific index. */ private void createSecurityRolesAndUsers() throws IOException { - // Create role for bank index access - createRole(BANK_ROLE, TEST_INDEX_BANK); + if (!initialized) { + // Create role for bank index access + createRole(BANK_ROLE, TEST_INDEX_BANK); - // Create role for dog index access - createRole(DOG_ROLE, TEST_INDEX_DOG); + // Create role for dog index access + createRole(DOG_ROLE, TEST_INDEX_DOG); - // Create users and map them to roles - createUser(BANK_USER, BANK_ROLE); - createUser(DOG_USER, DOG_ROLE); + // Create users and map them to roles + createUser(BANK_USER, BANK_ROLE); + createUser(DOG_USER, DOG_ROLE); - // Create roles for testing missing permissions - createRoleWithMissingPermissions(); + // Create roles for testing missing permissions + createRoleWithMissingPermissions(); - // Create user with minimal permissions for plugin-based PIT testing - createMinimalUserForPitTesting(); + // Create user with minimal permissions for plugin-based PIT testing + createMinimalUserForPitTesting(); - // Create user without PIT permissions to test PIT requirement - createNoPitUserForTesting(); + // Create user without PIT permissions to test PIT requirement + createNoPitUserForTesting(); + initialized = true; + } } private void createRole(String roleName, String indexPattern) throws IOException {