Skip to content

Commit

Permalink
Drop stored scripts with the old style-id (#48078)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jdconrad authored Oct 16, 2019
1 parent c6037dc commit 18a694f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,12 @@ public static ScriptMetaData fromXContent(XContentParser parser) throws IOExcept
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 " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Collections;

public class ScriptMetaDataTests extends AbstractSerializingTestCase<ScriptMetaData> {

Expand Down Expand Up @@ -168,6 +169,42 @@ public void testLoadEmptyScripts() throws IOException {
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;
Expand Down

0 comments on commit 18a694f

Please sign in to comment.