Scripting: remove support for script.disable_dynamic setting
Now that fine-grained script settings are supported (#10116) we can remove support for the script.disable_dynamic setting. Same result as `script.disable_dynamic: false` can be obtained as follows: ``` script.inline: on script.indexed: on ``` An exception is thrown at startup when the old setting is set, so we make sure we tell users they have to change it rather than ignoring the setting. Closes #10286
This commit is contained in:
parent
7a595d7911
commit
83fb0a10e5
|
@ -286,7 +286,27 @@ setting. Please however note that using a non-default codec is discouraged as
|
|||
it could prevent future versions of Elasticsearch from being able to read the
|
||||
index.
|
||||
|
||||
=== Scripts
|
||||
=== Scripting settings
|
||||
|
||||
Removed support for `script.disable_dynamic` node setting, replaced by
|
||||
fine-grained script settings described in the <<enable-dynamic-scripting,scripting docs>>.
|
||||
The following setting previously used to enable dynamic scripts:
|
||||
|
||||
[source,yaml]
|
||||
---------------
|
||||
script.disable_dynamic: false
|
||||
---------------
|
||||
|
||||
can be replaced with the following two settings in `elasticsearch.yml` that
|
||||
achieve the same result:
|
||||
|
||||
[source,yaml]
|
||||
---------------
|
||||
script.inline: on
|
||||
script.indexed: on
|
||||
---------------
|
||||
|
||||
=== Script parameters
|
||||
|
||||
Deprecated script parameters `id`, `file`, and `scriptField` have been removed
|
||||
from all scriptable APIs. `script_id`, `script_file` and `script` should be used
|
||||
|
|
|
@ -246,8 +246,6 @@ application inbetween. If you *do* intend to expose Elasticsearch directly to
|
|||
your users, then you have to decide whether you trust them enough to run scripts
|
||||
on your box or not.
|
||||
|
||||
deprecated[1.6.0, the `script.disable_dynamic` setting is deprecated in favour of fine-grained settings described as follows]
|
||||
|
||||
It is possible to enable scripts based on their source, for
|
||||
every script engine, through the following settings that need to be added to the
|
||||
`config/elasticsearch.yml` file on every node.
|
||||
|
|
|
@ -20,15 +20,16 @@
|
|||
package org.elasticsearch.script;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.script.ScriptService.ScriptType;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* Holds the {@link org.elasticsearch.script.ScriptMode}s for each of the different scripting languages available,
|
||||
|
@ -41,15 +42,15 @@ public class ScriptModes {
|
|||
|
||||
final ImmutableMap<String, ScriptMode> scriptModes;
|
||||
|
||||
ScriptModes(Map<String, ScriptEngineService> scriptEngines, Settings settings, ESLogger logger) {
|
||||
ScriptModes(Map<String, ScriptEngineService> scriptEngines, Settings settings) {
|
||||
//filter out the native engine as we don't want to apply fine grained settings to it.
|
||||
//native scripts are always on as they are static by definition.
|
||||
Map<String, ScriptEngineService> filteredEngines = Maps.newHashMap(scriptEngines);
|
||||
filteredEngines.remove(NativeScriptEngineService.NAME);
|
||||
this.scriptModes = buildScriptModeSettingsMap(settings, filteredEngines, logger);
|
||||
this.scriptModes = buildScriptModeSettingsMap(settings, filteredEngines);
|
||||
}
|
||||
|
||||
private ImmutableMap<String, ScriptMode> buildScriptModeSettingsMap(Settings settings, Map<String, ScriptEngineService> scriptEngines, ESLogger logger) {
|
||||
private ImmutableMap<String, ScriptMode> buildScriptModeSettingsMap(Settings settings, Map<String, ScriptEngineService> scriptEngines) {
|
||||
HashMap<String, ScriptMode> scriptModesMap = Maps.newHashMap();
|
||||
|
||||
//file scripts are enabled by default, for any language
|
||||
|
@ -59,39 +60,35 @@ public class ScriptModes {
|
|||
//dynamic scripts are enabled by default only for sandboxed languages
|
||||
addGlobalScriptTypeModes(scriptEngines.keySet(), ScriptType.INLINE, ScriptMode.SANDBOX, scriptModesMap);
|
||||
|
||||
List<String> processedSettings = Lists.newArrayList();
|
||||
processSourceBasedGlobalSettings(settings, scriptEngines, processedSettings, scriptModesMap);
|
||||
processOperationBasedGlobalSettings(settings, scriptEngines, processedSettings, scriptModesMap);
|
||||
processEngineSpecificSettings(settings, scriptEngines, processedSettings, scriptModesMap);
|
||||
processDisableDynamicDeprecatedSetting(settings, scriptEngines, processedSettings, scriptModesMap, logger);
|
||||
processSourceBasedGlobalSettings(settings, scriptEngines, scriptModesMap);
|
||||
processOperationBasedGlobalSettings(settings, scriptEngines, scriptModesMap);
|
||||
processEngineSpecificSettings(settings, scriptEngines, scriptModesMap);
|
||||
return ImmutableMap.copyOf(scriptModesMap);
|
||||
}
|
||||
|
||||
private static void processSourceBasedGlobalSettings(Settings settings, Map<String, ScriptEngineService> scriptEngines, List<String> processedSettings, Map<String, ScriptMode> scriptModes) {
|
||||
private static void processSourceBasedGlobalSettings(Settings settings, Map<String, ScriptEngineService> scriptEngines, Map<String, ScriptMode> scriptModes) {
|
||||
//read custom source based settings for all operations (e.g. script.indexed: on)
|
||||
for (ScriptType scriptType : ScriptType.values()) {
|
||||
String scriptTypeSetting = settings.get(SCRIPT_SETTINGS_PREFIX + scriptType);
|
||||
if (Strings.hasLength(scriptTypeSetting)) {
|
||||
ScriptMode scriptTypeMode = ScriptMode.parse(scriptTypeSetting);
|
||||
processedSettings.add(SCRIPT_SETTINGS_PREFIX + scriptType + ": " + scriptTypeMode);
|
||||
addGlobalScriptTypeModes(scriptEngines.keySet(), scriptType, scriptTypeMode, scriptModes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void processOperationBasedGlobalSettings(Settings settings, Map<String, ScriptEngineService> scriptEngines, List<String> processedSettings, Map<String, ScriptMode> scriptModes) {
|
||||
private static void processOperationBasedGlobalSettings(Settings settings, Map<String, ScriptEngineService> scriptEngines, Map<String, ScriptMode> scriptModes) {
|
||||
//read custom op based settings for all sources (e.g. script.aggs: off)
|
||||
//op based settings take precedence over source based settings, hence they get expanded later
|
||||
for (ScriptContext scriptContext : ScriptContext.values()) {
|
||||
ScriptMode scriptMode = getScriptContextMode(settings, SCRIPT_SETTINGS_PREFIX, scriptContext);
|
||||
if (scriptMode != null) {
|
||||
processedSettings.add(SCRIPT_SETTINGS_PREFIX + scriptContext + ": " + scriptMode);
|
||||
addGlobalScriptContextModes(scriptEngines.keySet(), scriptContext, scriptMode, scriptModes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void processEngineSpecificSettings(Settings settings, Map<String, ScriptEngineService> scriptEngines, List<String> processedSettings, Map<String, ScriptMode> scriptModes) {
|
||||
private static void processEngineSpecificSettings(Settings settings, Map<String, ScriptEngineService> scriptEngines, Map<String, ScriptMode> scriptModes) {
|
||||
Map<String, Settings> langGroupedSettings = settings.getGroups(ENGINE_SETTINGS_PREFIX, true);
|
||||
for (Map.Entry<String, Settings> langSettings : langGroupedSettings.entrySet()) {
|
||||
//read engine specific settings that refer to a non existing script lang will be ignored
|
||||
|
@ -103,7 +100,6 @@ public class ScriptModes {
|
|||
for (ScriptContext scriptContext : ScriptContext.values()) {
|
||||
ScriptMode scriptMode = getScriptContextMode(langSettings.getValue(), scriptTypePrefix, scriptContext);
|
||||
if (scriptMode != null) {
|
||||
processedSettings.add(enginePrefix + scriptTypePrefix + scriptContext + ": " + scriptMode);
|
||||
addScriptMode(scriptEngineService, scriptType, scriptContext, scriptMode, scriptModes);
|
||||
}
|
||||
}
|
||||
|
@ -112,32 +108,6 @@ public class ScriptModes {
|
|||
}
|
||||
}
|
||||
|
||||
private void processDisableDynamicDeprecatedSetting(Settings settings, Map<String, ScriptEngineService> scriptEngines,
|
||||
List<String> processedSettings, Map<String, ScriptMode> scriptModes, ESLogger logger) {
|
||||
//read deprecated disable_dynamic setting, apply only if none of the new settings is used
|
||||
String disableDynamicSetting = settings.get(ScriptService.DISABLE_DYNAMIC_SCRIPTING_SETTING);
|
||||
if (disableDynamicSetting != null) {
|
||||
if (processedSettings.isEmpty()) {
|
||||
ScriptService.DynamicScriptDisabling dynamicScriptDisabling = ScriptService.DynamicScriptDisabling.parse(disableDynamicSetting);
|
||||
switch(dynamicScriptDisabling) {
|
||||
case EVERYTHING_ALLOWED:
|
||||
addGlobalScriptTypeModes(scriptEngines.keySet(), ScriptType.INDEXED, ScriptMode.ON, scriptModes);
|
||||
addGlobalScriptTypeModes(scriptEngines.keySet(), ScriptType.INLINE, ScriptMode.ON, scriptModes);
|
||||
break;
|
||||
case ONLY_DISK_ALLOWED:
|
||||
addGlobalScriptTypeModes(scriptEngines.keySet(), ScriptType.INDEXED, ScriptMode.OFF, scriptModes);
|
||||
addGlobalScriptTypeModes(scriptEngines.keySet(), ScriptType.INLINE, ScriptMode.OFF, scriptModes);
|
||||
break;
|
||||
}
|
||||
logger.warn("deprecated setting [{}] is set, replace with fine-grained scripting settings (e.g. script.inline, script.indexed, script.file)", ScriptService.DISABLE_DYNAMIC_SCRIPTING_SETTING);
|
||||
} else {
|
||||
processedSettings.add(ScriptService.DISABLE_DYNAMIC_SCRIPTING_SETTING + ": " + disableDynamicSetting);
|
||||
throw new ElasticsearchIllegalArgumentException("conflicting scripting settings have been specified, use either "
|
||||
+ ScriptService.DISABLE_DYNAMIC_SCRIPTING_SETTING + " (deprecated) or the newer fine-grained settings (e.g. script.inline, script.indexed, script.file), not both at the same time:\n" + processedSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static ScriptMode getScriptContextMode(Settings settings, String prefix, ScriptContext scriptContext) {
|
||||
String settingValue = settings.get(prefix + scriptContext);
|
||||
if (Strings.hasLength(settingValue)) {
|
||||
|
|
|
@ -81,8 +81,9 @@ import java.util.concurrent.TimeUnit;
|
|||
*/
|
||||
public class ScriptService extends AbstractComponent implements Closeable {
|
||||
|
||||
static final String DISABLE_DYNAMIC_SCRIPTING_SETTING = "script.disable_dynamic";
|
||||
|
||||
public static final String DEFAULT_SCRIPTING_LANGUAGE_SETTING = "script.default_lang";
|
||||
public static final String DISABLE_DYNAMIC_SCRIPTING_SETTING = "script.disable_dynamic";
|
||||
public static final String SCRIPT_CACHE_SIZE_SETTING = "script.cache.max_size";
|
||||
public static final String SCRIPT_CACHE_EXPIRE_SETTING = "script.cache.expire";
|
||||
public static final String SCRIPT_INDEX = ".scripts";
|
||||
|
@ -105,37 +106,6 @@ public class ScriptService extends AbstractComponent implements Closeable {
|
|||
|
||||
private Client client = null;
|
||||
|
||||
/**
|
||||
* Enum defining the different dynamic settings for scripting, either
|
||||
* ONLY_DISK_ALLOWED (scripts must be placed on disk), EVERYTHING_ALLOWED
|
||||
* (all dynamic scripting is enabled), or SANDBOXED_ONLY (only sandboxed
|
||||
* scripting languages are allowed)
|
||||
*/
|
||||
enum DynamicScriptDisabling {
|
||||
EVERYTHING_ALLOWED,
|
||||
ONLY_DISK_ALLOWED,
|
||||
SANDBOXED_ONLY;
|
||||
|
||||
static DynamicScriptDisabling parse(String s) {
|
||||
switch (s.toLowerCase(Locale.ROOT)) {
|
||||
// true for "disable_dynamic" means only on-disk scripts are enabled
|
||||
case "true":
|
||||
case "all":
|
||||
return ONLY_DISK_ALLOWED;
|
||||
// false for "disable_dynamic" means all scripts are enabled
|
||||
case "false":
|
||||
case "none":
|
||||
return EVERYTHING_ALLOWED;
|
||||
// only sandboxed scripting is enabled
|
||||
case "sandbox":
|
||||
case "sandboxed":
|
||||
return SANDBOXED_ONLY;
|
||||
default:
|
||||
throw new ElasticsearchIllegalArgumentException("Unrecognized script allowance setting: [" + s + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final ParseField SCRIPT_LANG = new ParseField("lang","script_lang");
|
||||
public static final ParseField SCRIPT_FILE = new ParseField("script_file");
|
||||
public static final ParseField SCRIPT_ID = new ParseField("script_id");
|
||||
|
@ -146,6 +116,11 @@ public class ScriptService extends AbstractComponent implements Closeable {
|
|||
ResourceWatcherService resourceWatcherService, NodeSettingsService nodeSettingsService) throws IOException {
|
||||
super(settings);
|
||||
|
||||
if (Strings.hasLength(settings.get(DISABLE_DYNAMIC_SCRIPTING_SETTING))) {
|
||||
throw new ElasticsearchIllegalArgumentException(DISABLE_DYNAMIC_SCRIPTING_SETTING + " is not a supported setting, replace with fine-grained script settings. \n" +
|
||||
"Dynamic scripts can be enabled for all languages and all operations by replacing `script.disable_dynamic: false` with `script.inline: on` and `script.indexed: on` in elasticsearch.yml");
|
||||
}
|
||||
|
||||
this.scriptEngines = scriptEngines;
|
||||
int cacheMaxSize = settings.getAsInt(SCRIPT_CACHE_SIZE_SETTING, 100);
|
||||
TimeValue cacheExpire = settings.getAsTime(SCRIPT_CACHE_EXPIRE_SETTING, null);
|
||||
|
@ -175,7 +150,7 @@ public class ScriptService extends AbstractComponent implements Closeable {
|
|||
this.scriptEnginesByLang = enginesByLangBuilder.build();
|
||||
this.scriptEnginesByExt = enginesByExtBuilder.build();
|
||||
|
||||
this.scriptModes = new ScriptModes(this.scriptEnginesByLang, settings, logger);
|
||||
this.scriptModes = new ScriptModes(this.scriptEnginesByLang, settings);
|
||||
|
||||
// add file watcher for static scripts
|
||||
scriptsDirectory = env.configFile().resolve("scripts");
|
||||
|
|
|
@ -27,7 +27,6 @@ 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;
|
||||
|
||||
|
@ -399,7 +398,6 @@ 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));
|
||||
}
|
||||
|
@ -409,7 +407,6 @@ 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));
|
||||
}
|
||||
|
|
|
@ -86,21 +86,6 @@ public class NativeScriptTests extends ElasticsearchTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisableDynamicDoesntAffectNativeScripts() throws IOException {
|
||||
Settings settings = ImmutableSettings.settingsBuilder().put(ScriptService.DISABLE_DYNAMIC_SCRIPTING_SETTING, randomFrom("true", "false", "sandbox")).build();
|
||||
Environment environment = new Environment(settings);
|
||||
ResourceWatcherService resourceWatcherService = new ResourceWatcherService(settings, null);
|
||||
Map<String, NativeScriptFactory> nativeScriptFactoryMap = new HashMap<>();
|
||||
nativeScriptFactoryMap.put("my", new MyNativeScriptFactory());
|
||||
Set<ScriptEngineService> scriptEngineServices = ImmutableSet.<ScriptEngineService>of(new NativeScriptEngineService(settings, nativeScriptFactoryMap));
|
||||
ScriptService scriptService = new ScriptService(settings, environment, scriptEngineServices, resourceWatcherService, new NodeSettingsService(settings));
|
||||
|
||||
for (ScriptContext scriptContext : ScriptContext.values()) {
|
||||
assertThat(scriptService.compile(NativeScriptEngineService.NAME, "my", ScriptType.INLINE, scriptContext), notNullValue());
|
||||
}
|
||||
}
|
||||
|
||||
static class MyNativeScriptFactory implements NativeScriptFactory {
|
||||
@Override
|
||||
public ExecutableScript newScript(@Nullable Map<String, Object> params) {
|
||||
|
|
|
@ -23,9 +23,7 @@ import com.google.common.collect.ImmutableMap;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.script.ScriptService.ScriptType;
|
||||
import org.elasticsearch.script.expression.ExpressionScriptEngineService;
|
||||
import org.elasticsearch.script.groovy.GroovyScriptEngineService;
|
||||
|
@ -41,7 +39,6 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
|
||||
|
@ -94,76 +91,22 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
|
||||
@Test
|
||||
public void testDefaultSettings() {
|
||||
this.scriptModes = new ScriptModes(scriptEngines, ImmutableSettings.EMPTY, Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, ImmutableSettings.EMPTY);
|
||||
assertScriptModesAllOps(ScriptMode.ON, ALL_LANGS, ScriptType.FILE);
|
||||
assertScriptModesAllOps(ScriptMode.SANDBOX, ALL_LANGS, ScriptType.INDEXED, ScriptType.INLINE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultSettingsDisableDynamicTrue() {
|
||||
//verify that disable_dynamic setting gets still read and applied, iff new settings are not present
|
||||
this.scriptModes = new ScriptModes(scriptEngines, ImmutableSettings.builder().put(ScriptService.DISABLE_DYNAMIC_SCRIPTING_SETTING, randomFrom("true", "all")).build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
assertScriptModesAllOps(ScriptMode.ON, ALL_LANGS, ScriptType.FILE);
|
||||
assertScriptModesAllOps(ScriptMode.OFF, ALL_LANGS, ScriptType.INDEXED, ScriptType.INLINE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultSettingsEnableDynamicFalse() {
|
||||
//verify that disable_dynamic setting gets still read and applied, iff new settings are not present
|
||||
this.scriptModes = new ScriptModes(scriptEngines, ImmutableSettings.builder().put(ScriptService.DISABLE_DYNAMIC_SCRIPTING_SETTING, randomFrom("false", "none")).build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
assertScriptModesAllOps(ScriptMode.ON, ALL_LANGS, ScriptType.FILE, ScriptType.INDEXED, ScriptType.INLINE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultSettingsDisableDynamicSandbox() {
|
||||
//verify that disable_dynamic setting gets still read and applied, iff new settings are not present
|
||||
this.scriptModes = new ScriptModes(scriptEngines, ImmutableSettings.builder().put(ScriptService.DISABLE_DYNAMIC_SCRIPTING_SETTING, ScriptMode.SANDBOX).build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
assertScriptModesAllOps(ScriptMode.ON, ALL_LANGS, ScriptType.FILE);
|
||||
assertScriptModesAllOps(ScriptMode.SANDBOX, ALL_LANGS, ScriptType.INDEXED, ScriptType.INLINE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConflictingSettings() {
|
||||
assertScriptModesNonNull = false;
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder()
|
||||
.put(ScriptService.DISABLE_DYNAMIC_SCRIPTING_SETTING, randomFrom("all", "true", "none", "false", "sandbox", "sandboxed"));
|
||||
|
||||
int iterations = randomIntBetween(1, 5);
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
if (randomBoolean()) {
|
||||
builder.put("script." + randomFrom(ScriptType.values()), randomFrom(ScriptMode.values()));
|
||||
} else {
|
||||
if (randomBoolean()) {
|
||||
builder.put(ScriptModes.SCRIPT_SETTINGS_PREFIX + randomFrom(ScriptContext.values()), randomFrom(ScriptMode.values()));
|
||||
} else {
|
||||
builder.put(specificEngineOpSettings(GroovyScriptEngineService.NAME, randomFrom(ScriptType.values()), randomFrom(ScriptContext.values())), randomFrom(ScriptMode.values()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Settings settings = builder.build();
|
||||
try {
|
||||
this.scriptModes = new ScriptModes(scriptEngines, settings, Loggers.getLogger(ScriptModesTests.class));
|
||||
fail("ScriptModes should have thrown an error due to conflicting settings");
|
||||
} catch(ElasticsearchIllegalArgumentException e) {
|
||||
assertThat(e.getMessage(), containsString("conflicting scripting settings have been specified"));
|
||||
for (Map.Entry<String, String> scriptSettingEntry : settings.getAsSettings("script").getAsMap().entrySet()) {
|
||||
assertThat(e.getMessage(), containsString(ScriptModes.SCRIPT_SETTINGS_PREFIX + scriptSettingEntry.getKey() + ": " + scriptSettingEntry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ElasticsearchIllegalArgumentException.class)
|
||||
public void testMissingSetting() {
|
||||
assertAllSettingsWereChecked = false;
|
||||
this.scriptModes = new ScriptModes(scriptEngines, ImmutableSettings.EMPTY, Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, ImmutableSettings.EMPTY);
|
||||
scriptModes.getScriptMode("non_existing", randomFrom(ScriptType.values()), randomFrom(ScriptContext.values()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnableInlineGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.inline", randomFrom(ENABLE_VALUES));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllOps(ScriptMode.ON, ALL_LANGS, ScriptType.FILE, ScriptType.INLINE);
|
||||
assertScriptModesAllOps(ScriptMode.SANDBOX, ALL_LANGS, ScriptType.INDEXED);
|
||||
}
|
||||
|
@ -171,7 +114,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
@Test
|
||||
public void testDisableInlineGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.inline", randomFrom(DISABLE_VALUES));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllOps(ScriptMode.ON, ALL_LANGS, ScriptType.FILE);
|
||||
assertScriptModesAllOps(ScriptMode.SANDBOX, ALL_LANGS, ScriptType.INDEXED);
|
||||
assertScriptModesAllOps(ScriptMode.OFF, ALL_LANGS, ScriptType.INLINE);
|
||||
|
@ -181,7 +124,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
public void testSandboxInlineGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.inline", randomFrom(ScriptMode.SANDBOX));
|
||||
//nothing changes if setting set is same as default
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllOps(ScriptMode.ON, ALL_LANGS, ScriptType.FILE);
|
||||
assertScriptModesAllOps(ScriptMode.SANDBOX, ALL_LANGS, ScriptType.INDEXED, ScriptType.INLINE);
|
||||
}
|
||||
|
@ -189,7 +132,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
@Test
|
||||
public void testEnableIndexedGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.indexed", randomFrom(ENABLE_VALUES));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllOps(ScriptMode.ON, ALL_LANGS, ScriptType.FILE, ScriptType.INDEXED);
|
||||
assertScriptModesAllOps(ScriptMode.SANDBOX, ALL_LANGS, ScriptType.INLINE);
|
||||
}
|
||||
|
@ -197,7 +140,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
@Test
|
||||
public void testDisableIndexedGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.indexed", randomFrom(DISABLE_VALUES));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllOps(ScriptMode.ON, ALL_LANGS, ScriptType.FILE);
|
||||
assertScriptModesAllOps(ScriptMode.OFF, ALL_LANGS, ScriptType.INDEXED);
|
||||
assertScriptModesAllOps(ScriptMode.SANDBOX, ALL_LANGS, ScriptType.INLINE);
|
||||
|
@ -207,7 +150,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
public void testSandboxIndexedGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.indexed", ScriptMode.SANDBOX);
|
||||
//nothing changes if setting set is same as default
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllOps(ScriptMode.ON, ALL_LANGS, ScriptType.FILE);
|
||||
assertScriptModesAllOps(ScriptMode.SANDBOX, ALL_LANGS, ScriptType.INDEXED, ScriptType.INLINE);
|
||||
}
|
||||
|
@ -216,7 +159,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
public void testEnableFileGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.file", randomFrom(ENABLE_VALUES));
|
||||
//nothing changes if setting set is same as default
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllOps(ScriptMode.ON, ALL_LANGS, ScriptType.FILE);
|
||||
assertScriptModesAllOps(ScriptMode.SANDBOX, ALL_LANGS, ScriptType.INDEXED, ScriptType.INLINE);
|
||||
}
|
||||
|
@ -224,7 +167,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
@Test
|
||||
public void testDisableFileGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.file", randomFrom(DISABLE_VALUES));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllOps(ScriptMode.OFF, ALL_LANGS, ScriptType.FILE);
|
||||
assertScriptModesAllOps(ScriptMode.SANDBOX, ALL_LANGS, ScriptType.INDEXED, ScriptType.INLINE);
|
||||
}
|
||||
|
@ -233,14 +176,14 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
public void testSandboxFileGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.file", ScriptMode.SANDBOX);
|
||||
//nothing changes if setting set is same as default
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllOps(ScriptMode.SANDBOX, ALL_LANGS, ScriptType.FILE, ScriptType.INDEXED, ScriptType.INLINE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleScriptTypeGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.file", ScriptMode.SANDBOX).put("script.inline", randomFrom(DISABLE_VALUES));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllOps(ScriptMode.SANDBOX, ALL_LANGS, ScriptType.FILE);
|
||||
assertScriptModesAllOps(ScriptMode.SANDBOX, ALL_LANGS, ScriptType.INDEXED);
|
||||
assertScriptModesAllOps(ScriptMode.OFF, ALL_LANGS, ScriptType.INLINE);
|
||||
|
@ -249,7 +192,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
@Test
|
||||
public void testEnableMappingGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.mapping", randomFrom(ENABLE_VALUES));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllTypes(ScriptMode.ON, ALL_LANGS, ScriptContext.MAPPING);
|
||||
assertScriptModes(ScriptMode.ON, ALL_LANGS, new ScriptType[]{ScriptType.FILE}, ScriptContext.AGGS, ScriptContext.SEARCH, ScriptContext.UPDATE);
|
||||
assertScriptModes(ScriptMode.SANDBOX, ALL_LANGS, new ScriptType[]{ScriptType.INDEXED, ScriptType.INLINE}, ScriptContext.AGGS, ScriptContext.SEARCH, ScriptContext.UPDATE);
|
||||
|
@ -258,7 +201,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
@Test
|
||||
public void testDisableMappingGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.mapping", randomFrom(DISABLE_VALUES));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllTypes(ScriptMode.OFF, ALL_LANGS, ScriptContext.MAPPING);
|
||||
assertScriptModes(ScriptMode.ON, ALL_LANGS, new ScriptType[]{ScriptType.FILE}, ScriptContext.AGGS, ScriptContext.SEARCH, ScriptContext.UPDATE);
|
||||
assertScriptModes(ScriptMode.SANDBOX, ALL_LANGS, new ScriptType[]{ScriptType.INDEXED, ScriptType.INLINE}, ScriptContext.AGGS, ScriptContext.SEARCH, ScriptContext.UPDATE);
|
||||
|
@ -267,7 +210,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
@Test
|
||||
public void testSandboxMappingGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.mapping", ScriptMode.SANDBOX);
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllTypes(ScriptMode.SANDBOX, ALL_LANGS, ScriptContext.MAPPING);
|
||||
assertScriptModes(ScriptMode.ON, ALL_LANGS, new ScriptType[]{ScriptType.FILE}, ScriptContext.AGGS, ScriptContext.SEARCH, ScriptContext.UPDATE);
|
||||
assertScriptModes(ScriptMode.SANDBOX, ALL_LANGS, new ScriptType[]{ScriptType.INDEXED, ScriptType.INLINE}, ScriptContext.AGGS, ScriptContext.SEARCH, ScriptContext.UPDATE);
|
||||
|
@ -276,7 +219,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
@Test
|
||||
public void testEnableSearchGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.search", randomFrom(ENABLE_VALUES));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllTypes(ScriptMode.ON, ALL_LANGS, ScriptContext.SEARCH);
|
||||
assertScriptModes(ScriptMode.ON, ALL_LANGS, new ScriptType[]{ScriptType.FILE}, ScriptContext.AGGS, ScriptContext.MAPPING, ScriptContext.UPDATE);
|
||||
assertScriptModes(ScriptMode.SANDBOX, ALL_LANGS, new ScriptType[]{ScriptType.INDEXED, ScriptType.INLINE}, ScriptContext.AGGS, ScriptContext.MAPPING, ScriptContext.UPDATE);
|
||||
|
@ -285,7 +228,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
@Test
|
||||
public void testDisableSearchGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.search", randomFrom(DISABLE_VALUES));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllTypes(ScriptMode.OFF, ALL_LANGS, ScriptContext.SEARCH);
|
||||
assertScriptModes(ScriptMode.ON, ALL_LANGS, new ScriptType[]{ScriptType.FILE}, ScriptContext.AGGS, ScriptContext.MAPPING, ScriptContext.UPDATE);
|
||||
assertScriptModes(ScriptMode.SANDBOX, ALL_LANGS, new ScriptType[]{ScriptType.INDEXED, ScriptType.INLINE}, ScriptContext.AGGS, ScriptContext.MAPPING, ScriptContext.UPDATE);
|
||||
|
@ -294,7 +237,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
@Test
|
||||
public void testSandboxSearchGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.search", ScriptMode.SANDBOX);
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllTypes(ScriptMode.SANDBOX, ALL_LANGS, ScriptContext.SEARCH);
|
||||
assertScriptModes(ScriptMode.ON, ALL_LANGS, new ScriptType[]{ScriptType.FILE}, ScriptContext.AGGS, ScriptContext.MAPPING, ScriptContext.UPDATE);
|
||||
assertScriptModes(ScriptMode.SANDBOX, ALL_LANGS, new ScriptType[]{ScriptType.INDEXED, ScriptType.INLINE}, ScriptContext.AGGS, ScriptContext.MAPPING, ScriptContext.UPDATE);
|
||||
|
@ -303,7 +246,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
@Test
|
||||
public void testEnableAggsGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.aggs", randomFrom(ENABLE_VALUES));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllTypes(ScriptMode.ON, ALL_LANGS, ScriptContext.AGGS);
|
||||
assertScriptModes(ScriptMode.ON, ALL_LANGS, new ScriptType[]{ScriptType.FILE}, ScriptContext.SEARCH, ScriptContext.MAPPING, ScriptContext.UPDATE);
|
||||
assertScriptModes(ScriptMode.SANDBOX, ALL_LANGS, new ScriptType[]{ScriptType.INDEXED, ScriptType.INLINE}, ScriptContext.SEARCH, ScriptContext.MAPPING, ScriptContext.UPDATE);
|
||||
|
@ -312,7 +255,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
@Test
|
||||
public void testDisableAggsGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.aggs", randomFrom(DISABLE_VALUES));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllTypes(ScriptMode.OFF, ALL_LANGS, ScriptContext.AGGS);
|
||||
assertScriptModes(ScriptMode.ON, ALL_LANGS, new ScriptType[]{ScriptType.FILE}, ScriptContext.SEARCH, ScriptContext.MAPPING, ScriptContext.UPDATE);
|
||||
assertScriptModes(ScriptMode.SANDBOX, ALL_LANGS, new ScriptType[]{ScriptType.INDEXED, ScriptType.INLINE}, ScriptContext.SEARCH, ScriptContext.MAPPING, ScriptContext.UPDATE);
|
||||
|
@ -321,7 +264,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
@Test
|
||||
public void testSandboxAggsGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.aggs", ScriptMode.SANDBOX);
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllTypes(ScriptMode.SANDBOX, ALL_LANGS, ScriptContext.AGGS);
|
||||
assertScriptModes(ScriptMode.ON, ALL_LANGS, new ScriptType[]{ScriptType.FILE}, ScriptContext.SEARCH, ScriptContext.MAPPING, ScriptContext.UPDATE);
|
||||
assertScriptModes(ScriptMode.SANDBOX, ALL_LANGS, new ScriptType[]{ScriptType.INDEXED, ScriptType.INLINE}, ScriptContext.SEARCH, ScriptContext.MAPPING, ScriptContext.UPDATE);
|
||||
|
@ -330,7 +273,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
@Test
|
||||
public void testEnableUpdateGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.update", randomFrom(ENABLE_VALUES));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllTypes(ScriptMode.ON, ALL_LANGS, ScriptContext.UPDATE);
|
||||
assertScriptModes(ScriptMode.ON, ALL_LANGS, new ScriptType[]{ScriptType.FILE}, ScriptContext.SEARCH, ScriptContext.MAPPING, ScriptContext.AGGS);
|
||||
assertScriptModes(ScriptMode.SANDBOX, ALL_LANGS, new ScriptType[]{ScriptType.INDEXED, ScriptType.INLINE}, ScriptContext.SEARCH, ScriptContext.MAPPING, ScriptContext.AGGS);
|
||||
|
@ -339,7 +282,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
@Test
|
||||
public void testDisableUpdateGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.update", randomFrom(DISABLE_VALUES));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllTypes(ScriptMode.OFF, ALL_LANGS, ScriptContext.UPDATE);
|
||||
assertScriptModes(ScriptMode.ON, ALL_LANGS, new ScriptType[]{ScriptType.FILE}, ScriptContext.SEARCH, ScriptContext.MAPPING, ScriptContext.AGGS);
|
||||
assertScriptModes(ScriptMode.SANDBOX, ALL_LANGS, new ScriptType[]{ScriptType.INDEXED, ScriptType.INLINE}, ScriptContext.SEARCH, ScriptContext.MAPPING, ScriptContext.AGGS);
|
||||
|
@ -348,7 +291,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
@Test
|
||||
public void testSandboxUpdateGenericSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.update", ScriptMode.SANDBOX);
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllTypes(ScriptMode.SANDBOX, ALL_LANGS, ScriptContext.UPDATE);
|
||||
assertScriptModes(ScriptMode.ON, ALL_LANGS, new ScriptType[]{ScriptType.FILE}, ScriptContext.SEARCH, ScriptContext.MAPPING, ScriptContext.AGGS);
|
||||
assertScriptModes(ScriptMode.SANDBOX, ALL_LANGS, new ScriptType[]{ScriptType.INDEXED, ScriptType.INLINE}, ScriptContext.SEARCH, ScriptContext.MAPPING, ScriptContext.AGGS);
|
||||
|
@ -359,7 +302,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.update", ScriptMode.SANDBOX)
|
||||
.put("script.aggs", randomFrom(DISABLE_VALUES))
|
||||
.put("script.search", randomFrom(ENABLE_VALUES));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllTypes(ScriptMode.SANDBOX, ALL_LANGS, ScriptContext.UPDATE);
|
||||
assertScriptModesAllTypes(ScriptMode.OFF, ALL_LANGS, ScriptContext.AGGS);
|
||||
assertScriptModesAllTypes(ScriptMode.ON, ALL_LANGS, ScriptContext.SEARCH);
|
||||
|
@ -372,7 +315,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put("script.update", randomFrom(DISABLE_VALUES))
|
||||
.put("script.indexed", randomFrom(ENABLE_VALUES)).put("script.inline", ScriptMode.SANDBOX);
|
||||
//operations generic settings have precedence over script type generic settings
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModesAllTypes(ScriptMode.OFF, ALL_LANGS, ScriptContext.UPDATE);
|
||||
assertScriptModes(ScriptMode.ON, ALL_LANGS, new ScriptType[]{ScriptType.FILE, ScriptType.INDEXED}, ScriptContext.MAPPING, ScriptContext.AGGS, ScriptContext.SEARCH);
|
||||
assertScriptModes(ScriptMode.SANDBOX, ALL_LANGS, new ScriptType[]{ScriptType.INLINE}, ScriptContext.MAPPING, ScriptContext.AGGS, ScriptContext.SEARCH);
|
||||
|
@ -386,7 +329,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
ImmutableSet<String> groovyLangSet = ImmutableSet.of(GroovyScriptEngineService.NAME);
|
||||
Set<String> allButGroovyLangSet = new HashSet<>(ALL_LANGS);
|
||||
allButGroovyLangSet.remove(GroovyScriptEngineService.NAME);
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModes(ScriptMode.OFF, groovyLangSet, new ScriptType[]{ScriptType.INLINE}, ScriptContext.MAPPING, ScriptContext.UPDATE);
|
||||
assertScriptModes(ScriptMode.SANDBOX, groovyLangSet, new ScriptType[]{ScriptType.INLINE}, ScriptContext.SEARCH, ScriptContext.AGGS);
|
||||
assertScriptModesAllOps(ScriptMode.SANDBOX, allButGroovyLangSet, ScriptType.INLINE);
|
||||
|
@ -402,7 +345,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
ImmutableSet<String> mustacheLangSet = ImmutableSet.of(MustacheScriptEngineService.NAME);
|
||||
Set<String> allButMustacheLangSet = new HashSet<>(ALL_LANGS);
|
||||
allButMustacheLangSet.remove(MustacheScriptEngineService.NAME);
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build(), Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, builder.build());
|
||||
assertScriptModes(ScriptMode.ON, mustacheLangSet, new ScriptType[]{ScriptType.INLINE}, ScriptContext.AGGS, ScriptContext.SEARCH);
|
||||
assertScriptModes(ScriptMode.OFF, mustacheLangSet, new ScriptType[]{ScriptType.INLINE}, ScriptContext.MAPPING, ScriptContext.UPDATE);
|
||||
assertScriptModesAllOps(ScriptMode.OFF, allButMustacheLangSet, ScriptType.INLINE);
|
||||
|
@ -413,7 +356,7 @@ public class ScriptModesTests extends ElasticsearchTestCase {
|
|||
@Test
|
||||
public void testDefaultSettingsToString() {
|
||||
assertAllSettingsWereChecked = false;
|
||||
this.scriptModes = new ScriptModes(scriptEngines, ImmutableSettings.EMPTY, Loggers.getLogger(ScriptModesTests.class));
|
||||
this.scriptModes = new ScriptModes(scriptEngines, ImmutableSettings.EMPTY);
|
||||
assertThat(scriptModes.toString(), equalTo(
|
||||
"script.engine.custom.file.aggs: on\n" +
|
||||
"script.engine.custom.file.mapping: on\n" +
|
||||
|
|
|
@ -93,6 +93,16 @@ public class ScriptServiceTests extends ElasticsearchTestCase {
|
|||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotSupportedDisableDynamicSetting() throws IOException {
|
||||
try {
|
||||
buildScriptService(ImmutableSettings.builder().put(ScriptService.DISABLE_DYNAMIC_SCRIPTING_SETTING, randomUnicodeOfLength(randomIntBetween(1, 10))).build());
|
||||
fail("script service should have thrown exception due to non supported script.disable_dynamic setting");
|
||||
} catch(ElasticsearchIllegalArgumentException e) {
|
||||
assertThat(e.getMessage(), containsString(ScriptService.DISABLE_DYNAMIC_SCRIPTING_SETTING + " is not a supported setting, replace with fine-grained script settings"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScriptsWithoutExtensions() throws IOException {
|
||||
buildScriptService(ImmutableSettings.EMPTY);
|
||||
|
@ -184,54 +194,6 @@ public class ScriptServiceTests extends ElasticsearchTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisableDynamicDeprecatedSetting() throws IOException {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder();
|
||||
ScriptService.DynamicScriptDisabling dynamicScriptDisabling = randomFrom(ScriptService.DynamicScriptDisabling.values());
|
||||
switch(dynamicScriptDisabling) {
|
||||
case EVERYTHING_ALLOWED:
|
||||
builder.put("script.disable_dynamic", randomFrom("false", "none"));
|
||||
break;
|
||||
case ONLY_DISK_ALLOWED:
|
||||
builder.put("script.disable_dynamic", randomFrom("true", "all"));
|
||||
break;
|
||||
case SANDBOXED_ONLY:
|
||||
builder.put("script.disable_dynamic", randomFrom("sandbox", "sandboxed"));
|
||||
break;
|
||||
}
|
||||
|
||||
buildScriptService(builder.build());
|
||||
createFileScripts("groovy", "expression", "mustache", "test");
|
||||
|
||||
for (ScriptContext scriptContext : ScriptContext.values()) {
|
||||
for (ScriptEngineService scriptEngineService : scriptEngineServices) {
|
||||
for (String lang : scriptEngineService.types()) {
|
||||
assertCompileAccepted(lang, "file_script", ScriptType.FILE, scriptContext);
|
||||
|
||||
switch (dynamicScriptDisabling) {
|
||||
case EVERYTHING_ALLOWED:
|
||||
assertCompileAccepted(lang, "script", ScriptType.INDEXED, scriptContext);
|
||||
assertCompileAccepted(lang, "script", ScriptType.INLINE, scriptContext);
|
||||
break;
|
||||
case ONLY_DISK_ALLOWED:
|
||||
assertCompileRejected(lang, "script", ScriptType.INDEXED, scriptContext);
|
||||
assertCompileRejected(lang, "script", ScriptType.INLINE, scriptContext);
|
||||
break;
|
||||
case SANDBOXED_ONLY:
|
||||
if (scriptEngineService.sandboxed()) {
|
||||
assertCompileAccepted(lang, "script", ScriptType.INDEXED, scriptContext);
|
||||
assertCompileAccepted(lang, "script", ScriptType.INLINE, scriptContext);
|
||||
} else {
|
||||
assertCompileRejected(lang, "script", ScriptType.INDEXED, scriptContext);
|
||||
assertCompileRejected(lang, "script", ScriptType.INLINE, scriptContext);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFineGrainedSettings() throws IOException {
|
||||
//collect the fine-grained settings to set for this run
|
||||
|
@ -324,7 +286,6 @@ public class ScriptServiceTests extends ElasticsearchTestCase {
|
|||
for (ScriptContext scriptContext : ScriptContext.values()) {
|
||||
//fallback mechanism: 1) engine specific settings 2) op based settings 3) source based settings
|
||||
ScriptMode scriptMode = engineSettings.get(scriptEngineService.types()[0] + "." + scriptType + "." + scriptContext);
|
||||
;
|
||||
if (scriptMode == null) {
|
||||
scriptMode = scriptContextSettings.get(scriptContext);
|
||||
}
|
||||
|
|
|
@ -18,14 +18,12 @@
|
|||
*/
|
||||
package org.elasticsearch.search.functionscore;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider;
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.test.ElasticsearchBackwardsCompatIntegrationTest;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -104,21 +102,9 @@ public class FunctionScoreBackwardCompatibilityTests extends ElasticsearchBackwa
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
//enable scripting on the internal nodes
|
||||
return ImmutableSettings.builder().put(super.nodeSettings(nodeOrdinal)).put("script.inline", "on").build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Settings externalNodeSettings(int nodeOrdinal) {
|
||||
//enable scripting on the external nodes using the proper setting depending on the bwc version
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put(super.externalNodeSettings(nodeOrdinal));
|
||||
if (compatibilityVersion().before(Version.V_1_6_0)) {
|
||||
builder.put(ScriptService.DISABLE_DYNAMIC_SCRIPTING_SETTING, false);
|
||||
} else {
|
||||
builder.put("script.inline", "on");
|
||||
}
|
||||
return builder.build();
|
||||
protected Settings commonNodeSettings(int nodeOrdinal) {
|
||||
return ImmutableSettings.builder().put(super.commonNodeSettings(nodeOrdinal))
|
||||
.put("script.inline", "on").build();
|
||||
}
|
||||
|
||||
private void checkFunctionScoreStillWorks(String... ids) throws ExecutionException, InterruptedException, IOException {
|
||||
|
|
Loading…
Reference in New Issue