|
5 | 5 |
|
6 | 6 | package io.opentelemetry.contrib.jmxscraper; |
7 | 7 |
|
| 8 | +import static io.opentelemetry.contrib.jmxscraper.TestKeyStoreUtil.addTrustedCertificate; |
| 9 | +import static io.opentelemetry.contrib.jmxscraper.TestKeyStoreUtil.createKeyStore; |
8 | 10 | import static org.assertj.core.api.Assertions.assertThat; |
9 | 11 |
|
| 12 | +import java.nio.file.Path; |
| 13 | +import java.security.cert.X509Certificate; |
10 | 14 | import java.util.function.Function; |
11 | 15 | import org.junit.jupiter.api.AfterAll; |
12 | 16 | import org.junit.jupiter.api.BeforeAll; |
13 | 17 | import org.junit.jupiter.api.Test; |
| 18 | +import org.junit.jupiter.api.io.TempDir; |
14 | 19 | import org.slf4j.Logger; |
15 | 20 | import org.slf4j.LoggerFactory; |
16 | 21 | import org.testcontainers.containers.GenericContainer; |
@@ -70,6 +75,31 @@ void userPassword() { |
70 | 75 | scraper -> scraper.withRmiServiceUrl(APP_HOST, JMX_PORT).withUser(login).withPassword(pwd)); |
71 | 76 | } |
72 | 77 |
|
| 78 | + @Test |
| 79 | + void serverSsl(@TempDir Path tempDir) { |
| 80 | + // two keystores: |
| 81 | + // server keystore with public/private key pair |
| 82 | + // client trust store with certificate from server |
| 83 | + |
| 84 | + String clientPassword = "client"; |
| 85 | + String serverPassword = "server"; |
| 86 | + |
| 87 | + Path serverKeystore = tempDir.resolve("server.jks"); |
| 88 | + Path clientKeystore = tempDir.resolve("client.jks"); |
| 89 | + |
| 90 | + X509Certificate serverCertificate = createKeyStore(serverKeystore, serverPassword); |
| 91 | + |
| 92 | + createKeyStore(clientKeystore, clientPassword); |
| 93 | + addTrustedCertificate(clientKeystore, clientPassword, serverCertificate); |
| 94 | + |
| 95 | + connectionTest( |
| 96 | + app -> app.withJmxPort(JMX_PORT).withJmxSsl().withKeyStore(serverKeystore, serverPassword), |
| 97 | + scraper -> |
| 98 | + scraper |
| 99 | + .withRmiServiceUrl(APP_HOST, JMX_PORT) |
| 100 | + .withTrustStore(clientKeystore, clientPassword)); |
| 101 | + } |
| 102 | + |
73 | 103 | private static void connectionTest( |
74 | 104 | Function<TestAppContainer, TestAppContainer> customizeApp, |
75 | 105 | Function<JmxScraperContainer, JmxScraperContainer> customizeScraper) { |
|
0 commit comments