How to use testElasticsearch8SecureByDefaultCustomCaCertFails method of org.testcontainers.elasticsearch.ElasticsearchContainerTest class

Best Testcontainers-java code snippet using org.testcontainers.elasticsearch.ElasticsearchContainerTest.testElasticsearch8SecureByDefaultCustomCaCertFails

Source:ElasticsearchContainerTest.java Github

copy

Full Screen

...272 assertThat(EntityUtils.toString(response.getEntity())).contains("cluster_name");273 }274 }275 @Test276 public void testElasticsearch8SecureByDefaultCustomCaCertFails() throws Exception {277 final MountableFile mountableFile = MountableFile.forClasspathResource("http_ca.crt");278 String caPath = "/tmp/http_ca.crt";279 try (280 ElasticsearchContainer container = new ElasticsearchContainer(281 "docker.elastic.co/elasticsearch/elasticsearch:8.1.2"282 )283 .withCopyToContainer(mountableFile, caPath)284 .withCertPath(caPath)285 ) {286 container.start();287 // this is expected, as a different cert is used for creating the SSL context288 assertThat(catchThrowable(() -> getClusterHealth(container)))289 .as(290 "PKIX path validation failed: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors"...

Full Screen

Full Screen

testElasticsearch8SecureByDefaultCustomCaCertFails

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.elasticsearch;2import org.junit.ClassRule;3import org.junit.Test;4import org.testcontainers.containers.GenericContainer;5import org.testcontainers.containers.Network;6import org.testcontainers.containers.wait.strategy.Wait;7import static org.rnorth.visibleassertions.VisibleAssertions.assertTrue;8public class ElasticsearchContainerTest {9 public static Network network = Network.newNetwork();10 public void testElasticsearch8SecureByDefaultCustomCaCertFails() {11 try (GenericContainer elasticsearch = new GenericContainer<>("docker.elastic.co/elasticsearch/elasticsearch:8.0.0-SNAPSHOT")12 .withEnv("xpack.security.enabled", "true")13 .withEnv("xpack.security.http.ssl.enabled", "true")14 .withEnv("xpack.security.http.ssl.key", "test-ssl/test-node.key")15 .withEnv("xpack.security.http.ssl.certificate", "test-ssl/test-node.crt")16 .withEnv("xpack.security.http.ssl.certificate_authorities", "test-ssl/ca.crt")17 .withClasspathResourceMapping("test-ssl", "/usr/share/elasticsearch/config/test-ssl", BindMode.READ_ONLY)18 .withExposedPorts(9200)19 .withNetwork(network)20 .withNetworkAliases("es8")21 .waitingFor(Wait.forHttp("/"))) {22 elasticsearch.start();23 try (RestClient restClient = RestClient.builder(24 new HttpHost(elasticsearch.getContainerIpAddress(), elasticsearch.getMappedPort(9200), "https"))25 .setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder26 .setSSLContext(new SSLContextBuilder()27 .loadTrustMaterial(new File("/usr/share/elasticsearch/config/test-ssl/ca.crt"), "testnode".toCharArray())28 .build())29 .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE))30 .build()) {31 restClient.performRequest(new Request("GET", "/"));32 }33 }34 }35}

Full Screen

Full Screen

testElasticsearch8SecureByDefaultCustomCaCertFails

Using AI Code Generation

copy

Full Screen

1org.junit.ComparisonFailure: expected:<[Connection refused: connect]> but was:<[Connection refused (Connection refused)]>2 at org.junit.Assert.assertEquals(Assert.java:117)3 at org.junit.Assert.assertEquals(Assert.java:146)4 at org.testcontainers.elasticsearch.ElasticsearchContainerTest.testElasticsearch8SecureByDefaultCustomCaCertFails(ElasticsearchContainerTest.java:103)5org.junit.ComparisonFailure: expected:<[Connection refused: connect]> but was:<[Connection refused (Connection refused)]>6 at org.junit.Assert.assertEquals(Assert.java:117)7 at org.junit.Assert.assertEquals(Assert.java:146)8 at org.testcontainers.elasticsearch.ElasticsearchContainerTest.testElasticsearch8SecureByDefaultCustomCaCertFails(ElasticsearchContainerTest.java:103)

Full Screen

Full Screen

testElasticsearch8SecureByDefaultCustomCaCertFails

Using AI Code Generation

copy

Full Screen

1import static org.junit.Assert.assertEquals;2import java.io.IOException;3import java.nio.file.Files;4import java.nio.file.Path;5import java.nio.file.Paths;6import java.util.concurrent.TimeUnit;7import org.elasticsearch.client.RestClient;8import org.elasticsearch.client.RestHighLevelClient;9import org.junit.ClassRule;10import org.junit.Test;11import org.testcontainers.containers.wait.strategy.Wait;12import org.testcontainers.elasticsearch.ElasticsearchContainer;13import org.testcontainers.utility.DockerImageName;14public class ElasticsearchContainerTest {15 private static final String ELASTICSEARCH_VERSION = "8.0.0";16 private static final String ELASTICSEARCH_IMAGE = "docker.elastic.co/elasticsearch/elasticsearch";17 private static final String ELASTICSEARCH_IMAGE_VERSION = ELASTICSEARCH_IMAGE + ":" + ELASTICSEARCH_VERSION;18 public static ElasticsearchContainer elasticsearchContainer = new ElasticsearchContainer(DockerImageName.parse(ELASTICSEARCH_IMAGE_VERSION))19 .withExposedPorts(9200)20 .waitingFor(Wait.forHttp("/").forStatusCode(200).withStartupTimeout(Duration.ofSeconds(60)))21 .withStartupTimeout(Duration.ofSeconds(120));22 public void testElasticsearch8SecureByDefaultCustomCaCertFails() throws IOException {23 Path customCaCertPath = Paths.get("src/test/resources/customCaCert.crt");24 String customCaCert = Files.readString(customCaCertPath);25 try (RestHighLevelClient client = new RestHighLevelClient(26 RestClient.builder(elasticsearchContainer.getHttpHostAddress())27 .setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder28 .setSSLContext(createSslContext(customCaCert))29 )) {30 assertEquals(200, client.info(RequestOptions.DEFAULT).getStatusLine().getStatusCode());31 }32 }33}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful