Search in sources :

Example 11 with SslClient

use of okhttp3.mockwebserver.internal.tls.SslClient in project okhttp by square.

the class OkHttp method prepare.

@Override
public void prepare(Benchmark benchmark) {
    super.prepare(benchmark);
    client = new OkHttpClient.Builder().protocols(benchmark.protocols).build();
    if (benchmark.tls) {
        SslClient sslClient = SslClient.localhost();
        SSLSocketFactory socketFactory = sslClient.socketFactory;
        HostnameVerifier hostnameVerifier = new HostnameVerifier() {

            @Override
            public boolean verify(String s, SSLSession session) {
                return true;
            }
        };
        client = new OkHttpClient.Builder().sslSocketFactory(socketFactory, sslClient.trustManager).hostnameVerifier(hostnameVerifier).build();
    }
}
Also used : OkHttpClient(okhttp3.OkHttpClient) SslClient(okhttp3.internal.tls.SslClient) SSLSession(javax.net.ssl.SSLSession) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 12 with SslClient

use of okhttp3.mockwebserver.internal.tls.SslClient in project okhttp by square.

the class UrlConnection method prepare.

@Override
public void prepare(Benchmark benchmark) {
    super.prepare(benchmark);
    if (benchmark.tls) {
        SslClient sslClient = SslClient.localhost();
        SSLSocketFactory socketFactory = sslClient.socketFactory;
        HostnameVerifier hostnameVerifier = new HostnameVerifier() {

            @Override
            public boolean verify(String s, SSLSession session) {
                return true;
            }
        };
        HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
        HttpsURLConnection.setDefaultSSLSocketFactory(socketFactory);
    }
}
Also used : SslClient(okhttp3.internal.tls.SslClient) SSLSession(javax.net.ssl.SSLSession) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 13 with SslClient

use of okhttp3.mockwebserver.internal.tls.SslClient in project mapbox-events-android by mapbox.

the class TelemetryClientTest method checksRequestTimeoutFailure.

@Test
public void checksRequestTimeoutFailure() throws Exception {
    Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS);
    MapboxTelemetry.applicationContext = mockedContext;
    OkHttpClient localOkHttpClientWithShortTimeout = new OkHttpClient.Builder().readTimeout(100, TimeUnit.MILLISECONDS).build();
    HttpUrl localUrl = obtainBaseEndpointUrl();
    SslClient sslClient = SslClient.localhost();
    TelemetryClientSettings telemetryClientSettings = new TelemetryClientSettings.Builder().client(localOkHttpClientWithShortTimeout).baseUrl(localUrl).sslSocketFactory(sslClient.socketFactory).x509TrustManager(sslClient.trustManager).hostnameVerifier(new HostnameVerifier() {

        @Override
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    }).build();
    TelemetryClient telemetryClient = new TelemetryClient("anyAccessToken", "anyUserAgent", telemetryClientSettings, mock(Logger.class));
    List<Event> theEvent = obtainAnEvent();
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<String> bodyRef = new AtomicReference<>();
    final AtomicBoolean failureRef = new AtomicBoolean();
    Callback aCallback = provideACallback(latch, bodyRef, failureRef);
    enqueueMockNoResponse(504);
    telemetryClient.sendEvents(theEvent, aCallback);
    latch.await();
    assertTrue(failureRef.get());
}
Also used : Context(android.content.Context) OkHttpClient(okhttp3.OkHttpClient) SslClient(okhttp3.mockwebserver.internal.tls.SslClient) SSLSession(javax.net.ssl.SSLSession) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) HttpUrl(okhttp3.HttpUrl) HostnameVerifier(javax.net.ssl.HostnameVerifier) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callback(okhttp3.Callback) Test(org.junit.Test)

Example 14 with SslClient

use of okhttp3.mockwebserver.internal.tls.SslClient in project keywhiz by square.

the class ClientUtilsTest method testSslOkHttpClientCreationWithCookies.

@Test
public void testSslOkHttpClientCreationWithCookies() throws Exception {
    OkHttpClient sslClient = ClientUtils.sslOkHttpClient(config.getDevTrustStore(), cookieList);
    assertThat(sslClient.followSslRedirects()).isFalse();
    assertThat(sslClient.cookieJar()).isNotNull();
    assertThat(sslClient.sslSocketFactory()).isNotNull();
    java.util.List<HttpCookie> cookieList = ClientUtils.getCookieManager().getCookieStore().getCookies();
    assertThat(cookieList).contains(sessionCookie);
}
Also used : OkHttpClient(okhttp3.OkHttpClient) HttpCookie(java.net.HttpCookie) Test(org.junit.Test)

Aggregations

SslClient (okhttp3.internal.tls.SslClient)10 Test (org.junit.Test)6 HostnameVerifier (javax.net.ssl.HostnameVerifier)5 SSLSession (javax.net.ssl.SSLSession)5 OkHttpClient (okhttp3.OkHttpClient)4 MockResponse (okhttp3.mockwebserver.MockResponse)4 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)3 IOException (java.io.IOException)2 HttpCookie (java.net.HttpCookie)2 Callback (okhttp3.Callback)2 HttpUrl (okhttp3.HttpUrl)2 HeldCertificate (okhttp3.internal.tls.HeldCertificate)2 MockWebServer (okhttp3.mockwebserver.MockWebServer)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 SslClient (okhttp3.mockwebserver.internal.tls.SslClient)2 Context (android.content.Context)1 Bootstrap (io.netty.bootstrap.Bootstrap)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1