use of com.dtflys.forest.ssl.SSLKeyStore in project forest by dromara.
the class TestSSLClient method prepareClient.
@BeforeClass
public static void prepareClient() {
configuration = ForestConfiguration.createConfiguration();
SSLKeyStore sslKeyStore = new SSLKeyStore("ssl_client", "ssl_client.keystore", "client", "456789", null, new MySSLSocketFactoryBuilder());
configuration.registerKeyStore(sslKeyStore);
SSLKeyStore sslKeyStore2 = new SSLKeyStore("ssl_client2", "ssl_client.keystore", "client", "456789", new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
if ("localhost".equals(s)) {
return false;
}
return true;
}
}, new MySSLSocketFactoryBuilder());
configuration.registerKeyStore(sslKeyStore2);
configuration.registerKeyStore(new SSLKeyStore("ssl_client3", null, null, null, new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
if ("localhost".equals(s)) {
return false;
}
return true;
}
}, null));
}
use of com.dtflys.forest.ssl.SSLKeyStore in project forest by dromara.
the class SSLTest2 method testConfiguration.
@Test
public void testConfiguration() {
ForestLogger logger = Mockito.mock(ForestLogger.class);
assertEquals(Integer.valueOf(300), sslConfig.getMaxConnections());
assertEquals(Integer.valueOf(300), sslConfig.getMaxRouteConnections());
assertEquals(Integer.valueOf(3000), sslConfig.getTimeout());
assertEquals(Integer.valueOf(3000), sslConfig.getConnectTimeout());
assertEquals(Integer.valueOf(2), sslConfig.getMaxRetryCount());
assertEquals(1, sslConfig.getSslKeyStores().size());
SSLKeyStore sslKeyStore = sslConfig.getKeyStore("keystore1");
assertThat(sslKeyStore).isNotNull();
// assertEquals("keystore1", sslKeyStore.getId());
// assertEquals("test.keystore", sslKeyStore.getFilePath());
// assertEquals("123456", sslKeyStore.getKeystorePass());
// assertEquals("123456", sslKeyStore.getCertPass());
// assertEquals(1, sslKeyStore.getProtocols().length);
// assertEquals("SSLv3", sslKeyStore.getProtocols()[0]);
assertThat(sslKeyStore.getSslSocketFactoryBuilder()).isNotNull().isInstanceOf(MySSLSocketFactoryBuilder.class);
assertThat(sslKeyStore.getHostnameVerifier()).isNotNull().isInstanceOf(MyHostnameVerifier.class);
ForestRequest<String> request = giteeClient.index2();
assertThat(request).isNotNull();
request.getLogConfiguration().getLogHandler().setLogger(logger);
String result = (String) request.execute();
assertThat(result.startsWith("Global: ")).isTrue();
Mockito.verify(logger).info("[Forest] [Test2] 请求: \n" + "\tGET https://gitee.com/dt_flys HTTPS");
Throwable th = null;
try {
giteeClient.index3();
} catch (ForestRuntimeException ex) {
th = ex.getCause();
}
assertThat(th).isNotNull();
}
Aggregations