Search in sources :

Example 31 with TestSSLContext

use of libcore.javax.net.ssl.TestSSLContext in project android_frameworks_base by DirtyUnicorns.

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());
}
Also used : RecordedRequest(com.google.mockwebserver.RecordedRequest) MockResponse(com.google.mockwebserver.MockResponse) Scheme(org.apache.http.conn.scheme.Scheme) AllowAllHostnameVerifier(org.apache.http.conn.ssl.AllowAllHostnameVerifier) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) TestSSLContext(libcore.javax.net.ssl.TestSSLContext) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory)

Example 32 with TestSSLContext

use of libcore.javax.net.ssl.TestSSLContext in project android_frameworks_base by crdroidandroid.

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());
}
Also used : RecordedRequest(com.google.mockwebserver.RecordedRequest) MockResponse(com.google.mockwebserver.MockResponse) Scheme(org.apache.http.conn.scheme.Scheme) AllowAllHostnameVerifier(org.apache.http.conn.ssl.AllowAllHostnameVerifier) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) TestSSLContext(libcore.javax.net.ssl.TestSSLContext) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory)

Aggregations

MockResponse (com.google.mockwebserver.MockResponse)32 TestSSLContext (libcore.javax.net.ssl.TestSSLContext)32 RecordedRequest (com.google.mockwebserver.RecordedRequest)22 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)19 HttpResponse (org.apache.http.HttpResponse)12 HttpClient (org.apache.http.client.HttpClient)12 HttpGet (org.apache.http.client.methods.HttpGet)12 Scheme (org.apache.http.conn.scheme.Scheme)12 AllowAllHostnameVerifier (org.apache.http.conn.ssl.AllowAllHostnameVerifier)12 SSLSocketFactory (org.apache.http.conn.ssl.SSLSocketFactory)12 URL (java.net.URL)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OutputStream (java.io.OutputStream)3 GZIPOutputStream (java.util.zip.GZIPOutputStream)3 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)2 IOException (java.io.IOException)1 CertificateException (java.security.cert.CertificateException)1 HostnameVerifier (javax.net.ssl.HostnameVerifier)1 SSLContext (javax.net.ssl.SSLContext)1