Skip to content

Commit ef3ce95

Browse files
committed
add test with server ssl
1 parent 83cd80a commit ef3ce95

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxConnectionTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55

66
package io.opentelemetry.contrib.jmxscraper;
77

8+
import static io.opentelemetry.contrib.jmxscraper.TestKeyStoreUtil.addTrustedCertificate;
9+
import static io.opentelemetry.contrib.jmxscraper.TestKeyStoreUtil.createKeyStore;
810
import static org.assertj.core.api.Assertions.assertThat;
911

12+
import java.nio.file.Path;
13+
import java.security.cert.X509Certificate;
1014
import java.util.function.Function;
1115
import org.junit.jupiter.api.AfterAll;
1216
import org.junit.jupiter.api.BeforeAll;
1317
import org.junit.jupiter.api.Test;
18+
import org.junit.jupiter.api.io.TempDir;
1419
import org.slf4j.Logger;
1520
import org.slf4j.LoggerFactory;
1621
import org.testcontainers.containers.GenericContainer;
@@ -70,6 +75,31 @@ void userPassword() {
7075
scraper -> scraper.withRmiServiceUrl(APP_HOST, JMX_PORT).withUser(login).withPassword(pwd));
7176
}
7277

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+
73103
private static void connectionTest(
74104
Function<TestAppContainer, TestAppContainer> customizeApp,
75105
Function<JmxScraperContainer, JmxScraperContainer> customizeScraper) {

0 commit comments

Comments
 (0)