Search in sources :

Example 1 with SingleInetAddressDns

use of okhttp3.internal.SingleInetAddressDns in project okhttp by square.

the class HttpOverHttp2Test method setUp.

@Before
public void setUp() throws Exception {
    server.useHttps(sslClient.socketFactory, false);
    cache = new Cache(tempDir.getRoot(), Integer.MAX_VALUE);
    client = defaultClient().newBuilder().protocols(Arrays.asList(Protocol.HTTP_2, Protocol.HTTP_1_1)).dns(new SingleInetAddressDns()).sslSocketFactory(sslClient.socketFactory, sslClient.trustManager).hostnameVerifier(hostnameVerifier).build();
}
Also used : SingleInetAddressDns(okhttp3.internal.SingleInetAddressDns) Cache(okhttp3.Cache) Before(org.junit.Before)

Example 2 with SingleInetAddressDns

use of okhttp3.internal.SingleInetAddressDns in project okhttp by square.

the class URLConnectionTest method sameConnectionRedirectAndReuse.

/**
   * Retry redirects if the socket is closed.
   * https://code.google.com/p/android/issues/detail?id=41576
   */
@Test
public void sameConnectionRedirectAndReuse() throws Exception {
    urlFactory.setClient(urlFactory.client().newBuilder().dns(new SingleInetAddressDns()).build());
    server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_MOVED_TEMP).setSocketPolicy(SHUTDOWN_INPUT_AT_END).addHeader("Location: /foo"));
    server.enqueue(new MockResponse().setBody("This is the new page!"));
    assertContent("This is the new page!", urlFactory.open(server.url("/").url()));
    assertEquals(0, server.takeRequest().getSequenceNumber());
    assertEquals(0, server.takeRequest().getSequenceNumber());
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) SingleInetAddressDns(okhttp3.internal.SingleInetAddressDns) Test(org.junit.Test)

Example 3 with SingleInetAddressDns

use of okhttp3.internal.SingleInetAddressDns in project okhttp by square.

the class CallTest method noRecoveryFromTlsHandshakeFailureWhenTlsFallbackIsDisabled.

@Test
public void noRecoveryFromTlsHandshakeFailureWhenTlsFallbackIsDisabled() throws Exception {
    client = client.newBuilder().connectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT)).hostnameVerifier(new RecordingHostnameVerifier()).dns(new SingleInetAddressDns()).sslSocketFactory(suppressTlsFallbackClientSocketFactory(), sslClient.trustManager).build();
    server.useHttps(sslClient.socketFactory, false);
    server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.FAIL_HANDSHAKE));
    Request request = new Request.Builder().url(server.url("/")).build();
    try {
        client.newCall(request).execute();
        fail();
    } catch (SSLProtocolException expected) {
    // RI response to the FAIL_HANDSHAKE
    } catch (SSLHandshakeException expected) {
    // Android's response to the FAIL_HANDSHAKE
    }
}
Also used : SSLProtocolException(javax.net.ssl.SSLProtocolException) MockResponse(okhttp3.mockwebserver.MockResponse) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) SingleInetAddressDns(okhttp3.internal.SingleInetAddressDns) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) Test(org.junit.Test)

Example 4 with SingleInetAddressDns

use of okhttp3.internal.SingleInetAddressDns in project okhttp by square.

the class CallTest method recoverFromTlsHandshakeFailure_tlsFallbackScsvEnabled.

@Test
public void recoverFromTlsHandshakeFailure_tlsFallbackScsvEnabled() throws Exception {
    final String tlsFallbackScsv = "TLS_FALLBACK_SCSV";
    List<String> supportedCiphers = Arrays.asList(sslClient.socketFactory.getSupportedCipherSuites());
    if (!supportedCiphers.contains(tlsFallbackScsv)) {
        // This only works if the client socket supports TLS_FALLBACK_SCSV.
        return;
    }
    server.useHttps(sslClient.socketFactory, false);
    server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.FAIL_HANDSHAKE));
    RecordingSSLSocketFactory clientSocketFactory = new RecordingSSLSocketFactory(sslClient.socketFactory);
    client = client.newBuilder().sslSocketFactory(clientSocketFactory, sslClient.trustManager).connectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS)).hostnameVerifier(new RecordingHostnameVerifier()).dns(new SingleInetAddressDns()).build();
    Request request = new Request.Builder().url(server.url("/")).build();
    try {
        client.newCall(request).execute();
        fail();
    } catch (SSLHandshakeException expected) {
    }
    List<SSLSocket> clientSockets = clientSocketFactory.getSocketsCreated();
    SSLSocket firstSocket = clientSockets.get(0);
    assertFalse(Arrays.asList(firstSocket.getEnabledCipherSuites()).contains(tlsFallbackScsv));
    SSLSocket secondSocket = clientSockets.get(1);
    assertTrue(Arrays.asList(secondSocket.getEnabledCipherSuites()).contains(tlsFallbackScsv));
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) SSLSocket(javax.net.ssl.SSLSocket) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) SingleInetAddressDns(okhttp3.internal.SingleInetAddressDns) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) Test(org.junit.Test)

Example 5 with SingleInetAddressDns

use of okhttp3.internal.SingleInetAddressDns in project okhttp by square.

the class CallTest method recoverFromTlsHandshakeFailure.

@Test
public void recoverFromTlsHandshakeFailure() throws Exception {
    server.useHttps(sslClient.socketFactory, false);
    server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.FAIL_HANDSHAKE));
    server.enqueue(new MockResponse().setBody("abc"));
    client = client.newBuilder().hostnameVerifier(new RecordingHostnameVerifier()).dns(new SingleInetAddressDns()).connectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS)).sslSocketFactory(suppressTlsFallbackClientSocketFactory(), sslClient.trustManager).build();
    executeSynchronously("/").assertBody("abc");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) SingleInetAddressDns(okhttp3.internal.SingleInetAddressDns) Test(org.junit.Test)

Aggregations

SingleInetAddressDns (okhttp3.internal.SingleInetAddressDns)6 MockResponse (okhttp3.mockwebserver.MockResponse)5 Test (org.junit.Test)5 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2 URL (java.net.URL)1 SSLProtocolException (javax.net.ssl.SSLProtocolException)1 SSLSocket (javax.net.ssl.SSLSocket)1 Cache (okhttp3.Cache)1 Before (org.junit.Before)1