Search in sources :

Example 36 with RecordingHostnameVerifier

use of okhttp3.RecordingHostnameVerifier in project okhttp by square.

the class URLConnectionTest method sslFallbackNotUsedWhenRecycledConnectionFails.

/**
   * When a pooled connection fails, don't blame the route. Otherwise pooled connection failures can
   * cause unnecessary SSL fallbacks.
   *
   * https://github.com/square/okhttp/issues/515
   */
@Test
public void sslFallbackNotUsedWhenRecycledConnectionFails() throws Exception {
    server.useHttps(sslClient.socketFactory, false);
    server.enqueue(new MockResponse().setBody("abc").setSocketPolicy(DISCONNECT_AT_END));
    server.enqueue(new MockResponse().setBody("def"));
    urlFactory.setClient(urlFactory.client().newBuilder().hostnameVerifier(new RecordingHostnameVerifier()).sslSocketFactory(suppressTlsFallbackClientSocketFactory(), sslClient.trustManager).build());
    assertContent("abc", urlFactory.open(server.url("/").url()));
    // Give the server time to disconnect.
    Thread.sleep(500);
    assertContent("def", urlFactory.open(server.url("/").url()));
    Set<TlsVersion> tlsVersions = // v1.2 on OpenJDK 8.
    EnumSet.of(TlsVersion.TLS_1_0, TlsVersion.TLS_1_2);
    RecordedRequest request1 = server.takeRequest();
    assertTrue(tlsVersions.contains(request1.getTlsVersion()));
    RecordedRequest request2 = server.takeRequest();
    assertTrue(tlsVersions.contains(request2.getTlsVersion()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 37 with RecordingHostnameVerifier

use of okhttp3.RecordingHostnameVerifier in project okhttp by square.

the class WebSocketHttpTest method httpsScheme.

@Test
public void httpsScheme() throws IOException {
    webServer.useHttps(sslClient.socketFactory, false);
    client = client.newBuilder().sslSocketFactory(sslClient.socketFactory, sslClient.trustManager).hostnameVerifier(new RecordingHostnameVerifier()).build();
    websocketScheme("https");
}
Also used : RecordingHostnameVerifier(okhttp3.RecordingHostnameVerifier) Test(org.junit.Test)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)35 Test (org.junit.Test)31 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)20 URL (java.net.URL)8 RecordingHostnameVerifier (okhttp3.RecordingHostnameVerifier)6 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)5 Call (okhttp3.Call)4 CertificatePinner (okhttp3.CertificatePinner)4 OkHttpClient (okhttp3.OkHttpClient)4 Request (okhttp3.Request)4 SingleInetAddressDns (okhttp3.internal.SingleInetAddressDns)4 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)3 RecordingOkAuthenticator (okhttp3.internal.RecordingOkAuthenticator)3 HttpURLConnection (java.net.HttpURLConnection)2 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)2 SSLContext (javax.net.ssl.SSLContext)2 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)2 SSLProtocolException (javax.net.ssl.SSLProtocolException)2 Response (okhttp3.Response)2 OkHttpURLConnection (okhttp3.internal.huc.OkHttpURLConnection)2