Search in sources :

Example 31 with Environment

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

the class UnsafeBootstrapAndDetachCommandIT method testBootstrapNoDataFolder.

public void testBootstrapNoDataFolder() {
    final Environment environment = TestEnvironment.newEnvironment(internalCluster().getDefaultSettings());
    expectThrows(() -> unsafeBootstrap(environment), OpenSearchNodeCommand.NO_NODE_FOLDER_FOUND_MSG);
}
Also used : TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) NodeEnvironment(org.opensearch.env.NodeEnvironment)

Example 32 with Environment

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

the class RemoveSettingsCommandIT method executeCommand.

private MockTerminal executeCommand(OpenSearchNodeCommand command, Environment environment, boolean abort, String... args) throws Exception {
    final MockTerminal terminal = new MockTerminal();
    final OptionSet options = command.getParser().parse(args);
    final String input;
    if (abort) {
        input = randomValueOtherThanMany(c -> c.equalsIgnoreCase("y"), () -> randomAlphaOfLength(1));
    } else {
        input = randomBoolean() ? "y" : "Y";
    }
    terminal.addTextInput(input);
    try {
        command.execute(terminal, options, environment);
    } finally {
        assertThat(terminal.getOutput(), containsString(OpenSearchNodeCommand.STOP_WARNING_MSG));
    }
    return terminal;
}
Also used : Environment(org.opensearch.env.Environment) UserException(org.opensearch.cli.UserException) TestEnvironment(org.opensearch.env.TestEnvironment) MockTerminal(org.opensearch.cli.MockTerminal) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.not(org.hamcrest.Matchers.not) Settings(org.opensearch.common.settings.Settings) OpenSearchException(org.opensearch.OpenSearchException) DiskThresholdSettings(org.opensearch.cluster.routing.allocation.DiskThresholdSettings) OpenSearchIntegTestCase(org.opensearch.test.OpenSearchIntegTestCase) Matchers.containsString(org.hamcrest.Matchers.containsString) OptionSet(joptsimple.OptionSet) Matchers.containsString(org.hamcrest.Matchers.containsString) OptionSet(joptsimple.OptionSet) MockTerminal(org.opensearch.cli.MockTerminal)

Example 33 with Environment

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

the class ReindexRestClientSslTests method testClientSucceedsWithCertificateAuthorities.

public void testClientSucceedsWithCertificateAuthorities() throws IOException {
    final List<Thread> threads = new ArrayList<>();
    final Path ca = getDataPath("ca.pem");
    final Settings settings = Settings.builder().put("path.home", createTempDir()).putList("reindex.ssl.certificate_authorities", ca.toString()).put("reindex.ssl.supported_protocols", "TLSv1.2").build();
    final Environment environment = TestEnvironment.newEnvironment(settings);
    final ReindexSslConfig ssl = new ReindexSslConfig(settings, environment, mock(ResourceWatcherService.class));
    try (RestClient client = Reindexer.buildRestClient(getRemoteInfo(), ssl, 1L, threads)) {
        final Response response = client.performRequest(new Request("GET", "/"));
        assertThat(response.getStatusLine().getStatusCode(), Matchers.is(200));
    }
}
Also used : Path(java.nio.file.Path) Response(org.opensearch.client.Response) ArrayList(java.util.ArrayList) RestClient(org.opensearch.client.RestClient) Request(org.opensearch.client.Request) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) ResourceWatcherService(org.opensearch.watcher.ResourceWatcherService) Settings(org.opensearch.common.settings.Settings)

Example 34 with Environment

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

the class ReindexRestClientSslTests method testClientSucceedsWithVerificationDisabled.

public void testClientSucceedsWithVerificationDisabled() throws IOException {
    assumeFalse("Cannot disable verification in FIPS JVM", inFipsJvm());
    final List<Thread> threads = new ArrayList<>();
    final Settings settings = Settings.builder().put("path.home", createTempDir()).put("reindex.ssl.verification_mode", "NONE").put("reindex.ssl.supported_protocols", "TLSv1.2").build();
    final Environment environment = TestEnvironment.newEnvironment(settings);
    final ReindexSslConfig ssl = new ReindexSslConfig(settings, environment, mock(ResourceWatcherService.class));
    try (RestClient client = Reindexer.buildRestClient(getRemoteInfo(), ssl, 1L, threads)) {
        final Response response = client.performRequest(new Request("GET", "/"));
        assertThat(response.getStatusLine().getStatusCode(), Matchers.is(200));
    }
}
Also used : Response(org.opensearch.client.Response) ArrayList(java.util.ArrayList) RestClient(org.opensearch.client.RestClient) Request(org.opensearch.client.Request) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) ResourceWatcherService(org.opensearch.watcher.ResourceWatcherService) Settings(org.opensearch.common.settings.Settings)

Example 35 with Environment

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

the class ReindexRestClientSslTests method testClientPassesClientCertificate.

public void testClientPassesClientCertificate() throws IOException {
    final List<Thread> threads = new ArrayList<>();
    final Path ca = getDataPath("ca.pem");
    final Path cert = getDataPath("client/client.crt");
    final Path key = getDataPath("client/client.key");
    final Settings settings = Settings.builder().put("path.home", createTempDir()).putList("reindex.ssl.certificate_authorities", ca.toString()).put("reindex.ssl.certificate", cert).put("reindex.ssl.key", key).put("reindex.ssl.key_passphrase", "client-password").put("reindex.ssl.supported_protocols", "TLSv1.2").build();
    AtomicReference<Certificate[]> clientCertificates = new AtomicReference<>();
    handler = https -> {
        try {
            clientCertificates.set(https.getSSLSession().getPeerCertificates());
        } catch (SSLPeerUnverifiedException e) {
            logger.warn("Client did not provide certificates", e);
            clientCertificates.set(null);
        }
    };
    final Environment environment = TestEnvironment.newEnvironment(settings);
    final ReindexSslConfig ssl = new ReindexSslConfig(settings, environment, mock(ResourceWatcherService.class));
    try (RestClient client = Reindexer.buildRestClient(getRemoteInfo(), ssl, 1L, threads)) {
        final Response response = client.performRequest(new Request("GET", "/"));
        assertThat(response.getStatusLine().getStatusCode(), Matchers.is(200));
        final Certificate[] certs = clientCertificates.get();
        assertThat(certs, Matchers.notNullValue());
        assertThat(certs, Matchers.arrayWithSize(1));
        assertThat(certs[0], Matchers.instanceOf(X509Certificate.class));
        final X509Certificate clientCert = (X509Certificate) certs[0];
        assertThat(clientCert.getSubjectDN().getName(), Matchers.is("CN=client"));
        assertThat(clientCert.getIssuerDN().getName(), Matchers.is("CN=Elastic Certificate Tool Autogenerated CA"));
    }
}
Also used : Path(java.nio.file.Path) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) ArrayList(java.util.ArrayList) RestClient(org.opensearch.client.RestClient) Request(org.opensearch.client.Request) AtomicReference(java.util.concurrent.atomic.AtomicReference) X509Certificate(java.security.cert.X509Certificate) Response(org.opensearch.client.Response) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) ResourceWatcherService(org.opensearch.watcher.ResourceWatcherService) Settings(org.opensearch.common.settings.Settings) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

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