use of libcore.javax.net.ssl.TestSSLContext in project robovm by robovm.
the class URLConnectionTest method testConnectViaHttpsReusingConnections.
public void testConnectViaHttpsReusingConnections() throws IOException, InterruptedException {
TestSSLContext testSSLContext = TestSSLContext.create();
SSLSocketFactory clientSocketFactory = testSSLContext.clientContext.getSocketFactory();
server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
server.enqueue(new MockResponse().setBody("this response comes via HTTPS"));
server.enqueue(new MockResponse().setBody("another response via HTTPS"));
server.play();
HttpsURLConnection connection = (HttpsURLConnection) server.getUrl("/").openConnection();
connection.setSSLSocketFactory(clientSocketFactory);
assertContent("this response comes via HTTPS", connection);
connection = (HttpsURLConnection) server.getUrl("/").openConnection();
connection.setSSLSocketFactory(clientSocketFactory);
assertContent("another response via HTTPS", connection);
assertEquals(0, server.takeRequest().getSequenceNumber());
assertEquals(1, server.takeRequest().getSequenceNumber());
}
use of libcore.javax.net.ssl.TestSSLContext in project robovm by robovm.
the class URLConnectionTest method testProxyWithConnectionClose.
// Don't disconnect after building a tunnel with CONNECT
// http://code.google.com/p/android/issues/detail?id=37221
public void testProxyWithConnectionClose() throws IOException {
TestSSLContext testSSLContext = TestSSLContext.create();
server.useHttps(testSSLContext.serverContext.getSocketFactory(), true);
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.UPGRADE_TO_SSL_AT_END).clearHeaders());
server.enqueue(new MockResponse().setBody("this response comes via a proxy"));
server.play();
URL url = new URL("https://android.com/foo");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(server.toProxyAddress());
connection.setRequestProperty("Connection", "close");
connection.setSSLSocketFactory(testSSLContext.clientContext.getSocketFactory());
connection.setHostnameVerifier(new RecordingHostnameVerifier());
assertContent("this response comes via a proxy", connection);
}
use of libcore.javax.net.ssl.TestSSLContext in project robovm by robovm.
the class URLConnectionTest method testRetryableRequestBodyAfterBrokenConnection.
public void testRetryableRequestBodyAfterBrokenConnection() throws Exception {
// Use SSL to make an alternate route available.
TestSSLContext testSSLContext = TestSSLContext.create();
server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
server.enqueue(new MockResponse().setBody("abc").setSocketPolicy(DISCONNECT_AFTER_READING_REQUEST));
server.enqueue(new MockResponse().setBody("abc"));
server.play();
HttpsURLConnection connection = (HttpsURLConnection) server.getUrl("").openConnection();
connection.setSSLSocketFactory(testSSLContext.clientContext.getSocketFactory());
connection.setDoOutput(true);
OutputStream out = connection.getOutputStream();
out.write(new byte[] { 1, 2, 3 });
out.close();
assertContent("abc", connection);
assertEquals(0, server.takeRequest().getSequenceNumber());
assertEquals(0, server.takeRequest().getSequenceNumber());
}
use of libcore.javax.net.ssl.TestSSLContext in project robovm by robovm.
the class URLConnectionTest method testProxyConnectIncludesProxyHeadersOnly.
/**
* Test which headers are sent unencrypted to the HTTP proxy.
*/
public void testProxyConnectIncludesProxyHeadersOnly() throws IOException, InterruptedException {
RecordingHostnameVerifier hostnameVerifier = new RecordingHostnameVerifier();
TestSSLContext testSSLContext = TestSSLContext.create();
server.useHttps(testSSLContext.serverContext.getSocketFactory(), true);
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.UPGRADE_TO_SSL_AT_END).clearHeaders());
server.enqueue(new MockResponse().setBody("encrypted response from the origin server"));
server.play();
URL url = new URL("https://android.com/foo");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(server.toProxyAddress());
connection.addRequestProperty("Private", "Secret");
connection.addRequestProperty("Proxy-Authorization", "bar");
connection.addRequestProperty("User-Agent", "baz");
connection.setSSLSocketFactory(testSSLContext.clientContext.getSocketFactory());
connection.setHostnameVerifier(hostnameVerifier);
assertContent("encrypted response from the origin server", connection);
RecordedRequest connect = server.takeRequest();
assertContainsNoneMatching(connect.getHeaders(), "Private.*");
assertContains(connect.getHeaders(), "Proxy-Authorization: bar");
assertContains(connect.getHeaders(), "User-Agent: baz");
assertContains(connect.getHeaders(), "Host: android.com");
assertContains(connect.getHeaders(), "Proxy-Connection: Keep-Alive");
RecordedRequest get = server.takeRequest();
assertContains(get.getHeaders(), "Private: Secret");
assertEquals(Arrays.asList("verify android.com"), hostnameVerifier.calls);
}
use of libcore.javax.net.ssl.TestSSLContext in project robovm by robovm.
the class URLConnectionTest method testRedirectedOnHttps.
public void testRedirectedOnHttps() throws IOException, InterruptedException {
TestSSLContext testSSLContext = TestSSLContext.create();
server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_MOVED_TEMP).addHeader("Location: /foo").setBody("This page has moved!"));
server.enqueue(new MockResponse().setBody("This is the new location!"));
server.play();
HttpsURLConnection connection = (HttpsURLConnection) server.getUrl("/").openConnection();
connection.setSSLSocketFactory(testSSLContext.clientContext.getSocketFactory());
assertEquals("This is the new location!", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
RecordedRequest first = server.takeRequest();
assertEquals("GET / HTTP/1.1", first.getRequestLine());
RecordedRequest retry = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", retry.getRequestLine());
assertEquals("Expected connection reuse", 1, retry.getSequenceNumber());
}
Aggregations