Skip to content

Commit

Permalink
Better SslOptions with custom HostnameVerifier
Browse files Browse the repository at this point in the history
in connectWithCustomHostNameVerifier() test
  • Loading branch information
sazzad16 committed Nov 28, 2024
1 parent ac1de9c commit 9e60a8e
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/test/java/redis/clients/jedis/SSLOptionsJedisClusterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,13 @@ public void connectWithCustomHostNameVerifier() {
HostnameVerifier hostnameVerifier = new BasicHostnameVerifier();
HostnameVerifier localhostVerifier = new LocalhostVerifier();

try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379),
DefaultJedisClientConfig.builder().password("cluster")
.sslOptions(SslOptions.builder()
SslOptions sslOptions = SslOptions.builder()
.truststore(new File("src/test/resources/truststore.jceks"))
.trustStoreType("jceks").build())
.trustStoreType("jceks")
.sslVerifyMode(SslVerifyMode.CA).build();

try (JedisCluster jc = new JedisCluster(new HostAndPort("localhost", 8379),
DefaultJedisClientConfig.builder().password("cluster").sslOptions(sslOptions)
.hostnameVerifier(hostnameVerifier).hostAndPortMapper(portMap).build(),
DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) {
jc.get("foo");
Expand All @@ -164,22 +166,15 @@ public void connectWithCustomHostNameVerifier() {
}

try (JedisCluster jc2 = new JedisCluster(new HostAndPort("127.0.0.1", 8379),
DefaultJedisClientConfig.builder().password("cluster")
.sslOptions(SslOptions.builder()
.truststore(new File("src/test/resources/truststore.jceks"))
.trustStoreType("jceks").build())
DefaultJedisClientConfig.builder().password("cluster").sslOptions(sslOptions)
.hostnameVerifier(hostnameVerifier).hostAndPortMapper(portMap).build(),
DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) {
} catch (JedisClusterOperationException e) {
assertEquals("Could not initialize cluster slots cache.", e.getMessage());
}

try (JedisCluster jc3 = new JedisCluster(new HostAndPort("localhost", 8379),
DefaultJedisClientConfig.builder().password("cluster")
.sslOptions(SslOptions.builder()
.truststore(new File("src/test/resources/truststore.jceks"))
.trustStoreType("jceks")
.sslVerifyMode(SslVerifyMode.CA).build())
DefaultJedisClientConfig.builder().password("cluster").sslOptions(sslOptions)
.hostnameVerifier(localhostVerifier).hostAndPortMapper(portMap).build(),
DEFAULT_REDIRECTIONS, DEFAULT_POOL_CONFIG)) {
jc3.get("foo");
Expand Down

0 comments on commit 9e60a8e

Please sign in to comment.