Remove uses of ScriptService.executable which takes Script (elastic/x-pack-elasticsearch#1164)
This is the xpack side of elastic/elasticsearch#24264 Original commit: elastic/x-pack-elasticsearch@ac36bc32aa
This commit is contained in:
parent
72a9bffff8
commit
c5b14197d4
|
@ -58,6 +58,7 @@ import org.elasticsearch.index.shard.IndexSearcherWrapper;
|
|||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.index.shard.ShardUtils;
|
||||
import org.elasticsearch.license.XPackLicenseState;
|
||||
import org.elasticsearch.script.CompiledScript;
|
||||
import org.elasticsearch.script.ExecutableScript;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptContext;
|
||||
|
@ -276,7 +277,8 @@ public class SecurityIndexSearcherWrapper extends IndexSearcherWrapper {
|
|||
params.put("_user", userModel);
|
||||
// Always enforce mustache script lang:
|
||||
script = new Script(script.getType(), "mustache", script.getIdOrCode(), script.getOptions(), params);
|
||||
ExecutableScript executable = scriptService.executable(script, ScriptContext.Standard.SEARCH);
|
||||
CompiledScript compiledScript = scriptService.compile(script, ScriptContext.Standard.SEARCH);
|
||||
ExecutableScript executable = scriptService.executable(compiledScript, script.getParams());
|
||||
return (BytesReference) executable.run();
|
||||
} else {
|
||||
return querySource;
|
||||
|
|
|
@ -68,6 +68,7 @@ import org.elasticsearch.index.shard.IndexShard;
|
|||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.indices.TermsLookup;
|
||||
import org.elasticsearch.license.XPackLicenseState;
|
||||
import org.elasticsearch.script.CompiledScript;
|
||||
import org.elasticsearch.script.ExecutableScript;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptContext;
|
||||
|
@ -457,8 +458,10 @@ public class SecurityIndexSearcherWrapperUnitTests extends ESTestCase {
|
|||
}
|
||||
};
|
||||
|
||||
CompiledScript compiledScript = mock(CompiledScript.class);
|
||||
when(scriptService.compile(any(Script.class), eq(ScriptContext.Standard.SEARCH))).thenReturn(compiledScript);
|
||||
ExecutableScript executableScript = mock(ExecutableScript.class);
|
||||
when(scriptService.executable(any(Script.class), eq(ScriptContext.Standard.SEARCH))).thenReturn(executableScript);
|
||||
when(scriptService.executable(eq(compiledScript), any())).thenReturn(executableScript);
|
||||
|
||||
XContentBuilder builder = jsonBuilder();
|
||||
String query = new TermQueryBuilder("field", "{{_user.username}}").toXContent(builder, ToXContent.EMPTY_PARAMS).string();
|
||||
|
@ -469,7 +472,7 @@ public class SecurityIndexSearcherWrapperUnitTests extends ESTestCase {
|
|||
|
||||
securityIndexSearcherWrapper.evaluateTemplate(querySource);
|
||||
ArgumentCaptor<Script> argument = ArgumentCaptor.forClass(Script.class);
|
||||
verify(scriptService).executable(argument.capture(), eq(ScriptContext.Standard.SEARCH));
|
||||
verify(scriptService).compile(argument.capture(), eq(ScriptContext.Standard.SEARCH));
|
||||
Script usedScript = argument.getValue();
|
||||
assertThat(usedScript.getIdOrCode(), equalTo(script.getIdOrCode()));
|
||||
assertThat(usedScript.getType(), equalTo(script.getType()));
|
||||
|
|
Loading…
Reference in New Issue