Skip to content

Commit fcf4114

Browse files
authored
Make sure that we don't detect files as maven coordinate when installing a plugin (#28163)
* This change makes sure that we don't detect a file path containing a ':' as a maven coordinate (e.g.: `file:C:\path\to\zip`) * restore test muted on master
1 parent ca6b15b commit fcf4114

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

distribution/tools/plugin-cli/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,14 @@ private Path download(Terminal terminal, String pluginId, Path tmpDir) throws Ex
232232

233233
// now try as maven coordinates, a valid URL would only have a colon and slash
234234
String[] coordinates = pluginId.split(":");
235-
if (coordinates.length == 3 && pluginId.contains("/") == false) {
235+
if (coordinates.length == 3 && pluginId.contains("/") == false && pluginId.startsWith("file:") == false) {
236236
String mavenUrl = getMavenUrl(terminal, coordinates, Platforms.PLATFORM_NAME);
237237
terminal.println("-> Downloading " + pluginId + " from maven central");
238238
return downloadZipAndChecksum(terminal, mavenUrl, tmpDir, true);
239239
}
240240

241241
// fall back to plain old URL
242-
if (pluginId.contains(":/") == false) {
242+
if (pluginId.contains(":") == false) {
243243
// definitely not a valid url, so assume it is a plugin name
244244
List<String> plugins = checkMisspelledPlugin(pluginId);
245245
String msg = "Unknown plugin " + pluginId;

distribution/tools/plugin-cli/src/test/java/org/elasticsearch/plugins/InstallPluginCommandTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
2323
import com.google.common.jimfs.Configuration;
2424
import com.google.common.jimfs.Jimfs;
25+
import org.apache.lucene.util.IOUtils;
2526
import org.apache.lucene.util.LuceneTestCase;
2627
import org.elasticsearch.Version;
2728
import org.elasticsearch.cli.ExitCodes;
@@ -44,6 +45,7 @@
4445
import org.junit.Before;
4546

4647
import java.io.BufferedReader;
48+
import java.io.FileNotFoundException;
4749
import java.io.IOException;
4850
import java.io.InputStream;
4951
import java.io.StringReader;
@@ -430,6 +432,16 @@ public void testMalformedUrlNotMaven() throws Exception {
430432
assertTrue(e.getMessage(), e.getMessage().contains("no protocol"));
431433
}
432434

435+
public void testFileNotMaven() throws Exception {
436+
Tuple<Path, Environment> env = createEnv(fs, temp);
437+
String dir = randomAlphaOfLength(10) + ":" + randomAlphaOfLength(5) + "\\" + randomAlphaOfLength(5);
438+
Exception e = expectThrows(Exception.class,
439+
// has two colons, so it appears similar to maven coordinates
440+
() -> installPlugin("file:" + dir, env.v1()));
441+
assertFalse(e.getMessage(), e.getMessage().contains("maven.org"));
442+
assertTrue(e.getMessage(), e.getMessage().contains(dir));
443+
}
444+
433445
public void testUnknownPlugin() throws Exception {
434446
Tuple<Path, Environment> env = createEnv(fs, temp);
435447
UserException e = expectThrows(UserException.class, () -> installPlugin("foo", env.v1()));

plugins/examples/meta-plugin/build.gradle

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ integTestCluster {
5050
distribution = 'zip'
5151

5252
// Install the meta plugin before start.
53-
/**
54-
* NORELEASE Tests fail on windows, see https://github.com/elastic/elasticsearch/pull/28163
55-
*/
56-
//setupCommand 'installMetaPlugin',
57-
// 'bin/elasticsearch-plugin', 'install', 'file:' + buildZip.archivePath
53+
setupCommand 'installMetaPlugin',
54+
'bin/elasticsearch-plugin', 'install', 'file:' + buildZip.archivePath
5855
}
5956
check.dependsOn integTest

plugins/examples/meta-plugin/src/test/resources/rest-api-spec/test/smoke_test_plugins/10_basic.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@
1010
- do:
1111
nodes.info: {}
1212

13-
# NORELEASE Tests fail on windows, see https://github.com/elastic/elasticsearch/pull/28163
14-
# - match: { nodes.$master.plugins.0.name: dummy-plugin1 }
15-
# - match: { nodes.$master.plugins.1.name: dummy-plugin2 }
13+
- match: { nodes.$master.plugins.0.name: dummy-plugin1 }
14+
- match: { nodes.$master.plugins.1.name: dummy-plugin2 }

0 commit comments

Comments
 (0)