Skip to content

Commit

Permalink
Make sure that we don't detect files as maven coordinate when install…
Browse files Browse the repository at this point in the history
…ing 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
  • Loading branch information
jimczi committed Jan 10, 2018
1 parent cbb3f6d commit e2e94b8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ private Path download(Terminal terminal, String pluginId, Path tmpDir) throws Ex

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

// fall back to plain old URL
if (pluginId.contains(":/") == false) {
if (pluginId.contains(":") == false) {
// definitely not a valid url, so assume it is a plugin name
List<String> plugins = checkMisspelledPlugin(pluginId);
String msg = "Unknown plugin " + pluginId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.Version;
import org.elasticsearch.cli.ExitCodes;
Expand All @@ -44,6 +45,7 @@
import org.junit.Before;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
Expand Down Expand Up @@ -430,6 +432,16 @@ public void testMalformedUrlNotMaven() throws Exception {
assertTrue(e.getMessage(), e.getMessage().contains("no protocol"));
}

public void testFileNotMaven() throws Exception {
Tuple<Path, Environment> env = createEnv(fs, temp);
String dir = randomAlphaOfLength(10) + ":" + randomAlphaOfLength(5) + "\\" + randomAlphaOfLength(5);
Exception e = expectThrows(Exception.class,
// has two colons, so it appears similar to maven coordinates
() -> installPlugin("file:" + dir, env.v1()));
assertFalse(e.getMessage(), e.getMessage().contains("maven.org"));
assertTrue(e.getMessage(), e.getMessage().contains(dir));
}

public void testUnknownPlugin() throws Exception {
Tuple<Path, Environment> env = createEnv(fs, temp);
UserException e = expectThrows(UserException.class, () -> installPlugin("foo", env.v1()));
Expand Down
7 changes: 2 additions & 5 deletions plugins/examples/meta-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ integTestCluster {
distribution = 'zip'

// Install the meta plugin before start.
/**
* NORELEASE Tests fail on windows, see https://github.com/elastic/elasticsearch/pull/28163
*/
//setupCommand 'installMetaPlugin',
// 'bin/elasticsearch-plugin', 'install', 'file:' + buildZip.archivePath
setupCommand 'installMetaPlugin',
'bin/elasticsearch-plugin', 'install', 'file:' + buildZip.archivePath
}
check.dependsOn integTest
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
- do:
nodes.info: {}

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

0 comments on commit e2e94b8

Please sign in to comment.