Skip to content

Commit 5535de3

Browse files
authored
Migrate x-pack-enrich legacy rest tests to new test framework (#131743) (#131857)
1 parent 60b7470 commit 5535de3

File tree

16 files changed

+150
-139
lines changed

16 files changed

+150
-139
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ private static ListMultimap<Class<?>, String> createLegacyRestTestBasePluginUsag
5959
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:deprecation:qa:early-deprecation-rest");
6060
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:deprecation:qa:rest");
6161
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:downsample:qa:with-security");
62-
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:enrich:qa:rest");
63-
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:enrich:qa:rest-with-advanced-security");
64-
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:enrich:qa:rest-with-security");
6562
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:ent-search:qa:rest");
6663
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:eql:qa:ccs-rolling-upgrade");
6764
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:eql:qa:correctness");

x-pack/plugin/enrich/build.gradle

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
apply plugin: 'elasticsearch.internal-es-plugin'
22
apply plugin: 'elasticsearch.internal-cluster-test'
3+
apply plugin: 'elasticsearch.internal-java-rest-test'
4+
apply plugin: 'elasticsearch.internal-yaml-rest-test'
5+
36
esplugin {
47
name = 'x-pack-enrich'
58
description = 'Elasticsearch Expanded Pack Plugin - Enrich'
6-
classname ='org.elasticsearch.xpack.enrich.EnrichPlugin'
9+
classname = 'org.elasticsearch.xpack.enrich.EnrichPlugin'
710
extendedPlugins = ['x-pack-core']
811
}
912
base {
@@ -20,6 +23,27 @@ dependencies {
2023
testImplementation project(xpackModule('spatial'))
2124
testImplementation(testArtifact(project(xpackModule('monitoring'))))
2225
internalClusterTestImplementation project(':modules:rest-root')
26+
27+
clusterModules project(':modules:analysis-common')
28+
clusterModules project(':modules:ingest-common')
29+
clusterModules project(':modules:mapper-extras')
30+
31+
clusterModules project(xpackModule('monitoring'))
32+
clusterModules project(xpackModule('ilm'))
33+
clusterModules project(xpackModule('wildcard'))
34+
}
35+
36+
tasks.named('yamlRestTest') {
37+
// single tests can be run using the same cluster configuration as used for Java REST tests, but cleanup inbetween tests fails
38+
usesDefaultDistribution("cleanUpCluster fails if not using the default distribution")
39+
}
40+
41+
restResources {
42+
restApi {
43+
include '_common', 'bulk', 'indices', 'index', 'ingest.delete_pipeline', 'ingest.put_pipeline', 'enrich', 'get', 'capabilities'
44+
}
45+
restTests {
46+
includeXpack 'enrich'
47+
}
2348
}
2449

25-
addQaCheckDependencies(project)

x-pack/plugin/enrich/qa/build.gradle

Whitespace-only changes.

x-pack/plugin/enrich/qa/common/build.gradle

Lines changed: 0 additions & 5 deletions
This file was deleted.

x-pack/plugin/enrich/qa/rest-with-advanced-security/build.gradle

Lines changed: 0 additions & 23 deletions
This file was deleted.

x-pack/plugin/enrich/qa/rest-with-security/build.gradle

Lines changed: 0 additions & 28 deletions
This file was deleted.

x-pack/plugin/enrich/qa/rest/build.gradle

Lines changed: 0 additions & 40 deletions
This file was deleted.

x-pack/plugin/enrich/qa/rest/src/javaRestTest/java/org/elasticsearch/xpack/enrich/EnrichIT.java

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
import org.elasticsearch.client.Response;
1212
import org.elasticsearch.client.ResponseException;
1313
import org.elasticsearch.common.Strings;
14+
import org.elasticsearch.common.settings.SecureString;
1415
import org.elasticsearch.common.settings.Settings;
16+
import org.elasticsearch.common.util.concurrent.ThreadContext;
1517
import org.elasticsearch.common.xcontent.XContentHelper;
1618
import org.elasticsearch.common.xcontent.support.XContentMapValues;
1719
import org.elasticsearch.index.query.QueryBuilders;
20+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
21+
import org.elasticsearch.test.cluster.local.LocalClusterSpecBuilder;
1822
import org.elasticsearch.test.rest.ESRestTestCase;
1923
import org.elasticsearch.xcontent.XContentBuilder;
2024
import org.elasticsearch.xcontent.json.JsonXContent;
@@ -34,6 +38,27 @@
3438

3539
public abstract class CommonEnrichRestTestCase extends ESRestTestCase {
3640

41+
static LocalClusterSpecBuilder<ElasticsearchCluster> enrichCluster(String license, boolean isSecurityEnabled) {
42+
return ElasticsearchCluster.local()
43+
.module("analysis-common")
44+
.module("ingest-common")
45+
.module("mapper-extras")
46+
.module("x-pack-enrich")
47+
.module("x-pack-monitoring")
48+
.module("x-pack-ilm")
49+
.module("wildcard")
50+
.setting("xpack.security.enabled", Boolean.toString(isSecurityEnabled))
51+
.setting("xpack.license.self_generated.type", license)
52+
// silence stats collector errors (we don't want to add all xpack modules here)
53+
.setting("logger.org.elasticsearch.xpack.monitoring.collector", "fatal")
54+
.setting("xpack.monitoring.collection.enabled", "true");
55+
}
56+
57+
static Settings authRequestHeaderSetting(String user, String password) {
58+
String token = basicAuthHeaderValue(user, new SecureString(password.toCharArray()));
59+
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
60+
}
61+
3762
private List<String> cleanupPipelines = new ArrayList<>();
3863

3964
/**
Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
* 2.0; you may not use this file except in compliance with the Elastic License
55
* 2.0.
66
*/
7-
package org.elasticsearch.xpack.enrich;
7+
package org.elasticsearch.test.enrich;
88

99
import org.elasticsearch.client.Request;
10-
import org.elasticsearch.common.settings.SecureString;
1110
import org.elasticsearch.common.settings.Settings;
12-
import org.elasticsearch.common.util.concurrent.ThreadContext;
13-
import org.elasticsearch.test.enrich.CommonEnrichRestTestCase;
11+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
12+
import org.elasticsearch.test.cluster.util.resource.Resource;
13+
import org.junit.ClassRule;
1414

1515
import java.io.IOException;
1616
import java.util.Map;
@@ -20,16 +20,29 @@
2020

2121
public class EnrichAdvancedSecurityIT extends CommonEnrichRestTestCase {
2222

23+
public static final String ADMIN_USER = "test_admin";
24+
public static final String ENRICH_USER = "test_enrich";
25+
public static final String TEST_PASSWORD = "x-pack-test-password";
26+
27+
@ClassRule
28+
public static ElasticsearchCluster cluster = enrichCluster("trial", true).rolesFile(Resource.fromClasspath("advanced_roles.yml"))
29+
.user(ADMIN_USER, TEST_PASSWORD, "superuser", true)
30+
.user(ENRICH_USER, TEST_PASSWORD, "integ_test_role", false)
31+
.build();
32+
33+
@Override
34+
protected String getTestRestCluster() {
35+
return cluster.getHttpAddresses();
36+
}
37+
2338
@Override
2439
protected Settings restClientSettings() {
25-
String token = basicAuthHeaderValue("test_enrich", new SecureString("x-pack-test-password".toCharArray()));
26-
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
40+
return authRequestHeaderSetting(ENRICH_USER, TEST_PASSWORD);
2741
}
2842

2943
@Override
3044
protected Settings restAdminSettings() {
31-
String token = basicAuthHeaderValue("test_admin", new SecureString("x-pack-test-password".toCharArray()));
32-
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
45+
return authRequestHeaderSetting(ADMIN_USER, TEST_PASSWORD);
3346
}
3447

3548
public void testEnrichEnforcesDLS() throws IOException {

0 commit comments

Comments
 (0)