Skip to content

Commit 1a1ae5d

Browse files
authored
add qa project for running ILM tests against security (#32218)
This is a bare-bones skeleton for running existing yaml tests with security enabled. Additional tests which test users and roles should follow
1 parent 5f696e1 commit 1a1ae5d

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
apply plugin: 'elasticsearch.standalone-rest-test'
2+
apply plugin: 'elasticsearch.rest-test'
3+
4+
dependencies {
5+
testCompile project(path: xpackProject('plugin').path, configuration: 'testArtifacts')
6+
}
7+
8+
// bring in ILM rest test suite
9+
task copyILMRestTests(type: Copy) {
10+
into project.sourceSets.test.output.resourcesDir
11+
from xpackProject('plugin').sourceSets.test.resources.srcDirs
12+
include 'rest-api-spec/test/index_lifecycle/**'
13+
}
14+
15+
def clusterCredentials = [username: System.getProperty('tests.rest.cluster.username', 'test_user'),
16+
password: System.getProperty('tests.rest.cluster.password', 'x-pack-test-password')]
17+
18+
integTestRunner {
19+
systemProperty 'tests.rest.cluster.username', clusterCredentials.username
20+
systemProperty 'tests.rest.cluster.password', clusterCredentials.password
21+
}
22+
23+
integTestCluster {
24+
dependsOn copyILMRestTests
25+
setting 'xpack.index_lifecycle.enabled', 'true'
26+
setting 'xpack.security.enabled', 'true'
27+
setting 'xpack.watcher.enabled', 'false'
28+
setting 'xpack.monitoring.enabled', 'false'
29+
setting 'xpack.ml.enabled', 'false'
30+
setting 'xpack.license.self_generated.type', 'trial'
31+
setupCommand 'setupDummyUser',
32+
'bin/elasticsearch-users',
33+
'useradd', clusterCredentials.username,
34+
'-p', clusterCredentials.password,
35+
'-r', 'superuser'
36+
waitCondition = { node, ant ->
37+
File tmpFile = new File(node.cwd, 'wait.success')
38+
ant.get(src: "http://${node.httpUri()}/_cluster/health?wait_for_nodes=>=${numNodes}&wait_for_status=yellow",
39+
dest: tmpFile.toString(),
40+
username: clusterCredentials.username,
41+
password: clusterCredentials.password,
42+
ignoreerrors: true,
43+
retries: 10)
44+
return tmpFile.exists()
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
package org.elasticsearch.xpack.security;
8+
9+
import com.carrotsearch.randomizedtesting.annotations.Name;
10+
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
11+
import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
12+
import org.apache.lucene.util.TimeUnits;
13+
import org.elasticsearch.common.settings.SecureString;
14+
import org.elasticsearch.common.settings.Settings;
15+
import org.elasticsearch.common.util.concurrent.ThreadContext;
16+
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
17+
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
18+
19+
import java.util.Objects;
20+
21+
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
22+
23+
@TimeoutSuite(millis = 30 * TimeUnits.MINUTE) // as default timeout seems not enough on the jenkins VMs
24+
public class IndexLifecycleWithSecurityClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
25+
26+
private static final String USER = Objects.requireNonNull(System.getProperty("tests.rest.cluster.username"));
27+
private static final String PASS = Objects.requireNonNull(System.getProperty("tests.rest.cluster.password"));
28+
29+
public IndexLifecycleWithSecurityClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {
30+
super(testCandidate);
31+
}
32+
33+
@ParametersFactory
34+
public static Iterable<Object[]> parameters() throws Exception {
35+
return ESClientYamlSuiteTestCase.createParameters();
36+
}
37+
38+
@Override
39+
protected Settings restClientSettings() {
40+
String token = basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray()));
41+
return Settings.builder()
42+
.put(super.restClientSettings())
43+
.put(ThreadContext.PREFIX + ".Authorization", token)
44+
.build();
45+
}
46+
}
47+

0 commit comments

Comments
 (0)