From 09ffff5b3f2a708c52563f042bacf34d58f471ec Mon Sep 17 00:00:00 2001 From: ggivo Date: Mon, 2 Dec 2024 11:31:34 +0200 Subject: [PATCH] Addressing review comments --- .../redis/clients/jedis/EndpointConfig.java | 13 +++++- .../redis/clients/jedis/SSLACLJedisTest.java | 13 +++--- .../redis/clients/jedis/SSLJedisTest.java | 2 +- .../SSLJedisPooledClientSideCacheTest.java | 2 +- .../clients/jedis/util/RedisVersionUtil.java | 9 ++-- src/test/resources/endpoints.json | 41 ++++++++++++------- src/test/resources/env/docker-compose.yml | 10 ++--- .../config/node-6379-6390/redis.conf | 0 .../config/node-6380/redis.conf | 0 .../config/node-6383-6391/redis.conf | 0 .../config/node-6386/redis.conf | 0 .../node-sentinel-26379-36379/redis.conf | 0 12 files changed, 56 insertions(+), 34 deletions(-) rename src/test/resources/env/{redis1-2-5-10-sentinel => redis1-2-5-8-sentinel}/config/node-6379-6390/redis.conf (100%) rename src/test/resources/env/{redis1-2-5-10-sentinel => redis1-2-5-8-sentinel}/config/node-6380/redis.conf (100%) rename src/test/resources/env/{redis1-2-5-10-sentinel => redis1-2-5-8-sentinel}/config/node-6383-6391/redis.conf (100%) rename src/test/resources/env/{redis1-2-5-10-sentinel => redis1-2-5-8-sentinel}/config/node-6386/redis.conf (100%) rename src/test/resources/env/{redis1-2-5-10-sentinel => redis1-2-5-8-sentinel}/config/node-sentinel-26379-36379/redis.conf (100%) diff --git a/src/test/java/redis/clients/jedis/EndpointConfig.java b/src/test/java/redis/clients/jedis/EndpointConfig.java index 27984577f3..447f0dcd67 100644 --- a/src/test/java/redis/clients/jedis/EndpointConfig.java +++ b/src/test/java/redis/clients/jedis/EndpointConfig.java @@ -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; @@ -17,14 +18,16 @@ public class EndpointConfig { private final String password; private final int bdbId; private final List 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() { @@ -61,6 +64,10 @@ public URI getURI() { return endpoints.get(0); } + public String getEnvironment() { + return environment; + } + public class EndpointURIBuilder { private boolean tls; @@ -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); } diff --git a/src/test/java/redis/clients/jedis/SSLACLJedisTest.java b/src/test/java/redis/clients/jedis/SSLACLJedisTest.java index 06b6fa1f79..6297298310 100644 --- a/src/test/java/redis/clients/jedis/SSLACLJedisTest.java +++ b/src/test/java/redis/clients/jedis/SSLACLJedisTest.java @@ -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.*; @@ -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)); } @@ -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()); @@ -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()); @@ -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()); } diff --git a/src/test/java/redis/clients/jedis/SSLJedisTest.java b/src/test/java/redis/clients/jedis/SSLJedisTest.java index 89a448fd30..8e0fed6252 100644 --- a/src/test/java/redis/clients/jedis/SSLJedisTest.java +++ b/src/test/java/redis/clients/jedis/SSLJedisTest.java @@ -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"); } diff --git a/src/test/java/redis/clients/jedis/csc/SSLJedisPooledClientSideCacheTest.java b/src/test/java/redis/clients/jedis/csc/SSLJedisPooledClientSideCacheTest.java index bf89e21b01..015abf2719 100644 --- a/src/test/java/redis/clients/jedis/csc/SSLJedisPooledClientSideCacheTest.java +++ b/src/test/java/redis/clients/jedis/csc/SSLJedisPooledClientSideCacheTest.java @@ -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"); diff --git a/src/test/java/redis/clients/jedis/util/RedisVersionUtil.java b/src/test/java/redis/clients/jedis/util/RedisVersionUtil.java index fe7de68b5a..480a89f3a3 100644 --- a/src/test/java/redis/clients/jedis/util/RedisVersionUtil.java +++ b/src/test/java/redis/clients/jedis/util/RedisVersionUtil.java @@ -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"; @@ -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); } } diff --git a/src/test/resources/endpoints.json b/src/test/resources/endpoints.json index c1d905bfb8..75211f14fd 100644 --- a/src/test/resources/endpoints.json +++ b/src/test/resources/endpoints.json @@ -4,7 +4,8 @@ "tls": false, "endpoints": [ "redis://localhost:6379" - ] + ], + "environment": "redis1-2-5-8-sentinel" }, "standalone0-tls": { "username": "default", @@ -12,7 +13,8 @@ "tls": true, "endpoints": [ "rediss://localhost:6390" - ] + ], + "environment": "redis1-2-5-8-sentinel" }, "standalone0-acl": { "username": "acljedis", @@ -20,7 +22,8 @@ "tls": false, "endpoints": [ "redis://localhost:6379" - ] + ], + "environment": "redis1-2-5-8-sentinel" }, "standalone0-acl-tls": { "username": "acljedis", @@ -28,7 +31,8 @@ "tls": true, "endpoints": [ "rediss://localhost:6390" - ] + ], + "environment": "redis1-2-5-8-sentinel" }, "standalone1": { "username": "default", @@ -36,7 +40,8 @@ "tls": false, "endpoints": [ "redis://localhost:6380" - ] + ], + "environment": "redis1-2-5-8-sentinel" }, "standalone2-primary": { "username": "default", @@ -44,7 +49,8 @@ "tls": false, "endpoints": [ "redis://localhost:6381" - ] + ], + "environment": "redis3-4-sentinel" }, "standalone3-replica-of-standalone2": { "username": "default", @@ -52,7 +58,8 @@ "tls": false, "endpoints": [ "redis://localhost:6382" - ] + ], + "environment": "redis3-4-sentinel" }, "standalone4-replica-of-standalone1": { "username": "default", @@ -60,7 +67,8 @@ "tls": false, "endpoints": [ "redis://localhost:6383" - ] + ], + "environment": "redis1-2-5-8-sentinel" }, "standalone5-primary": { "username": "default", @@ -68,7 +76,8 @@ "tls": false, "endpoints": [ "redis://localhost:6384" - ] + ], + "environment": "redis6-7-sentinel" }, "standalone6-replica-of-standalone5": { "username": "default", @@ -76,7 +85,8 @@ "tls": false, "endpoints": [ "redis://localhost:6385" - ] + ], + "environment": "redis6-7-sentinel" }, "standalone7-with-lfu-policy": { "username": "default", @@ -84,19 +94,22 @@ "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, @@ -104,4 +117,4 @@ "redis://localhost:6479" ] } -} \ No newline at end of file +} diff --git a/src/test/resources/env/docker-compose.yml b/src/test/resources/env/docker-compose.yml index c6bab9b2fd..0b81a666cd 100644 --- a/src/test/resources/env/docker-compose.yml +++ b/src/test/resources/env/docker-compose.yml @@ -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 @@ -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 @@ -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/" \ No newline at end of file +# - "./work/redis_uds/work:/tmp/docker/" diff --git a/src/test/resources/env/redis1-2-5-10-sentinel/config/node-6379-6390/redis.conf b/src/test/resources/env/redis1-2-5-8-sentinel/config/node-6379-6390/redis.conf similarity index 100% rename from src/test/resources/env/redis1-2-5-10-sentinel/config/node-6379-6390/redis.conf rename to src/test/resources/env/redis1-2-5-8-sentinel/config/node-6379-6390/redis.conf diff --git a/src/test/resources/env/redis1-2-5-10-sentinel/config/node-6380/redis.conf b/src/test/resources/env/redis1-2-5-8-sentinel/config/node-6380/redis.conf similarity index 100% rename from src/test/resources/env/redis1-2-5-10-sentinel/config/node-6380/redis.conf rename to src/test/resources/env/redis1-2-5-8-sentinel/config/node-6380/redis.conf diff --git a/src/test/resources/env/redis1-2-5-10-sentinel/config/node-6383-6391/redis.conf b/src/test/resources/env/redis1-2-5-8-sentinel/config/node-6383-6391/redis.conf similarity index 100% rename from src/test/resources/env/redis1-2-5-10-sentinel/config/node-6383-6391/redis.conf rename to src/test/resources/env/redis1-2-5-8-sentinel/config/node-6383-6391/redis.conf diff --git a/src/test/resources/env/redis1-2-5-10-sentinel/config/node-6386/redis.conf b/src/test/resources/env/redis1-2-5-8-sentinel/config/node-6386/redis.conf similarity index 100% rename from src/test/resources/env/redis1-2-5-10-sentinel/config/node-6386/redis.conf rename to src/test/resources/env/redis1-2-5-8-sentinel/config/node-6386/redis.conf diff --git a/src/test/resources/env/redis1-2-5-10-sentinel/config/node-sentinel-26379-36379/redis.conf b/src/test/resources/env/redis1-2-5-8-sentinel/config/node-sentinel-26379-36379/redis.conf similarity index 100% rename from src/test/resources/env/redis1-2-5-10-sentinel/config/node-sentinel-26379-36379/redis.conf rename to src/test/resources/env/redis1-2-5-8-sentinel/config/node-sentinel-26379-36379/redis.conf