Search in sources :

Example 1 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class InstallPluginCommandTests method testPlatformBinPermissions.

public void testPlatformBinPermissions() throws Exception {
    assumeTrue("posix filesystem", isPosix);
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    Path platformDir = pluginDir.resolve("platform");
    Path platformNameDir = platformDir.resolve("linux-x86_64");
    Path platformBinDir = platformNameDir.resolve("bin");
    Files.createDirectories(platformBinDir);
    Path programFile = Files.createFile(platformBinDir.resolve("someprogram"));
    // a file created with Files.createFile() should not have execute permissions
    Set<PosixFilePermission> sourcePerms = Files.getPosixFilePermissions(programFile);
    assertFalse(sourcePerms.contains(PosixFilePermission.OWNER_EXECUTE));
    assertFalse(sourcePerms.contains(PosixFilePermission.GROUP_EXECUTE));
    assertFalse(sourcePerms.contains(PosixFilePermission.OTHERS_EXECUTE));
    String pluginZip = createPlugin("fake", pluginDir);
    installPlugin(pluginZip, env.v1());
    assertPlugin("fake", pluginDir, env.v2());
    // check that the installed program has execute permissions, even though the one added to the plugin didn't
    Path installedPlatformBinDir = env.v2().pluginsFile().resolve("fake").resolve("platform").resolve("linux-x86_64").resolve("bin");
    assertTrue(Files.isDirectory(installedPlatformBinDir));
    Path installedProgramFile = installedPlatformBinDir.resolve("someprogram");
    assertTrue(Files.isRegularFile(installedProgramFile));
    Set<PosixFilePermission> installedPerms = Files.getPosixFilePermissions(installedProgramFile);
    assertTrue(installedPerms.contains(PosixFilePermission.OWNER_EXECUTE));
    assertTrue(installedPerms.contains(PosixFilePermission.GROUP_EXECUTE));
    assertTrue(installedPerms.contains(PosixFilePermission.OTHERS_EXECUTE));
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) Matchers.containsString(org.hamcrest.Matchers.containsString) PosixFilePermission(java.nio.file.attribute.PosixFilePermission)

Example 2 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class InstallPluginCommandTests method testMissingDescriptor.

public void testMissingDescriptor() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    Files.createFile(pluginDir.resolve("fake.yml"));
    String pluginZip = writeZip(pluginDir, "elasticsearch");
    NoSuchFileException e = expectThrows(NoSuchFileException.class, () -> installPlugin(pluginZip, env.v1()));
    assertTrue(e.getMessage(), e.getMessage().contains("plugin-descriptor.properties"));
    assertInstallCleaned(env.v2());
}
Also used : Path(java.nio.file.Path) NoSuchFileException(java.nio.file.NoSuchFileException) Environment(org.elasticsearch.env.Environment) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 3 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class InstallPluginCommandTests method testJarHell.

public void testJarHell() throws Exception {
    // jar hell test needs a real filesystem
    assumeTrue("real filesystem", isReal);
    Tuple<Path, Environment> environment = createEnv(fs, temp);
    Path pluginDirectory = createPluginDir(temp);
    writeJar(pluginDirectory.resolve("other.jar"), "FakePlugin");
    // adds plugin.jar with FakePlugin
    String pluginZip = createPlugin("fake", pluginDirectory);
    IllegalStateException e = expectThrows(IllegalStateException.class, () -> installPlugin(pluginZip, environment.v1(), true));
    assertTrue(e.getMessage(), e.getMessage().contains("jar hell"));
    assertInstallCleaned(environment.v2());
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 4 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class InstallPluginCommandTests method testBinContainsDir.

public void testBinContainsDir() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    Path dirInBinDir = pluginDir.resolve("bin").resolve("foo");
    Files.createDirectories(dirInBinDir);
    Files.createFile(dirInBinDir.resolve("somescript"));
    String pluginZip = createPlugin("fake", pluginDir);
    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());
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) Matchers.containsString(org.hamcrest.Matchers.containsString) UserException(org.elasticsearch.cli.UserException)

Example 5 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class InstallPluginCommandTests method testUnknownPlugin.

public void testUnknownPlugin() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    UserException e = expectThrows(UserException.class, () -> installPlugin("foo", env.v1()));
    assertTrue(e.getMessage(), e.getMessage().contains("Unknown plugin foo"));
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) UserException(org.elasticsearch.cli.UserException)

Aggregations

Environment (org.elasticsearch.env.Environment)130 Settings (org.elasticsearch.common.settings.Settings)84 Path (java.nio.file.Path)66 Matchers.containsString (org.hamcrest.Matchers.containsString)42 NodeEnvironment (org.elasticsearch.env.NodeEnvironment)26 TestEnvironment (org.elasticsearch.env.TestEnvironment)22 IndexSettings (org.elasticsearch.index.IndexSettings)21 UserException (org.elasticsearch.cli.UserException)17 IOException (java.io.IOException)15 AnalysisModule (org.elasticsearch.indices.analysis.AnalysisModule)9 MockTerminal (org.elasticsearch.cli.MockTerminal)8 ClusterState (org.elasticsearch.cluster.ClusterState)8 ScriptService (org.elasticsearch.script.ScriptService)8 HashMap (java.util.HashMap)7 ScriptContextRegistry (org.elasticsearch.script.ScriptContextRegistry)7 ScriptEngineRegistry (org.elasticsearch.script.ScriptEngineRegistry)7 ScriptSettings (org.elasticsearch.script.ScriptSettings)7 ArrayList (java.util.ArrayList)6 ElasticsearchException (org.elasticsearch.ElasticsearchException)6 Before (org.junit.Before)6