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);
}
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;
}
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));
}
}
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));
}
}
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"));
}
}
Aggregations