SSLOptionsRedisClientTest.java
package redis.clients.jedis;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Tag;
import redis.clients.jedis.util.TlsUtil;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
@Tag("integration")
public class SSLOptionsRedisClientTest {
protected static final EndpointConfig endpoint = HostAndPorts.getRedisEndpoint("standalone0-tls");
protected static final EndpointConfig aclEndpoint = HostAndPorts.getRedisEndpoint("standalone0-acl-tls");
private static final String trustStoreName = SSLACLJedisTest.class.getSimpleName();
private static Path trustStorePath;
@BeforeAll
public static void prepare() {
List<Path> trustedCertLocation = Arrays.asList(endpoint.getCertificatesLocation(),
aclEndpoint.getCertificatesLocation());
trustStorePath = TlsUtil.createAndSaveTestTruststore(trustStoreName, trustedCertLocation,
"changeit");
}
@Test
public void connectWithClientConfig() {
try (RedisClient jedis = RedisClient.builder()
.hostAndPort(endpoint.getHostAndPort())
.clientConfig(endpoint.getClientConfigBuilder()
.sslOptions(SslOptions.builder()
.truststore(trustStorePath.toFile())
.trustStoreType("jceks")
.build()).build())
.build()) {
assertEquals("PONG", jedis.ping());
}
}
@Test
public void connectWithSslInsecure() {
try (RedisClient jedis = RedisClient.builder()
.hostAndPort(endpoint.getHostAndPort())
.clientConfig(endpoint.getClientConfigBuilder()
.sslOptions(SslOptions.builder()
.sslVerifyMode(SslVerifyMode.INSECURE)
.build()).build())
.build()) {
assertEquals("PONG", jedis.ping());
}
}
@Test
public void connectWithSslContextProtocol() {
try (RedisClient jedis = RedisClient.builder()
.hostAndPort(endpoint.getHostAndPort())
.clientConfig(endpoint.getClientConfigBuilder()
.sslOptions(SslOptions.builder()
.sslProtocol("SSL")
.truststore(trustStorePath.toFile())
.trustStoreType("jceks")
.build()).build())
.build()) {
assertEquals("PONG", jedis.ping());
}
}
@Test
public void connectWithAcl() {
try (RedisClient jedis = RedisClient.builder()
.hostAndPort(aclEndpoint.getHostAndPort())
.clientConfig(aclEndpoint.getClientConfigBuilder()
.sslOptions(SslOptions.builder()
.truststore(trustStorePath.toFile())
.trustStoreType("jceks")
.build()).build())
.build()) {
assertEquals("PONG", jedis.ping());
}
}
}