SSLOptionsJedisSentinelPoolIT.java
package redis.clients.jedis.tls;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import redis.clients.jedis.DefaultJedisClientConfig;
import redis.clients.jedis.EndpointConfig;
import redis.clients.jedis.Endpoints;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisSentinelPool;
/**
* SSL/TLS tests for {@link JedisSentinelPool} using SslOptions builder pattern.
* <p>
* Tests various combinations of SSL on master and sentinel connections:
* <ul>
* <li>Sentinel without SSL, Redis master with SSL (using SslOptions)</li>
* <li>Sentinel with SSL (using SslOptions), Redis master without SSL</li>
* <li>Both sentinel and Redis master with SSL (using SslOptions)</li>
* </ul>
*/
public class SSLOptionsJedisSentinelPoolIT extends RedisSentinelTlsTestBase {
private static final GenericObjectPoolConfig<Jedis> POOL_CONFIG = new GenericObjectPoolConfig<>();
// Endpoints for different SSL configurations
private static EndpointConfig aclTlsEndpoint;
private static EndpointConfig aclEndpoint;
private static EndpointConfig sentinelTlsEndpoint;
@BeforeAll
public static void setUp() {
aclTlsEndpoint = Endpoints.getRedisEndpoint("standalone0-acl-tls");
aclEndpoint = Endpoints.getRedisEndpoint("standalone0-acl");
sentinelTlsEndpoint = Endpoints.getRedisEndpoint("sentinel-standalone0-tls");
}
/**
* Tests sentinel without SSL connecting to Redis master with SSL using SslOptions.
*/
@Test
public void sentinelWithoutSslConnectsToRedisWithSsl() {
DefaultJedisClientConfig masterConfig = aclTlsEndpoint.getClientConfigBuilder()
.clientName("master-client").sslOptions(sslOptions)
.hostAndPortMapper(PRIMARY_SSL_PORT_MAPPER).build();
DefaultJedisClientConfig sentinelConfig = createSentinelConfigWithoutSsl();
try (JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, masterConfig,
sentinelConfig)) {
pool.getResource().close();
}
try (JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, POOL_CONFIG,
masterConfig, sentinelConfig)) {
pool.getResource().close();
}
}
/**
* Tests sentinel with SSL (using SslOptions) connecting to Redis master without SSL.
*/
@Test
public void sentinelWithSslConnectsToRedisWithoutSsl() {
DefaultJedisClientConfig masterConfig = aclEndpoint.getClientConfigBuilder()
.clientName("master-client").build();
DefaultJedisClientConfig sentinelConfig = sentinelTlsEndpoint.getClientConfigBuilder()
.sslOptions(sslOptions).hostAndPortMapper(SENTINEL_SSL_PORT_MAPPER).build();
try (JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, masterConfig,
sentinelConfig)) {
pool.getResource().close();
}
try (JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, POOL_CONFIG,
masterConfig, sentinelConfig)) {
pool.getResource().close();
}
}
/**
* Tests both sentinel and Redis master with SSL using SslOptions.
*/
@Test
public void sentinelWithSslConnectsToRedisWithSsl() {
DefaultJedisClientConfig masterConfig = aclTlsEndpoint.getClientConfigBuilder()
.clientName("master-client").sslOptions(sslOptions)
.hostAndPortMapper(PRIMARY_SSL_PORT_MAPPER).build();
DefaultJedisClientConfig sentinelConfig = createSentinelConfigWithSsl(sslOptions);
try (JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, masterConfig,
sentinelConfig)) {
pool.getResource().close();
}
try (JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, POOL_CONFIG,
masterConfig, sentinelConfig)) {
pool.getResource().close();
}
}
}