Browse Source

Convert security-trial to internal rest test (#99036)

Converts x-pack/plugin/security/qa/security-trial from legacy java rest
test to internal java rest test framework
Tim Vernum 2 năm trước cách đây
mục cha
commit
22499a91d8

+ 4 - 25
x-pack/plugin/security/qa/security-trial/build.gradle

@@ -1,6 +1,6 @@
 import org.elasticsearch.gradle.Version
 
-apply plugin: 'elasticsearch.legacy-java-rest-test'
+apply plugin: 'elasticsearch.internal-java-rest-test'
 
 dependencies {
   javaRestTestImplementation project(path: xpackModule('core'))
@@ -9,28 +9,7 @@ dependencies {
   javaRestTestImplementation project(":client:rest-high-level")
 }
 
-testClusters.matching { it.name == 'javaRestTest' }.configureEach {
-  testDistribution = 'DEFAULT'
-  numberOfNodes = 2
-
-  setting 'xpack.ml.enabled', 'false'
-  setting 'xpack.license.self_generated.type', 'trial'
-  setting 'xpack.security.enabled', 'true'
-  setting 'xpack.security.ssl.diagnose.trust', 'true'
-  setting 'xpack.security.http.ssl.enabled', 'false'
-  setting 'xpack.security.transport.ssl.enabled', 'false'
-  setting 'xpack.security.authc.token.enabled', 'true'
-  setting 'xpack.security.authc.api_key.enabled', 'true'
-  setting 'xpack.security.remote_cluster_client.ssl.enabled', 'false'
-
-  keystore 'cluster.remote.my_remote_cluster_a.credentials', 'cluster_a_credentials'
-  keystore 'cluster.remote.my_remote_cluster_b.credentials', 'cluster_b_credentials'
-  keystore 'cluster.remote.my_remote_cluster_a_1.credentials', 'cluster_a_credentials'
-  keystore 'cluster.remote.my_remote_cluster_a_2.credentials', 'cluster_a_credentials'
-
-  rolesFile file('src/javaRestTest/resources/roles.yml')
-  user username: "admin_user", password: "admin-password"
-  user username: "security_test_user", password: "security-test-password", role: "security_test_role"
-  user username: "x_pack_rest_user", password: "x-pack-test-password"
-  user username: "cat_test_user", password: "cat-test-password", role: "cat_test_role"
+tasks.named('javaRestTest') {
+  usesDefaultDistribution()
 }
+

+ 35 - 0
x-pack/plugin/security/qa/security-trial/src/javaRestTest/java/org/elasticsearch/xpack/security/SecurityOnTrialLicenseRestTestCase.java

@@ -12,19 +12,54 @@ import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.util.concurrent.ThreadContext;
 import org.elasticsearch.core.Tuple;
 import org.elasticsearch.test.TestSecurityClient;
+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.xpack.core.security.action.apikey.ApiKey;
 import org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken;
 import org.elasticsearch.xpack.core.security.authz.RoleDescriptor;
 import org.elasticsearch.xpack.core.security.user.User;
+import org.junit.ClassRule;
 
 import java.io.IOException;
 import java.util.Collection;
 import java.util.List;
 
+import static org.elasticsearch.test.cluster.local.model.User.ROOT_USER_ROLE;
+
 public abstract class SecurityOnTrialLicenseRestTestCase extends ESRestTestCase {
     private TestSecurityClient securityClient;
 
+    @ClassRule
+    public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
+        .nodes(2)
+        .distribution(DistributionType.DEFAULT)
+        .setting("xpack.ml.enabled", "false")
+        .setting("xpack.license.self_generated.type", "trial")
+        .setting("xpack.security.enabled", "true")
+        .setting("xpack.security.ssl.diagnose.trust", "true")
+        .setting("xpack.security.http.ssl.enabled", "false")
+        .setting("xpack.security.transport.ssl.enabled", "false")
+        .setting("xpack.security.authc.token.enabled", "true")
+        .setting("xpack.security.authc.api_key.enabled", "true")
+        .setting("xpack.security.remote_cluster_client.ssl.enabled", "false")
+        .keystore("cluster.remote.my_remote_cluster_a.credentials", "cluster_a_credentials")
+        .keystore("cluster.remote.my_remote_cluster_b.credentials", "cluster_b_credentials")
+        .keystore("cluster.remote.my_remote_cluster_a_1.credentials", "cluster_a_credentials")
+        .keystore("cluster.remote.my_remote_cluster_a_2.credentials", "cluster_a_credentials")
+        .rolesFile(Resource.fromClasspath("roles.yml"))
+        .user("admin_user", "admin-password", ROOT_USER_ROLE, true)
+        .user("security_test_user", "security-test-password", "security_test_role", false)
+        .user("x_pack_rest_user", "x-pack-test-password", ROOT_USER_ROLE, true)
+        .user("cat_test_user", "cat-test-password", "cat_test_role", false)
+        .build();
+
+    @Override
+    protected String getTestRestCluster() {
+        return cluster.getHttpAddresses();
+    }
+
     @Override
     protected Settings restAdminSettings() {
         String token = basicAuthHeaderValue("admin_user", new SecureString("admin-password".toCharArray()));

+ 3 - 2
x-pack/plugin/security/qa/security-trial/src/javaRestTest/java/org/elasticsearch/xpack/test/rest/CatIndicesWithSecurityIT.java

@@ -14,13 +14,14 @@ import org.elasticsearch.common.settings.SecureString;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.util.concurrent.ThreadContext;
 import org.elasticsearch.test.SecuritySettingsSourceField;
-import org.elasticsearch.test.rest.ESRestTestCase;
+import org.elasticsearch.xpack.security.SecurityOnTrialLicenseRestTestCase;
 
 import java.io.IOException;
 
 import static org.hamcrest.Matchers.matchesRegex;
 
-public class CatIndicesWithSecurityIT extends ESRestTestCase {
+public class CatIndicesWithSecurityIT extends SecurityOnTrialLicenseRestTestCase {
+
     @Override
     protected Settings restAdminSettings() {
         String token = basicAuthHeaderValue("x_pack_rest_user", SecuritySettingsSourceField.TEST_PASSWORD_SECURE_STRING);