[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;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.RandomizedTest;
|
||||
import com.carrotsearch.randomizedtesting.SysGlobals;
|
||||
import com.carrotsearch.randomizedtesting.annotations.Name;
|
||||
import com.carrotsearch.randomizedtesting.annotations.TestGroup;
|
||||
import com.google.common.base.Charsets;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.io.Streams;
|
||||
|
@ -57,87 +59,102 @@ public class ShieldRestTests extends ElasticsearchRestTests {
|
|||
" '.*': ALL\n";
|
||||
|
||||
static {
|
||||
final byte[] key;
|
||||
|
||||
TestGroup testGroup = Rest.class.getAnnotation(TestGroup.class);
|
||||
String sysProperty = TestGroup.Utilities.getSysProperty(Rest.class);
|
||||
boolean enabled;
|
||||
try {
|
||||
key = InternalKeyService.generateKey();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
enabled = RandomizedTest.systemPropertyAsBoolean(sysProperty, testGroup.enabled());
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Ignore malformed system property, disable the group if malformed though.
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
InternalTestCluster.DEFAULT_SETTINGS_SOURCE = new SettingsSource() {
|
||||
|
||||
@Override
|
||||
public Settings node(int nodeOrdinal) {
|
||||
File store;
|
||||
try {
|
||||
store = new File(getClass().getResource("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode.jks").toURI());
|
||||
assertThat(store.exists(), is(true));
|
||||
} 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();
|
||||
//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
|
||||
if (enabled) {
|
||||
final byte[] key;
|
||||
try {
|
||||
key = InternalKeyService.generateKey();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@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);
|
||||
InternalTestCluster.DEFAULT_SETTINGS_SOURCE = new SettingsSource() {
|
||||
|
||||
@Override
|
||||
public Settings node(int nodeOrdinal) {
|
||||
File store;
|
||||
try {
|
||||
store = new File(getClass().getResource("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode.jks").toURI());
|
||||
assertThat(store.exists(), is(true));
|
||||
} 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()
|
||||
.put("request.headers.Authorization", basicAuthHeaderValue(DEFAULT_USER_NAME, SecuredStringTests.build(DEFAULT_PASSWORD)))
|
||||
.put(TransportModule.TRANSPORT_TYPE_KEY, NettySecuredTransport.class.getName())
|
||||
.put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false)
|
||||
.put("node.mode", "network")
|
||||
.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("cluster.name", internalCluster().getClusterName())
|
||||
.build();
|
||||
}
|
||||
};
|
||||
File folder = createFolder();
|
||||
|
||||
return ImmutableSettings.builder()
|
||||
.put("request.headers.Authorization", basicAuthHeaderValue(DEFAULT_USER_NAME, SecuredStringTests.build(DEFAULT_PASSWORD)))
|
||||
.put(TransportModule.TRANSPORT_TYPE_KEY, NettySecuredTransport.class.getName())
|
||||
.put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false)
|
||||
.put("node.mode", "network")
|
||||
.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("cluster.name", internalCluster().getClusterName())
|
||||
.build();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ClassRule
|
||||
|
|
Loading…
Reference in New Issue