use of okhttp3.RecordingHostnameVerifier in project okhttp by square.
the class URLConnectionTest method proxyConnectIncludesProxyHeadersOnly.
/** Test which headers are sent unencrypted to the HTTP proxy. */
@Test
public void proxyConnectIncludesProxyHeadersOnly() throws IOException, InterruptedException {
RecordingHostnameVerifier hostnameVerifier = new RecordingHostnameVerifier();
server.useHttps(sslClient.socketFactory, true);
server.enqueue(new MockResponse().setSocketPolicy(UPGRADE_TO_SSL_AT_END).clearHeaders());
server.enqueue(new MockResponse().setBody("encrypted response from the origin server"));
urlFactory.setClient(urlFactory.client().newBuilder().proxy(server.toProxyAddress()).sslSocketFactory(sslClient.socketFactory, sslClient.trustManager).hostnameVerifier(hostnameVerifier).build());
URL url = new URL("https://android.com/foo");
connection = urlFactory.open(url);
connection.addRequestProperty("Private", "Secret");
connection.addRequestProperty("Proxy-Authorization", "bar");
connection.addRequestProperty("User-Agent", "baz");
assertContent("encrypted response from the origin server", connection);
RecordedRequest connect = server.takeRequest();
assertNull(connect.getHeader("Private"));
assertNull(connect.getHeader("Proxy-Authorization"));
assertEquals(Version.userAgent(), connect.getHeader("User-Agent"));
assertEquals("android.com:443", connect.getHeader("Host"));
assertEquals("Keep-Alive", connect.getHeader("Proxy-Connection"));
RecordedRequest get = server.takeRequest();
assertEquals("Secret", get.getHeader("Private"));
assertEquals(Arrays.asList("verify android.com"), hostnameVerifier.calls);
}
use of okhttp3.RecordingHostnameVerifier in project okhttp by square.
the class URLConnectionTest method proxyWithConnectionReuse.
@Test
public void proxyWithConnectionReuse() throws IOException {
SSLSocketFactory socketFactory = sslClient.socketFactory;
RecordingHostnameVerifier hostnameVerifier = new RecordingHostnameVerifier();
server.useHttps(socketFactory, true);
server.enqueue(new MockResponse().setSocketPolicy(UPGRADE_TO_SSL_AT_END).clearHeaders());
server.enqueue(new MockResponse().setBody("response 1"));
server.enqueue(new MockResponse().setBody("response 2"));
urlFactory.setClient(urlFactory.client().newBuilder().proxy(server.toProxyAddress()).sslSocketFactory(socketFactory, sslClient.trustManager).hostnameVerifier(hostnameVerifier).build());
URL url = new URL("https://android.com/foo");
assertContent("response 1", urlFactory.open(url));
assertContent("response 2", urlFactory.open(url));
}
use of okhttp3.RecordingHostnameVerifier in project okhttp by square.
the class URLConnectionTest method connectViaHttps.
@Test
public void connectViaHttps() throws Exception {
server.useHttps(sslClient.socketFactory, false);
server.enqueue(new MockResponse().setBody("this response comes via HTTPS"));
urlFactory.setClient(urlFactory.client().newBuilder().sslSocketFactory(sslClient.socketFactory, sslClient.trustManager).hostnameVerifier(new RecordingHostnameVerifier()).build());
connection = urlFactory.open(server.url("/foo").url());
assertContent("this response comes via HTTPS", connection);
RecordedRequest request = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
}
use of okhttp3.RecordingHostnameVerifier in project okhttp by square.
the class URLConnectionTest method testConnectViaDirectProxyToHttps.
private void testConnectViaDirectProxyToHttps(ProxyConfig proxyConfig) throws Exception {
server.useHttps(sslClient.socketFactory, false);
server.enqueue(new MockResponse().setBody("this response comes via HTTPS"));
URL url = server.url("/foo").url();
urlFactory.setClient(urlFactory.client().newBuilder().sslSocketFactory(sslClient.socketFactory, sslClient.trustManager).hostnameVerifier(new RecordingHostnameVerifier()).build());
connection = proxyConfig.connect(server, urlFactory, url);
assertContent("this response comes via HTTPS", connection);
RecordedRequest request = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
}
use of okhttp3.RecordingHostnameVerifier in project okhttp by square.
the class URLConnectionTest method testConnectViaHttpProxyToHttps.
/**
* We were verifying the wrong hostname when connecting to an HTTPS site through a proxy.
* http://b/3097277
*/
private void testConnectViaHttpProxyToHttps(ProxyConfig proxyConfig) throws Exception {
RecordingHostnameVerifier hostnameVerifier = new RecordingHostnameVerifier();
server.useHttps(sslClient.socketFactory, true);
server.enqueue(new MockResponse().setSocketPolicy(UPGRADE_TO_SSL_AT_END).clearHeaders());
server.enqueue(new MockResponse().setBody("this response comes via a secure proxy"));
URL url = new URL("https://android.com/foo");
urlFactory.setClient(urlFactory.client().newBuilder().sslSocketFactory(sslClient.socketFactory, sslClient.trustManager).hostnameVerifier(hostnameVerifier).build());
connection = proxyConfig.connect(server, urlFactory, url);
assertContent("this response comes via a secure proxy", connection);
RecordedRequest connect = server.takeRequest();
assertEquals("Connect line failure on proxy", "CONNECT android.com:443 HTTP/1.1", connect.getRequestLine());
assertEquals("android.com:443", connect.getHeader("Host"));
RecordedRequest get = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", get.getRequestLine());
assertEquals("android.com", get.getHeader("Host"));
assertEquals(Arrays.asList("verify android.com"), hostnameVerifier.calls);
}
Aggregations