| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/http/http_proxy_client_socket_pool.h" | 5 #include "net/http/http_proxy_client_socket_pool.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 return scoped_refptr<HttpProxySocketParams>( | 124 return scoped_refptr<HttpProxySocketParams>( |
| 125 new HttpProxySocketParams( | 125 new HttpProxySocketParams( |
| 126 GetTcpParams(), | 126 GetTcpParams(), |
| 127 GetSslParams(), | 127 GetSslParams(), |
| 128 GURL(tunnel ? "https://www.google.com/" : "http://www.google.com"), | 128 GURL(tunnel ? "https://www.google.com/" : "http://www.google.com"), |
| 129 "", | 129 "", |
| 130 HostPortPair("www.google.com", tunnel ? 443 : 80), | 130 HostPortPair("www.google.com", tunnel ? 443 : 80), |
| 131 session_->http_auth_cache(), | 131 session_->http_auth_cache(), |
| 132 session_->http_auth_handler_factory(), | 132 session_->http_auth_handler_factory(), |
| 133 session_->spdy_session_pool(), | 133 session_->spdy_session_pool(), |
| 134 tunnel)); | 134 tunnel, |
| 135 base::Bind(&HttpProxyClientSocketPoolTest::OnNeedsProxyAuthCallback, |
| 136 base::Unretained(this)))); |
| 135 } | 137 } |
| 136 | 138 |
| 137 scoped_refptr<HttpProxySocketParams> GetTunnelParams() { | 139 scoped_refptr<HttpProxySocketParams> GetTunnelParams() { |
| 138 return GetParams(true); | 140 return GetParams(true); |
| 139 } | 141 } |
| 140 | 142 |
| 141 scoped_refptr<HttpProxySocketParams> GetNoTunnelParams() { | 143 scoped_refptr<HttpProxySocketParams> GetNoTunnelParams() { |
| 142 return GetParams(false); | 144 return GetParams(false); |
| 143 } | 145 } |
| 144 | 146 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 params.host_resolver = &host_resolver_; | 186 params.host_resolver = &host_resolver_; |
| 185 params.cert_verifier = &cert_verifier_; | 187 params.cert_verifier = &cert_verifier_; |
| 186 params.proxy_service = proxy_service_.get(); | 188 params.proxy_service = proxy_service_.get(); |
| 187 params.client_socket_factory = &socket_factory_; | 189 params.client_socket_factory = &socket_factory_; |
| 188 params.ssl_config_service = ssl_config_service_; | 190 params.ssl_config_service = ssl_config_service_; |
| 189 params.http_auth_handler_factory = http_auth_handler_factory_.get(); | 191 params.http_auth_handler_factory = http_auth_handler_factory_.get(); |
| 190 params.http_server_properties = &http_server_properties_; | 192 params.http_server_properties = &http_server_properties_; |
| 191 return new HttpNetworkSession(params); | 193 return new HttpNetworkSession(params); |
| 192 } | 194 } |
| 193 | 195 |
| 196 void OnNeedsProxyAuthCallback(const HttpResponseInfo& response_info, |
| 197 HttpAuthController* auth_controller, |
| 198 CompletionCallback cb) { |
| 199 // Don't add any auth, just run the callback |
| 200 cb.Run(OK); |
| 201 } |
| 202 |
| 203 |
| 194 private: | 204 private: |
| 195 SSLConfig ssl_config_; | 205 SSLConfig ssl_config_; |
| 196 | 206 |
| 197 scoped_refptr<TransportSocketParams> ignored_transport_socket_params_; | 207 scoped_refptr<TransportSocketParams> ignored_transport_socket_params_; |
| 198 scoped_refptr<SSLSocketParams> ignored_ssl_socket_params_; | 208 scoped_refptr<SSLSocketParams> ignored_ssl_socket_params_; |
| 199 ClientSocketPoolHistograms tcp_histograms_; | 209 ClientSocketPoolHistograms tcp_histograms_; |
| 200 DeterministicMockClientSocketFactory socket_factory_; | 210 DeterministicMockClientSocketFactory socket_factory_; |
| 201 MockTransportClientSocketPool transport_socket_pool_; | 211 MockTransportClientSocketPool transport_socket_pool_; |
| 202 ClientSocketPoolHistograms ssl_histograms_; | 212 ClientSocketPoolHistograms ssl_histograms_; |
| 203 MockHostResolver host_resolver_; | 213 MockHostResolver host_resolver_; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 MockRead(true, 2, "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | 261 MockRead(true, 2, "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 252 MockRead(true, 3, "Content-Length: 10\r\n\r\n"), | 262 MockRead(true, 3, "Content-Length: 10\r\n\r\n"), |
| 253 MockRead(true, 4, "0123456789"), | 263 MockRead(true, 4, "0123456789"), |
| 254 }; | 264 }; |
| 255 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyConnect(NULL, 0, 1)); | 265 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyConnect(NULL, 0, 1)); |
| 256 scoped_ptr<spdy::SpdyFrame> rst(ConstructSpdyRstStream(1, spdy::CANCEL)); | 266 scoped_ptr<spdy::SpdyFrame> rst(ConstructSpdyRstStream(1, spdy::CANCEL)); |
| 257 MockWrite spdy_writes[] = { | 267 MockWrite spdy_writes[] = { |
| 258 CreateMockWrite(*req, 0, true), | 268 CreateMockWrite(*req, 0, true), |
| 259 CreateMockWrite(*rst, 2, true), | 269 CreateMockWrite(*rst, 2, true), |
| 260 }; | 270 }; |
| 271 static const char* const kAuthChallenge[] = { |
| 272 "status", "407 Proxy Authentication Required", |
| 273 "version", "HTTP/1.1", |
| 274 "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 275 }; |
| 261 scoped_ptr<spdy::SpdyFrame> resp( | 276 scoped_ptr<spdy::SpdyFrame> resp( |
| 262 ConstructSpdySynReplyError( | 277 ConstructSpdyControlFrame(NULL, |
| 263 "407 Proxy Authentication Required", NULL, 0, 1)); | 278 0, |
| 279 false, |
| 280 1, |
| 281 LOWEST, |
| 282 spdy::SYN_REPLY, |
| 283 spdy::CONTROL_FLAG_NONE, |
| 284 kAuthChallenge, |
| 285 arraysize(kAuthChallenge))); |
| 264 MockRead spdy_reads[] = { | 286 MockRead spdy_reads[] = { |
| 265 CreateMockWrite(*resp, 1, true), | 287 CreateMockWrite(*resp, 1, true), |
| 266 MockRead(true, 0, 3) | 288 MockRead(true, 0, 3) |
| 267 }; | 289 }; |
| 268 | 290 |
| 269 Initialize(false, reads, arraysize(reads), writes, arraysize(writes), | 291 Initialize(false, reads, arraysize(reads), writes, arraysize(writes), |
| 270 spdy_reads, arraysize(spdy_reads), spdy_writes, | 292 spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 271 arraysize(spdy_writes)); | 293 arraysize(spdy_writes)); |
| 272 | 294 |
| 273 data_->StopAfter(4); | 295 data_->StopAfter(4); |
| 274 int rv = handle_.Init("a", GetTunnelParams(), LOW, callback_.callback(), | 296 int rv = handle_.Init("a", GetTunnelParams(), LOW, callback_.callback(), |
| 275 &pool_, BoundNetLog()); | 297 &pool_, BoundNetLog()); |
| 276 EXPECT_EQ(ERR_IO_PENDING, rv); | 298 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 277 EXPECT_FALSE(handle_.is_initialized()); | 299 EXPECT_FALSE(handle_.is_initialized()); |
| 278 EXPECT_FALSE(handle_.socket()); | 300 EXPECT_FALSE(handle_.socket()); |
| 279 | 301 |
| 280 data_->RunFor(4); | 302 data_->RunFor(GetParam() == SPDY ? 2 : 4); |
| 281 rv = callback_.WaitForResult(); | 303 rv = callback_.WaitForResult(); |
| 304 EXPECT_EQ(ERR_PROXY_AUTH_REQUESTED, rv); |
| 305 EXPECT_TRUE(handle_.is_initialized()); |
| 306 ASSERT_TRUE(handle_.socket()); |
| 282 if (GetParam() != SPDY) { | 307 if (GetParam() != SPDY) { |
| 283 EXPECT_EQ(ERR_PROXY_AUTH_REQUESTED, rv); | |
| 284 EXPECT_TRUE(handle_.is_initialized()); | |
| 285 ASSERT_TRUE(handle_.socket()); | |
| 286 HttpProxyClientSocket* tunnel_socket = | 308 HttpProxyClientSocket* tunnel_socket = |
| 287 static_cast<HttpProxyClientSocket*>(handle_.socket()); | 309 static_cast<HttpProxyClientSocket*>(handle_.socket()); |
| 288 EXPECT_FALSE(tunnel_socket->IsConnected()); | 310 EXPECT_FALSE(tunnel_socket->IsConnected()); |
| 289 EXPECT_FALSE(tunnel_socket->using_spdy()); | 311 EXPECT_FALSE(tunnel_socket->using_spdy()); |
| 290 } else { | |
| 291 // Proxy auth is not really implemented for SPDY yet | |
| 292 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); | |
| 293 EXPECT_FALSE(handle_.is_initialized()); | |
| 294 EXPECT_FALSE(handle_.socket()); | |
| 295 } | 312 } |
| 296 } | 313 } |
| 297 | 314 |
| 298 TEST_P(HttpProxyClientSocketPoolTest, HaveAuth) { | 315 TEST_P(HttpProxyClientSocketPoolTest, HaveAuth) { |
| 299 // It's pretty much impossible to make the SPDY case behave synchronously | 316 // It's pretty much impossible to make the SPDY case behave synchronously |
| 300 // so we skip this test for SPDY | 317 // so we skip this test for SPDY |
| 301 if (GetParam() == SPDY) | 318 if (GetParam() == SPDY) |
| 302 return; | 319 return; |
| 303 MockWrite writes[] = { | 320 MockWrite writes[] = { |
| 304 MockWrite(false, 0, | 321 MockWrite(false, 0, |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 // HTTPS or SPDY Proxy CONNECT responses are trustworthy | 538 // HTTPS or SPDY Proxy CONNECT responses are trustworthy |
| 522 EXPECT_EQ(ERR_HTTPS_PROXY_TUNNEL_RESPONSE, rv); | 539 EXPECT_EQ(ERR_HTTPS_PROXY_TUNNEL_RESPONSE, rv); |
| 523 EXPECT_TRUE(handle_.is_initialized()); | 540 EXPECT_TRUE(handle_.is_initialized()); |
| 524 EXPECT_TRUE(handle_.socket()); | 541 EXPECT_TRUE(handle_.socket()); |
| 525 } | 542 } |
| 526 } | 543 } |
| 527 | 544 |
| 528 // It would be nice to also test the timeouts in HttpProxyClientSocketPool. | 545 // It would be nice to also test the timeouts in HttpProxyClientSocketPool. |
| 529 | 546 |
| 530 } // namespace net | 547 } // namespace net |
| OLD | NEW |