OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stdarg.h> | 8 #include <stdarg.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 2532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2543 ExpectLogContainsSomewhere( | 2543 ExpectLogContainsSomewhere( |
2544 entries, pos, | 2544 entries, pos, |
2545 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, | 2545 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
2546 NetLog::PHASE_NONE); | 2546 NetLog::PHASE_NONE); |
2547 | 2547 |
2548 const HttpResponseInfo* response = trans->GetResponseInfo(); | 2548 const HttpResponseInfo* response = trans->GetResponseInfo(); |
2549 ASSERT_TRUE(response != NULL); | 2549 ASSERT_TRUE(response != NULL); |
2550 ASSERT_FALSE(response->headers.get() == NULL); | 2550 ASSERT_FALSE(response->headers.get() == NULL); |
2551 EXPECT_TRUE(response->headers->IsKeepAlive()); | 2551 EXPECT_TRUE(response->headers->IsKeepAlive()); |
2552 EXPECT_EQ(407, response->headers->response_code()); | 2552 EXPECT_EQ(407, response->headers->response_code()); |
2553 EXPECT_EQ(10, response->headers->GetContentLength()); | |
Ryan Sleevi
2014/12/19 22:06:25
Rather than deleting these, you should be assertin
Deprecated (see juliatuttle)
2015/01/02 19:40:55
Well, at least asserting that there is no Content-
| |
2554 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | 2553 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
2555 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); | 2554 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
2556 | 2555 |
2557 TestCompletionCallback callback2; | 2556 TestCompletionCallback callback2; |
2558 | 2557 |
2559 // Wrong password (should be "bar"). | 2558 // Wrong password (should be "bar"). |
2560 rv = trans->RestartWithAuth( | 2559 rv = trans->RestartWithAuth( |
2561 AuthCredentials(kFoo, kBaz), callback2.callback()); | 2560 AuthCredentials(kFoo, kBaz), callback2.callback()); |
2562 EXPECT_EQ(ERR_IO_PENDING, rv); | 2561 EXPECT_EQ(ERR_IO_PENDING, rv); |
2563 | 2562 |
2564 rv = callback2.WaitForResult(); | 2563 rv = callback2.WaitForResult(); |
2565 EXPECT_EQ(OK, rv); | 2564 EXPECT_EQ(OK, rv); |
2566 | 2565 |
2567 response = trans->GetResponseInfo(); | 2566 response = trans->GetResponseInfo(); |
2568 ASSERT_TRUE(response != NULL); | 2567 ASSERT_TRUE(response != NULL); |
2569 ASSERT_FALSE(response->headers.get() == NULL); | 2568 ASSERT_FALSE(response->headers.get() == NULL); |
2570 EXPECT_TRUE(response->headers->IsKeepAlive()); | 2569 EXPECT_TRUE(response->headers->IsKeepAlive()); |
2571 EXPECT_EQ(407, response->headers->response_code()); | 2570 EXPECT_EQ(407, response->headers->response_code()); |
2572 EXPECT_EQ(10, response->headers->GetContentLength()); | |
2573 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | 2571 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
2574 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); | 2572 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
2575 | 2573 |
2576 // Flush the idle socket before the NetLog and HttpNetworkTransaction go | 2574 // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
2577 // out of scope. | 2575 // out of scope. |
2578 session->CloseAllConnections(); | 2576 session->CloseAllConnections(); |
2579 } | 2577 } |
2580 | 2578 |
2581 // Test that we don't read the response body when we fail to establish a tunnel, | 2579 // Test that we don't read the response body when we fail to establish a tunnel, |
2582 // even if the user cancels the proxy's auth attempt. | 2580 // even if the user cancels the proxy's auth attempt. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2619 EXPECT_EQ(ERR_IO_PENDING, rv); | 2617 EXPECT_EQ(ERR_IO_PENDING, rv); |
2620 | 2618 |
2621 rv = callback.WaitForResult(); | 2619 rv = callback.WaitForResult(); |
2622 EXPECT_EQ(OK, rv); | 2620 EXPECT_EQ(OK, rv); |
2623 | 2621 |
2624 const HttpResponseInfo* response = trans->GetResponseInfo(); | 2622 const HttpResponseInfo* response = trans->GetResponseInfo(); |
2625 ASSERT_TRUE(response != NULL); | 2623 ASSERT_TRUE(response != NULL); |
2626 | 2624 |
2627 EXPECT_TRUE(response->headers->IsKeepAlive()); | 2625 EXPECT_TRUE(response->headers->IsKeepAlive()); |
2628 EXPECT_EQ(407, response->headers->response_code()); | 2626 EXPECT_EQ(407, response->headers->response_code()); |
2629 EXPECT_EQ(10, response->headers->GetContentLength()); | |
2630 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | 2627 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
2631 | 2628 |
2632 std::string response_data; | 2629 std::string response_data; |
2633 rv = ReadTransaction(trans.get(), &response_data); | 2630 rv = ReadTransaction(trans.get(), &response_data); |
2634 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); | 2631 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
2635 | 2632 |
2636 // Flush the idle socket before the HttpNetworkTransaction goes out of scope. | 2633 // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
2637 session->CloseAllConnections(); | 2634 session->CloseAllConnections(); |
2638 } | 2635 } |
2639 | 2636 |
2637 // Test that we don't pass extraneous headers from the proxy's response to the | |
2638 // caller when the proxy responds to CONNECT with 407. | |
2639 TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { | |
2640 HttpRequestInfo request; | |
2641 request.method = "GET"; | |
2642 request.url = GURL("https://www.google.com/"); | |
2643 request.load_flags = 0; | |
2644 | |
2645 // Configure against proxy server "myproxy:70". | |
2646 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); | |
2647 | |
2648 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
2649 | |
2650 scoped_ptr<HttpTransaction> trans( | |
2651 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
2652 | |
2653 // Since we have proxy, should try to establish tunnel. | |
2654 MockWrite data_writes[] = { | |
2655 MockWrite( | |
2656 "CONNECT www.google.com:443 HTTP/1.1\r\n" | |
2657 "Host: www.google.com\r\n" | |
2658 "Proxy-Connection: keep-alive\r\n\r\n"), | |
2659 }; | |
2660 | |
2661 // The proxy responds to the connect with a 407. | |
2662 MockRead data_reads[] = { | |
2663 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), | |
2664 MockRead("X-Foo: bar\r\n"), | |
Ryan Sleevi
2014/12/19 22:06:25
Can you explicitly add a test for Set-Cookie behav
Deprecated (see juliatuttle)
2015/01/02 19:40:55
Done. I don't see any way to test it besides just
| |
2665 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | |
2666 MockRead("Content-Length: 10\r\n\r\n"), | |
2667 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. | |
Ryan Sleevi
2014/12/19 22:06:24
I'd feel better for this test if you explicitly ad
| |
2668 }; | |
2669 | |
2670 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, | |
2671 arraysize(data_writes)); | |
2672 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
2673 | |
2674 TestCompletionCallback callback; | |
2675 | |
2676 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
2677 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2678 | |
2679 rv = callback.WaitForResult(); | |
2680 EXPECT_EQ(OK, rv); | |
2681 | |
2682 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
2683 ASSERT_TRUE(response != NULL); | |
2684 | |
2685 EXPECT_TRUE(response->headers->IsKeepAlive()); | |
2686 EXPECT_EQ(407, response->headers->response_code()); | |
2687 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | |
2688 EXPECT_FALSE(response->headers->HasHeaderValue("X-Foo", "bar")); | |
2689 | |
2690 std::string response_data; | |
2691 rv = ReadTransaction(trans.get(), &response_data); | |
2692 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); | |
2693 | |
2694 // Flush the idle socket before the HttpNetworkTransaction goes out of scope. | |
2695 session->CloseAllConnections(); | |
2696 } | |
2697 | |
2640 // Test when a server (non-proxy) returns a 407 (proxy-authenticate). | 2698 // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
2641 // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. | 2699 // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
2642 TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { | 2700 TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
2643 HttpRequestInfo request; | 2701 HttpRequestInfo request; |
2644 request.method = "GET"; | 2702 request.method = "GET"; |
2645 request.url = GURL("http://www.google.com/"); | 2703 request.url = GURL("http://www.google.com/"); |
2646 request.load_flags = 0; | 2704 request.load_flags = 0; |
2647 | 2705 |
2648 // We are using a DIRECT connection (i.e. no proxy) for this session. | 2706 // We are using a DIRECT connection (i.e. no proxy) for this session. |
2649 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 2707 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
(...skipping 10535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13185 EXPECT_EQ(ERR_IO_PENDING, rv); | 13243 EXPECT_EQ(ERR_IO_PENDING, rv); |
13186 | 13244 |
13187 rv = callback.WaitForResult(); | 13245 rv = callback.WaitForResult(); |
13188 EXPECT_EQ(ERR_CONNECTION_RESET, rv); | 13246 EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
13189 | 13247 |
13190 const HttpResponseInfo* response = trans->GetResponseInfo(); | 13248 const HttpResponseInfo* response = trans->GetResponseInfo(); |
13191 EXPECT_TRUE(response == NULL); | 13249 EXPECT_TRUE(response == NULL); |
13192 } | 13250 } |
13193 | 13251 |
13194 } // namespace net | 13252 } // namespace net |
OLD | NEW |