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

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: Fix sleevi's nit Created 5 years, 11 months 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') | no next file with comments »
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 2528 matching lines...) Expand 10 before | Expand all | Expand 10 after
2539 log.GetEntries(&entries); 2539 log.GetEntries(&entries);
2540 size_t pos = ExpectLogContainsSomewhere( 2540 size_t pos = ExpectLogContainsSomewhere(
2541 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, 2541 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
2542 NetLog::PHASE_NONE); 2542 NetLog::PHASE_NONE);
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);
2550 ASSERT_FALSE(response->headers.get() == NULL); 2550 ASSERT_TRUE(response->headers);
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()); 2553 EXPECT_EQ(-1, response->headers->GetContentLength());
2554 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); 2554 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2555 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); 2555 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
2556 2556
2557 TestCompletionCallback callback2; 2557 TestCompletionCallback callback2;
2558 2558
2559 // Wrong password (should be "bar"). 2559 // Wrong password (should be "bar").
2560 rv = trans->RestartWithAuth( 2560 rv = trans->RestartWithAuth(
2561 AuthCredentials(kFoo, kBaz), callback2.callback()); 2561 AuthCredentials(kFoo, kBaz), callback2.callback());
2562 EXPECT_EQ(ERR_IO_PENDING, rv); 2562 EXPECT_EQ(ERR_IO_PENDING, rv);
2563 2563
2564 rv = callback2.WaitForResult(); 2564 rv = callback2.WaitForResult();
2565 EXPECT_EQ(OK, rv); 2565 EXPECT_EQ(OK, rv);
2566 2566
2567 response = trans->GetResponseInfo(); 2567 response = trans->GetResponseInfo();
2568 ASSERT_TRUE(response != NULL); 2568 ASSERT_TRUE(response);
2569 ASSERT_FALSE(response->headers.get() == NULL); 2569 ASSERT_TRUE(response->headers);
2570 EXPECT_TRUE(response->headers->IsKeepAlive()); 2570 EXPECT_TRUE(response->headers->IsKeepAlive());
2571 EXPECT_EQ(407, response->headers->response_code()); 2571 EXPECT_EQ(407, response->headers->response_code());
2572 EXPECT_EQ(10, response->headers->GetContentLength()); 2572 EXPECT_EQ(-1, response->headers->GetContentLength());
2573 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); 2573 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2574 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); 2574 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
2575 2575
2576 // Flush the idle socket before the NetLog and HttpNetworkTransaction go 2576 // Flush the idle socket before the NetLog and HttpNetworkTransaction go
2577 // out of scope. 2577 // out of scope.
2578 session->CloseAllConnections(); 2578 session->CloseAllConnections();
2579 } 2579 }
2580 2580
2581 // 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,
2582 // even if the user cancels the proxy's auth attempt. 2582 // even if the user cancels the proxy's auth attempt.
(...skipping 13 matching lines...) Expand all
2596 2596
2597 // Since we have proxy, should try to establish tunnel. 2597 // Since we have proxy, should try to establish tunnel.
2598 MockWrite data_writes[] = { 2598 MockWrite data_writes[] = {
2599 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" 2599 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2600 "Host: www.google.com\r\n" 2600 "Host: www.google.com\r\n"
2601 "Proxy-Connection: keep-alive\r\n\r\n"), 2601 "Proxy-Connection: keep-alive\r\n\r\n"),
2602 }; 2602 };
2603 2603
2604 // The proxy responds to the connect with a 407. 2604 // The proxy responds to the connect with a 407.
2605 MockRead data_reads[] = { 2605 MockRead data_reads[] = {
2606 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), 2606 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
2607 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), 2607 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2608 MockRead("Content-Length: 10\r\n\r\n"), 2608 MockRead("Content-Length: 10\r\n\r\n"),
2609 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. 2609 MockRead("0123456789"), // Should not be reached.
2610 MockRead(SYNCHRONOUS, ERR_UNEXPECTED),
2610 }; 2611 };
2611 2612
2612 StaticSocketDataProvider data(data_reads, arraysize(data_reads), 2613 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
2613 data_writes, arraysize(data_writes)); 2614 data_writes, arraysize(data_writes));
2614 session_deps_.socket_factory->AddSocketDataProvider(&data); 2615 session_deps_.socket_factory->AddSocketDataProvider(&data);
2615 2616
2616 TestCompletionCallback callback; 2617 TestCompletionCallback callback;
2617 2618
2618 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 2619 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
2619 EXPECT_EQ(ERR_IO_PENDING, rv); 2620 EXPECT_EQ(ERR_IO_PENDING, rv);
2620 2621
2621 rv = callback.WaitForResult(); 2622 rv = callback.WaitForResult();
2622 EXPECT_EQ(OK, rv); 2623 EXPECT_EQ(OK, rv);
2623 2624
2624 const HttpResponseInfo* response = trans->GetResponseInfo(); 2625 const HttpResponseInfo* response = trans->GetResponseInfo();
2625 ASSERT_TRUE(response != NULL); 2626 ASSERT_TRUE(response);
2626 2627 ASSERT_TRUE(response->headers);
2627 EXPECT_TRUE(response->headers->IsKeepAlive()); 2628 EXPECT_TRUE(response->headers->IsKeepAlive());
2628 EXPECT_EQ(407, response->headers->response_code()); 2629 EXPECT_EQ(407, response->headers->response_code());
2629 EXPECT_EQ(10, response->headers->GetContentLength());
2630 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); 2630 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2631 2631
2632 std::string response_data; 2632 std::string response_data;
2633 rv = ReadTransaction(trans.get(), &response_data); 2633 rv = ReadTransaction(trans.get(), &response_data);
2634 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
2635
2636 // Flush the idle socket before the HttpNetworkTransaction goes out of scope.
2637 session->CloseAllConnections();
2638 }
2639
2640 // Test that we don't pass extraneous headers from the proxy's response to the
2641 // caller when the proxy responds to CONNECT with 407.
2642 TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) {
2643 HttpRequestInfo request;
2644 request.method = "GET";
2645 request.url = GURL("https://www.google.com/");
2646 request.load_flags = 0;
2647
2648 // Configure against proxy server "myproxy:70".
2649 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
2650
2651 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
2652
2653 scoped_ptr<HttpTransaction> trans(
2654 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
2655
2656 // Since we have proxy, should try to establish tunnel.
2657 MockWrite data_writes[] = {
2658 MockWrite(
2659 "CONNECT www.google.com:443 HTTP/1.1\r\n"
2660 "Host: www.google.com\r\n"
2661 "Proxy-Connection: keep-alive\r\n\r\n"),
2662 };
2663
2664 // The proxy responds to the connect with a 407.
2665 MockRead data_reads[] = {
2666 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
2667 MockRead("X-Foo: bar\r\n"),
2668 MockRead("Set-Cookie: foo=bar\r\n"),
2669 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2670 MockRead("Content-Length: 10\r\n\r\n"),
2671 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
2672 };
2673
2674 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
2675 arraysize(data_writes));
2676 session_deps_.socket_factory->AddSocketDataProvider(&data);
2677
2678 TestCompletionCallback callback;
2679
2680 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
2681 EXPECT_EQ(ERR_IO_PENDING, rv);
2682
2683 rv = callback.WaitForResult();
2684 EXPECT_EQ(OK, rv);
2685
2686 const HttpResponseInfo* response = trans->GetResponseInfo();
2687 ASSERT_TRUE(response);
2688 ASSERT_TRUE(response->headers);
2689 EXPECT_TRUE(response->headers->IsKeepAlive());
2690 EXPECT_EQ(407, response->headers->response_code());
2691 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2692 EXPECT_FALSE(response->headers->HasHeader("X-Foo"));
2693 EXPECT_FALSE(response->headers->HasHeader("Set-Cookie"));
2694
2695 std::string response_data;
2696 rv = ReadTransaction(trans.get(), &response_data);
2634 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); 2697 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
2635 2698
2636 // Flush the idle socket before the HttpNetworkTransaction goes out of scope. 2699 // Flush the idle socket before the HttpNetworkTransaction goes out of scope.
2637 session->CloseAllConnections(); 2700 session->CloseAllConnections();
2638 } 2701 }
2639 2702
2640 // Test when a server (non-proxy) returns a 407 (proxy-authenticate). 2703 // Test when a server (non-proxy) returns a 407 (proxy-authenticate).
2641 // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. 2704 // The request should fail with ERR_UNEXPECTED_PROXY_AUTH.
2642 TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { 2705 TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) {
2643 HttpRequestInfo request; 2706 HttpRequestInfo request;
(...skipping 10541 matching lines...) Expand 10 before | Expand all | Expand 10 after
13185 EXPECT_EQ(ERR_IO_PENDING, rv); 13248 EXPECT_EQ(ERR_IO_PENDING, rv);
13186 13249
13187 rv = callback.WaitForResult(); 13250 rv = callback.WaitForResult();
13188 EXPECT_EQ(ERR_CONNECTION_RESET, rv); 13251 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
13189 13252
13190 const HttpResponseInfo* response = trans->GetResponseInfo(); 13253 const HttpResponseInfo* response = trans->GetResponseInfo();
13191 EXPECT_TRUE(response == NULL); 13254 EXPECT_TRUE(response == NULL);
13192 } 13255 }
13193 13256
13194 } // namespace net 13257 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_proxy_client_socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698