3939import org .junit .jupiter .api .BeforeAll ;
4040import org .junit .jupiter .api .TestInstance ;
4141import org .junit .jupiter .api .extension .ExtendWith ;
42+ import org .junit .jupiter .api .io .TempDir ;
4243import org .slf4j .Logger ;
4344import org .slf4j .LoggerFactory ;
4445
7273import org .apache .cassandra .sidecar .common .utils .DriverUtils ;
7374import org .apache .cassandra .sidecar .common .utils .SidecarVersionProvider ;
7475import org .apache .cassandra .sidecar .config .JmxConfiguration ;
76+ import org .apache .cassandra .sidecar .config .KeyStoreConfiguration ;
7577import org .apache .cassandra .sidecar .config .ServiceConfiguration ;
7678import org .apache .cassandra .sidecar .config .SidecarConfiguration ;
79+ import org .apache .cassandra .sidecar .config .SslConfiguration ;
80+ import org .apache .cassandra .sidecar .config .yaml .KeyStoreConfigurationImpl ;
7781import org .apache .cassandra .sidecar .config .yaml .ServiceConfigurationImpl ;
7882import org .apache .cassandra .sidecar .config .yaml .SidecarConfigurationImpl ;
83+ import org .apache .cassandra .sidecar .config .yaml .SslConfigurationImpl ;
7984import org .apache .cassandra .sidecar .exceptions .ThrowableUtils ;
8085import org .apache .cassandra .sidecar .server .MainModule ;
8186import org .apache .cassandra .sidecar .server .Server ;
8792import org .apache .cassandra .testing .TestVersion ;
8893import org .apache .cassandra .testing .TestVersionSupplier ;
8994
95+ import static org .apache .cassandra .sidecar .testing .MtlsTestHelper .CASSANDRA_INTEGRATION_TEST_ENABLE_MTLS ;
9096import static org .assertj .core .api .Assertions .assertThat ;
9197
9298/**
@@ -131,12 +137,16 @@ public abstract class SharedClusterIntegrationTestBase
131137 protected final Logger logger = LoggerFactory .getLogger (SharedClusterIntegrationTestBase .class );
132138 private static final int MAX_CLUSTER_PROVISION_RETRIES = 5 ;
133139
140+ @ TempDir
141+ static Path secretsPath ;
142+
134143 protected Vertx vertx ;
135144 protected DnsResolver dnsResolver ;
136145 protected IClusterExtension <? extends IInstance > cluster ;
137146 protected Server server ;
138147 protected Injector injector ;
139148 protected TestVersion testVersion ;
149+ protected MtlsTestHelper mtlsTestHelper ;
140150 private IsolatedDTestClassLoaderWrapper classLoaderWrapper ;
141151
142152 static
@@ -146,7 +156,7 @@ public abstract class SharedClusterIntegrationTestBase
146156 }
147157
148158 @ BeforeAll
149- protected void setup () throws InterruptedException
159+ protected void setup () throws Exception
150160 {
151161 Optional <TestVersion > maybeTestVersion = TestVersionSupplier .testVersions ().findFirst ();
152162 assertThat (maybeTestVersion ).isPresent ();
@@ -161,6 +171,7 @@ protected void setup() throws InterruptedException
161171 assertThat (cluster ).isNotNull ();
162172 afterClusterProvisioned ();
163173 initializeSchemaForTest ();
174+ mtlsTestHelper = new MtlsTestHelper (secretsPath );
164175 startSidecar (cluster );
165176 beforeTestStart ();
166177 }
@@ -306,7 +317,8 @@ protected void createTestTable(QualifiedName name, String createTableStatement)
306317 protected void startSidecar (ICluster <? extends IInstance > cluster ) throws InterruptedException
307318 {
308319 VertxTestContext context = new VertxTestContext ();
309- injector = Guice .createInjector (Modules .override (new MainModule ()).with (new IntegrationTestModule (cluster , classLoaderWrapper )));
320+ AbstractModule testModule = new IntegrationTestModule (cluster , classLoaderWrapper , mtlsTestHelper );
321+ injector = Guice .createInjector (Modules .override (new MainModule ()).with (testModule ));
310322 dnsResolver = injector .getInstance (DnsResolver .class );
311323 vertx = injector .getInstance (Vertx .class );
312324 server = injector .getInstance (Server .class );
@@ -455,13 +467,18 @@ public static Cluster createDriverCluster(ICluster<? extends IInstance> dtest)
455467
456468 static class IntegrationTestModule extends AbstractModule
457469 {
470+ private static final Logger LOGGER = LoggerFactory .getLogger (IntegrationTestModule .class );
458471 private final ICluster <? extends IInstance > cluster ;
459472 private final IsolatedDTestClassLoaderWrapper wrapper ;
473+ private final MtlsTestHelper mtlsTestHelper ;
460474
461- IntegrationTestModule (ICluster <? extends IInstance > cluster , IsolatedDTestClassLoaderWrapper wrapper )
475+ IntegrationTestModule (ICluster <? extends IInstance > cluster ,
476+ IsolatedDTestClassLoaderWrapper wrapper ,
477+ MtlsTestHelper mtlsTestHelper )
462478 {
463479 this .cluster = cluster ;
464480 this .wrapper = wrapper ;
481+ this .mtlsTestHelper = mtlsTestHelper ;
465482 }
466483
467484 @ Provides
@@ -500,8 +517,39 @@ public SidecarConfiguration sidecarConfiguration()
500517 .host ("0.0.0.0" ) // binds to all interfaces, potential security issue if left running for long
501518 .port (0 ) // let the test find an available port
502519 .build ();
520+
521+
522+ SslConfiguration sslConfiguration = null ;
523+ if (mtlsTestHelper .isEnabled ())
524+ {
525+ LOGGER .info ("Enabling test mTLS certificate/keystore." );
526+
527+ KeyStoreConfiguration truststoreConfiguration =
528+ new KeyStoreConfigurationImpl (mtlsTestHelper .trustStorePath (),
529+ mtlsTestHelper .trustStorePassword (),
530+ mtlsTestHelper .trustStoreType (),
531+ -1 );
532+
533+ KeyStoreConfiguration keyStoreConfiguration =
534+ new KeyStoreConfigurationImpl (mtlsTestHelper .serverKeyStorePath (),
535+ mtlsTestHelper .serverKeyStorePassword (),
536+ mtlsTestHelper .serverKeyStoreType (),
537+ -1 );
538+
539+ sslConfiguration = SslConfigurationImpl .builder ()
540+ .enabled (true )
541+ .keystore (keyStoreConfiguration )
542+ .truststore (truststoreConfiguration )
543+ .build ();
544+ }
545+ else
546+ {
547+ LOGGER .info ("Not enabling mTLS for testing purposes. Set '{}' to 'true' if you would " +
548+ "like mTLS enabled." , CASSANDRA_INTEGRATION_TEST_ENABLE_MTLS );
549+ }
503550 return SidecarConfigurationImpl .builder ()
504551 .serviceConfiguration (conf )
552+ .sslConfiguration (sslConfiguration )
505553 .build ();
506554 }
507555
0 commit comments