|
19 | 19 | import static org.mockito.Mockito.*; |
20 | 20 |
|
21 | 21 | import redis.clients.jedis.JedisCluster; |
| 22 | +import redis.clients.jedis.JedisClusterConnectionHandler; |
| 23 | +import redis.clients.jedis.JedisClusterInfoCache; |
22 | 24 | import redis.clients.jedis.JedisPoolConfig; |
23 | 25 | import sun.net.www.protocol.https.DefaultHostnameVerifier; |
24 | 26 |
|
|
27 | 29 | import java.time.Duration; |
28 | 30 | import java.time.temporal.ChronoUnit; |
29 | 31 |
|
| 32 | +import javax.net.ssl.HostnameVerifier; |
30 | 33 | import javax.net.ssl.SSLContext; |
31 | 34 | import javax.net.ssl.SSLParameters; |
32 | 35 | import javax.net.ssl.SSLSocketFactory; |
33 | 36 |
|
34 | 37 | import org.apache.commons.pool2.impl.GenericObjectPoolConfig; |
35 | 38 | import org.junit.Test; |
36 | 39 | import org.springframework.data.redis.connection.RedisClusterConfiguration; |
| 40 | +import org.springframework.data.redis.connection.RedisClusterConnection; |
37 | 41 | import org.springframework.data.redis.connection.RedisPassword; |
38 | 42 | import org.springframework.data.redis.connection.RedisSentinelConfiguration; |
39 | 43 | import org.springframework.data.redis.connection.RedisStandaloneConfiguration; |
@@ -287,6 +291,49 @@ public void shouldReturnClusterConfiguration() { |
287 | 291 | assertThat(connectionFactory.getClusterConfiguration()).isSameAs(configuration); |
288 | 292 | } |
289 | 293 |
|
| 294 | +@Test // DATAREDIS-975 |
| 295 | +public void shouldApplySslConfigWhenCreatingClusterClient() throws NoSuchAlgorithmException { |
| 296 | + |
| 297 | +SSLParameters sslParameters = new SSLParameters(); |
| 298 | +SSLContext context = SSLContext.getDefault(); |
| 299 | +SSLSocketFactory socketFactory = context.getSocketFactory(); |
| 300 | +JedisPoolConfig poolConfig = new JedisPoolConfig(); |
| 301 | +HostnameVerifier hostNameVerifier = new DefaultHostnameVerifier(); |
| 302 | + |
| 303 | +JedisClientConfiguration configuration = JedisClientConfiguration.builder() // |
| 304 | +.useSsl() // |
| 305 | +.hostnameVerifier(hostNameVerifier) // |
| 306 | +.sslParameters(sslParameters) // |
| 307 | +.sslSocketFactory(socketFactory).and() // |
| 308 | +.clientName("my-client") // |
| 309 | +.connectTimeout(Duration.ofMinutes(1)) // |
| 310 | +.readTimeout(Duration.ofMinutes(5)) // |
| 311 | +.usePooling().poolConfig(poolConfig) // |
| 312 | +.build(); |
| 313 | + |
| 314 | +connectionFactory = new JedisConnectionFactory(new RedisClusterConfiguration(), configuration); |
| 315 | +connectionFactory.afterPropertiesSet(); |
| 316 | + |
| 317 | +RedisClusterConnection connection = connectionFactory.getClusterConnection(); |
| 318 | +assertThat(connection).isInstanceOf(JedisClusterConnection.class); |
| 319 | + |
| 320 | +JedisCluster cluster = ((JedisClusterConnection) connection).getCluster(); |
| 321 | + |
| 322 | +JedisClusterConnectionHandler connectionHandler = (JedisClusterConnectionHandler) ReflectionTestUtils |
| 323 | +.getField(cluster, "connectionHandler"); |
| 324 | +JedisClusterInfoCache cache = (JedisClusterInfoCache) ReflectionTestUtils.getField(connectionHandler, "cache"); |
| 325 | + |
| 326 | +assertThat(ReflectionTestUtils.getField(cache, "connectionTimeout")).isEqualTo(60000); |
| 327 | +assertThat(ReflectionTestUtils.getField(cache, "soTimeout")).isEqualTo(300000); |
| 328 | +assertThat(ReflectionTestUtils.getField(cache, "password")).isNull(); |
| 329 | +assertThat(ReflectionTestUtils.getField(cache, "clientName")).isEqualTo("my-client"); |
| 330 | +assertThat(ReflectionTestUtils.getField(cache, "ssl")).isEqualTo(true); |
| 331 | +assertThat(ReflectionTestUtils.getField(cache, "sslSocketFactory")).isEqualTo(socketFactory); |
| 332 | +assertThat(ReflectionTestUtils.getField(cache, "sslParameters")).isEqualTo(sslParameters); |
| 333 | +assertThat(ReflectionTestUtils.getField(cache, "hostnameVerifier")).isEqualTo(hostNameVerifier); |
| 334 | +assertThat(ReflectionTestUtils.getField(cache, "hostAndPortMap")).isNull(); |
| 335 | +} |
| 336 | + |
290 | 337 | @Test(expected = IllegalStateException.class) // DATAREDIS-574 |
291 | 338 | public void shouldDenyChangesToImmutableClientConfiguration() throws NoSuchAlgorithmException { |
292 | 339 |
|
|
0 commit comments