OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 2257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2268 ssl2.next_proto = "spdy/2"; | 2268 ssl2.next_proto = "spdy/2"; |
2269 ssl2.was_npn_negotiated = true; | 2269 ssl2.was_npn_negotiated = true; |
2270 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl2); | 2270 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl2); |
2271 | 2271 |
2272 TestCompletionCallback callback1; | 2272 TestCompletionCallback callback1; |
2273 | 2273 |
2274 int rv = trans->Start(&request, &callback1, log.bound()); | 2274 int rv = trans->Start(&request, &callback1, log.bound()); |
2275 EXPECT_EQ(ERR_IO_PENDING, rv); | 2275 EXPECT_EQ(ERR_IO_PENDING, rv); |
2276 | 2276 |
2277 rv = callback1.WaitForResult(); | 2277 rv = callback1.WaitForResult(); |
2278 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); | 2278 EXPECT_EQ(OK, rv); |
2279 | 2279 |
2280 const HttpResponseInfo* response = trans->GetResponseInfo(); | 2280 const HttpResponseInfo* response = trans->GetResponseInfo(); |
2281 ASSERT_TRUE(response == NULL); | 2281 ASSERT_FALSE(response == NULL); |
2282 EXPECT_EQ(500, response->headers->response_code()); | |
2282 } | 2283 } |
2283 | 2284 |
2284 // Test the challenge-response-retry sequence through an HTTPS Proxy | 2285 // Test the challenge-response-retry sequence through an HTTPS Proxy |
2285 TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { | 2286 TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
2286 // Configure against https proxy server "proxy:70". | 2287 // Configure against https proxy server "proxy:70". |
2287 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") ); | 2288 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") ); |
2288 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 2289 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
2289 session_deps.net_log = log.bound().net_log(); | 2290 session_deps.net_log = log.bound().net_log(); |
2290 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 2291 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
2291 | 2292 |
(...skipping 2167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4459 const HttpResponseInfo* response = trans->GetResponseInfo(); | 4460 const HttpResponseInfo* response = trans->GetResponseInfo(); |
4460 | 4461 |
4461 ASSERT_FALSE(response == NULL); | 4462 ASSERT_FALSE(response == NULL); |
4462 | 4463 |
4463 EXPECT_TRUE(response->headers->IsKeepAlive()); | 4464 EXPECT_TRUE(response->headers->IsKeepAlive()); |
4464 EXPECT_EQ(200, response->headers->response_code()); | 4465 EXPECT_EQ(200, response->headers->response_code()); |
4465 EXPECT_EQ(100, response->headers->GetContentLength()); | 4466 EXPECT_EQ(100, response->headers->GetContentLength()); |
4466 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | 4467 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
4467 } | 4468 } |
4468 | 4469 |
4470 // Test an HTTPS Proxy's ability to redirect a CONNECT request | |
4471 TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { | |
4472 SessionDependencies session_deps( | |
4473 ProxyService::CreateFixed("https://proxy:70")); | |
4474 | |
4475 HttpRequestInfo request; | |
4476 request.method = "GET"; | |
4477 request.url = GURL("https://www.google.com/"); | |
4478 request.load_flags = 0; | |
4479 | |
4480 MockWrite data_writes[] = { | |
4481 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
4482 "Host: www.google.com\r\n" | |
4483 "Proxy-Connection: keep-alive\r\n\r\n"), | |
4484 }; | |
4485 | |
4486 MockRead data_reads[] = { | |
4487 MockRead("HTTP/1.1 302 Redirect\r\n"), | |
4488 MockRead("Location: http://login.example.com/\r\n"), | |
4489 MockRead("Content-Length: 0\r\n\r\n"), | |
4490 MockRead(false, OK), | |
4491 }; | |
4492 | |
4493 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
4494 data_writes, arraysize(data_writes)); | |
4495 SSLSocketDataProvider proxy_ssl(true, OK); // SSL to the proxy | |
4496 | |
4497 session_deps.socket_factory.AddSocketDataProvider(&data); | |
4498 session_deps.socket_factory.AddSSLSocketDataProvider(&proxy_ssl); | |
4499 | |
4500 TestCompletionCallback callback; | |
4501 | |
4502 scoped_ptr<HttpTransaction> trans( | |
4503 new HttpNetworkTransaction(CreateSession(&session_deps))); | |
4504 | |
4505 int rv = trans->Start(&request, &callback, BoundNetLog()); | |
4506 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4507 | |
4508 rv = callback.WaitForResult(); | |
4509 EXPECT_EQ(OK, rv); | |
4510 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4511 | |
4512 ASSERT_FALSE(response == NULL); | |
4513 | |
4514 EXPECT_EQ(302, response->headers->response_code()); | |
4515 std::string url; | |
4516 EXPECT_TRUE(response->headers->IsRedirect(&url)); | |
4517 EXPECT_EQ("http://login.example.com/", url); | |
4518 } | |
4519 | |
4520 // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request | |
4521 TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { | |
4522 SessionDependencies session_deps( | |
4523 ProxyService::CreateFixed("https://proxy:70")); | |
4524 | |
4525 HttpRequestInfo request; | |
4526 request.method = "GET"; | |
4527 request.url = GURL("https://www.google.com/"); | |
4528 request.load_flags = 0; | |
4529 | |
4530 scoped_ptr<spdy::SpdyFrame> conn(ConstructSpdyConnect(NULL, 0, 1)); | |
4531 scoped_ptr<spdy::SpdyFrame> goaway(ConstructSpdyRstStream(1, spdy::CANCEL)); | |
4532 MockWrite data_writes[] = { | |
4533 CreateMockWrite(*conn.get(), 0, false), | |
4534 }; | |
4535 | |
4536 static const char* const kExtraHeaders[] = { | |
4537 "location", | |
4538 "http://login.example.com/", | |
4539 }; | |
4540 scoped_ptr<spdy::SpdyFrame> resp( | |
4541 ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, | |
4542 arraysize(kExtraHeaders)/2, 1)); | |
4543 MockRead data_reads[] = { | |
4544 CreateMockRead(*resp.get(), 1, false), | |
4545 MockRead(true, 0, 2), // EOF | |
4546 }; | |
4547 | |
4548 scoped_refptr<DelayedSocketData> data( | |
4549 new DelayedSocketData( | |
4550 1, // wait for one write to finish before reading. | |
4551 data_reads, arraysize(data_reads), | |
4552 data_writes, arraysize(data_writes))); | |
4553 SSLSocketDataProvider proxy_ssl(true, OK); // SSL to the proxy | |
4554 proxy_ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; | |
4555 proxy_ssl.next_proto = "spdy/2"; | |
4556 proxy_ssl.was_npn_negotiated = true; | |
4557 | |
4558 session_deps.socket_factory.AddSocketDataProvider(data.get()); | |
4559 session_deps.socket_factory.AddSSLSocketDataProvider(&proxy_ssl); | |
4560 | |
4561 TestCompletionCallback callback; | |
4562 | |
4563 scoped_ptr<HttpTransaction> trans( | |
4564 new HttpNetworkTransaction(CreateSession(&session_deps))); | |
4565 | |
4566 int rv = trans->Start(&request, &callback, BoundNetLog()); | |
4567 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4568 | |
4569 rv = callback.WaitForResult(); | |
4570 EXPECT_EQ(OK, rv); | |
4571 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4572 | |
4573 ASSERT_FALSE(response == NULL); | |
4574 | |
4575 EXPECT_EQ(302, response->headers->response_code()); | |
4576 std::string url; | |
4577 EXPECT_TRUE(response->headers->IsRedirect(&url)); | |
4578 EXPECT_EQ("http://login.example.com/", url); | |
4579 } | |
4580 | |
4581 // Test an HTTPS Proxy's ability to provide a response to a CONNECT request | |
4582 TEST_F(HttpNetworkTransactionTest, ErrorResponseTofHttpsConnectViaHttpsProxy) { | |
vandebo (ex-Chrome)
2010/12/16 02:24:31
Can you check, in this test and the next, that the
Ryan Hamilton
2010/12/16 05:23:50
Done.
| |
4583 SessionDependencies session_deps( | |
4584 ProxyService::CreateFixed("https://proxy:70")); | |
4585 | |
4586 HttpRequestInfo request; | |
4587 request.method = "GET"; | |
4588 request.url = GURL("https://www.google.com/"); | |
4589 request.load_flags = 0; | |
4590 | |
4591 MockWrite data_writes[] = { | |
4592 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
4593 "Host: www.google.com\r\n" | |
4594 "Proxy-Connection: keep-alive\r\n\r\n"), | |
4595 }; | |
4596 | |
4597 MockRead data_reads[] = { | |
4598 MockRead("HTTP/1.1 404 Not Found\r\n"), | |
4599 MockRead("Content-Length: 23\r\n\r\n"), | |
4600 MockRead("The host does not exist"), | |
4601 MockRead(false, OK), | |
4602 }; | |
4603 | |
4604 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
4605 data_writes, arraysize(data_writes)); | |
4606 SSLSocketDataProvider proxy_ssl(true, OK); // SSL to the proxy | |
4607 | |
4608 session_deps.socket_factory.AddSocketDataProvider(&data); | |
4609 session_deps.socket_factory.AddSSLSocketDataProvider(&proxy_ssl); | |
4610 | |
4611 TestCompletionCallback callback; | |
4612 | |
4613 scoped_ptr<HttpTransaction> trans( | |
4614 new HttpNetworkTransaction(CreateSession(&session_deps))); | |
4615 | |
4616 int rv = trans->Start(&request, &callback, BoundNetLog()); | |
4617 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4618 | |
4619 rv = callback.WaitForResult(); | |
4620 EXPECT_EQ(OK, rv); | |
4621 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4622 | |
4623 ASSERT_FALSE(response == NULL); | |
4624 | |
4625 EXPECT_EQ(404, response->headers->response_code()); | |
4626 EXPECT_EQ(23, response->headers->GetContentLength()); | |
4627 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | |
4628 | |
4629 std::string response_data; | |
4630 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
4631 EXPECT_EQ("The host does not exist", response_data); | |
4632 } | |
4633 | |
4634 // Test an HTTPS (SPDY) Proxy's ability to provide a response to a CONNECT | |
4635 // request | |
4636 TEST_F(HttpNetworkTransactionTest, ErrorResponseTofHttpsConnectViaSpdyProxy) { | |
4637 SessionDependencies session_deps( | |
4638 ProxyService::CreateFixed("https://proxy:70")); | |
4639 | |
4640 HttpRequestInfo request; | |
4641 request.method = "GET"; | |
4642 request.url = GURL("https://www.google.com/"); | |
4643 request.load_flags = 0; | |
4644 | |
4645 scoped_ptr<spdy::SpdyFrame> conn(ConstructSpdyConnect(NULL, 0, 1)); | |
4646 scoped_ptr<spdy::SpdyFrame> goaway(ConstructSpdyRstStream(1, spdy::CANCEL)); | |
4647 MockWrite data_writes[] = { | |
4648 CreateMockWrite(*conn.get(), 0, false), | |
4649 }; | |
4650 | |
4651 static const char* const kExtraHeaders[] = { | |
4652 "location", | |
4653 "http://login.example.com/", | |
4654 }; | |
4655 scoped_ptr<spdy::SpdyFrame> resp( | |
4656 ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, | |
4657 arraysize(kExtraHeaders)/2, 1)); | |
4658 scoped_ptr<spdy::SpdyFrame> body( | |
4659 ConstructSpdyBodyFrame(1, "The host does not exist", 23, true)); | |
4660 MockRead data_reads[] = { | |
4661 CreateMockRead(*resp.get(), 1, false), | |
4662 CreateMockRead(*body.get(), 2, false), | |
4663 MockRead(true, 0, 3), // EOF | |
4664 }; | |
4665 | |
4666 scoped_refptr<DelayedSocketData> data( | |
4667 new DelayedSocketData( | |
4668 1, // wait for one write to finish before reading. | |
4669 data_reads, arraysize(data_reads), | |
4670 data_writes, arraysize(data_writes))); | |
4671 SSLSocketDataProvider proxy_ssl(true, OK); // SSL to the proxy | |
4672 proxy_ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; | |
4673 proxy_ssl.next_proto = "spdy/2"; | |
4674 proxy_ssl.was_npn_negotiated = true; | |
4675 | |
4676 session_deps.socket_factory.AddSocketDataProvider(data.get()); | |
4677 session_deps.socket_factory.AddSSLSocketDataProvider(&proxy_ssl); | |
4678 | |
4679 TestCompletionCallback callback; | |
4680 | |
4681 scoped_ptr<HttpTransaction> trans( | |
4682 new HttpNetworkTransaction(CreateSession(&session_deps))); | |
4683 | |
4684 int rv = trans->Start(&request, &callback, BoundNetLog()); | |
4685 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4686 | |
4687 rv = callback.WaitForResult(); | |
4688 EXPECT_EQ(OK, rv); | |
4689 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4690 | |
4691 ASSERT_FALSE(response == NULL); | |
4692 | |
4693 EXPECT_EQ(404, response->headers->response_code()); | |
4694 | |
4695 std::string response_data; | |
4696 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
4697 EXPECT_EQ("The host does not exist", response_data); | |
4698 } | |
4699 | |
4469 // Test HTTPS connections to a site with a bad certificate, going through an | 4700 // Test HTTPS connections to a site with a bad certificate, going through an |
4470 // HTTPS proxy | 4701 // HTTPS proxy |
4471 TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { | 4702 TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
4472 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") ); | 4703 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") ); |
4473 | 4704 |
4474 HttpRequestInfo request; | 4705 HttpRequestInfo request; |
4475 request.method = "GET"; | 4706 request.method = "GET"; |
4476 request.url = GURL("https://www.google.com/"); | 4707 request.url = GURL("https://www.google.com/"); |
4477 request.load_flags = 0; | 4708 request.load_flags = 0; |
4478 | 4709 |
(...skipping 3479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7958 rv = callback.WaitForResult(); | 8189 rv = callback.WaitForResult(); |
7959 ASSERT_EQ(OK, rv); | 8190 ASSERT_EQ(OK, rv); |
7960 | 8191 |
7961 std::string contents; | 8192 std::string contents; |
7962 rv = ReadTransaction(trans.get(), &contents); | 8193 rv = ReadTransaction(trans.get(), &contents); |
7963 EXPECT_EQ(net::OK, rv); | 8194 EXPECT_EQ(net::OK, rv); |
7964 EXPECT_EQ("hello world", contents); | 8195 EXPECT_EQ("hello world", contents); |
7965 } | 8196 } |
7966 | 8197 |
7967 } // namespace net | 8198 } // namespace net |
OLD | NEW |