From 381dc32dba0a02497a29f267f11d074d4fe39bcd Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Wed, 5 Aug 2015 21:37:49 +0100 Subject: Revert "Revert "Changes associated with an OkHttp bad proxy response fix"" This reverts commit 11c3934f61c6c873fd9caae16947285bc0068965. commit 11c3934f61c6c873fd9caae16947285bc0068965 was incorrectly merged from lollipop-cts-dev into lollipop-mr1-cts-dev. Change-Id: I66fa65f08397fb34d6af1cb73d2c0fa7f57ef1b6 --- .../java/libcore/java/net/URLConnectionTest.java | 26 +++++++--------------- 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'luni/src/test/java') diff --git a/luni/src/test/java/libcore/java/net/URLConnectionTest.java b/luni/src/test/java/libcore/java/net/URLConnectionTest.java index f664b08..c09939f 100644 --- a/luni/src/test/java/libcore/java/net/URLConnectionTest.java +++ b/luni/src/test/java/libcore/java/net/URLConnectionTest.java @@ -642,42 +642,32 @@ public final class URLConnectionTest extends AbstractResourceLeakageDetectorTest * Tolerate bad https proxy response when using HttpResponseCache. http://b/6754912 */ public void testConnectViaHttpProxyToHttpsUsingBadProxyAndHttpResponseCache() throws Exception { - ProxyConfig proxyConfig = ProxyConfig.PROXY_SYSTEM_PROPERTY; - TestSSLContext testSSLContext = TestSSLContext.create(); initResponseCache(); server.useHttps(testSSLContext.serverContext.getSocketFactory(), true); + + // The inclusion of a body in the response to the CONNECT is key to reproducing b/6754912. MockResponse badProxyResponse = new MockResponse() .setSocketPolicy(SocketPolicy.UPGRADE_TO_SSL_AT_END) .clearHeaders() - .setBody("bogus proxy connect response content"); // Key to reproducing b/6754912 + .setBody("bogus proxy connect response content"); - // We enqueue the bad response twice because the connection will - // be retried with TLS_MODE_COMPATIBLE after the first connection - // fails. - server.enqueue(badProxyResponse); server.enqueue(badProxyResponse); + server.enqueue(new MockResponse().setBody("response")); server.play(); URL url = new URL("https://android.com/foo"); + ProxyConfig proxyConfig = ProxyConfig.PROXY_SYSTEM_PROPERTY; HttpsURLConnection connection = (HttpsURLConnection) proxyConfig.connect(server, url); connection.setSSLSocketFactory(testSSLContext.clientContext.getSocketFactory()); - - try { - connection.connect(); - fail(); - } catch (SSLHandshakeException expected) { - // Thrown when the connect causes SSLSocket.startHandshake() to throw - // when it sees the "bogus proxy connect response content" - // instead of a ServerHello handshake message. - } + connection.setHostnameVerifier(new RecordingHostnameVerifier()); + assertContent("response", connection); RecordedRequest connect = server.takeRequest(); - assertEquals("Connect line failure on proxy", - "CONNECT android.com:443 HTTP/1.1", connect.getRequestLine()); + assertEquals("CONNECT android.com:443 HTTP/1.1", connect.getRequestLine()); assertContains(connect.getHeaders(), "Host: android.com"); } -- cgit v1.1