Search in sources :

Example 6 with SSLKeyStore

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));
}
Also used : SSLKeyStore(com.dtflys.forest.ssl.SSLKeyStore) SSLSession(javax.net.ssl.SSLSession) MyHostnameVerifier(com.dtflys.test.http.ssl.MyHostnameVerifier) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 7 with SSLKeyStore

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();
}
Also used : ForestRuntimeException(com.dtflys.forest.exceptions.ForestRuntimeException) SSLKeyStore(com.dtflys.forest.ssl.SSLKeyStore) ForestLogger(com.dtflys.forest.logging.ForestLogger) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

SSLKeyStore (com.dtflys.forest.ssl.SSLKeyStore)7 ForestRuntimeException (com.dtflys.forest.exceptions.ForestRuntimeException)4 ForestRequest (com.dtflys.forest.http.ForestRequest)2 ForestLogger (com.dtflys.forest.logging.ForestLogger)2 MalformedURLException (java.net.MalformedURLException)2 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 AddressSource (com.dtflys.forest.callback.AddressSource)1 OnError (com.dtflys.forest.callback.OnError)1 OnLoadCookie (com.dtflys.forest.callback.OnLoadCookie)1 OnProgress (com.dtflys.forest.callback.OnProgress)1 OnRedirection (com.dtflys.forest.callback.OnRedirection)1 OnSaveCookie (com.dtflys.forest.callback.OnSaveCookie)1 OnSuccess (com.dtflys.forest.callback.OnSuccess)1 ForestConfiguration (com.dtflys.forest.config.ForestConfiguration)1 VariableScope (com.dtflys.forest.config.VariableScope)1 ForestJsonConverter (com.dtflys.forest.converter.json.ForestJsonConverter)1 ForestRetryException (com.dtflys.forest.exceptions.ForestRetryException)1 ForestVariableUndefinedException (com.dtflys.forest.exceptions.ForestVariableUndefinedException)1