Drop stored scripts with the old style-id (#48078)

This PR fixes (#47593). Stored scripts with the old-style id of lang#id are 
saved through the upgrade process but are no longer accessible in recent 
versions. This fix will drop those scripts altogether since there is no way for 
a user to access them.
This commit is contained in:
Jack Conradson 2019-10-16 16:09:22 -07:00
parent ac1ed6e740
commit fa99721295
2 changed files with 43 additions and 1 deletions

View File

@ -249,7 +249,12 @@ public final class ScriptMetaData implements MetaData.Custom, Writeable, ToXCont
source = StoredScriptSource.fromXContent(parser, true);
if (exists == null) {
scripts.put(id, source);
// due to a bug (https://github.com/elastic/elasticsearch/issues/47593)
// scripts may have been retained during upgrade that include the old-style
// id of lang#id; these scripts are unreachable after 7.0, so they are dropped
if (id.contains("#") == false) {
scripts.put(id, source);
}
} else if (exists.getLang().equals(source.getLang()) == false) {
throw new IllegalArgumentException("illegal stored script, id [" + id + "] used for multiple scripts with " +
"different languages [" + exists.getLang() + "] and [" + source.getLang() + "]; scripts using the old " +

View File

@ -32,6 +32,7 @@ import org.elasticsearch.test.AbstractSerializingTestCase;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Collections;
public class ScriptMetaDataTests extends AbstractSerializingTestCase<ScriptMetaData> {
@ -168,6 +169,42 @@ public class ScriptMetaDataTests extends AbstractSerializingTestCase<ScriptMetaD
assertWarnings("empty templates should no longer be used");
}
public void testOldStyleDropped() throws IOException {
XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent());
builder.startObject();
{
builder.startObject("painless#test");
{
builder.field("lang", "painless");
builder.field("source", "code");
}
builder.endObject();
builder.startObject("lang#test");
{
builder.field("lang", "test");
builder.field("source", "code");
}
builder.endObject();
builder.startObject("test");
{
builder.field("lang", "painless");
builder.field("source", "code");
}
builder.endObject();
}
builder.endObject();
XContentParser parser = XContentType.JSON.xContent()
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
BytesReference.bytes(builder).streamInput());
ScriptMetaData smd = ScriptMetaData.fromXContent(parser);
assertNull(smd.getStoredScript("painless#test"));
assertNull(smd.getStoredScript("lang#test"));
assertEquals(new StoredScriptSource("painless", "code", Collections.emptyMap()), smd.getStoredScript("test"));
assertEquals(1, smd.getStoredScripts().size());
}
@Override
protected boolean enableWarningsCheck() {
return true;