mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-27 15:39:49 +00:00
[TEST] make sandbox settings explicit in Tests
This commit is contained in:
parent
0b0cd1c46c
commit
764fda6420
@ -70,7 +70,7 @@ public class GroovyScriptEngineService extends AbstractComponent implements Scri
|
||||
@Inject
|
||||
public GroovyScriptEngineService(Settings settings) {
|
||||
super(settings);
|
||||
this.sandboxed = settings.getAsBoolean(GROOVY_SCRIPT_SANDBOX_ENABLED, true);
|
||||
this.sandboxed = settings.getAsBoolean(GROOVY_SCRIPT_SANDBOX_ENABLED, false);
|
||||
this.blacklistAdditions = ImmutableSet.copyOf(settings.getAsArray(GROOVY_SCRIPT_BLACKLIST_PATCH, Strings.EMPTY_ARRAY));
|
||||
reloadConfig();
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -394,6 +395,7 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase {
|
||||
.put(settings)
|
||||
.put("path.home", newTempDirPath().toAbsolutePath().toString())
|
||||
.put(NodeEnvironment.SETTING_CUSTOM_DATA_PATH_ENABLED, true)
|
||||
.put(ScriptService.DISABLE_DYNAMIC_SCRIPTING_SETTING, false)
|
||||
.putArray("path.data", tmpPaths()).build();
|
||||
return new NodeEnvironment(build, new Environment(build));
|
||||
}
|
||||
@ -403,6 +405,7 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase {
|
||||
.put(settings)
|
||||
.put("path.home", newTempDirPath().toAbsolutePath().toString())
|
||||
.put(NodeEnvironment.SETTING_CUSTOM_DATA_PATH_ENABLED, true)
|
||||
.put(ScriptService.DISABLE_DYNAMIC_SCRIPTING_SETTING, false)
|
||||
.putArray("path.data", dataPaths).build();
|
||||
return new NodeEnvironment(build, new Environment(build));
|
||||
}
|
||||
|
@ -34,11 +34,18 @@ import static org.hamcrest.CoreMatchers.equalTo;
|
||||
/**
|
||||
* Tests for the Groovy scripting sandbox
|
||||
*/
|
||||
@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.TEST)
|
||||
@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.TEST, numDataNodes = 0)
|
||||
public class GroovySandboxScriptTests extends ElasticsearchIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testSandboxedGroovyScript() {
|
||||
public void testSandboxedGroovyScript() throws Exception {
|
||||
int nodes = randomIntBetween(1, 3);
|
||||
Settings nodeSettings = ImmutableSettings.builder()
|
||||
.put(GroovyScriptEngineService.GROOVY_SCRIPT_SANDBOX_ENABLED, true)
|
||||
.build();
|
||||
internalCluster().startNodesAsync(nodes, nodeSettings).get();
|
||||
client().admin().cluster().prepareHealth().setWaitForNodes(nodes + "").get();
|
||||
|
||||
client().prepareIndex("test", "doc", "1").setSource("foo", 5).setRefresh(true).get();
|
||||
|
||||
// Plain test
|
||||
@ -102,6 +109,13 @@ public class GroovySandboxScriptTests extends ElasticsearchIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testDynamicBlacklist() throws Exception {
|
||||
int nodes = randomIntBetween(1, 3);
|
||||
Settings nodeSettings = ImmutableSettings.builder()
|
||||
.put(GroovyScriptEngineService.GROOVY_SCRIPT_SANDBOX_ENABLED, true)
|
||||
.build();
|
||||
internalCluster().startNodesAsync(nodes, nodeSettings).get();
|
||||
client().admin().cluster().prepareHealth().setWaitForNodes(nodes + "").get();
|
||||
|
||||
client().prepareIndex("test", "doc", "1").setSource("foo", 5).setRefresh(true).get();
|
||||
|
||||
testSuccess("[doc['foo'].value, 3, 4].isEmpty()");
|
||||
|
@ -83,19 +83,6 @@ public class GroovyScriptTests extends ElasticsearchIntegrationTest {
|
||||
ExceptionsHelper.detailedMessage(e).contains("No such property: not_found"), equalTo(true));
|
||||
}
|
||||
|
||||
try {
|
||||
client().prepareSearch("test").setQuery(constantScoreQuery(
|
||||
scriptFilter("pr = Runtime.getRuntime().exec(\"touch /tmp/gotcha\"); pr.waitFor()").lang("groovy"))).get();
|
||||
fail("should have thrown an exception");
|
||||
} catch (SearchPhaseExecutionException e) {
|
||||
assertThat(ExceptionsHelper.detailedMessage(e) + "should not contained NotSerializableTransportException",
|
||||
ExceptionsHelper.detailedMessage(e).contains("NotSerializableTransportException"), equalTo(false));
|
||||
assertThat(ExceptionsHelper.detailedMessage(e) + "should have contained GroovyScriptCompilationException",
|
||||
ExceptionsHelper.detailedMessage(e).contains("GroovyScriptCompilationException"), equalTo(true));
|
||||
assertThat(ExceptionsHelper.detailedMessage(e) + "should have contained Method calls not allowed on [java.lang.Runtime]",
|
||||
ExceptionsHelper.detailedMessage(e).contains("Method calls not allowed on [java.lang.Runtime]"), equalTo(true));
|
||||
}
|
||||
|
||||
try {
|
||||
client().prepareSearch("test").setQuery(constantScoreQuery(
|
||||
scriptFilter("assert false").lang("groovy"))).get();
|
||||
|
@ -98,6 +98,7 @@ public abstract class ElasticsearchSingleNodeTest extends ElasticsearchTestCase
|
||||
.put("node.name", nodeName())
|
||||
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
|
||||
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
|
||||
.put("script.disable_dynamic", false)
|
||||
.put(EsExecutors.PROCESSORS, 1) // limit the number of threads created
|
||||
.put("http.enabled", false)
|
||||
.put("config.ignore_system_properties", true) // make sure we get what we set :)
|
||||
|
Loading…
x
Reference in New Issue
Block a user