[TEST] customize test global cluster for REST tests only if REST tests are enabled
Closes elastic/elasticsearch#107 Original commit: elastic/x-pack-elasticsearch@55eea46460
This commit is contained in:
parent
0d702c2fbc
commit
6f4acfa93b
|
@ -5,8 +5,10 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.test;
|
package org.elasticsearch.test;
|
||||||
|
|
||||||
|
import com.carrotsearch.randomizedtesting.RandomizedTest;
|
||||||
import com.carrotsearch.randomizedtesting.SysGlobals;
|
import com.carrotsearch.randomizedtesting.SysGlobals;
|
||||||
import com.carrotsearch.randomizedtesting.annotations.Name;
|
import com.carrotsearch.randomizedtesting.annotations.Name;
|
||||||
|
import com.carrotsearch.randomizedtesting.annotations.TestGroup;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import org.elasticsearch.ElasticsearchException;
|
import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.common.io.Streams;
|
import org.elasticsearch.common.io.Streams;
|
||||||
|
@ -57,87 +59,102 @@ public class ShieldRestTests extends ElasticsearchRestTests {
|
||||||
" '.*': ALL\n";
|
" '.*': ALL\n";
|
||||||
|
|
||||||
static {
|
static {
|
||||||
final byte[] key;
|
|
||||||
|
TestGroup testGroup = Rest.class.getAnnotation(TestGroup.class);
|
||||||
|
String sysProperty = TestGroup.Utilities.getSysProperty(Rest.class);
|
||||||
|
boolean enabled;
|
||||||
try {
|
try {
|
||||||
key = InternalKeyService.generateKey();
|
enabled = RandomizedTest.systemPropertyAsBoolean(sysProperty, testGroup.enabled());
|
||||||
} catch (Exception e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new RuntimeException(e);
|
// Ignore malformed system property, disable the group if malformed though.
|
||||||
|
enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
InternalTestCluster.DEFAULT_SETTINGS_SOURCE = new SettingsSource() {
|
//customize the global cluster only if rest tests are enabled
|
||||||
|
//not perfect but good enough as REST tests are supposed to be run only separately on CI
|
||||||
@Override
|
if (enabled) {
|
||||||
public Settings node(int nodeOrdinal) {
|
final byte[] key;
|
||||||
File store;
|
try {
|
||||||
try {
|
key = InternalKeyService.generateKey();
|
||||||
store = new File(getClass().getResource("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode.jks").toURI());
|
} catch (Exception e) {
|
||||||
assertThat(store.exists(), is(true));
|
throw new RuntimeException(e);
|
||||||
} catch (Exception e) {
|
|
||||||
throw new ElasticsearchException("Error reading test node cert", e);
|
|
||||||
}
|
|
||||||
String password = "testnode";
|
|
||||||
|
|
||||||
File folder = createFolder();
|
|
||||||
|
|
||||||
String keyFile = writeFile(folder, "system_key", key);
|
|
||||||
|
|
||||||
ImmutableSettings.Builder builder = ImmutableSettings.builder()
|
|
||||||
.put(InternalKeyService.FILE_SETTING, keyFile)
|
|
||||||
.put("request.headers.Authorization", basicAuthHeaderValue(DEFAULT_USER_NAME, SecuredStringTests.build(DEFAULT_PASSWORD)))
|
|
||||||
.put("discovery.zen.ping.multicast.enabled", false)
|
|
||||||
.put("discovery.type", "zen")
|
|
||||||
.put("node.mode", "network")
|
|
||||||
.put("plugin.types", ShieldPlugin.class.getName())
|
|
||||||
.put("shield.authc.esusers.files.users", createFile(folder, "users", CONFIG_STANDARD_USER))
|
|
||||||
.put("shield.authc.esusers.files.users_roles", createFile(folder, "users_roles", CONFIG_STANDARD_USER_ROLES))
|
|
||||||
.put("shield.authz.store.files.roles", createFile(folder, "roles.yml", CONFIG_ROLE_ALLOW_ALL))
|
|
||||||
.put("shield.transport.n2n.ip_filter.file", createFile(folder, "ip_filter.yml", CONFIG_IPFILTER_ALLOW_ALL))
|
|
||||||
.put("shield.transport.ssl", ENABLE_TRANSPORT_SSL)
|
|
||||||
.put("shield.transport.ssl.keystore", store.getPath())
|
|
||||||
.put("shield.transport.ssl.keystore_password", password)
|
|
||||||
.put("shield.transport.ssl.truststore", store.getPath())
|
|
||||||
.put("shield.transport.ssl.truststore_password", password)
|
|
||||||
.put("shield.http.ssl", false)
|
|
||||||
.put("transport.tcp.port", BASE_PORT_RANGE)
|
|
||||||
.putArray("discovery.zen.ping.unicast.hosts", "127.0.0.1:" + BASE_PORT, "127.0.0.1:" + (BASE_PORT + 1), "127.0.0.1:" + (BASE_PORT + 2), "127.0.0.1:" + (BASE_PORT + 3))
|
|
||||||
.put("shield.audit.enabled", SHIELD_AUDIT_ENABLED);
|
|
||||||
|
|
||||||
builder.put("network.host", "127.0.0.1");
|
|
||||||
if (OsUtils.MAC) {
|
|
||||||
builder.put("network.host", randomBoolean() ? "127.0.0.1" : "::1");
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
InternalTestCluster.DEFAULT_SETTINGS_SOURCE = new SettingsSource() {
|
||||||
public Settings transportClient() {
|
|
||||||
File store;
|
@Override
|
||||||
String password = "testclient";
|
public Settings node(int nodeOrdinal) {
|
||||||
try {
|
File store;
|
||||||
store = new File(getClass().getResource("/org/elasticsearch/shield/transport/ssl/certs/simple/testclient.jks").toURI());
|
try {
|
||||||
assertThat(store.exists(), is(true));
|
store = new File(getClass().getResource("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode.jks").toURI());
|
||||||
} catch (Exception e) {
|
assertThat(store.exists(), is(true));
|
||||||
throw new ElasticsearchException("Error reading test client cert", e);
|
} catch (Exception e) {
|
||||||
|
throw new ElasticsearchException("Error reading test node cert", e);
|
||||||
|
}
|
||||||
|
String password = "testnode";
|
||||||
|
|
||||||
|
File folder = createFolder();
|
||||||
|
|
||||||
|
String keyFile = writeFile(folder, "system_key", key);
|
||||||
|
|
||||||
|
ImmutableSettings.Builder builder = ImmutableSettings.builder()
|
||||||
|
.put(InternalKeyService.FILE_SETTING, keyFile)
|
||||||
|
.put("request.headers.Authorization", basicAuthHeaderValue(DEFAULT_USER_NAME, SecuredStringTests.build(DEFAULT_PASSWORD)))
|
||||||
|
.put("discovery.zen.ping.multicast.enabled", false)
|
||||||
|
.put("discovery.type", "zen")
|
||||||
|
.put("node.mode", "network")
|
||||||
|
.put("plugin.types", ShieldPlugin.class.getName())
|
||||||
|
.put("shield.authc.esusers.files.users", createFile(folder, "users", CONFIG_STANDARD_USER))
|
||||||
|
.put("shield.authc.esusers.files.users_roles", createFile(folder, "users_roles", CONFIG_STANDARD_USER_ROLES))
|
||||||
|
.put("shield.authz.store.files.roles", createFile(folder, "roles.yml", CONFIG_ROLE_ALLOW_ALL))
|
||||||
|
.put("shield.transport.n2n.ip_filter.file", createFile(folder, "ip_filter.yml", CONFIG_IPFILTER_ALLOW_ALL))
|
||||||
|
.put("shield.transport.ssl", ENABLE_TRANSPORT_SSL)
|
||||||
|
.put("shield.transport.ssl.keystore", store.getPath())
|
||||||
|
.put("shield.transport.ssl.keystore_password", password)
|
||||||
|
.put("shield.transport.ssl.truststore", store.getPath())
|
||||||
|
.put("shield.transport.ssl.truststore_password", password)
|
||||||
|
.put("shield.http.ssl", false)
|
||||||
|
.put("transport.tcp.port", BASE_PORT_RANGE)
|
||||||
|
.putArray("discovery.zen.ping.unicast.hosts", "127.0.0.1:" + BASE_PORT, "127.0.0.1:" + (BASE_PORT + 1), "127.0.0.1:" + (BASE_PORT + 2), "127.0.0.1:" + (BASE_PORT + 3))
|
||||||
|
.put("shield.audit.enabled", SHIELD_AUDIT_ENABLED);
|
||||||
|
|
||||||
|
builder.put("network.host", "127.0.0.1");
|
||||||
|
if (OsUtils.MAC) {
|
||||||
|
builder.put("network.host", randomBoolean() ? "127.0.0.1" : "::1");
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
File folder = createFolder();
|
@Override
|
||||||
|
public Settings transportClient() {
|
||||||
|
File store;
|
||||||
|
String password = "testclient";
|
||||||
|
try {
|
||||||
|
store = new File(getClass().getResource("/org/elasticsearch/shield/transport/ssl/certs/simple/testclient.jks").toURI());
|
||||||
|
assertThat(store.exists(), is(true));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ElasticsearchException("Error reading test client cert", e);
|
||||||
|
}
|
||||||
|
|
||||||
return ImmutableSettings.builder()
|
File folder = createFolder();
|
||||||
.put("request.headers.Authorization", basicAuthHeaderValue(DEFAULT_USER_NAME, SecuredStringTests.build(DEFAULT_PASSWORD)))
|
|
||||||
.put(TransportModule.TRANSPORT_TYPE_KEY, NettySecuredTransport.class.getName())
|
return ImmutableSettings.builder()
|
||||||
.put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false)
|
.put("request.headers.Authorization", basicAuthHeaderValue(DEFAULT_USER_NAME, SecuredStringTests.build(DEFAULT_PASSWORD)))
|
||||||
.put("node.mode", "network")
|
.put(TransportModule.TRANSPORT_TYPE_KEY, NettySecuredTransport.class.getName())
|
||||||
.put("shield.transport.n2n.ip_filter.file", createFile(folder, "ip_filter.yml", CONFIG_IPFILTER_ALLOW_ALL))
|
.put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false)
|
||||||
.put("shield.transport.ssl", ENABLE_TRANSPORT_SSL)
|
.put("node.mode", "network")
|
||||||
.put("shield.transport.ssl.keystore", store.getPath())
|
.put("shield.transport.n2n.ip_filter.file", createFile(folder, "ip_filter.yml", CONFIG_IPFILTER_ALLOW_ALL))
|
||||||
.put("shield.transport.ssl.keystore_password", password)
|
.put("shield.transport.ssl", ENABLE_TRANSPORT_SSL)
|
||||||
.put("shield.transport.ssl.truststore", store.getPath())
|
.put("shield.transport.ssl.keystore", store.getPath())
|
||||||
.put("shield.transport.ssl.truststore_password", password)
|
.put("shield.transport.ssl.keystore_password", password)
|
||||||
.put("cluster.name", internalCluster().getClusterName())
|
.put("shield.transport.ssl.truststore", store.getPath())
|
||||||
.build();
|
.put("shield.transport.ssl.truststore_password", password)
|
||||||
}
|
.put("cluster.name", internalCluster().getClusterName())
|
||||||
};
|
.build();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ClassRule
|
@ClassRule
|
||||||
|
|
Loading…
Reference in New Issue