Updated xpack for changed in elastic/elasticsearch#19425 related to templates
Original commit: elastic/x-pack-elasticsearch@7747f92b89
This commit is contained in:
parent
c827a4be79
commit
5b5e0bd787
|
@ -7,14 +7,13 @@ package org.elasticsearch.messy.tests;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticsearchSecurityException;
|
import org.elasticsearch.ElasticsearchSecurityException;
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.action.search.SearchPhaseExecutionException;
|
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
import org.elasticsearch.indices.TermsLookup;
|
import org.elasticsearch.indices.TermsLookup;
|
||||||
import org.elasticsearch.plugins.Plugin;
|
import org.elasticsearch.plugins.Plugin;
|
||||||
import org.elasticsearch.script.Template;
|
import org.elasticsearch.script.ScriptService;
|
||||||
import org.elasticsearch.script.mustache.MustachePlugin;
|
import org.elasticsearch.script.mustache.MustachePlugin;
|
||||||
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
|
import org.elasticsearch.script.mustache.TemplateQueryBuilder;
|
||||||
import org.elasticsearch.test.SecurityIntegTestCase;
|
import org.elasticsearch.test.SecurityIntegTestCase;
|
||||||
import org.elasticsearch.test.SecuritySettingsSource;
|
import org.elasticsearch.test.SecuritySettingsSource;
|
||||||
import org.elasticsearch.xpack.security.authc.support.SecuredString;
|
import org.elasticsearch.xpack.security.authc.support.SecuredString;
|
||||||
|
@ -25,7 +24,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import static java.util.Collections.singletonMap;
|
import static java.util.Collections.singletonMap;
|
||||||
import static org.elasticsearch.script.ScriptService.ScriptType.INLINE;
|
|
||||||
import static org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
import static org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
|
@ -109,7 +107,7 @@ public class SecurityCachePermissionIT extends SecurityIntegTestCase {
|
||||||
|
|
||||||
//Template template = new Template(source, INLINE, MustacheScriptEngineService.NAME, null, singletonMap("name", "token"));
|
//Template template = new Template(source, INLINE, MustacheScriptEngineService.NAME, null, singletonMap("name", "token"));
|
||||||
SearchResponse response = client().prepareSearch("data").setTypes("a")
|
SearchResponse response = client().prepareSearch("data").setTypes("a")
|
||||||
.setQuery(QueryBuilders.templateQuery(source, singletonMap("name", "token")))
|
.setQuery(new TemplateQueryBuilder(source, ScriptService.ScriptType.INLINE, singletonMap("name", "token")))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
assertThat(response.isTimedOut(), is(false));
|
assertThat(response.isTimedOut(), is(false));
|
||||||
assertThat(response.getHits().hits().length, is(1));
|
assertThat(response.getHits().hits().length, is(1));
|
||||||
|
@ -119,7 +117,7 @@ public class SecurityCachePermissionIT extends SecurityIntegTestCase {
|
||||||
.filterWithHeader(singletonMap("Authorization", basicAuthHeaderValue(READ_ONE_IDX_USER,
|
.filterWithHeader(singletonMap("Authorization", basicAuthHeaderValue(READ_ONE_IDX_USER,
|
||||||
new SecuredString("changeme".toCharArray()))))
|
new SecuredString("changeme".toCharArray()))))
|
||||||
.prepareSearch("data").setTypes("a")
|
.prepareSearch("data").setTypes("a")
|
||||||
.setQuery(QueryBuilders.templateQuery(source, singletonMap("name", "token")))
|
.setQuery(new TemplateQueryBuilder(source, ScriptService.ScriptType.INLINE, singletonMap("name", "token")))
|
||||||
.execute().actionGet());
|
.execute().actionGet());
|
||||||
assertThat(e.toString(), containsString("ElasticsearchSecurityException[action"));
|
assertThat(e.toString(), containsString("ElasticsearchSecurityException[action"));
|
||||||
assertThat(e.toString(), containsString("unauthorized"));
|
assertThat(e.toString(), containsString("unauthorized"));
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.elasticsearch.script.CompiledScript;
|
import org.elasticsearch.script.CompiledScript;
|
||||||
import org.elasticsearch.script.ExecutableScript;
|
import org.elasticsearch.script.ExecutableScript;
|
||||||
import org.elasticsearch.script.Template;
|
import org.elasticsearch.script.Script;
|
||||||
import org.elasticsearch.xpack.common.ScriptServiceProxy;
|
import org.elasticsearch.xpack.common.ScriptServiceProxy;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -79,11 +79,11 @@ public class DefaultTextTemplateEngine extends AbstractComponent implements Text
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Template convert(TextTemplate textTemplate, Map<String, Object> model) {
|
private Script convert(TextTemplate textTemplate, Map<String, Object> model) {
|
||||||
Map<String, Object> mergedModel = new HashMap<>();
|
Map<String, Object> mergedModel = new HashMap<>();
|
||||||
mergedModel.putAll(textTemplate.getParams());
|
mergedModel.putAll(textTemplate.getParams());
|
||||||
mergedModel.putAll(model);
|
mergedModel.putAll(model);
|
||||||
return new Template(textTemplate.getTemplate(), textTemplate.getType(), "mustache", textTemplate.getContentType(), mergedModel);
|
return new Script(textTemplate.getTemplate(), textTemplate.getType(), "mustache", mergedModel, textTemplate.getContentType());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> compileParams(XContentType contentType) {
|
private Map<String, String> compileParams(XContentType contentType) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||||
import org.elasticsearch.script.CompiledScript;
|
import org.elasticsearch.script.CompiledScript;
|
||||||
import org.elasticsearch.script.ExecutableScript;
|
import org.elasticsearch.script.ExecutableScript;
|
||||||
import org.elasticsearch.script.ScriptService.ScriptType;
|
import org.elasticsearch.script.ScriptService.ScriptType;
|
||||||
import org.elasticsearch.script.Template;
|
import org.elasticsearch.script.Script;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.elasticsearch.xpack.common.ScriptServiceProxy;
|
import org.elasticsearch.xpack.common.ScriptServiceProxy;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -59,7 +59,7 @@ public class TextTemplateTests extends ESTestCase {
|
||||||
ScriptType type = randomFrom(ScriptType.values());
|
ScriptType type = randomFrom(ScriptType.values());
|
||||||
|
|
||||||
CompiledScript compiledScript = mock(CompiledScript.class);
|
CompiledScript compiledScript = mock(CompiledScript.class);
|
||||||
when(proxy.compile(new Template(templateText, type, lang, null, merged), Collections.singletonMap("content_type", "text/plain")))
|
when(proxy.compile(new Script(templateText, type, lang, merged), Collections.singletonMap("content_type", "text/plain")))
|
||||||
.thenReturn(compiledScript);
|
.thenReturn(compiledScript);
|
||||||
when(proxy.executable(compiledScript, model)).thenReturn(script);
|
when(proxy.executable(compiledScript, model)).thenReturn(script);
|
||||||
when(script.run()).thenReturn("rendered_text");
|
when(script.run()).thenReturn("rendered_text");
|
||||||
|
@ -75,7 +75,7 @@ public class TextTemplateTests extends ESTestCase {
|
||||||
ScriptType scriptType = randomFrom(ScriptType.values());
|
ScriptType scriptType = randomFrom(ScriptType.values());
|
||||||
|
|
||||||
CompiledScript compiledScript = mock(CompiledScript.class);
|
CompiledScript compiledScript = mock(CompiledScript.class);
|
||||||
when(proxy.compile(new Template(templateText, scriptType, lang, null, model),
|
when(proxy.compile(new Script(templateText, scriptType, lang, model),
|
||||||
Collections.singletonMap("content_type", "text/plain")))
|
Collections.singletonMap("content_type", "text/plain")))
|
||||||
.thenReturn(compiledScript);
|
.thenReturn(compiledScript);
|
||||||
when(proxy.executable(compiledScript, model)).thenReturn(script);
|
when(proxy.executable(compiledScript, model)).thenReturn(script);
|
||||||
|
@ -90,7 +90,7 @@ public class TextTemplateTests extends ESTestCase {
|
||||||
Map<String, Object> model = singletonMap("key", "model_val");
|
Map<String, Object> model = singletonMap("key", "model_val");
|
||||||
|
|
||||||
CompiledScript compiledScript = mock(CompiledScript.class);
|
CompiledScript compiledScript = mock(CompiledScript.class);
|
||||||
when(proxy.compile(new Template(templateText, ScriptType.INLINE, lang, null, model),
|
when(proxy.compile(new Script(templateText, ScriptType.INLINE, lang, model),
|
||||||
Collections.singletonMap("content_type", "text/plain")))
|
Collections.singletonMap("content_type", "text/plain")))
|
||||||
.thenReturn(compiledScript);
|
.thenReturn(compiledScript);
|
||||||
when(proxy.executable(compiledScript, model)).thenReturn(script);
|
when(proxy.executable(compiledScript, model)).thenReturn(script);
|
||||||
|
|
Loading…
Reference in New Issue