Skip to content

Commit c3f426e

Browse files
committed
fix:allow any hostname for testing purposes
1 parent 18e8d9c commit c3f426e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

parsec-jca-java-test/src/test/java/org/parallaxsecond/parsec/jce/provider/HttpClientTlsTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
import static java.util.Optional.ofNullable;
1414
import java.util.stream.Stream;
1515

16+
import javax.net.ssl.HostnameVerifier;
1617
import javax.net.ssl.KeyManagerFactory;
1718
import javax.net.ssl.KeyStoreBuilderParameters;
1819
import javax.net.ssl.SSLContext;
20+
import javax.net.ssl.SSLSession;
1921
import javax.net.ssl.TrustManagerFactory;
2022

2123
import org.apache.hc.client5.http.classic.methods.HttpGet;
@@ -117,6 +119,14 @@ private String absFile(String f) {
117119
return new File(f).getAbsolutePath();
118120
}
119121

122+
// Allow all hostnames for testing purposes
123+
HostnameVerifier allowAll = new HostnameVerifier() {
124+
@Override
125+
public boolean verify(String hostName, SSLSession session) {
126+
return true;
127+
}
128+
};
129+
120130
@BeforeEach
121131
@SneakyThrows
122132
void setup() {
@@ -170,8 +180,8 @@ void testHttpClient(String description, int expectedResponseCode,
170180

171181
assertNotNull(sslContext.getProvider());
172182

173-
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext,
174-
new DefaultHostnameVerifier());
183+
SSLConnectionSocketFactory sslsf =
184+
new SSLConnectionSocketFactory(sslContext, allowAll);
175185

176186
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
177187
.<ConnectionSocketFactory>create().register("https", sslsf).build();

0 commit comments

Comments
 (0)