Skip to content

Commit

Permalink
Increase code reuse for LocalhostVerifier
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 committed Nov 24, 2024
1 parent bcce93b commit 1fa23f2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
12 changes: 1 addition & 11 deletions src/test/java/redis/clients/jedis/SSLJedisClusterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.Map;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;

import org.junit.AfterClass;
Expand All @@ -17,6 +16,7 @@

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

public class SSLJedisClusterTest extends JedisClusterTestBase {

Expand Down Expand Up @@ -237,14 +237,4 @@ public void defaultHostAndPortUsedIfMapReturnsNull() {
assertTrue(clusterNodes.containsKey("127.0.0.1:7381"));
}
}

public class LocalhostVerifier extends BasicHostnameVerifier {
@Override
public boolean verify(String hostname, SSLSession session) {
if (hostname.equals("127.0.0.1")) {
hostname = "localhost";
}
return super.verify(hostname, session);
}
}
}
10 changes: 10 additions & 0 deletions src/test/java/redis/clients/jedis/SSLJedisTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,14 @@ private String getCommonName(X509Certificate peerCertificate) {
throw new IllegalArgumentException("The certificate has no common name.");
}
}

static class LocalhostVerifier extends BasicHostnameVerifier {
@Override
public boolean verify(String hostname, SSLSession session) {
if (hostname.equals("127.0.0.1")) {
hostname = "localhost";
}
return super.verify(hostname, session);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import java.util.Map;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;

import org.junit.Assert;
import org.junit.Test;

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

public class SSLOptionsJedisClusterTest extends JedisClusterTestBase {

Expand Down Expand Up @@ -203,14 +203,4 @@ public void connectWithEmptyTrustStore() throws Exception {
assertEquals("Could not initialize cluster slots cache.", e.getMessage());
}
}

public class LocalhostVerifier extends BasicHostnameVerifier {
@Override
public boolean verify(String hostname, SSLSession session) {
if (hostname.equals("127.0.0.1")) {
hostname = "localhost";
}
return super.verify(hostname, session);
}
}
}

0 comments on commit 1fa23f2

Please sign in to comment.