Skip to content

jmx-scraper test config sources #1750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 13, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
Expand Down Expand Up @@ -44,6 +46,9 @@ public class JmxConnectionTest {

private static Network network;

// temporary folder for files that are copied to container
@TempDir private Path tempDir;

@BeforeAll
static void beforeAll() {
network = Network.newNetwork();
Expand All @@ -63,32 +68,43 @@ void connectionError() {
}
}

@Test
void connectNoAuth() {
@ParameterizedTest
@EnumSource
void connectNoAuth(JmxScraperContainer.ConfigSource configSource) {
connectionTest(
app -> app.withJmxPort(JMX_PORT), scraper -> scraper.withRmiServiceUrl(APP_HOST, JMX_PORT));
app -> app.withJmxPort(JMX_PORT),
scraper -> scraper.withRmiServiceUrl(APP_HOST, JMX_PORT).withConfigSource(configSource));
}

@Test
void userPassword() {
@ParameterizedTest
@EnumSource
void userPassword(JmxScraperContainer.ConfigSource configSource) {
String login = "user";
String pwd = "t0p!Secret";
connectionTest(
app -> app.withJmxPort(JMX_PORT).withUserAuth(login, pwd),
scraper -> scraper.withRmiServiceUrl(APP_HOST, JMX_PORT).withUser(login).withPassword(pwd));
scraper ->
scraper
.withRmiServiceUrl(APP_HOST, JMX_PORT)
.withUser(login)
.withPassword(pwd)
.withConfigSource(configSource));
}

@Test
void serverSsl(@TempDir Path tempDir) {
testServerSsl(tempDir, /* sslRmiRegistry= */ false);
@ParameterizedTest
@EnumSource
void serverSsl(JmxScraperContainer.ConfigSource configSource) {
testServerSsl(/* sslRmiRegistry= */ false, configSource);
}

@Test
void serverSslWithSslRmiRegistry(@TempDir Path tempDir) {
testServerSsl(tempDir, /* sslRmiRegistry= */ true);
@ParameterizedTest
@EnumSource
void serverSslWithSslRmiRegistry(JmxScraperContainer.ConfigSource configSource) {
testServerSsl(/* sslRmiRegistry= */ true, configSource);
}

private static void testServerSsl(Path tempDir, boolean sslRmiRegistry) {
private void testServerSsl(
boolean sslRmiRegistry, JmxScraperContainer.ConfigSource configSource) {
// two keystores:
// server keystore with public/private key pair
// client trust store with certificate from server
Expand All @@ -110,11 +126,13 @@ private static void testServerSsl(Path tempDir, boolean sslRmiRegistry) {
scraper ->
(sslRmiRegistry ? scraper.withSslRmiRegistry() : scraper)
.withRmiServiceUrl(APP_HOST, JMX_PORT)
.withTrustStore(clientTrustStore));
.withTrustStore(clientTrustStore)
.withConfigSource(configSource));
}

@Test
void serverSslClientSsl(@TempDir Path tempDir) {
@ParameterizedTest
@EnumSource(value = JmxScraperContainer.ConfigSource.class)
void serverSslClientSsl(JmxScraperContainer.ConfigSource configSource) {
// Note: this could have been made simpler by relying on the fact that keystore could be used
// as a trust store, but having clear split provides also some extra clarity
//
Expand Down Expand Up @@ -153,7 +171,8 @@ void serverSslClientSsl(@TempDir Path tempDir) {
scraper
.withRmiServiceUrl(APP_HOST, JMX_PORT)
.withKeyStore(clientKeyStore)
.withTrustStore(clientTrustStore));
.withTrustStore(clientTrustStore)
.withConfigSource(configSource));
}

private static void connectionTest(
Expand Down
Loading
Loading