4242import java .io .File ;
4343import java .net .MalformedURLException ;
4444import java .net .URL ;
45+ import java .nio .file .Path ;
46+ import java .nio .file .Paths ;
4547import java .time .Duration ;
4648import java .util .List ;
4749import java .util .function .Function ;
5052
5153import static io .lettuce .TestTags .INTEGRATION_TEST ;
5254import static io .lettuce .test .settings .TestSettings .sslPort ;
55+ import static io .lettuce .test .settings .TlsSettings .*;
5356import static org .assertj .core .api .Assertions .assertThat ;
5457import static org .assertj .core .api .Assertions .assertThatThrownBy ;
5558import static org .junit .jupiter .api .Assumptions .assumeTrue ;
@@ -66,11 +69,9 @@ class SslIntegrationTests extends TestSupport {
6669
6770 private static final String KEYSTORE = "work/keystore.jks" ;
6871
69- private static final String TRUSTSTORE = "work/truststore.jks" ;
72+ private static File truststoreFile ;
7073
71- private static final File TRUSTSTORE_FILE = new File (TRUSTSTORE );
72-
73- private static final File CA_CERT_FILE = new File ("work/ca/certs/ca.cert.pem" );
74+ private static File cacertFile ;
7475
7576 private static final int MASTER_SLAVE_BASE_PORT_OFFSET = 2000 ;
7677
@@ -111,9 +112,12 @@ class SslIntegrationTests extends TestSupport {
111112
112113 @ BeforeAll
113114 static void beforeClass () {
114-
115+ Path path = createAndSaveTestTruststore ("redis-standalone-1" , Paths .get ("work/tls" ), "changeit" );
116+ truststoreFile = path .toFile ();
117+ cacertFile = envCa (Paths .get ("redis-standalone-1/work/tls" )).toFile ();
118+ // do for 6444 and 8444
115119 assumeTrue (CanConnect .to (TestSettings .host (), sslPort ()), "Assume that stunnel runs on port 6443" );
116- assertThat (TRUSTSTORE_FILE ).exists ();
120+ assertThat (truststoreFile ).exists ();
117121 }
118122
119123 @ Test
@@ -130,7 +134,7 @@ void standaloneWithJdkSsl() {
130134
131135 SslOptions sslOptions = SslOptions .builder () //
132136 .jdkSslProvider () //
133- .truststore (TRUSTSTORE_FILE ) //
137+ .truststore (truststoreFile , "changeit" ) //
134138 .build ();
135139 setOptions (sslOptions );
136140
@@ -142,7 +146,7 @@ void standaloneWithVerifyCaOnly() {
142146
143147 SslOptions sslOptions = SslOptions .builder () //
144148 .jdkSslProvider () //
145- .truststore (TRUSTSTORE_FILE ) //
149+ .truststore (truststoreFile , "changeit" ) //
146150 .build ();
147151 setOptions (sslOptions );
148152
@@ -153,7 +157,7 @@ void standaloneWithVerifyCaOnly() {
153157 void standaloneWithPemCert () {
154158
155159 SslOptions sslOptions = SslOptions .builder () //
156- .trustManager (CA_CERT_FILE ) //
160+ .trustManager (cacertFile ) //
157161 .build ();
158162 setOptions (sslOptions );
159163 verifyConnection (URI_VERIFY );
@@ -164,7 +168,7 @@ void standaloneWithPemCertAndImpossibleTimeout() {
164168
165169 Assertions .setMaxStackTraceElementsDisplayed (30 );
166170 SslOptions sslOptions = SslOptions .builder () //
167- .trustManager (CA_CERT_FILE ) //
171+ .trustManager (cacertFile ) //
168172 .build ();
169173 setOptions (sslOptions );
170174 redisClient .setOptions (ClientOptions .builder ().protocolVersion (ProtocolVersion .RESP3 ).sslOptions (sslOptions ).build ());
@@ -196,7 +200,7 @@ void standaloneWithClientCertificates() {
196200 SslOptions sslOptions = SslOptions .builder () //
197201 .jdkSslProvider () //
198202 .keystore (new File (KEYSTORE ), "changeit" .toCharArray ()) //
199- .truststore (TRUSTSTORE_FILE ) //
203+ .truststore (truststoreFile , "changeit" ) //
200204 .build ();
201205 setOptions (sslOptions );
202206
@@ -208,7 +212,7 @@ void standaloneWithClientCertificatesWithoutKeystore() {
208212
209213 SslOptions sslOptions = SslOptions .builder () //
210214 .jdkSslProvider () //
211- .truststore (TRUSTSTORE_FILE ) //
215+ .truststore (truststoreFile , "changeit" ) //
212216 .build ();
213217 setOptions (sslOptions );
214218
@@ -245,7 +249,7 @@ void standaloneWithOpenSsl() {
245249
246250 SslOptions sslOptions = SslOptions .builder () //
247251 .openSslProvider () //
248- .truststore (TRUSTSTORE_FILE ) //
252+ .truststore (truststoreFile , "changeit" ) //
249253 .build ();
250254 setOptions (sslOptions );
251255
@@ -298,7 +302,7 @@ void masterSlaveWithJdkSsl() {
298302
299303 SslOptions sslOptions = SslOptions .builder () //
300304 .jdkSslProvider () //
301- .truststore (TRUSTSTORE_FILE ) //
305+ .truststore (truststoreFile , "changeit" ) //
302306 .build ();
303307 setOptions (sslOptions );
304308
@@ -363,7 +367,7 @@ void masterSlaveSslWithOneInvalidHostWillSucceed() {
363367
364368 SslOptions sslOptions = SslOptions .builder () //
365369 .jdkSslProvider () //
366- .truststore (TRUSTSTORE_FILE ) //
370+ .truststore (truststoreFile , "changeit" ) //
367371 .build ();
368372 setOptions (sslOptions );
369373
@@ -375,7 +379,7 @@ void masterSlaveSslWithAllInvalidHostsWillFail() {
375379
376380 SslOptions sslOptions = SslOptions .builder () //
377381 .jdkSslProvider () //
378- .truststore (TRUSTSTORE_FILE ) //
382+ .truststore (truststoreFile , "changeit" ) //
379383 .build ();
380384 setOptions (sslOptions );
381385
@@ -416,7 +420,7 @@ private static List<RedisURI> sslUris(IntStream masterSlaveOffsets,
416420 }
417421
418422 private URL truststoreURL () throws MalformedURLException {
419- return TRUSTSTORE_FILE .toURI ().toURL ();
423+ return truststoreFile .toURI ().toURL ();
420424 }
421425
422426 private void setOptions (SslOptions sslOptions ) {
0 commit comments