From d3b3fe783dc59a38067ece195fbb415d6a5321e7 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 25 May 2017 12:18:55 -0700 Subject: [PATCH] Use new context constants for SearchScript and ExecutableScript (elastic/x-pack-elasticsearch#1550) This is the xpack side of https://github.com/elastic/elasticsearch/pull/24883. Original commit: elastic/x-pack-elasticsearch@9e612ec22292ec4a63bb5adc3dde9c54ad6b9f2e --- .../authz/accesscontrol/SecurityIndexSearcherWrapper.java | 3 ++- .../accesscontrol/SecurityIndexSearcherWrapperUnitTests.java | 5 +++-- .../elasticsearch/xpack/watcher/test/WatcherTestUtils.java | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/plugin/src/main/java/org/elasticsearch/xpack/security/authz/accesscontrol/SecurityIndexSearcherWrapper.java b/plugin/src/main/java/org/elasticsearch/xpack/security/authz/accesscontrol/SecurityIndexSearcherWrapper.java index a9bb3a9b72d..7f6d718b222 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/security/authz/accesscontrol/SecurityIndexSearcherWrapper.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/security/authz/accesscontrol/SecurityIndexSearcherWrapper.java @@ -56,6 +56,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.ExecutableScript; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptService; @@ -274,7 +275,7 @@ 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); - CompiledTemplate compiledTemplate = scriptService.compileTemplate(script, ScriptContext.EXECUTABLE); + CompiledTemplate compiledTemplate = scriptService.compileTemplate(script, ExecutableScript.CONTEXT); return compiledTemplate.run(script.getParams()); } else { return querySource; diff --git a/plugin/src/test/java/org/elasticsearch/xpack/security/authz/accesscontrol/SecurityIndexSearcherWrapperUnitTests.java b/plugin/src/test/java/org/elasticsearch/xpack/security/authz/accesscontrol/SecurityIndexSearcherWrapperUnitTests.java index a58cf80675a..a611e6358ef 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/security/authz/accesscontrol/SecurityIndexSearcherWrapperUnitTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/security/authz/accesscontrol/SecurityIndexSearcherWrapperUnitTests.java @@ -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.ExecutableScript; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptService; @@ -458,7 +459,7 @@ public class SecurityIndexSearcherWrapperUnitTests extends ESTestCase { }; CompiledTemplate compiledScript = mock(CompiledTemplate.class); - when(scriptService.compileTemplate(any(Script.class), eq(ScriptContext.EXECUTABLE))).thenReturn(compiledScript); + when(scriptService.compileTemplate(any(Script.class), eq(ExecutableScript.CONTEXT))).thenReturn(compiledScript); XContentBuilder builder = jsonBuilder(); String query = new TermQueryBuilder("field", "{{_user.username}}").toXContent(builder, ToXContent.EMPTY_PARAMS).string(); @@ -469,7 +470,7 @@ public class SecurityIndexSearcherWrapperUnitTests extends ESTestCase { securityIndexSearcherWrapper.evaluateTemplate(querySource); ArgumentCaptor