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

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 net_unittests 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
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 2458 matching lines...) Expand 10 before | Expand all | Expand 10 after
2469 EXPECT_TRUE(response->auth_challenge.get() == NULL); 2469 EXPECT_TRUE(response->auth_challenge.get() == NULL);
2470 2470
2471 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); 2471 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
2472 TestLoadTimingNotReusedWithPac(load_timing_info, 2472 TestLoadTimingNotReusedWithPac(load_timing_info,
2473 CONNECT_TIMING_HAS_SSL_TIMES); 2473 CONNECT_TIMING_HAS_SSL_TIMES);
2474 2474
2475 trans.reset(); 2475 trans.reset();
2476 session->CloseAllConnections(); 2476 session->CloseAllConnections();
2477 } 2477 }
2478 2478
2479 // Test the request-challenge-retry sequence for basic auth, over a keep-alive
2480 // proxy connection, when setting up an SSL tunnel.
Ryan Sleevi 2014/12/08 22:04:39 Is my reading of your deletion of this test correc
Ryan Hamilton 2014/12/08 22:51:59 ... because that would be Bad (tm). I broke this
Deprecated (see juliatuttle) 2014/12/09 15:31:15 Yes; our fake response does not have a keep-alive
asanka 2014/12/09 17:33:02 Respecting keep-alive is important for connection
Deprecated (see juliatuttle) 2014/12/10 20:38:40 Gross, but fixed.
2481 TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) {
2482 HttpRequestInfo request;
2483 request.method = "GET";
2484 request.url = GURL("https://www.google.com/");
2485 // Ensure that proxy authentication is attempted even
2486 // when the no authentication data flag is set.
2487 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
2488
2489 // Configure against proxy server "myproxy:70".
2490 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
2491 CapturingBoundNetLog log;
2492 session_deps_.net_log = log.bound().net_log();
2493 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
2494
2495 scoped_ptr<HttpTransaction> trans(
2496 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
2497
2498 // Since we have proxy, should try to establish tunnel.
2499 MockWrite data_writes1[] = {
2500 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2501 "Host: www.google.com\r\n"
2502 "Proxy-Connection: keep-alive\r\n\r\n"),
2503
2504 // After calling trans->RestartWithAuth(), this is the request we should
2505 // be issuing -- the final header line contains the credentials.
2506 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2507 "Host: www.google.com\r\n"
2508 "Proxy-Connection: keep-alive\r\n"
2509 "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"),
2510 };
2511
2512 // The proxy responds to the connect with a 407, using a persistent
2513 // connection.
2514 MockRead data_reads1[] = {
2515 // No credentials.
2516 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
2517 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2518 MockRead("Content-Length: 10\r\n\r\n"),
2519 MockRead("0123456789"),
2520
2521 // Wrong credentials (wrong password).
2522 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
2523 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2524 MockRead("Content-Length: 10\r\n\r\n"),
2525 // No response body because the test stops reading here.
2526 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
2527 };
2528
2529 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2530 data_writes1, arraysize(data_writes1));
2531 session_deps_.socket_factory->AddSocketDataProvider(&data1);
2532
2533 TestCompletionCallback callback1;
2534
2535 int rv = trans->Start(&request, callback1.callback(), log.bound());
2536 EXPECT_EQ(ERR_IO_PENDING, rv);
2537
2538 rv = callback1.WaitForResult();
2539 EXPECT_EQ(OK, rv);
2540 net::CapturingNetLog::CapturedEntryList entries;
2541 log.GetEntries(&entries);
2542 size_t pos = ExpectLogContainsSomewhere(
2543 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
2544 NetLog::PHASE_NONE);
2545 ExpectLogContainsSomewhere(
2546 entries, pos,
2547 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
2548 NetLog::PHASE_NONE);
2549
2550 const HttpResponseInfo* response = trans->GetResponseInfo();
2551 ASSERT_TRUE(response != NULL);
2552 ASSERT_FALSE(response->headers.get() == NULL);
2553 EXPECT_TRUE(response->headers->IsKeepAlive());
2554 EXPECT_EQ(407, response->headers->response_code());
2555 EXPECT_EQ(10, response->headers->GetContentLength());
2556 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2557 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
2558
2559 TestCompletionCallback callback2;
2560
2561 // Wrong password (should be "bar").
2562 rv = trans->RestartWithAuth(
2563 AuthCredentials(kFoo, kBaz), callback2.callback());
2564 EXPECT_EQ(ERR_IO_PENDING, rv);
2565
2566 rv = callback2.WaitForResult();
2567 EXPECT_EQ(OK, rv);
2568
2569 response = trans->GetResponseInfo();
2570 ASSERT_TRUE(response != NULL);
2571 ASSERT_FALSE(response->headers.get() == NULL);
2572 EXPECT_TRUE(response->headers->IsKeepAlive());
2573 EXPECT_EQ(407, response->headers->response_code());
2574 EXPECT_EQ(10, response->headers->GetContentLength());
2575 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2576 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
2577
2578 // Flush the idle socket before the NetLog and HttpNetworkTransaction go
2579 // out of scope.
2580 session->CloseAllConnections();
2581 }
2582
2583 // Test that we don't read the response body when we fail to establish a tunnel, 2479 // 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. 2480 // even if the user cancels the proxy's auth attempt.
2585 TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { 2481 TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) {
2586 HttpRequestInfo request; 2482 HttpRequestInfo request;
2587 request.method = "GET"; 2483 request.method = "GET";
2588 request.url = GURL("https://www.google.com/"); 2484 request.url = GURL("https://www.google.com/");
2589 request.load_flags = 0; 2485 request.load_flags = 0;
2590 2486
2591 // Configure against proxy server "myproxy:70". 2487 // Configure against proxy server "myproxy:70".
2592 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); 2488 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
(...skipping 26 matching lines...) Expand all
2619 2515
2620 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 2516 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
2621 EXPECT_EQ(ERR_IO_PENDING, rv); 2517 EXPECT_EQ(ERR_IO_PENDING, rv);
2622 2518
2623 rv = callback.WaitForResult(); 2519 rv = callback.WaitForResult();
2624 EXPECT_EQ(OK, rv); 2520 EXPECT_EQ(OK, rv);
2625 2521
2626 const HttpResponseInfo* response = trans->GetResponseInfo(); 2522 const HttpResponseInfo* response = trans->GetResponseInfo();
2627 ASSERT_TRUE(response != NULL); 2523 ASSERT_TRUE(response != NULL);
2628 2524
2629 EXPECT_TRUE(response->headers->IsKeepAlive());
2630 EXPECT_EQ(407, response->headers->response_code()); 2525 EXPECT_EQ(407, response->headers->response_code());
2631 EXPECT_EQ(10, response->headers->GetContentLength()); 2526 EXPECT_EQ(0, response->headers->GetContentLength());
2632 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2633 2527
2634 std::string response_data; 2528 std::string response_data;
2635 rv = ReadTransaction(trans.get(), &response_data); 2529 rv = ReadTransaction(trans.get(), &response_data);
2636 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); 2530 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
2637 2531
2638 // Flush the idle socket before the HttpNetworkTransaction goes out of scope. 2532 // Flush the idle socket before the HttpNetworkTransaction goes out of scope.
2639 session->CloseAllConnections(); 2533 session->CloseAllConnections();
2640 } 2534 }
2641 2535
2642 // Test when a server (non-proxy) returns a 407 (proxy-authenticate). 2536 // Test when a server (non-proxy) returns a 407 (proxy-authenticate).
(...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after
4112 ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); 4006 ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n"));
4113 } 4007 }
4114 4008
4115 TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { 4009 TEST_P(HttpNetworkTransactionTest, ConnectStatus406) {
4116 ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); 4010 ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n"));
4117 } 4011 }
4118 4012
4119 TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { 4013 TEST_P(HttpNetworkTransactionTest, ConnectStatus407) {
4120 ConnectStatusHelperWithExpectedStatus( 4014 ConnectStatusHelperWithExpectedStatus(
4121 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), 4015 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
4122 ERR_PROXY_AUTH_UNSUPPORTED); 4016 ERR_TUNNEL_CONNECTION_FAILED);
4123 } 4017 }
4124 4018
4125 TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { 4019 TEST_P(HttpNetworkTransactionTest, ConnectStatus408) {
4126 ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); 4020 ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n"));
4127 } 4021 }
4128 4022
4129 TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { 4023 TEST_P(HttpNetworkTransactionTest, ConnectStatus409) {
4130 ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); 4024 ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n"));
4131 } 4025 }
4132 4026
(...skipping 9054 matching lines...) Expand 10 before | Expand all | Expand 10 after
13187 EXPECT_EQ(ERR_IO_PENDING, rv); 13081 EXPECT_EQ(ERR_IO_PENDING, rv);
13188 13082
13189 rv = callback.WaitForResult(); 13083 rv = callback.WaitForResult();
13190 EXPECT_EQ(ERR_CONNECTION_RESET, rv); 13084 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
13191 13085
13192 const HttpResponseInfo* response = trans->GetResponseInfo(); 13086 const HttpResponseInfo* response = trans->GetResponseInfo();
13193 EXPECT_TRUE(response == NULL); 13087 EXPECT_TRUE(response == NULL);
13194 } 13088 }
13195 13089
13196 } // namespace net 13090 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_proxy_client_socket.cc » ('j') | net/http/http_proxy_client_socket.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698