Search in sources :

Example 91 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class InstallPluginCommandTests method testBinPermissions.

public void testBinPermissions() throws Exception {
    assumeTrue("posix filesystem", isPosix);
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    Path binDir = pluginDir.resolve("bin");
    Files.createDirectory(binDir);
    Files.createFile(binDir.resolve("somescript"));
    String pluginZip = createPluginUrl("fake", pluginDir);
    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());
        assertPlugin("fake", pluginDir, env.v2());
    }
}
Also used : Path(java.nio.file.Path) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) PosixPermissionsResetter(org.opensearch.test.PosixPermissionsResetter)

Example 92 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class InstallPluginCommandTests method testDuplicateInstall.

public void testDuplicateInstall() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    String pluginZip = createPluginUrl("fake", pluginDir);
    final UserException e = expectThrows(UserException.class, () -> installPlugins(Arrays.asList(pluginZip, pluginZip), env.v1()));
    assertThat(e, hasToString(containsString("duplicate plugin id [" + pluginZip + "]")));
}
Also used : Path(java.nio.file.Path) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) UserException(org.opensearch.cli.UserException)

Example 93 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class InstallPluginCommandTests method installPlugin.

private void installPlugin(MockTerminal terminal, boolean isBatch) throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    // if batch is enabled, we also want to add a security policy
    if (isBatch) {
        writePluginSecurityPolicy(pluginDir, "setFactory");
    }
    String pluginZip = createPlugin("fake", pluginDir).toUri().toURL().toString();
    skipJarHellCommand.execute(terminal, Collections.singletonList(pluginZip), isBatch, env.v2());
}
Also used : Path(java.nio.file.Path) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 94 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class InstallPluginCommandTests method testZipRelativeOutsideEntryName.

public void testZipRelativeOutsideEntryName() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path zip = createTempDir().resolve("broken.zip");
    try (ZipOutputStream stream = new ZipOutputStream(Files.newOutputStream(zip))) {
        stream.putNextEntry(new ZipEntry("../blah"));
    }
    String pluginZip = zip.toUri().toURL().toString();
    UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
    assertTrue(e.getMessage(), e.getMessage().contains("resolving outside of plugin directory"));
    assertInstallCleaned(env.v2());
}
Also used : Path(java.nio.file.Path) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) UserException(org.opensearch.cli.UserException)

Example 95 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class InstallPluginCommandTests method testMultipleWorks.

public void testMultipleWorks() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    String fake1PluginZip = createPluginUrl("fake1", pluginDir);
    String fake2PluginZip = createPluginUrl("fake2", pluginDir);
    installPlugins(Arrays.asList(fake1PluginZip, fake2PluginZip), env.v1());
    assertPlugin("fake1", pluginDir, env.v2());
    assertPlugin("fake2", pluginDir, env.v2());
}
Also used : Path(java.nio.file.Path) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

Environment (org.opensearch.env.Environment)142 TestEnvironment (org.opensearch.env.TestEnvironment)98 Path (java.nio.file.Path)80 Settings (org.opensearch.common.settings.Settings)79 Matchers.containsString (org.hamcrest.Matchers.containsString)69 Matchers.hasToString (org.hamcrest.Matchers.hasToString)40 NodeEnvironment (org.opensearch.env.NodeEnvironment)32 IOException (java.io.IOException)27 UserException (org.opensearch.cli.UserException)23 ClusterState (org.opensearch.cluster.ClusterState)22 IndexSettings (org.opensearch.index.IndexSettings)22 MockTerminal (org.opensearch.cli.MockTerminal)19 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)19 OpenSearchException (org.opensearch.OpenSearchException)18 Map (java.util.Map)16 OptionSet (joptsimple.OptionSet)15 DiscoverySettings (org.opensearch.node.Node.DiscoverySettings)14 Version (org.opensearch.Version)13 Files (java.nio.file.Files)11 Arrays (java.util.Arrays)11