Skip to content

Commit

Permalink
Enable existing SSL tests without impacting new ones
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 committed Nov 18, 2024
1 parent ff88451 commit 315d73d
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 17 deletions.
13 changes: 9 additions & 4 deletions src/test/java/redis/clients/jedis/SSLACLJedisClusterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -18,7 +19,6 @@
import redis.clients.jedis.SSLJedisTest.BasicHostnameVerifier;
import redis.clients.jedis.util.RedisVersionUtil;

@org.junit.Ignore // TODO: enable -- (in a different way?)
public class SSLACLJedisClusterTest extends JedisClusterTestBase {

private static final int DEFAULT_REDIRECTIONS = 5;
Expand All @@ -44,15 +44,20 @@ public class SSLACLJedisClusterTest extends JedisClusterTestBase {

@BeforeClass
public static void prepare() {
// We need to set up certificates first before connecting to the endpoint with enabled TLS
SSLJedisTest.setupTrustStore();

// TODO(imalinovskyi): Remove hardcoded connection settings
// once this test is refactored to support RE
org.junit.Assume.assumeTrue("Not running ACL test on this version of Redis",
RedisVersionUtil.checkRedisMajorVersionNumber(6,
new EndpointConfig(new HostAndPort("localhost", 8379),
"default", "cluster", true)));

// We need to set up certificates first before connecting to the endpoint with enabled TLS
SSLJedisTest.setupTrustStore();
}

@AfterClass
public static void unprepare() {
SSLJedisTest.cleanupTrustStore();
}

@Test
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/redis/clients/jedis/SSLACLJedisTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.Assert.*;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

Expand All @@ -28,6 +29,11 @@ public static void prepare() {
RedisVersionUtil.checkRedisMajorVersionNumber(6, endpoint));
}

@AfterClass
public static void unprepare() {
SSLJedisTest.cleanupTrustStore();
}

@Test
public void connectWithSsl() {
try (Jedis jedis = new Jedis(endpoint.getHost(), endpoint.getPort(), true)) {
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/redis/clients/jedis/SSLJedisClusterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import redis.clients.jedis.exceptions.JedisClusterOperationException;
import redis.clients.jedis.SSLJedisTest.BasicHostnameVerifier;

@org.junit.Ignore // TODO: enable -- (in a different way?)
public class SSLJedisClusterTest extends JedisClusterTestBase {

private static final int DEFAULT_REDIRECTIONS = 5;
Expand Down Expand Up @@ -46,6 +46,11 @@ public static void prepare() {
SSLJedisTest.setupTrustStore(); // set up trust store for SSL tests
}

@AfterClass
public static void unprepare() {
SSLJedisTest.cleanupTrustStore();
}

@Test
public void testSSLDiscoverNodesAutomatically() {
try (JedisCluster jc = new JedisCluster(Collections.singleton(new HostAndPort("localhost", 8379)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

@org.junit.Ignore // TODO: enable -- (in a different way?)
public class SSLJedisSentinelPoolTest {

private static final String MASTER_NAME = "aclmaster";
Expand All @@ -25,6 +25,11 @@ public static void prepare() {
sentinels.add(HostAndPorts.getSentinelServers().get(4));
}

@AfterClass
public static void unprepare() {
SSLJedisTest.cleanupTrustStore();
}

@Test
public void sentinelWithoutSslConnectsToRedisWithSsl() {

Expand Down
34 changes: 24 additions & 10 deletions src/test/java/redis/clients/jedis/SSLJedisTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,44 @@
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

@org.junit.Ignore // TODO: enable -- (in a different way?)
public class SSLJedisTest {

protected static final EndpointConfig endpoint = HostAndPorts.getRedisEndpoint("standalone0-tls");

public static void setupTrustStore() {
setJvmTrustStore("src/test/resources/truststore.jceks", "jceks");
}

private static void setJvmTrustStore(String trustStoreFilePath, String trustStoreType) {
assertTrue(String.format("Could not find trust store at '%s'.", trustStoreFilePath),
new File(trustStoreFilePath).exists());
System.setProperty("javax.net.ssl.trustStore", trustStoreFilePath);
System.setProperty("javax.net.ssl.trustStoreType", trustStoreType);
}

public static void cleanupTrustStore() {
clearJvmTrustStore();
}

private static void clearJvmTrustStore() {
System.clearProperty("javax.net.ssl.trustStore");
System.clearProperty("javax.net.ssl.trustStoreType");
}

@BeforeClass
public static void prepare() {
setupTrustStore();
}

public static void setupTrustStore() {
// setJvmTrustStore("src/test/resources/truststore.jceks", "jceks");
@AfterClass
public static void unprepare() {
cleanupTrustStore();
}

// private static void setJvmTrustStore(String trustStoreFilePath, String trustStoreType) {
// assertTrue(String.format("Could not find trust store at '%s'.", trustStoreFilePath),
// new File(trustStoreFilePath).exists());
// System.setProperty("javax.net.ssl.trustStore", trustStoreFilePath);
// System.setProperty("javax.net.ssl.trustStoreType", trustStoreType);
// }

@Test
public void connectWithSsl() {
try (Jedis jedis = new Jedis(endpoint.getHost(), endpoint.getPort(), true)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package redis.clients.jedis.csc;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import redis.clients.jedis.HostAndPorts;
import redis.clients.jedis.SSLJedisTest;

@org.junit.Ignore // TODO: enable
public class SSLJedisPooledClientSideCacheTest extends JedisPooledClientSideCacheTestBase {

@BeforeClass
Expand All @@ -14,4 +14,9 @@ public static void prepare() {
endpoint = HostAndPorts.getRedisEndpoint("standalone0-tls");
}

@AfterClass
public static void unprepare() {
SSLJedisTest.cleanupTrustStore();
}

}

0 comments on commit 315d73d

Please sign in to comment.