Skip to content

Commit b5b528b

Browse files
committed
Make sure that we don't detect files as maven coordinate when installing a plugin
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`)
1 parent ca6b15b commit b5b528b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.junit.Before;
4545

4646
import java.io.BufferedReader;
47+
import java.io.FileNotFoundException;
4748
import java.io.IOException;
4849
import java.io.InputStream;
4950
import java.io.StringReader;
@@ -430,6 +431,14 @@ public void testMalformedUrlNotMaven() throws Exception {
430431
assertTrue(e.getMessage(), e.getMessage().contains("no protocol"));
431432
}
432433

434+
public void testFileNotMaven() throws Exception {
435+
Tuple<Path, Environment> env = createEnv(fs, temp);
436+
// has two colons, so it appears similar to maven coordinates
437+
FileNotFoundException e = expectThrows(FileNotFoundException.class,
438+
() -> installPlugin("file:C:\\path\\to\\plugin\\does_not_exists.zip", env.v1()));
439+
assertTrue(e.getMessage(), e.getMessage().startsWith("C:\\path\\to\\plugin\\does_not_exists.zip"));
440+
}
441+
433442
public void testUnknownPlugin() throws Exception {
434443
Tuple<Path, Environment> env = createEnv(fs, temp);
435444
UserException e = expectThrows(UserException.class, () -> installPlugin("foo", env.v1()));

0 commit comments

Comments
 (0)