Browse Source

Migrate ESQL security QA to new framework (#103745)

This PR migrates the ESQL security QA module to the 
new test framework.
Nhat Nguyen 1 year ago
parent
commit
6165c71d2c

+ 0 - 1
build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/RestrictedBuildApiService.java

@@ -123,7 +123,6 @@ public abstract class RestrictedBuildApiService implements BuildService<Restrict
         map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:eql:qa:ccs-rolling-upgrade");
         map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:eql:qa:correctness");
         map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:eql:qa:mixed-node");
-        map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:esql:qa:security");
         map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:esql:qa:server:heap-attack");
         map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:esql:qa:server:multi-node");
         map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:esql:qa:server:single-node");

+ 3 - 14
x-pack/plugin/esql/qa/security/build.gradle

@@ -1,16 +1,5 @@
-apply plugin: 'elasticsearch.legacy-java-rest-test'
+apply plugin: 'elasticsearch.internal-java-rest-test'
 
-testClusters.configureEach {
-  testDistribution = 'DEFAULT'
-  setting 'xpack.license.self_generated.type', 'trial'
-  setting 'xpack.monitoring.collection.enabled', 'false'
-  setting 'xpack.security.enabled', 'true'
-  numberOfNodes = 1
-  extraConfigFile 'roles.yml', file('roles.yml')
-  user username: "test-admin", password: 'x-pack-test-password', role: "test-admin"
-  user username: "user1", password: 'x-pack-test-password', role: "user1"
-  user username: "user2", password: 'x-pack-test-password', role: "user2"
-  user username: "user3", password: 'x-pack-test-password', role: "user3"
-  user username: "user4", password: 'x-pack-test-password', role: "user4"
-  user username: "user5", password: 'x-pack-test-password', role: "user5"
+tasks.named('javaRestTest') {
+  usesDefaultDistribution()
 }

+ 24 - 0
x-pack/plugin/esql/qa/security/src/javaRestTest/java/org/elasticsearch/xpack/esql/EsqlSecurityIT.java

@@ -17,10 +17,14 @@ import org.elasticsearch.common.Strings;
 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.cluster.local.distribution.DistributionType;
+import org.elasticsearch.test.cluster.util.resource.Resource;
 import org.elasticsearch.test.rest.ESRestTestCase;
 import org.elasticsearch.xcontent.XContentBuilder;
 import org.elasticsearch.xcontent.json.JsonXContent;
 import org.junit.Before;
+import org.junit.ClassRule;
 
 import java.io.IOException;
 import java.util.List;
@@ -31,6 +35,26 @@ import static org.hamcrest.Matchers.equalTo;
 
 public class EsqlSecurityIT extends ESRestTestCase {
 
+    @ClassRule
+    public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
+        .distribution(DistributionType.DEFAULT)
+        .nodes(2)
+        .setting("xpack.license.self_generated.type", "trial")
+        .setting("xpack.security.enabled", "true")
+        .rolesFile(Resource.fromClasspath("roles.yml"))
+        .user("test-admin", "x-pack-test-password", "test-admin", false)
+        .user("user1", "x-pack-test-password", "user1", false)
+        .user("user2", "x-pack-test-password", "user2", false)
+        .user("user3", "x-pack-test-password", "user3", false)
+        .user("user4", "x-pack-test-password", "user4", false)
+        .user("user5", "x-pack-test-password", "user5", false)
+        .build();
+
+    @Override
+    protected String getTestRestCluster() {
+        return cluster.getHttpAddresses();
+    }
+
     @Override
     protected Settings restClientSettings() {
         String token = basicAuthHeaderValue("test-admin", new SecureString("x-pack-test-password".toCharArray()));

+ 0 - 0
x-pack/plugin/esql/qa/security/roles.yml → x-pack/plugin/esql/qa/security/src/javaRestTest/resources/roles.yml