Skip to content

Commit

Permalink
Addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ggivo committed Dec 2, 2024
1 parent 6f299aa commit 09ffff5
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 34 deletions.
13 changes: 12 additions & 1 deletion src/test/java/redis/clients/jedis/EndpointConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import redis.clients.jedis.util.JedisURIHelper;
import redis.clients.jedis.util.TlsUtil;

import java.io.FileReader;
import java.net.URI;
Expand All @@ -17,14 +18,16 @@ public class EndpointConfig {
private final String password;
private final int bdbId;
private final List<URI> endpoints;
private final String environment;

public EndpointConfig(HostAndPort hnp, String username, String password, boolean tls) {
public EndpointConfig(HostAndPort hnp, String username, String password, boolean tls, String environment) {
this.tls = tls;
this.username = username;
this.password = password;
this.bdbId = 0;
this.endpoints = Collections.singletonList(
URI.create(getURISchema(tls) + hnp.getHost() + ":" + hnp.getPort()));
this.environment = environment;
}

public HostAndPort getHostAndPort() {
Expand Down Expand Up @@ -61,6 +64,10 @@ public URI getURI() {
return endpoints.get(0);
}

public String getEnvironment() {
return environment;
}

public class EndpointURIBuilder {
private boolean tls;

Expand Down Expand Up @@ -116,6 +123,10 @@ public DefaultJedisClientConfig.Builder getClientConfigBuilder() {
DefaultJedisClientConfig.Builder builder = DefaultJedisClientConfig.builder()
.password(password).ssl(tls);

if (tls & environment != null) {
builder.sslSocketFactory(TlsUtil.sslSocketFactoryForEnv(environment));
}

if (username != null) {
return builder.user(username);
}
Expand Down
13 changes: 7 additions & 6 deletions src/test/java/redis/clients/jedis/SSLACLJedisTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package redis.clients.jedis;

import static org.junit.Assume.assumeTrue;
import static redis.clients.jedis.util.RedisVersionUtil.getRedisVersion;
import static org.junit.Assert.*;
import static redis.clients.jedis.util.TlsUtil.*;
Expand All @@ -26,10 +27,10 @@ public class SSLACLJedisTest {

@BeforeClass
public static void prepare() {
Path trusStorePath = createAndSaveEnvTruststore("redis1-2-5-10-sentinel", "changeit");
Path trusStorePath = createAndSaveEnvTruststore("redis1-2-5-8-sentinel", "changeit");
TlsUtil.setCustomTrustStore(trusStorePath, "changeit");
// Use to check if the ACL test should be ran. ACL are available only in 6.0 and later
org.junit.Assume.assumeTrue("Not running ACL test on this version of Redis",
assumeTrue("Not running ACL test on this version of Redis",
getRedisVersion(endpoint).isGreaterThanOrEqualTo(RedisVersion.V6_0_0));
}

Expand All @@ -42,7 +43,7 @@ public static void teardownTrustStore() {
public void connectWithSsl() {
try (Jedis jedis = new Jedis(endpoint.getHost(), endpoint.getPort(),
DefaultJedisClientConfig.builder()
.sslSocketFactory(sslSocketFactoryForEnv("redis1-2-5-10-sentinel"))
.sslSocketFactory(sslSocketFactoryForEnv("redis1-2-5-8-sentinel"))
.ssl(true)
.build())) {
jedis.auth(endpoint.getUsername(), endpoint.getPassword());
Expand All @@ -54,7 +55,7 @@ public void connectWithSsl() {
public void connectWithConfig() {
try (Jedis jedis = new Jedis(endpoint.getHostAndPort(),
DefaultJedisClientConfig.builder()
.sslSocketFactory(sslSocketFactoryForEnv("redis1-2-5-10-sentinel"))
.sslSocketFactory(sslSocketFactoryForEnv("redis1-2-5-8-sentinel"))
.ssl(true).build())) {
jedis.auth(endpoint.getUsername(), endpoint.getPassword());
assertEquals("PONG", jedis.ping());
Expand All @@ -81,13 +82,13 @@ public void connectWithUri() {
endpointWithDefaultUser.getURIBuilder()
.defaultCredentials().build(),
DefaultJedisClientConfig.builder()
.sslSocketFactory(sslSocketFactoryForEnv("redis1-2-5-10-sentinel"))
.sslSocketFactory(sslSocketFactoryForEnv("redis1-2-5-8-sentinel"))
.build())) {
assertEquals("PONG", jedis.ping());
}
try (Jedis jedis = new Jedis(endpoint.getURIBuilder().defaultCredentials().build(),
DefaultJedisClientConfig.builder()
.sslSocketFactory(sslSocketFactoryForEnv("redis1-2-5-10-sentinel"))
.sslSocketFactory(sslSocketFactoryForEnv("redis1-2-5-8-sentinel"))
.build())) {
assertEquals("PONG", jedis.ping());
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/redis/clients/jedis/SSLJedisTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class SSLJedisTest {

@BeforeClass
public static void prepare() {
Path trusStorePath = TlsUtil.createAndSaveEnvTruststore("redis1-2-5-10-sentinel", "changeit");
Path trusStorePath = TlsUtil.createAndSaveEnvTruststore("redis1-2-5-8-sentinel", "changeit");
TlsUtil.setCustomTrustStore(trusStorePath, "changeit");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class SSLJedisPooledClientSideCacheTest extends JedisPooledClientSideCach

@BeforeClass
public static void prepare() {
Path trusStorePath = TlsUtil.createAndSaveEnvTruststore("redis1-2-5-10-sentinel", "changeit");
Path trusStorePath = TlsUtil.createAndSaveEnvTruststore("redis1-2-5-8-sentinel", "changeit");
TlsUtil.setCustomTrustStore(trusStorePath, "changeit");

endpoint = HostAndPorts.getRedisEndpoint("standalone0-tls");
Expand Down
9 changes: 3 additions & 6 deletions src/test/java/redis/clients/jedis/util/RedisVersionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import io.redis.test.utils.RedisVersion;
import redis.clients.jedis.*;

import static redis.clients.jedis.util.TlsUtil.createTrustAllSslSocketFactory;

public class RedisVersionUtil {

static final String FORCE_REDIS_SERVER_VERSION_ENV = "forceRedisServerVersion";
Expand Down Expand Up @@ -51,10 +49,9 @@ public static RedisVersion getRedisVersion(EndpointConfig endpoint) {
}

DefaultJedisClientConfig.Builder builder = endpoint.getClientConfigBuilder();
if (endpoint.isTls()) {
builder.sslSocketFactory(createTrustAllSslSocketFactory());
}
try (Jedis jedis = new Jedis(endpoint.getHostAndPort(), builder.build())) {
DefaultJedisClientConfig clientConfig = builder.build();

try (Jedis jedis = new Jedis(endpoint.getHostAndPort(), clientConfig)) {
return getRedisVersion(jedis);
}
}
Expand Down
41 changes: 27 additions & 14 deletions src/test/resources/endpoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,104 +4,117 @@
"tls": false,
"endpoints": [
"redis://localhost:6379"
]
],
"environment": "redis1-2-5-8-sentinel"
},
"standalone0-tls": {
"username": "default",
"password": "foobared",
"tls": true,
"endpoints": [
"rediss://localhost:6390"
]
],
"environment": "redis1-2-5-8-sentinel"
},
"standalone0-acl": {
"username": "acljedis",
"password": "fizzbuzz",
"tls": false,
"endpoints": [
"redis://localhost:6379"
]
],
"environment": "redis1-2-5-8-sentinel"
},
"standalone0-acl-tls": {
"username": "acljedis",
"password": "fizzbuzz",
"tls": true,
"endpoints": [
"rediss://localhost:6390"
]
],
"environment": "redis1-2-5-8-sentinel"
},
"standalone1": {
"username": "default",
"password": "foobared",
"tls": false,
"endpoints": [
"redis://localhost:6380"
]
],
"environment": "redis1-2-5-8-sentinel"
},
"standalone2-primary": {
"username": "default",
"password": "foobared",
"tls": false,
"endpoints": [
"redis://localhost:6381"
]
],
"environment": "redis3-4-sentinel"
},
"standalone3-replica-of-standalone2": {
"username": "default",
"password": "foobared",
"tls": false,
"endpoints": [
"redis://localhost:6382"
]
],
"environment": "redis3-4-sentinel"
},
"standalone4-replica-of-standalone1": {
"username": "default",
"password": "foobared",
"tls": false,
"endpoints": [
"redis://localhost:6383"
]
],
"environment": "redis1-2-5-8-sentinel"
},
"standalone5-primary": {
"username": "default",
"password": "foobared",
"tls": false,
"endpoints": [
"redis://localhost:6384"
]
],
"environment": "redis6-7-sentinel"
},
"standalone6-replica-of-standalone5": {
"username": "default",
"password": "foobared",
"tls": false,
"endpoints": [
"redis://localhost:6385"
]
],
"environment": "redis6-7-sentinel"
},
"standalone7-with-lfu-policy": {
"username": "default",
"password": "foobared",
"tls": false,
"endpoints": [
"redis://localhost:6386"
]
],
"environment": "redis1-2-5-8-sentinel"
},
"standalone9": {
"tls": false,
"endpoints": [
"redis://localhost:6388"
]
],
"environment": "redis10-11"
},
"standalone10-replica-of-standalone9": {
"tls": false,
"endpoints": [
"redis://localhost:6389"
]
],
"environment": "redis10-11"
},
"modules-docker": {
"tls": false,
"endpoints": [
"redis://localhost:6479"
]
}
}
}
10 changes: 5 additions & 5 deletions src/test/resources/env/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
services:
redis1-2-5-10-sentinel:
redis1-2-5-8-sentinel:
sysctls:
- net.ipv6.conf.all.disable_ipv6=1
image: "${CLIENT_LIBS_TEST_IMAGE}:${REDIS_VERSION:-8.0-M01}"
container_name: redis1-2-5-10-sentinel
container_name: redis1-2-5-8-sentinel
#network_mode: host
environment:
- REDIS_CLUSTER=no
Expand All @@ -20,8 +20,8 @@ services:
- "36379:36379" # sentinel tls
command: ${ENABLE_MODULE_COMMAND_DIRECTIVE}
volumes:
- ${REDIS_ENV_CONF_DIR}/redis1-2-5-10-sentinel/config:/redis/config:r
- ${REDIS_ENV_WORK_DIR}/redis1-2-5-10-sentinel/work:/redis/work:rw
- ${REDIS_ENV_CONF_DIR}/redis1-2-5-8-sentinel/config:/redis/config:r
- ${REDIS_ENV_WORK_DIR}/redis1-2-5-8-sentinel/work:/redis/work:rw
redis3-4-sentinel:
sysctls:
- net.ipv6.conf.all.disable_ipv6=1
Expand Down Expand Up @@ -157,4 +157,4 @@ services:
# command: redis-server /etc/redis.conf
# volumes:
# - "./redis_uds/config/node-0/redis.conf:/etc/redis.conf"
# - "./work/redis_uds/work:/tmp/docker/"
# - "./work/redis_uds/work:/tmp/docker/"

0 comments on commit 09ffff5

Please sign in to comment.