| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 HttpProxyClientSocketPoolTestParams(HTTP, kProtoSPDY3), | 241 HttpProxyClientSocketPoolTestParams(HTTP, kProtoSPDY3), |
| 242 HttpProxyClientSocketPoolTestParams(HTTPS, kProtoSPDY3), | 242 HttpProxyClientSocketPoolTestParams(HTTPS, kProtoSPDY3), |
| 243 HttpProxyClientSocketPoolTestParams(SPDY, kProtoSPDY3), | 243 HttpProxyClientSocketPoolTestParams(SPDY, kProtoSPDY3), |
| 244 HttpProxyClientSocketPoolTestParams(HTTP, kProtoSPDY31), | 244 HttpProxyClientSocketPoolTestParams(HTTP, kProtoSPDY31), |
| 245 HttpProxyClientSocketPoolTestParams(HTTPS, kProtoSPDY31), | 245 HttpProxyClientSocketPoolTestParams(HTTPS, kProtoSPDY31), |
| 246 HttpProxyClientSocketPoolTestParams(SPDY, kProtoSPDY31), | 246 HttpProxyClientSocketPoolTestParams(SPDY, kProtoSPDY31), |
| 247 HttpProxyClientSocketPoolTestParams(HTTP, kProtoSPDY4a2), | 247 HttpProxyClientSocketPoolTestParams(HTTP, kProtoSPDY4a2), |
| 248 HttpProxyClientSocketPoolTestParams(HTTPS, kProtoSPDY4a2), | 248 HttpProxyClientSocketPoolTestParams(HTTPS, kProtoSPDY4a2), |
| 249 HttpProxyClientSocketPoolTestParams(SPDY, kProtoSPDY4a2))); | 249 HttpProxyClientSocketPoolTestParams(SPDY, kProtoSPDY4a2))); |
| 250 | 250 |
| 251 // TODO(akalin): Don't early-exit in the tests below for protocols > | |
| 252 // kProtoSPDY3. | |
| 253 | |
| 254 TEST_P(HttpProxyClientSocketPoolTest, NoTunnel) { | 251 TEST_P(HttpProxyClientSocketPoolTest, NoTunnel) { |
| 255 Initialize(NULL, 0, NULL, 0, NULL, 0, NULL, 0); | 252 Initialize(NULL, 0, NULL, 0, NULL, 0, NULL, 0); |
| 256 | 253 |
| 257 int rv = handle_.Init("a", GetNoTunnelParams(), LOW, CompletionCallback(), | 254 int rv = handle_.Init("a", GetNoTunnelParams(), LOW, CompletionCallback(), |
| 258 &pool_, BoundNetLog()); | 255 &pool_, BoundNetLog()); |
| 259 EXPECT_EQ(OK, rv); | 256 EXPECT_EQ(OK, rv); |
| 260 EXPECT_TRUE(handle_.is_initialized()); | 257 EXPECT_TRUE(handle_.is_initialized()); |
| 261 ASSERT_TRUE(handle_.socket()); | 258 ASSERT_TRUE(handle_.socket()); |
| 262 HttpProxyClientSocket* tunnel_socket = | 259 HttpProxyClientSocket* tunnel_socket = |
| 263 static_cast<HttpProxyClientSocket*>(handle_.socket()); | 260 static_cast<HttpProxyClientSocket*>(handle_.socket()); |
| 264 EXPECT_TRUE(tunnel_socket->IsConnected()); | 261 EXPECT_TRUE(tunnel_socket->IsConnected()); |
| 265 } | 262 } |
| 266 | 263 |
| 267 TEST_P(HttpProxyClientSocketPoolTest, NeedAuth) { | 264 TEST_P(HttpProxyClientSocketPoolTest, NeedAuth) { |
| 268 if (GetParam().protocol > kProtoSPDY3) | |
| 269 return; | |
| 270 | |
| 271 MockWrite writes[] = { | 265 MockWrite writes[] = { |
| 272 MockWrite(ASYNC, 0, "CONNECT www.google.com:443 HTTP/1.1\r\n" | 266 MockWrite(ASYNC, 0, "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 273 "Host: www.google.com\r\n" | 267 "Host: www.google.com\r\n" |
| 274 "Proxy-Connection: keep-alive\r\n\r\n"), | 268 "Proxy-Connection: keep-alive\r\n\r\n"), |
| 275 }; | 269 }; |
| 276 MockRead reads[] = { | 270 MockRead reads[] = { |
| 277 // No credentials. | 271 // No credentials. |
| 278 MockRead(ASYNC, 1, "HTTP/1.1 407 Proxy Authentication Required\r\n"), | 272 MockRead(ASYNC, 1, "HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 279 MockRead(ASYNC, 2, "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | 273 MockRead(ASYNC, 2, "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 280 MockRead(ASYNC, 3, "Content-Length: 10\r\n\r\n"), | 274 MockRead(ASYNC, 3, "Content-Length: 10\r\n\r\n"), |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 &pool_, BoundNetLog()); | 355 &pool_, BoundNetLog()); |
| 362 EXPECT_EQ(OK, rv); | 356 EXPECT_EQ(OK, rv); |
| 363 EXPECT_TRUE(handle_.is_initialized()); | 357 EXPECT_TRUE(handle_.is_initialized()); |
| 364 ASSERT_TRUE(handle_.socket()); | 358 ASSERT_TRUE(handle_.socket()); |
| 365 HttpProxyClientSocket* tunnel_socket = | 359 HttpProxyClientSocket* tunnel_socket = |
| 366 static_cast<HttpProxyClientSocket*>(handle_.socket()); | 360 static_cast<HttpProxyClientSocket*>(handle_.socket()); |
| 367 EXPECT_TRUE(tunnel_socket->IsConnected()); | 361 EXPECT_TRUE(tunnel_socket->IsConnected()); |
| 368 } | 362 } |
| 369 | 363 |
| 370 TEST_P(HttpProxyClientSocketPoolTest, AsyncHaveAuth) { | 364 TEST_P(HttpProxyClientSocketPoolTest, AsyncHaveAuth) { |
| 371 if (GetParam().protocol > kProtoSPDY3) | |
| 372 return; | |
| 373 | |
| 374 MockWrite writes[] = { | 365 MockWrite writes[] = { |
| 375 MockWrite(ASYNC, 0, "CONNECT www.google.com:443 HTTP/1.1\r\n" | 366 MockWrite(ASYNC, 0, "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 376 "Host: www.google.com\r\n" | 367 "Host: www.google.com\r\n" |
| 377 "Proxy-Connection: keep-alive\r\n" | 368 "Proxy-Connection: keep-alive\r\n" |
| 378 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | 369 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 379 }; | 370 }; |
| 380 MockRead reads[] = { | 371 MockRead reads[] = { |
| 381 MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), | 372 MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 382 }; | 373 }; |
| 383 | 374 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 EXPECT_FALSE(handle_.is_initialized()); | 466 EXPECT_FALSE(handle_.is_initialized()); |
| 476 EXPECT_FALSE(handle_.socket()); | 467 EXPECT_FALSE(handle_.socket()); |
| 477 | 468 |
| 478 EXPECT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, callback_.WaitForResult()); | 469 EXPECT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, callback_.WaitForResult()); |
| 479 | 470 |
| 480 EXPECT_FALSE(handle_.is_initialized()); | 471 EXPECT_FALSE(handle_.is_initialized()); |
| 481 EXPECT_FALSE(handle_.socket()); | 472 EXPECT_FALSE(handle_.socket()); |
| 482 } | 473 } |
| 483 | 474 |
| 484 TEST_P(HttpProxyClientSocketPoolTest, TunnelUnexpectedClose) { | 475 TEST_P(HttpProxyClientSocketPoolTest, TunnelUnexpectedClose) { |
| 485 if (GetParam().protocol > kProtoSPDY3) | |
| 486 return; | |
| 487 | |
| 488 MockWrite writes[] = { | 476 MockWrite writes[] = { |
| 489 MockWrite(ASYNC, 0, | 477 MockWrite(ASYNC, 0, |
| 490 "CONNECT www.google.com:443 HTTP/1.1\r\n" | 478 "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 491 "Host: www.google.com\r\n" | 479 "Host: www.google.com\r\n" |
| 492 "Proxy-Connection: keep-alive\r\n" | 480 "Proxy-Connection: keep-alive\r\n" |
| 493 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | 481 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 494 }; | 482 }; |
| 495 MockRead reads[] = { | 483 MockRead reads[] = { |
| 496 MockRead(ASYNC, 1, "HTTP/1.1 200 Conn"), | 484 MockRead(ASYNC, 1, "HTTP/1.1 200 Conn"), |
| 497 MockRead(ASYNC, ERR_CONNECTION_CLOSED, 2), | 485 MockRead(ASYNC, ERR_CONNECTION_CLOSED, 2), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 522 // returns ERR_CONNECTION_CLOSED in this case. | 510 // returns ERR_CONNECTION_CLOSED in this case. |
| 523 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback_.WaitForResult()); | 511 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback_.WaitForResult()); |
| 524 } else { | 512 } else { |
| 525 EXPECT_EQ(ERR_RESPONSE_HEADERS_TRUNCATED, callback_.WaitForResult()); | 513 EXPECT_EQ(ERR_RESPONSE_HEADERS_TRUNCATED, callback_.WaitForResult()); |
| 526 } | 514 } |
| 527 EXPECT_FALSE(handle_.is_initialized()); | 515 EXPECT_FALSE(handle_.is_initialized()); |
| 528 EXPECT_FALSE(handle_.socket()); | 516 EXPECT_FALSE(handle_.socket()); |
| 529 } | 517 } |
| 530 | 518 |
| 531 TEST_P(HttpProxyClientSocketPoolTest, TunnelSetupError) { | 519 TEST_P(HttpProxyClientSocketPoolTest, TunnelSetupError) { |
| 532 if (GetParam().protocol > kProtoSPDY3) | |
| 533 return; | |
| 534 | |
| 535 MockWrite writes[] = { | 520 MockWrite writes[] = { |
| 536 MockWrite(ASYNC, 0, | 521 MockWrite(ASYNC, 0, |
| 537 "CONNECT www.google.com:443 HTTP/1.1\r\n" | 522 "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 538 "Host: www.google.com\r\n" | 523 "Host: www.google.com\r\n" |
| 539 "Proxy-Connection: keep-alive\r\n" | 524 "Proxy-Connection: keep-alive\r\n" |
| 540 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | 525 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 541 }; | 526 }; |
| 542 MockRead reads[] = { | 527 MockRead reads[] = { |
| 543 MockRead(ASYNC, 1, "HTTP/1.1 304 Not Modified\r\n\r\n"), | 528 MockRead(ASYNC, 1, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 544 }; | 529 }; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 570 data_->RunFor(2); | 555 data_->RunFor(2); |
| 571 | 556 |
| 572 rv = callback_.WaitForResult(); | 557 rv = callback_.WaitForResult(); |
| 573 // All Proxy CONNECT responses are not trustworthy | 558 // All Proxy CONNECT responses are not trustworthy |
| 574 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); | 559 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 575 EXPECT_FALSE(handle_.is_initialized()); | 560 EXPECT_FALSE(handle_.is_initialized()); |
| 576 EXPECT_FALSE(handle_.socket()); | 561 EXPECT_FALSE(handle_.socket()); |
| 577 } | 562 } |
| 578 | 563 |
| 579 TEST_P(HttpProxyClientSocketPoolTest, TunnelSetupRedirect) { | 564 TEST_P(HttpProxyClientSocketPoolTest, TunnelSetupRedirect) { |
| 580 if (GetParam().protocol > kProtoSPDY3) | |
| 581 return; | |
| 582 | |
| 583 const std::string redirectTarget = "https://foo.google.com/"; | 565 const std::string redirectTarget = "https://foo.google.com/"; |
| 584 | 566 |
| 585 const std::string responseText = "HTTP/1.1 302 Found\r\n" | 567 const std::string responseText = "HTTP/1.1 302 Found\r\n" |
| 586 "Location: " + redirectTarget + "\r\n" | 568 "Location: " + redirectTarget + "\r\n" |
| 587 "Set-Cookie: foo=bar\r\n" | 569 "Set-Cookie: foo=bar\r\n" |
| 588 "\r\n"; | 570 "\r\n"; |
| 589 MockWrite writes[] = { | 571 MockWrite writes[] = { |
| 590 MockWrite(ASYNC, 0, | 572 MockWrite(ASYNC, 0, |
| 591 "CONNECT www.google.com:443 HTTP/1.1\r\n" | 573 "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 592 "Host: www.google.com\r\n" | 574 "Host: www.google.com\r\n" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 // Make sure Location header was included and correct. | 643 // Make sure Location header was included and correct. |
| 662 std::string location; | 644 std::string location; |
| 663 EXPECT_TRUE(headers->IsRedirect(&location)); | 645 EXPECT_TRUE(headers->IsRedirect(&location)); |
| 664 EXPECT_EQ(location, redirectTarget); | 646 EXPECT_EQ(location, redirectTarget); |
| 665 } | 647 } |
| 666 } | 648 } |
| 667 | 649 |
| 668 // It would be nice to also test the timeouts in HttpProxyClientSocketPool. | 650 // It would be nice to also test the timeouts in HttpProxyClientSocketPool. |
| 669 | 651 |
| 670 } // namespace net | 652 } // namespace net |
| OLD | NEW |