use of com.google.mockwebserver.RecordedRequest in project robovm by robovm.
the class URLConnectionTest method testConnectViaHttpProxyToHttpsUsingBadProxyAndHttpResponseCache.
/**
* 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);
MockResponse badProxyResponse = new MockResponse().setSocketPolicy(SocketPolicy.UPGRADE_TO_SSL_AT_END).clearHeaders().setBody(// Key to reproducing b/6754912
"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.play();
URL url = new URL("https://android.com/foo");
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.
}
RecordedRequest connect = server.takeRequest();
assertEquals("Connect line failure on proxy", "CONNECT android.com:443 HTTP/1.1", connect.getRequestLine());
assertContains(connect.getHeaders(), "Host: android.com");
}
use of com.google.mockwebserver.RecordedRequest in project robovm by robovm.
the class URLConnectionTest method testConnectViaDirectProxyToHttps.
private void testConnectViaDirectProxyToHttps(ProxyConfig proxyConfig) throws Exception {
TestSSLContext testSSLContext = TestSSLContext.create();
server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
server.enqueue(new MockResponse().setBody("this response comes via HTTPS"));
server.play();
URL url = server.getUrl("/foo");
HttpsURLConnection connection = (HttpsURLConnection) proxyConfig.connect(server, url);
connection.setSSLSocketFactory(testSSLContext.clientContext.getSocketFactory());
assertContent("this response comes via HTTPS", connection);
RecordedRequest request = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
}
use of com.google.mockwebserver.RecordedRequest in project robovm by robovm.
the class URLConnectionTest method testSecureStreamingPost.
/**
* Users have reported problems using HTTPS with streaming request bodies.
* http://code.google.com/p/android/issues/detail?id=12860
*/
private void testSecureStreamingPost(StreamingMode streamingMode) throws Exception {
TestSSLContext testSSLContext = TestSSLContext.create();
server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
server.enqueue(new MockResponse().setBody("Success!"));
server.play();
HttpsURLConnection connection = (HttpsURLConnection) server.getUrl("/").openConnection();
connection.setSSLSocketFactory(testSSLContext.clientContext.getSocketFactory());
connection.setDoOutput(true);
byte[] requestBody = { 'A', 'B', 'C', 'D' };
if (streamingMode == StreamingMode.FIXED_LENGTH) {
connection.setFixedLengthStreamingMode(requestBody.length);
} else if (streamingMode == StreamingMode.CHUNKED) {
connection.setChunkedStreamingMode(0);
}
OutputStream outputStream = connection.getOutputStream();
outputStream.write(requestBody);
outputStream.close();
assertEquals("Success!", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
RecordedRequest request = server.takeRequest();
assertEquals("POST / HTTP/1.1", request.getRequestLine());
if (streamingMode == StreamingMode.FIXED_LENGTH) {
assertEquals(Collections.<Integer>emptyList(), request.getChunkSizes());
} else if (streamingMode == StreamingMode.CHUNKED) {
assertEquals(Arrays.asList(4), request.getChunkSizes());
}
assertEquals(Arrays.toString(requestBody), Arrays.toString(request.getBody()));
}
use of com.google.mockwebserver.RecordedRequest in project platform_frameworks_base by android.
the class AbstractProxyTest method testExplicitNoProxyCancelsSystemProperty.
public void testExplicitNoProxyCancelsSystemProperty() throws Exception {
server.enqueue(new MockResponse().setBody("Via the origin server!"));
server.play();
System.setProperty("http.proxyHost", "proxy.foo");
System.setProperty("http.proxyPort", "8080");
HttpClient client = newHttpClient();
HttpGet request = new HttpGet(server.getUrl("/bar").toURI());
request.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, ConnRouteParams.NO_HOST);
HttpResponse response = client.execute(request);
assertEquals("Via the origin server!", contentToString(response));
RecordedRequest recordedRequest = server.takeRequest();
assertEquals("GET /bar HTTP/1.1", recordedRequest.getRequestLine());
}
use of com.google.mockwebserver.RecordedRequest in project platform_frameworks_base by android.
the class AbstractProxyTest method testConnectToHttps.
public void testConnectToHttps() throws Exception {
TestSSLContext testSSLContext = TestSSLContext.create();
server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
server.enqueue(new MockResponse().setResponseCode(200).setBody("this response comes via HTTPS"));
server.play();
HttpClient httpClient = newHttpClient();
SSLSocketFactory sslSocketFactory = newSslSocketFactory(testSSLContext);
sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier());
httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", sslSocketFactory, server.getPort()));
HttpResponse response = httpClient.execute(new HttpGet("https://localhost:" + server.getPort() + "/foo"));
assertEquals("this response comes via HTTPS", contentToString(response));
RecordedRequest request = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
}
Aggregations