|
@@ -115,7 +115,7 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
super.setUp();
|
|
|
skipJarHellCommand = new InstallPluginCommand() {
|
|
|
@Override
|
|
|
- void jarHellCheck(PluginInfo info, Path candidate, Path pluginsDir, Path modulesDir) throws Exception {
|
|
|
+ void jarHellCheck(PluginInfo candidateInfo, Path candidate, Path pluginsDir, Path modulesDir) throws Exception {
|
|
|
// no jarhell check
|
|
|
}
|
|
|
};
|
|
@@ -214,7 +214,19 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
return createPlugin(name, structure, false, additionalProps).toUri().toURL().toString();
|
|
|
}
|
|
|
|
|
|
- static Path createPlugin(String name, Path structure, boolean createSecurityPolicyFile, String... additionalProps) throws IOException {
|
|
|
+ /** creates an meta plugin .zip and returns the url for testing */
|
|
|
+ static String createMetaPluginUrl(String name, Path structure) throws IOException {
|
|
|
+ return createMetaPlugin(name, structure).toUri().toURL().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ static void writeMetaPlugin(String name, Path structure) throws IOException {
|
|
|
+ PluginTestUtil.writeMetaPluginProperties(structure,
|
|
|
+ "description", "fake desc",
|
|
|
+ "name", name
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ static void writePlugin(String name, Path structure, boolean createSecurityPolicyFile, String... additionalProps) throws IOException {
|
|
|
String[] properties = Stream.concat(Stream.of(
|
|
|
"description", "fake desc",
|
|
|
"name", name,
|
|
@@ -223,12 +235,22 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
"java.version", System.getProperty("java.specification.version"),
|
|
|
"classname", "FakePlugin"
|
|
|
), Arrays.stream(additionalProps)).toArray(String[]::new);
|
|
|
- PluginTestUtil.writeProperties(structure, properties);
|
|
|
+ PluginTestUtil.writePluginProperties(structure, properties);
|
|
|
if (createSecurityPolicyFile) {
|
|
|
String securityPolicyContent = "grant {\n permission java.lang.RuntimePermission \"setFactory\";\n};\n";
|
|
|
Files.write(structure.resolve("plugin-security.policy"), securityPolicyContent.getBytes(StandardCharsets.UTF_8));
|
|
|
}
|
|
|
- writeJar(structure.resolve("plugin.jar"), "FakePlugin");
|
|
|
+ String className = name.substring(0, 1).toUpperCase(Locale.ENGLISH) + name.substring(1) + "Plugin";
|
|
|
+ writeJar(structure.resolve("plugin.jar"), className);
|
|
|
+ }
|
|
|
+
|
|
|
+ static Path createPlugin(String name, Path structure, boolean createSecurityPolicyFile, String... additionalProps) throws IOException {
|
|
|
+ writePlugin(name, structure, createSecurityPolicyFile, additionalProps);
|
|
|
+ return writeZip(structure, "elasticsearch");
|
|
|
+ }
|
|
|
+
|
|
|
+ static Path createMetaPlugin(String name, Path structure) throws IOException {
|
|
|
+ writeMetaPlugin(name, structure);
|
|
|
return writeZip(structure, "elasticsearch");
|
|
|
}
|
|
|
|
|
@@ -243,8 +265,20 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
return terminal;
|
|
|
}
|
|
|
|
|
|
+ void assertMetaPlugin(String metaPlugin, String name, Path original, Environment env) throws IOException {
|
|
|
+ assertPluginInternal(name, original, env,
|
|
|
+ env.pluginsFile().resolve(metaPlugin), env.configFile().resolve(metaPlugin), env.binFile().resolve(metaPlugin));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
void assertPlugin(String name, Path original, Environment env) throws IOException {
|
|
|
- Path got = env.pluginsFile().resolve(name);
|
|
|
+ assertPluginInternal(name, original, env,
|
|
|
+ env.pluginsFile(), env.configFile(), env.binFile());
|
|
|
+ }
|
|
|
+
|
|
|
+ void assertPluginInternal(String name, Path original, Environment env,
|
|
|
+ Path pluginsFile, Path configFile, Path binFile) throws IOException {
|
|
|
+ Path got = pluginsFile.resolve(name);
|
|
|
assertTrue("dir " + name + " exists", Files.exists(got));
|
|
|
|
|
|
if (isPosix) {
|
|
@@ -265,12 +299,12 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
assertFalse("bin was not copied", Files.exists(got.resolve("bin")));
|
|
|
assertFalse("config was not copied", Files.exists(got.resolve("config")));
|
|
|
if (Files.exists(original.resolve("bin"))) {
|
|
|
- Path binDir = env.binFile().resolve(name);
|
|
|
+ Path binDir = binFile.resolve(name);
|
|
|
assertTrue("bin dir exists", Files.exists(binDir));
|
|
|
assertTrue("bin is a dir", Files.isDirectory(binDir));
|
|
|
PosixFileAttributes binAttributes = null;
|
|
|
if (isPosix) {
|
|
|
- binAttributes = Files.readAttributes(env.binFile(), PosixFileAttributes.class);
|
|
|
+ binAttributes = Files.readAttributes(binFile, PosixFileAttributes.class);
|
|
|
}
|
|
|
try (DirectoryStream<Path> stream = Files.newDirectoryStream(binDir)) {
|
|
|
for (Path file : stream) {
|
|
@@ -283,7 +317,7 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
}
|
|
|
}
|
|
|
if (Files.exists(original.resolve("config"))) {
|
|
|
- Path configDir = env.configFile().resolve(name);
|
|
|
+ Path configDir = configFile.resolve(name);
|
|
|
assertTrue("config dir exists", Files.exists(configDir));
|
|
|
assertTrue("config is a dir", Files.isDirectory(configDir));
|
|
|
|
|
@@ -292,7 +326,7 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
|
|
|
if (isPosix) {
|
|
|
PosixFileAttributes configAttributes =
|
|
|
- Files.getFileAttributeView(env.configFile(), PosixFileAttributeView.class).readAttributes();
|
|
|
+ Files.getFileAttributeView(configFile, PosixFileAttributeView.class).readAttributes();
|
|
|
user = configAttributes.owner();
|
|
|
group = configAttributes.group();
|
|
|
|
|
@@ -344,9 +378,23 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
assertPlugin("fake", pluginDir, env.v2());
|
|
|
}
|
|
|
|
|
|
- public void testInstallFailsIfPreviouslyRemovedPluginFailed() throws Exception {
|
|
|
+ public void testWithMetaPlugin() throws Exception {
|
|
|
Tuple<Path, Environment> env = createEnv(fs, temp);
|
|
|
Path pluginDir = createPluginDir(temp);
|
|
|
+ Files.createDirectory(pluginDir.resolve("fake1"));
|
|
|
+ writePlugin("fake1", pluginDir.resolve("fake1"), false);
|
|
|
+ Files.createDirectory(pluginDir.resolve("fake2"));
|
|
|
+ writePlugin("fake2", pluginDir.resolve("fake2"), false);
|
|
|
+ String pluginZip = createMetaPluginUrl("my_plugins", pluginDir);
|
|
|
+ installPlugin(pluginZip, env.v1());
|
|
|
+ assertMetaPlugin("my_plugins", "fake1", pluginDir, env.v2());
|
|
|
+ assertMetaPlugin("my_plugins", "fake2", pluginDir, env.v2());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testInstallFailsIfPreviouslyRemovedPluginFailed() throws Exception {
|
|
|
+ Tuple<Path, Environment> env = createEnv(fs, temp);
|
|
|
+ Path metaDir = createPluginDir(temp);
|
|
|
+ Path pluginDir = metaDir.resolve("fake");
|
|
|
String pluginZip = createPluginUrl("fake", pluginDir);
|
|
|
final Path removing = env.v2().pluginsFile().resolve(".removing-failed");
|
|
|
Files.createDirectory(removing);
|
|
@@ -356,6 +404,11 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
"found file [%s] from a failed attempt to remove the plugin [failed]; execute [elasticsearch-plugin remove failed]",
|
|
|
removing);
|
|
|
assertThat(e, hasToString(containsString(expected)));
|
|
|
+
|
|
|
+ // test with meta plugin
|
|
|
+ String metaZip = createMetaPluginUrl("my_plugins", metaDir);
|
|
|
+ final IllegalStateException e1 = expectThrows(IllegalStateException.class, () -> installPlugin(metaZip, env.v1()));
|
|
|
+ assertThat(e1, hasToString(containsString(expected)));
|
|
|
}
|
|
|
|
|
|
public void testSpaceInUrl() throws Exception {
|
|
@@ -418,6 +471,23 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
assertInstallCleaned(environment.v2());
|
|
|
}
|
|
|
|
|
|
+ public void testJarHellInMetaPlugin() throws Exception {
|
|
|
+ // jar hell test needs a real filesystem
|
|
|
+ assumeTrue("real filesystem", isReal);
|
|
|
+ Tuple<Path, Environment> environment = createEnv(fs, temp);
|
|
|
+ Path pluginDir = createPluginDir(temp);
|
|
|
+ Files.createDirectory(pluginDir.resolve("fake1"));
|
|
|
+ writePlugin("fake1", pluginDir.resolve("fake1"), false);
|
|
|
+ Files.createDirectory(pluginDir.resolve("fake2"));
|
|
|
+ writePlugin("fake2", pluginDir.resolve("fake2"), false); // adds plugin.jar with Fake2Plugin
|
|
|
+ writeJar(pluginDir.resolve("fake2").resolve("other.jar"), "Fake2Plugin");
|
|
|
+ String pluginZip = createMetaPluginUrl("my_plugins", pluginDir);
|
|
|
+ IllegalStateException e = expectThrows(IllegalStateException.class,
|
|
|
+ () -> installPlugin(pluginZip, environment.v1(), defaultCommand));
|
|
|
+ assertTrue(e.getMessage(), e.getMessage().contains("jar hell"));
|
|
|
+ assertInstallCleaned(environment.v2());
|
|
|
+ }
|
|
|
+
|
|
|
public void testIsolatedPlugins() throws Exception {
|
|
|
Tuple<Path, Environment> env = createEnv(fs, temp);
|
|
|
// these both share the same FakePlugin class
|
|
@@ -441,6 +511,23 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
assertInstallCleaned(env.v2());
|
|
|
}
|
|
|
|
|
|
+ public void testExistingMetaPlugin() throws Exception {
|
|
|
+ Tuple<Path, Environment> env = createEnv(fs, temp);
|
|
|
+ Path metaZip = createPluginDir(temp);
|
|
|
+ Path pluginDir = metaZip.resolve("fake");
|
|
|
+ Files.createDirectory(pluginDir);
|
|
|
+ String pluginZip = createPluginUrl("fake", pluginDir);
|
|
|
+ installPlugin(pluginZip, env.v1());
|
|
|
+ UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
|
|
|
+ assertTrue(e.getMessage(), e.getMessage().contains("already exists"));
|
|
|
+ assertInstallCleaned(env.v2());
|
|
|
+
|
|
|
+ String anotherZip = createMetaPluginUrl("another_plugins", metaZip);
|
|
|
+ e = expectThrows(UserException.class, () -> installPlugin(anotherZip, env.v1()));
|
|
|
+ assertTrue(e.getMessage(), e.getMessage().contains("already exists"));
|
|
|
+ assertInstallCleaned(env.v2());
|
|
|
+ }
|
|
|
+
|
|
|
public void testBin() throws Exception {
|
|
|
Tuple<Path, Environment> env = createEnv(fs, temp);
|
|
|
Path pluginDir = createPluginDir(temp);
|
|
@@ -452,20 +539,43 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
assertPlugin("fake", pluginDir, env.v2());
|
|
|
}
|
|
|
|
|
|
+ public void testMetaBin() throws Exception {
|
|
|
+ Tuple<Path, Environment> env = createEnv(fs, temp);
|
|
|
+ Path metaDir = createPluginDir(temp);
|
|
|
+ Path pluginDir = metaDir.resolve("fake");
|
|
|
+ Files.createDirectory(pluginDir);
|
|
|
+ writePlugin("fake", pluginDir, false);
|
|
|
+ Path binDir = pluginDir.resolve("bin");
|
|
|
+ Files.createDirectory(binDir);
|
|
|
+ Files.createFile(binDir.resolve("somescript"));
|
|
|
+ String pluginZip = createMetaPluginUrl("my_plugins", metaDir);
|
|
|
+ installPlugin(pluginZip, env.v1());
|
|
|
+ assertMetaPlugin("my_plugins","fake", pluginDir, env.v2());
|
|
|
+ }
|
|
|
+
|
|
|
public void testBinNotDir() throws Exception {
|
|
|
Tuple<Path, Environment> env = createEnv(fs, temp);
|
|
|
- Path pluginDir = createPluginDir(temp);
|
|
|
+ Path metaDir = createPluginDir(temp);
|
|
|
+ Path pluginDir = metaDir.resolve("fake");
|
|
|
+ Files.createDirectory(pluginDir);
|
|
|
Path binDir = pluginDir.resolve("bin");
|
|
|
Files.createFile(binDir);
|
|
|
String pluginZip = createPluginUrl("fake", pluginDir);
|
|
|
UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
|
|
|
assertTrue(e.getMessage(), e.getMessage().contains("not a directory"));
|
|
|
assertInstallCleaned(env.v2());
|
|
|
+
|
|
|
+ String metaZip = createMetaPluginUrl("my_plugins", metaDir);
|
|
|
+ e = expectThrows(UserException.class, () -> installPlugin(metaZip, env.v1()));
|
|
|
+ assertTrue(e.getMessage(), e.getMessage().contains("not a directory"));
|
|
|
+ assertInstallCleaned(env.v2());
|
|
|
}
|
|
|
|
|
|
public void testBinContainsDir() throws Exception {
|
|
|
Tuple<Path, Environment> env = createEnv(fs, temp);
|
|
|
- Path pluginDir = createPluginDir(temp);
|
|
|
+ Path metaDir = createPluginDir(temp);
|
|
|
+ Path pluginDir = metaDir.resolve("fake");
|
|
|
+ Files.createDirectory(pluginDir);
|
|
|
Path dirInBinDir = pluginDir.resolve("bin").resolve("foo");
|
|
|
Files.createDirectories(dirInBinDir);
|
|
|
Files.createFile(dirInBinDir.resolve("somescript"));
|
|
@@ -473,11 +583,16 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
|
|
|
assertTrue(e.getMessage(), e.getMessage().contains("Directories not allowed in bin dir for plugin"));
|
|
|
assertInstallCleaned(env.v2());
|
|
|
+
|
|
|
+ String metaZip = createMetaPluginUrl("my_plugins", metaDir);
|
|
|
+ e = expectThrows(UserException.class, () -> installPlugin(metaZip, env.v1()));
|
|
|
+ assertTrue(e.getMessage(), e.getMessage().contains("Directories not allowed in bin dir for plugin"));
|
|
|
+ assertInstallCleaned(env.v2());
|
|
|
}
|
|
|
|
|
|
public void testBinConflict() throws Exception {
|
|
|
Tuple<Path, Environment> env = createEnv(fs, temp);
|
|
|
- Path pluginDir = createPluginDir(temp);
|
|
|
+ Path pluginDir = createPluginDir(temp);
|
|
|
Path binDir = pluginDir.resolve("bin");
|
|
|
Files.createDirectory(binDir);
|
|
|
Files.createFile(binDir.resolve("somescript"));
|
|
@@ -505,6 +620,27 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void testMetaBinPermissions() throws Exception {
|
|
|
+ assumeTrue("posix filesystem", isPosix);
|
|
|
+ Tuple<Path, Environment> env = createEnv(fs, temp);
|
|
|
+ Path metaDir = createPluginDir(temp);
|
|
|
+ Path pluginDir = metaDir.resolve("fake");
|
|
|
+ Files.createDirectory(pluginDir);
|
|
|
+ writePlugin("fake", pluginDir, false);
|
|
|
+ Path binDir = pluginDir.resolve("bin");
|
|
|
+ Files.createDirectory(binDir);
|
|
|
+ Files.createFile(binDir.resolve("somescript"));
|
|
|
+ String pluginZip = createMetaPluginUrl("my_plugins", metaDir);
|
|
|
+ try (PosixPermissionsResetter binAttrs = new PosixPermissionsResetter(env.v2().binFile())) {
|
|
|
+ Set<PosixFilePermission> perms = binAttrs.getCopyPermissions();
|
|
|
+ // make sure at least one execute perm is missing, so we know we forced it during installation
|
|
|
+ perms.remove(PosixFilePermission.GROUP_EXECUTE);
|
|
|
+ binAttrs.setPermissions(perms);
|
|
|
+ installPlugin(pluginZip, env.v1());
|
|
|
+ assertMetaPlugin("my_plugins", "fake", pluginDir, env.v2());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void testPluginPermissions() throws Exception {
|
|
|
assumeTrue("posix filesystem", isPosix);
|
|
|
|
|
@@ -596,15 +732,44 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
assertTrue(Files.exists(envConfigDir.resolve("other.yml")));
|
|
|
}
|
|
|
|
|
|
+ public void testExistingMetaConfig() throws Exception {
|
|
|
+ Tuple<Path, Environment> env = createEnv(fs, temp);
|
|
|
+ Path envConfigDir = env.v2().configFile().resolve("my_plugins").resolve("fake");
|
|
|
+ Files.createDirectories(envConfigDir);
|
|
|
+ Files.write(envConfigDir.resolve("custom.yml"), "existing config".getBytes(StandardCharsets.UTF_8));
|
|
|
+ Path metaDir = createPluginDir(temp);
|
|
|
+ Path pluginDir = metaDir.resolve("fake");
|
|
|
+ Files.createDirectory(pluginDir);
|
|
|
+ writePlugin("fake", pluginDir, false);
|
|
|
+ Path configDir = pluginDir.resolve("config");
|
|
|
+ Files.createDirectory(configDir);
|
|
|
+ Files.write(configDir.resolve("custom.yml"), "new config".getBytes(StandardCharsets.UTF_8));
|
|
|
+ Files.createFile(configDir.resolve("other.yml"));
|
|
|
+ String pluginZip = createMetaPluginUrl("my_plugins", metaDir);
|
|
|
+ installPlugin(pluginZip, env.v1());
|
|
|
+ assertMetaPlugin("my_plugins", "fake", pluginDir, env.v2());
|
|
|
+ List<String> configLines = Files.readAllLines(envConfigDir.resolve("custom.yml"), StandardCharsets.UTF_8);
|
|
|
+ assertEquals(1, configLines.size());
|
|
|
+ assertEquals("existing config", configLines.get(0));
|
|
|
+ assertTrue(Files.exists(envConfigDir.resolve("other.yml")));
|
|
|
+ }
|
|
|
+
|
|
|
public void testConfigNotDir() throws Exception {
|
|
|
Tuple<Path, Environment> env = createEnv(fs, temp);
|
|
|
- Path pluginDir = createPluginDir(temp);
|
|
|
+ Path metaDir = createPluginDir(temp);
|
|
|
+ Path pluginDir = metaDir.resolve("fake");
|
|
|
+ Files.createDirectories(pluginDir);
|
|
|
Path configDir = pluginDir.resolve("config");
|
|
|
Files.createFile(configDir);
|
|
|
String pluginZip = createPluginUrl("fake", pluginDir);
|
|
|
UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
|
|
|
assertTrue(e.getMessage(), e.getMessage().contains("not a directory"));
|
|
|
assertInstallCleaned(env.v2());
|
|
|
+
|
|
|
+ String metaZip = createMetaPluginUrl("my_plugins", metaDir);
|
|
|
+ e = expectThrows(UserException.class, () -> installPlugin(metaZip, env.v1()));
|
|
|
+ assertTrue(e.getMessage(), e.getMessage().contains("not a directory"));
|
|
|
+ assertInstallCleaned(env.v2());
|
|
|
}
|
|
|
|
|
|
public void testConfigContainsDir() throws Exception {
|
|
@@ -619,26 +784,21 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
assertInstallCleaned(env.v2());
|
|
|
}
|
|
|
|
|
|
- public void testConfigConflict() throws Exception {
|
|
|
- Tuple<Path, Environment> env = createEnv(fs, temp);
|
|
|
- Path pluginDir = createPluginDir(temp);
|
|
|
- Path configDir = pluginDir.resolve("config");
|
|
|
- Files.createDirectory(configDir);
|
|
|
- Files.createFile(configDir.resolve("myconfig.yml"));
|
|
|
- String pluginZip = createPluginUrl("elasticsearch.yml", pluginDir);
|
|
|
- FileAlreadyExistsException e = expectThrows(FileAlreadyExistsException.class, () -> installPlugin(pluginZip, env.v1()));
|
|
|
- assertTrue(e.getMessage(), e.getMessage().contains(env.v2().configFile().resolve("elasticsearch.yml").toString()));
|
|
|
- assertInstallCleaned(env.v2());
|
|
|
- }
|
|
|
-
|
|
|
public void testMissingDescriptor() throws Exception {
|
|
|
Tuple<Path, Environment> env = createEnv(fs, temp);
|
|
|
- Path pluginDir = createPluginDir(temp);
|
|
|
+ Path metaDir = createPluginDir(temp);
|
|
|
+ Path pluginDir = metaDir.resolve("fake");
|
|
|
+ Files.createDirectory(pluginDir);
|
|
|
Files.createFile(pluginDir.resolve("fake.yml"));
|
|
|
String pluginZip = writeZip(pluginDir, "elasticsearch").toUri().toURL().toString();
|
|
|
NoSuchFileException e = expectThrows(NoSuchFileException.class, () -> installPlugin(pluginZip, env.v1()));
|
|
|
assertTrue(e.getMessage(), e.getMessage().contains("plugin-descriptor.properties"));
|
|
|
assertInstallCleaned(env.v2());
|
|
|
+
|
|
|
+ String metaZip = createMetaPluginUrl("my_plugins", metaDir);
|
|
|
+ e = expectThrows(NoSuchFileException.class, () -> installPlugin(metaZip, env.v1()));
|
|
|
+ assertTrue(e.getMessage(), e.getMessage().contains("plugin-descriptor.properties"));
|
|
|
+ assertInstallCleaned(env.v2());
|
|
|
}
|
|
|
|
|
|
public void testMissingDirectory() throws Exception {
|
|
@@ -651,6 +811,16 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
assertInstallCleaned(env.v2());
|
|
|
}
|
|
|
|
|
|
+ public void testMissingDirectoryMeta() throws Exception {
|
|
|
+ Tuple<Path, Environment> env = createEnv(fs, temp);
|
|
|
+ Path pluginDir = createPluginDir(temp);
|
|
|
+ Files.createFile(pluginDir.resolve(MetaPluginInfo.ES_META_PLUGIN_PROPERTIES));
|
|
|
+ String pluginZip = writeZip(pluginDir, null).toUri().toURL().toString();
|
|
|
+ UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
|
|
|
+ assertTrue(e.getMessage(), e.getMessage().contains("`elasticsearch` directory is missing in the plugin zip"));
|
|
|
+ assertInstallCleaned(env.v2());
|
|
|
+ }
|
|
|
+
|
|
|
public void testZipRelativeOutsideEntryName() throws Exception {
|
|
|
Tuple<Path, Environment> env = createEnv(fs, temp);
|
|
|
Path zip = createTempDir().resolve("broken.zip");
|
|
@@ -748,6 +918,29 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
"if you need to update the plugin, uninstall it first using command 'remove fake'"));
|
|
|
}
|
|
|
|
|
|
+ public void testMetaPluginAlreadyInstalled() throws Exception {
|
|
|
+ Tuple<Path, Environment> env = createEnv(fs, temp);
|
|
|
+ {
|
|
|
+ // install fake plugin
|
|
|
+ Path pluginDir = createPluginDir(temp);
|
|
|
+ String pluginZip = createPluginUrl("fake", pluginDir);
|
|
|
+ installPlugin(pluginZip, env.v1());
|
|
|
+ }
|
|
|
+
|
|
|
+ Path pluginDir = createPluginDir(temp);
|
|
|
+ Files.createDirectory(pluginDir.resolve("fake"));
|
|
|
+ writePlugin("fake", pluginDir.resolve("fake"), false);
|
|
|
+ Files.createDirectory(pluginDir.resolve("other"));
|
|
|
+ writePlugin("other", pluginDir.resolve("other"), false);
|
|
|
+ String metaZip = createMetaPluginUrl("meta", pluginDir);
|
|
|
+ final UserException e = expectThrows(UserException.class,
|
|
|
+ () -> installPlugin(metaZip, env.v1(), randomFrom(skipJarHellCommand, defaultCommand)));
|
|
|
+ assertThat(
|
|
|
+ e.getMessage(),
|
|
|
+ equalTo("plugin directory [" + env.v2().pluginsFile().resolve("fake") + "] already exists; " +
|
|
|
+ "if you need to update the plugin, uninstall it first using command 'remove fake'"));
|
|
|
+ }
|
|
|
+
|
|
|
private void installPlugin(MockTerminal terminal, boolean isBatch) throws Exception {
|
|
|
Tuple<Path, Environment> env = createEnv(fs, temp);
|
|
|
Path pluginDir = createPluginDir(temp);
|
|
@@ -791,7 +984,7 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
return stagingHash;
|
|
|
}
|
|
|
@Override
|
|
|
- void jarHellCheck(PluginInfo info, Path candidate, Path pluginsDir, Path modulesDir) throws Exception {
|
|
|
+ void jarHellCheck(PluginInfo candidateInfo, Path candidate, Path pluginsDir, Path modulesDir) throws Exception {
|
|
|
// no jarhell check
|
|
|
}
|
|
|
};
|
|
@@ -951,6 +1144,17 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|
|
assertTrue(Files.exists(KeyStoreWrapper.keystorePath(env.v2().configFile())));
|
|
|
}
|
|
|
|
|
|
+ public void testKeystoreRequiredCreatedWithMetaPlugin() throws Exception {
|
|
|
+ Tuple<Path, Environment> env = createEnv(fs, temp);
|
|
|
+ Path metaDir = createPluginDir(temp);
|
|
|
+ Path pluginDir = metaDir.resolve("fake");
|
|
|
+ Files.createDirectory(pluginDir);
|
|
|
+ writePlugin("fake", pluginDir, false, "requires.keystore", "true");
|
|
|
+ String metaZip = createMetaPluginUrl("my_plugins", metaDir);
|
|
|
+ MockTerminal terminal = installPlugin(metaZip, env.v1());
|
|
|
+ assertTrue(Files.exists(KeyStoreWrapper.keystorePath(env.v2().configFile())));
|
|
|
+ }
|
|
|
+
|
|
|
private Function<byte[], String> checksum(final MessageDigest digest) {
|
|
|
return checksumAndString(digest, "");
|
|
|
}
|