Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(917)

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 769043003: Sanitize headers in Proxy Authentication Required responses (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/http/http_proxy_client_socket.cc » ('j') | net/http/proxy_client_socket.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2534 matching lines...) Expand 10 before | Expand all | Expand 10 after
2545 ExpectLogContainsSomewhere( 2545 ExpectLogContainsSomewhere(
2546 entries, pos, 2546 entries, pos,
2547 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, 2547 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
2548 NetLog::PHASE_NONE); 2548 NetLog::PHASE_NONE);
2549 2549
2550 const HttpResponseInfo* response = trans->GetResponseInfo(); 2550 const HttpResponseInfo* response = trans->GetResponseInfo();
2551 ASSERT_TRUE(response != NULL); 2551 ASSERT_TRUE(response != NULL);
2552 ASSERT_FALSE(response->headers.get() == NULL); 2552 ASSERT_FALSE(response->headers.get() == NULL);
2553 EXPECT_TRUE(response->headers->IsKeepAlive()); 2553 EXPECT_TRUE(response->headers->IsKeepAlive());
2554 EXPECT_EQ(407, response->headers->response_code()); 2554 EXPECT_EQ(407, response->headers->response_code());
2555 EXPECT_EQ(10, response->headers->GetContentLength());
2556 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); 2555 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2557 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); 2556 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
2558 2557
2559 TestCompletionCallback callback2; 2558 TestCompletionCallback callback2;
2560 2559
2561 // Wrong password (should be "bar"). 2560 // Wrong password (should be "bar").
2562 rv = trans->RestartWithAuth( 2561 rv = trans->RestartWithAuth(
2563 AuthCredentials(kFoo, kBaz), callback2.callback()); 2562 AuthCredentials(kFoo, kBaz), callback2.callback());
2564 EXPECT_EQ(ERR_IO_PENDING, rv); 2563 EXPECT_EQ(ERR_IO_PENDING, rv);
2565 2564
2566 rv = callback2.WaitForResult(); 2565 rv = callback2.WaitForResult();
2567 EXPECT_EQ(OK, rv); 2566 EXPECT_EQ(OK, rv);
2568 2567
2569 response = trans->GetResponseInfo(); 2568 response = trans->GetResponseInfo();
2570 ASSERT_TRUE(response != NULL); 2569 ASSERT_TRUE(response != NULL);
2571 ASSERT_FALSE(response->headers.get() == NULL); 2570 ASSERT_FALSE(response->headers.get() == NULL);
2572 EXPECT_TRUE(response->headers->IsKeepAlive()); 2571 EXPECT_TRUE(response->headers->IsKeepAlive());
2573 EXPECT_EQ(407, response->headers->response_code()); 2572 EXPECT_EQ(407, response->headers->response_code());
2574 EXPECT_EQ(10, response->headers->GetContentLength());
2575 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); 2573 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2576 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); 2574 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
2577 2575
2578 // Flush the idle socket before the NetLog and HttpNetworkTransaction go 2576 // Flush the idle socket before the NetLog and HttpNetworkTransaction go
2579 // out of scope. 2577 // out of scope.
2580 session->CloseAllConnections(); 2578 session->CloseAllConnections();
2581 } 2579 }
2582 2580
2583 // Test that we don't read the response body when we fail to establish a tunnel, 2581 // Test that we don't read the response body when we fail to establish a tunnel,
2584 // even if the user cancels the proxy's auth attempt. 2582 // even if the user cancels the proxy's auth attempt.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2621 EXPECT_EQ(ERR_IO_PENDING, rv); 2619 EXPECT_EQ(ERR_IO_PENDING, rv);
2622 2620
2623 rv = callback.WaitForResult(); 2621 rv = callback.WaitForResult();
2624 EXPECT_EQ(OK, rv); 2622 EXPECT_EQ(OK, rv);
2625 2623
2626 const HttpResponseInfo* response = trans->GetResponseInfo(); 2624 const HttpResponseInfo* response = trans->GetResponseInfo();
2627 ASSERT_TRUE(response != NULL); 2625 ASSERT_TRUE(response != NULL);
2628 2626
2629 EXPECT_TRUE(response->headers->IsKeepAlive()); 2627 EXPECT_TRUE(response->headers->IsKeepAlive());
2630 EXPECT_EQ(407, response->headers->response_code()); 2628 EXPECT_EQ(407, response->headers->response_code());
2631 EXPECT_EQ(10, response->headers->GetContentLength());
2632 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); 2629 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2633 2630
2634 std::string response_data; 2631 std::string response_data;
2635 rv = ReadTransaction(trans.get(), &response_data); 2632 rv = ReadTransaction(trans.get(), &response_data);
2636 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); 2633 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
2637 2634
2638 // Flush the idle socket before the HttpNetworkTransaction goes out of scope. 2635 // Flush the idle socket before the HttpNetworkTransaction goes out of scope.
2639 session->CloseAllConnections(); 2636 session->CloseAllConnections();
2640 } 2637 }
2641 2638
2639 // Test that we don't pass extraneous headers from the proxy's response to the
2640 // caller when the proxy responds to CONNECT with 407.
2641 TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) {
2642 HttpRequestInfo request;
2643 request.method = "GET";
2644 request.url = GURL("https://www.google.com/");
2645 request.load_flags = 0;
2646
2647 // Configure against proxy server "myproxy:70".
2648 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
2649
2650 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
2651
2652 scoped_ptr<HttpTransaction> trans(
2653 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
2654
2655 // Since we have proxy, should try to establish tunnel.
2656 MockWrite data_writes[] = {
2657 MockWrite(
2658 "CONNECT www.google.com:443 HTTP/1.1\r\n"
2659 "Host: www.google.com\r\n"
2660 "Proxy-Connection: keep-alive\r\n\r\n"),
2661 };
2662
2663 // The proxy responds to the connect with a 407.
2664 MockRead data_reads[] = {
2665 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
2666 MockRead("X-Foo: bar\r\n"),
2667 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2668 MockRead("Content-Length: 10\r\n\r\n"),
2669 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
Ryan Sleevi 2014/12/17 22:37:12 Wait, why shouldn't it be reached? We should drain
2670 };
2671
2672 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
2673 arraysize(data_writes));
2674 session_deps_.socket_factory->AddSocketDataProvider(&data);
2675
2676 TestCompletionCallback callback;
2677
2678 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
2679 EXPECT_EQ(ERR_IO_PENDING, rv);
2680
2681 rv = callback.WaitForResult();
2682 EXPECT_EQ(OK, rv);
2683
2684 const HttpResponseInfo* response = trans->GetResponseInfo();
2685 ASSERT_TRUE(response != NULL);
2686
2687 EXPECT_TRUE(response->headers->IsKeepAlive());
2688 EXPECT_EQ(407, response->headers->response_code());
2689 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2690 EXPECT_FALSE(response->headers->HasHeaderValue("X-Foo", "bar"));
2691
2692 std::string response_data;
2693 rv = ReadTransaction(trans.get(), &response_data);
2694 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
2695
2696 // Flush the idle socket before the HttpNetworkTransaction goes out of scope.
2697 session->CloseAllConnections();
2698 }
2699
2642 // Test when a server (non-proxy) returns a 407 (proxy-authenticate). 2700 // Test when a server (non-proxy) returns a 407 (proxy-authenticate).
2643 // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. 2701 // The request should fail with ERR_UNEXPECTED_PROXY_AUTH.
2644 TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { 2702 TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) {
2645 HttpRequestInfo request; 2703 HttpRequestInfo request;
2646 request.method = "GET"; 2704 request.method = "GET";
2647 request.url = GURL("http://www.google.com/"); 2705 request.url = GURL("http://www.google.com/");
2648 request.load_flags = 0; 2706 request.load_flags = 0;
2649 2707
2650 // We are using a DIRECT connection (i.e. no proxy) for this session. 2708 // We are using a DIRECT connection (i.e. no proxy) for this session.
2651 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 2709 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
(...skipping 10535 matching lines...) Expand 10 before | Expand all | Expand 10 after
13187 EXPECT_EQ(ERR_IO_PENDING, rv); 13245 EXPECT_EQ(ERR_IO_PENDING, rv);
13188 13246
13189 rv = callback.WaitForResult(); 13247 rv = callback.WaitForResult();
13190 EXPECT_EQ(ERR_CONNECTION_RESET, rv); 13248 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
13191 13249
13192 const HttpResponseInfo* response = trans->GetResponseInfo(); 13250 const HttpResponseInfo* response = trans->GetResponseInfo();
13193 EXPECT_TRUE(response == NULL); 13251 EXPECT_TRUE(response == NULL);
13194 } 13252 }
13195 13253
13196 } // namespace net 13254 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_proxy_client_socket.cc » ('j') | net/http/proxy_client_socket.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698