2015-12-04 02:36:35 -05:00
|
|
|
import org.elasticsearch.gradle.MavenFilteringHack
|
2016-08-30 12:57:42 -04:00
|
|
|
import org.elasticsearch.gradle.test.NodeInfo
|
|
|
|
|
|
|
|
import javax.net.ssl.HttpsURLConnection
|
2018-07-24 05:48:14 -04:00
|
|
|
import javax.net.ssl.KeyManager
|
2016-08-30 12:57:42 -04:00
|
|
|
import javax.net.ssl.SSLContext
|
|
|
|
import javax.net.ssl.TrustManagerFactory
|
|
|
|
import java.nio.charset.StandardCharsets
|
|
|
|
import java.security.KeyStore
|
|
|
|
import java.security.SecureRandom
|
2015-11-25 03:13:59 -05:00
|
|
|
|
2017-01-04 14:27:53 -05:00
|
|
|
apply plugin: 'elasticsearch.standalone-rest-test'
|
2015-11-24 23:19:04 -05:00
|
|
|
apply plugin: 'elasticsearch.rest-test'
|
|
|
|
|
|
|
|
dependencies {
|
2018-08-21 20:03:28 -04:00
|
|
|
testCompile "org.elasticsearch.plugin:x-pack-core:${version}"
|
2015-11-24 23:19:04 -05:00
|
|
|
}
|
|
|
|
|
2018-04-26 18:36:14 -04:00
|
|
|
String outputDir = "${buildDir}/generated-resources/${project.name}"
|
2016-04-12 09:19:07 -04:00
|
|
|
task copyXPackPluginProps(type: Copy) {
|
2018-01-27 00:48:30 -05:00
|
|
|
from project(xpackModule('core')).file('src/main/plugin-metadata')
|
|
|
|
from project(xpackModule('core')).tasks.pluginProperties
|
2016-04-12 09:19:07 -04:00
|
|
|
into outputDir
|
|
|
|
}
|
|
|
|
project.sourceSets.test.output.dir(outputDir, builtBy: copyXPackPluginProps)
|
|
|
|
|
2016-02-08 08:33:27 -05:00
|
|
|
// location of generated keystores and certificates
|
|
|
|
File keystoreDir = new File(project.buildDir, 'keystore')
|
2018-07-24 05:48:14 -04:00
|
|
|
File nodeKeystore = file("$keystoreDir/testnode.jks")
|
|
|
|
File nodeKey = file("$keystoreDir/testnode.pem")
|
|
|
|
File nodeCert = file("$keystoreDir/testnode.crt")
|
|
|
|
File clientKeyStore = file("$keystoreDir/testclient.jks")
|
|
|
|
File clientKey = file("$keystoreDir/testclient.pem")
|
|
|
|
File clientCert = file("$keystoreDir/testclient.crt")
|
2016-02-08 08:33:27 -05:00
|
|
|
|
2018-07-24 05:48:14 -04:00
|
|
|
// Add keystores to test classpath: it expects it there
|
|
|
|
task copyKeyCerts(type: Copy) {
|
|
|
|
from('./') {
|
|
|
|
include '*.crt', '*.pem', '*.jks'
|
2016-02-08 08:33:27 -05:00
|
|
|
}
|
2018-07-24 05:48:14 -04:00
|
|
|
into keystoreDir
|
2016-02-08 08:33:27 -05:00
|
|
|
}
|
|
|
|
// Add keystores to test classpath: it expects it there
|
|
|
|
sourceSets.test.resources.srcDir(keystoreDir)
|
2018-07-24 05:48:14 -04:00
|
|
|
processTestResources.dependsOn(copyKeyCerts)
|
2015-11-25 03:13:59 -05:00
|
|
|
|
2018-07-24 05:48:14 -04:00
|
|
|
integTestCluster.dependsOn(copyKeyCerts)
|
2017-09-14 14:18:54 -04:00
|
|
|
|
2018-01-20 00:30:17 -05:00
|
|
|
ext.pluginsCount = 0
|
2018-04-27 10:49:06 -04:00
|
|
|
project(':plugins').getChildProjects().each { pluginName, pluginProject ->
|
2015-12-04 02:36:35 -05:00
|
|
|
// need to get a non-decorated project object, so must re-lookup the project by path
|
2018-04-27 10:49:06 -04:00
|
|
|
integTestCluster.plugin(pluginProject.path)
|
2016-02-21 13:10:21 -05:00
|
|
|
pluginsCount += 1
|
2015-11-25 03:13:59 -05:00
|
|
|
}
|
2015-11-24 23:19:04 -05:00
|
|
|
|
2017-02-22 03:56:52 -05:00
|
|
|
integTestCluster {
|
2018-02-23 10:33:34 -05:00
|
|
|
setting 'xpack.monitoring.collection.interval', '1s'
|
2017-02-22 03:56:52 -05:00
|
|
|
setting 'xpack.monitoring.exporters._http.type', 'http'
|
|
|
|
setting 'xpack.monitoring.exporters._http.enabled', 'false'
|
|
|
|
setting 'xpack.monitoring.exporters._http.auth.username', 'monitoring_agent'
|
2017-06-29 16:27:57 -04:00
|
|
|
setting 'xpack.monitoring.exporters._http.auth.password', 'x-pack-test-password'
|
2017-12-05 06:07:04 -05:00
|
|
|
setting 'xpack.monitoring.exporters._http.ssl.verification_mode', 'full'
|
2019-01-14 16:06:22 -05:00
|
|
|
setting 'xpack.monitoring.exporters._http.ssl.certificate_authorities', 'testnode.crt'
|
2017-02-22 03:56:52 -05:00
|
|
|
|
2018-05-03 12:33:08 -04:00
|
|
|
setting 'xpack.license.self_generated.type', 'trial'
|
2018-03-21 23:09:44 -04:00
|
|
|
setting 'xpack.security.enabled', 'true'
|
2017-02-22 03:56:52 -05:00
|
|
|
setting 'xpack.security.http.ssl.enabled', 'true'
|
2018-07-24 05:48:14 -04:00
|
|
|
setting 'xpack.security.http.ssl.key', 'testnode.pem'
|
|
|
|
setting 'xpack.security.http.ssl.certificate', 'testnode.crt'
|
2019-01-14 16:06:22 -05:00
|
|
|
setting 'xpack.security.http.ssl.certificate_authorities', 'testnode.crt'
|
2018-07-24 05:48:14 -04:00
|
|
|
keystoreSetting 'xpack.security.http.ssl.secure_key_passphrase', 'testnode'
|
2017-02-22 03:56:52 -05:00
|
|
|
|
2018-08-02 13:05:11 -04:00
|
|
|
setting 'xpack.ilm.enabled', 'false'
|
2017-03-02 12:01:05 -05:00
|
|
|
setting 'xpack.ml.enabled', 'false'
|
2018-07-24 05:48:14 -04:00
|
|
|
// copy keystores, keys and certificates into config/
|
2017-02-22 03:56:52 -05:00
|
|
|
extraConfigFile nodeKeystore.name, nodeKeystore
|
2018-07-24 05:48:14 -04:00
|
|
|
extraConfigFile nodeKey.name, nodeKey
|
|
|
|
extraConfigFile nodeCert.name, nodeCert
|
2017-02-22 03:56:52 -05:00
|
|
|
extraConfigFile clientKeyStore.name, clientKeyStore
|
2018-07-24 05:48:14 -04:00
|
|
|
extraConfigFile clientKey.name, clientKey
|
|
|
|
extraConfigFile clientCert.name, clientCert
|
2017-02-22 03:56:52 -05:00
|
|
|
|
|
|
|
setupCommand 'setupTestUser',
|
2018-04-11 11:36:12 -04:00
|
|
|
'bin/elasticsearch-users', 'useradd', 'test_user', '-p', 'x-pack-test-password', '-r', 'superuser'
|
2017-02-22 03:56:52 -05:00
|
|
|
setupCommand 'setupMonitoringUser',
|
2018-04-11 11:36:12 -04:00
|
|
|
'bin/elasticsearch-users', 'useradd', 'monitoring_agent', '-p', 'x-pack-test-password', '-r', 'remote_monitoring_agent'
|
2017-02-22 03:56:52 -05:00
|
|
|
|
|
|
|
waitCondition = { NodeInfo node, AntBuilder ant ->
|
|
|
|
File tmpFile = new File(node.cwd, 'wait.success')
|
|
|
|
KeyStore keyStore = KeyStore.getInstance("JKS");
|
2018-07-24 05:48:14 -04:00
|
|
|
keyStore.load(clientKeyStore.newInputStream(), 'testclient'.toCharArray());
|
2017-02-22 03:56:52 -05:00
|
|
|
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
|
|
|
tmf.init(keyStore);
|
2018-07-24 05:48:14 -04:00
|
|
|
// We don't need a KeyManager as there won't be client auth required so pass an empty array
|
2017-02-22 03:56:52 -05:00
|
|
|
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
|
2018-07-24 05:48:14 -04:00
|
|
|
sslContext.init(new KeyManager[0], tmf.getTrustManagers(), new SecureRandom());
|
2017-02-22 03:56:52 -05:00
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
// we use custom wait logic here for HTTPS
|
|
|
|
HttpsURLConnection httpURLConnection = null;
|
|
|
|
try {
|
2017-03-15 13:23:26 -04:00
|
|
|
httpURLConnection = (HttpsURLConnection) new URL("https://${node.httpUri()}/_cluster/health?wait_for_nodes=${numNodes}&wait_for_status=yellow").openConnection();
|
2017-02-22 03:56:52 -05:00
|
|
|
httpURLConnection.setSSLSocketFactory(sslContext.getSocketFactory());
|
|
|
|
httpURLConnection.setRequestProperty("Authorization", "Basic " +
|
2017-06-29 16:27:57 -04:00
|
|
|
Base64.getEncoder().encodeToString("test_user:x-pack-test-password".getBytes(StandardCharsets.UTF_8)));
|
2017-02-22 03:56:52 -05:00
|
|
|
httpURLConnection.setRequestMethod("GET");
|
|
|
|
httpURLConnection.connect();
|
|
|
|
if (httpURLConnection.getResponseCode() == 200) {
|
|
|
|
tmpFile.withWriter StandardCharsets.UTF_8.name(), {
|
|
|
|
it.write(httpURLConnection.getInputStream().getText(StandardCharsets.UTF_8.name()))
|
2016-08-30 12:57:42 -04:00
|
|
|
}
|
2016-02-08 08:33:27 -05:00
|
|
|
}
|
2017-02-22 03:56:52 -05:00
|
|
|
} catch (IOException e) {
|
|
|
|
if (i == 9) {
|
|
|
|
logger.error("final attempt of calling cluster health failed", e)
|
|
|
|
} else {
|
|
|
|
logger.debug("failed to call cluster health", e)
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if (httpURLConnection != null) {
|
|
|
|
httpURLConnection.disconnect();
|
|
|
|
}
|
2016-02-08 08:33:27 -05:00
|
|
|
}
|
2017-02-22 03:56:52 -05:00
|
|
|
|
|
|
|
// did not start, so wait a bit before trying again
|
|
|
|
Thread.sleep(500L);
|
2015-11-24 23:19:04 -05:00
|
|
|
}
|
2017-02-22 03:56:52 -05:00
|
|
|
return tmpFile.exists()
|
2015-11-24 23:19:04 -05:00
|
|
|
}
|
2015-11-28 21:07:37 -05:00
|
|
|
}
|
2015-12-04 02:36:35 -05:00
|
|
|
|
|
|
|
ext.expansions = [
|
|
|
|
'expected.plugins.count': pluginsCount
|
|
|
|
]
|
|
|
|
|
|
|
|
processTestResources {
|
|
|
|
from(sourceSets.test.resources.srcDirs) {
|
2017-05-17 21:07:42 -04:00
|
|
|
include '**/*.yml'
|
2015-12-04 02:36:35 -05:00
|
|
|
inputs.properties(expansions)
|
|
|
|
MavenFilteringHack.filter(it, expansions)
|
|
|
|
}
|
2018-08-21 20:03:28 -04:00
|
|
|
}
|