Skip to content

Commit 8d56ebb

Browse files
reduce test failures to 3
1 parent d56bd91 commit 8d56ebb

File tree

6 files changed

+76
-31
lines changed

6 files changed

+76
-31
lines changed

src/test/java/io/lettuce/core/SslIntegrationTests.java

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ class SslIntegrationTests extends TestSupport {
6969

7070
private static final String KEYSTORE = "work/keystore.jks";
7171

72-
private static File truststoreFile;
72+
private static File truststoreFile0;
73+
private static File truststoreFile1;
74+
private static File truststoreFile2;
7375

7476
private static File cacertFile;
7577

@@ -112,12 +114,25 @@ class SslIntegrationTests extends TestSupport {
112114

113115
@BeforeAll
114116
static void beforeClass() {
115-
Path path = createAndSaveTestTruststore("redis-standalone-1", Paths.get("work/tls"), "changeit");
116-
truststoreFile = path.toFile();
117+
Path path0 = createAndSaveTestTruststore("redis-standalone-0", Paths.get("redis-standalone-0/work/tls"), "changeit");
118+
truststoreFile0 = path0.toFile();
119+
cacertFile = envCa(Paths.get("redis-standalone-0/work/tls")).toFile();
120+
121+
Path path = createAndSaveTestTruststore("redis-standalone-1", Paths.get("redis-standalone-1/work/tls"), "changeit");
122+
truststoreFile1 = path.toFile();
117123
cacertFile = envCa(Paths.get("redis-standalone-1/work/tls")).toFile();
118-
// do for 6444 and 8444
124+
125+
Path path2 = createAndSaveTestTruststore("redis-standalone-sentinel-controlled", Paths.get("redis-standalone-sentinel-controlled/work/tls"), "changeit");
126+
truststoreFile2 = path2.toFile();
127+
cacertFile = envCa(Paths.get("redis-standalone-sentinel-controlled/work/tls")).toFile();
128+
129+
130+
119131
assumeTrue(CanConnect.to(TestSettings.host(), sslPort()), "Assume that stunnel runs on port 6443");
120-
assertThat(truststoreFile).exists();
132+
// Maybe we should do a list.
133+
assertThat(truststoreFile0).exists();
134+
assertThat(truststoreFile1).exists();
135+
assertThat(truststoreFile2).exists();
121136
}
122137

123138
@Test
@@ -134,7 +149,7 @@ void standaloneWithJdkSsl() {
134149

135150
SslOptions sslOptions = SslOptions.builder() //
136151
.jdkSslProvider() //
137-
.truststore(truststoreFile, "changeit") //
152+
.truststore(truststoreFile1, "changeit") //
138153
.build();
139154
setOptions(sslOptions);
140155

@@ -146,7 +161,7 @@ void standaloneWithVerifyCaOnly() {
146161

147162
SslOptions sslOptions = SslOptions.builder() //
148163
.jdkSslProvider() //
149-
.truststore(truststoreFile, "changeit") //
164+
.truststore(truststoreFile0, "changeit") //
150165
.build();
151166
setOptions(sslOptions);
152167

@@ -157,7 +172,7 @@ void standaloneWithVerifyCaOnly() {
157172
void standaloneWithPemCert() {
158173

159174
SslOptions sslOptions = SslOptions.builder() //
160-
.trustManager(cacertFile) //
175+
.trustManager(envCa(Paths.get("redis-standalone-1/work/tls")).toFile()) //
161176
.build();
162177
setOptions(sslOptions);
163178
verifyConnection(URI_VERIFY);
@@ -168,7 +183,7 @@ void standaloneWithPemCertAndImpossibleTimeout() {
168183

169184
Assertions.setMaxStackTraceElementsDisplayed(30);
170185
SslOptions sslOptions = SslOptions.builder() //
171-
.trustManager(cacertFile) //
186+
.trustManager(envCa(Paths.get("redis-standalone-1/work/tls")).toFile()) //
172187
.build();
173188
setOptions(sslOptions);
174189
redisClient.setOptions(ClientOptions.builder().protocolVersion(ProtocolVersion.RESP3).sslOptions(sslOptions).build());
@@ -187,7 +202,7 @@ void standaloneWithJdkSslUsingTruststoreUrl() throws Exception {
187202

188203
SslOptions sslOptions = SslOptions.builder() //
189204
.jdkSslProvider() //
190-
.truststore(truststoreURL()) //
205+
.truststore(truststoreURL(truststoreFile1)) //
191206
.build();
192207
setOptions(sslOptions);
193208

@@ -196,11 +211,11 @@ void standaloneWithJdkSslUsingTruststoreUrl() throws Exception {
196211

197212
@Test
198213
void standaloneWithClientCertificates() {
199-
214+
//6445
200215
SslOptions sslOptions = SslOptions.builder() //
201216
.jdkSslProvider() //
202217
.keystore(new File(KEYSTORE), "changeit".toCharArray()) //
203-
.truststore(truststoreFile, "changeit") //
218+
.truststore(truststoreFile1, "changeit") //
204219
.build();
205220
setOptions(sslOptions);
206221

@@ -212,7 +227,7 @@ void standaloneWithClientCertificatesWithoutKeystore() {
212227

213228
SslOptions sslOptions = SslOptions.builder() //
214229
.jdkSslProvider() //
215-
.truststore(truststoreFile, "changeit") //
230+
.truststore(truststoreFile0, "changeit") //
216231
.build();
217232
setOptions(sslOptions);
218233

@@ -224,7 +239,7 @@ void standaloneWithJdkSslUsingTruststoreUrlWithWrongPassword() throws Exception
224239

225240
SslOptions sslOptions = SslOptions.builder() //
226241
.jdkSslProvider() //
227-
.truststore(truststoreURL(), "knödel") //
242+
.truststore(truststoreURL(truststoreFile0), "knödel") //
228243
.build();
229244
setOptions(sslOptions);
230245

@@ -249,7 +264,7 @@ void standaloneWithOpenSsl() {
249264

250265
SslOptions sslOptions = SslOptions.builder() //
251266
.openSslProvider() //
252-
.truststore(truststoreFile, "changeit") //
267+
.truststore(truststoreFile0, "changeit") //
253268
.build();
254269
setOptions(sslOptions);
255270

@@ -302,7 +317,7 @@ void masterSlaveWithJdkSsl() {
302317

303318
SslOptions sslOptions = SslOptions.builder() //
304319
.jdkSslProvider() //
305-
.truststore(truststoreFile, "changeit") //
320+
.truststore(truststoreFile2, "changeit") //
306321
.build();
307322
setOptions(sslOptions);
308323

@@ -314,7 +329,7 @@ void masterSlaveWithJdkSslUsingTruststoreUrl() throws Exception {
314329

315330
SslOptions sslOptions = SslOptions.builder() //
316331
.jdkSslProvider() //
317-
.truststore(truststoreURL()) //
332+
.truststore(truststoreURL(truststoreFile2)) //
318333
.build();
319334
setOptions(sslOptions);
320335

@@ -326,7 +341,7 @@ void masterSlaveWithJdkSslUsingTruststoreUrlWithWrongPassword() throws Exception
326341

327342
SslOptions sslOptions = SslOptions.builder() //
328343
.jdkSslProvider() //
329-
.truststore(truststoreURL(), "knödel") //
344+
.truststore(truststoreURL(truststoreFile0), "knödel") //
330345
.build();
331346
setOptions(sslOptions);
332347

@@ -367,7 +382,7 @@ void masterSlaveSslWithOneInvalidHostWillSucceed() {
367382

368383
SslOptions sslOptions = SslOptions.builder() //
369384
.jdkSslProvider() //
370-
.truststore(truststoreFile, "changeit") //
385+
.truststore(truststoreFile2, "changeit") //
371386
.build();
372387
setOptions(sslOptions);
373388

@@ -379,7 +394,7 @@ void masterSlaveSslWithAllInvalidHostsWillFail() {
379394

380395
SslOptions sslOptions = SslOptions.builder() //
381396
.jdkSslProvider() //
382-
.truststore(truststoreFile, "changeit") //
397+
.truststore(truststoreFile0, "changeit") //
383398
.build();
384399
setOptions(sslOptions);
385400

@@ -419,7 +434,7 @@ private static List<RedisURI> sslUris(IntStream masterSlaveOffsets,
419434
.map(builderCustomizer).map(RedisURI.Builder::build).collect(Collectors.toList());
420435
}
421436

422-
private URL truststoreURL() throws MalformedURLException {
437+
private URL truststoreURL(File truststoreFile) throws MalformedURLException {
423438
return truststoreFile.toURI().toURL();
424439
}
425440

src/test/java/io/lettuce/test/settings/TlsSettings.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ public static Path testTruststorePath(String name) {
4343
* Creates an empty truststore.
4444
*
4545
* @return An empty KeyStore object.
46-
* @throws KeyStoreException If there's an error initializing the truststore.
47-
* @throws IOException If there's an error loading the truststore.
46+
* @throws KeyStoreException If there's an error initializing the truststore.
47+
* @throws IOException If there's an error loading the truststore.
4848
* @throws NoSuchAlgorithmException If the algorithm used to check the integrity of the truststore cannot be found.
49-
* @throws CertificateException If any of the certificates in the truststore could not be loaded.
49+
* @throws CertificateException If any of the certificates in the truststore could not be loaded.
5050
*/
5151
private static KeyStore createTruststore()
5252
throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException {
@@ -73,8 +73,8 @@ private static X509Certificate loadCertificate(Path certPath) throws Exception {
7373
* Adds a trusted certificate to the given truststore.
7474
*
7575
* @param trustStore The KeyStore object.
76-
* @param alias Alias for the certificate.
77-
* @param certPath Path to the certificate file.
76+
* @param alias Alias for the certificate.
77+
* @param certPath Path to the certificate file.
7878
* @throws Exception If there's an error adding the certificate.
7979
*/
8080
private static void addTrustedCertificate(KeyStore trustStore, String alias, Path certPath) throws Exception {
@@ -85,8 +85,8 @@ private static void addTrustedCertificate(KeyStore trustStore, String alias, Pat
8585
/**
8686
* Creates a truststore, adds multiple trusted certificates, and saves it to the specified path.
8787
*
88-
* @param trustedCertPaths List of certificate file paths to add to the truststore.
89-
* @param truststorePath Path to save the generated truststore.
88+
* @param trustedCertPaths List of certificate file paths to add to the truststore.
89+
* @param truststorePath Path to save the generated truststore.
9090
* @param truststorePassword Password for the truststore.
9191
* @return Path to the saved truststore file.
9292
*/
@@ -111,7 +111,7 @@ public static Path createAndSaveTruststore(List<Path> trustedCertPaths, Path tru
111111
}
112112

113113
public static Path createAndSaveTestTruststore(String trustStoreName, Path certificateLocations,
114-
String truststorePassword) {
114+
String truststorePassword) {
115115
List<Path> trustedCertPaths = new ArrayList<>();
116116
trustedCertPaths.add(envCa(certificateLocations).toAbsolutePath());
117117
trustedCertPaths.add(envServerCert(certificateLocations).toAbsolutePath());
@@ -120,5 +120,4 @@ public static Path createAndSaveTestTruststore(String trustStoreName, Path certi
120120

121121
return createAndSaveTruststore(trustedCertPaths, trustStorePath, truststorePassword);
122122
}
123-
124-
}
123+
}

src/test/resources/docker-env/docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
services:
22
# Standalone Redis Servers
3+
redis-standalone-0:
4+
image: redislabs/client-libs-test:8.0-M02
5+
container_name: redis-standalone-0
6+
environment:
7+
- TLS_ENABLED=yes
8+
volumes:
9+
- ./redis-standalone-0/config:/redis/config:r
10+
- ${REDIS_ENV_WORK_DIR}/redis-standalone-0/work:/redis/work:rw
11+
ports:
12+
- "6478:6478"
13+
- "6444:6444" # TLS Port
14+
networks:
15+
- redis-network
16+
317
redis-standalone-1:
418
image: redislabs/client-libs-test:8.0-M02
519
container_name: redis-standalone-1
@@ -56,12 +70,15 @@ services:
5670
- TLS_ENABLED=yes
5771
volumes:
5872
- ./redis-standalone-sentinel-controlled/config:/redis/config:r
73+
- ${REDIS_ENV_WORK_DIR}/redis-standalone-sentinel-controlled/work:/redis/work:rw
5974
ports:
6075
- "26380:26380"
6176
- "26822:26822" # sentinel tls port
6277
- "26379:26379"
6378
- "6482:6482"
6479
- "6483:6483"
80+
- "8443:8443" # TLS Port
81+
- "8444:8444" # TLS Port
6582
networks:
6683
- redis-network
6784

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
port 6478
2+
tls-port 6444
3+
tls-auth-clients no
4+
save ""
5+
appendonly no
6+
client-output-buffer-limit pubsub 256k 128k 5
7+
enable-debug-command yes
8+
unixsocket /work/socket-6478
9+
unixsocketperm 777
10+
replica-announce-ip localhost

src/test/resources/docker-env/redis-standalone-sentinel-controlled/config/node-6482/redis.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
port 6482
2+
tls-port 8443
3+
tls-auth-clients no
24
save ""
35
appendonly no
46
client-output-buffer-limit pubsub 256k 128k 5

src/test/resources/docker-env/redis-standalone-sentinel-controlled/config/node-6483/redis.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
port 6483
2+
tls-port 8444
3+
tls-auth-clients no
24
save ""
35
appendonly no
46
client-output-buffer-limit pubsub 256k 128k 5

0 commit comments

Comments
 (0)