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 <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 10216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10227 "Host: www.example.com\r\n" | 10227 "Host: www.example.com\r\n" |
10228 "Connection: keep-alive\r\n\r\n"); | 10228 "Connection: keep-alive\r\n\r\n"); |
10229 const MockWrite kGetProxy( | 10229 const MockWrite kGetProxy( |
10230 "GET http://www.example.com/ HTTP/1.1\r\n" | 10230 "GET http://www.example.com/ HTTP/1.1\r\n" |
10231 "Host: www.example.com\r\n" | 10231 "Host: www.example.com\r\n" |
10232 "Proxy-Connection: keep-alive\r\n\r\n"); | 10232 "Proxy-Connection: keep-alive\r\n\r\n"); |
10233 const MockWrite kGetAuth( | 10233 const MockWrite kGetAuth( |
10234 "GET / HTTP/1.1\r\n" | 10234 "GET / HTTP/1.1\r\n" |
10235 "Host: www.example.com\r\n" | 10235 "Host: www.example.com\r\n" |
10236 "Connection: keep-alive\r\n" | 10236 "Connection: keep-alive\r\n" |
10237 "Authorization: auth_token\r\n\r\n"); | 10237 "Authorization: mock auth_token,realm=server\r\n\r\n"); |
10238 const MockWrite kGetProxyAuth( | 10238 const MockWrite kGetProxyAuth( |
10239 "GET http://www.example.com/ HTTP/1.1\r\n" | 10239 "GET http://www.example.com/ HTTP/1.1\r\n" |
10240 "Host: www.example.com\r\n" | 10240 "Host: www.example.com\r\n" |
10241 "Proxy-Connection: keep-alive\r\n" | 10241 "Proxy-Connection: keep-alive\r\n" |
10242 "Proxy-Authorization: auth_token\r\n\r\n"); | 10242 "Proxy-Authorization: mock auth_token,realm=proxy\r\n\r\n"); |
10243 const MockWrite kGetAuthThroughProxy( | 10243 const MockWrite kGetAuthThroughProxy( |
10244 "GET http://www.example.com/ HTTP/1.1\r\n" | 10244 "GET http://www.example.com/ HTTP/1.1\r\n" |
10245 "Host: www.example.com\r\n" | 10245 "Host: www.example.com\r\n" |
10246 "Proxy-Connection: keep-alive\r\n" | 10246 "Proxy-Connection: keep-alive\r\n" |
10247 "Authorization: auth_token\r\n\r\n"); | 10247 "Authorization: mock auth_token,realm=server\r\n\r\n"); |
10248 const MockWrite kGetAuthWithProxyAuth( | 10248 const MockWrite kGetAuthWithProxyAuth( |
10249 "GET http://www.example.com/ HTTP/1.1\r\n" | 10249 "GET http://www.example.com/ HTTP/1.1\r\n" |
10250 "Host: www.example.com\r\n" | 10250 "Host: www.example.com\r\n" |
10251 "Proxy-Connection: keep-alive\r\n" | 10251 "Proxy-Connection: keep-alive\r\n" |
10252 "Proxy-Authorization: auth_token\r\n" | 10252 "Proxy-Authorization: mock auth_token,realm=proxy\r\n" |
10253 "Authorization: auth_token\r\n\r\n"); | 10253 "Authorization: mock auth_token,realm=server\r\n\r\n"); |
10254 const MockWrite kConnect( | 10254 const MockWrite kConnect( |
10255 "CONNECT www.example.com:443 HTTP/1.1\r\n" | 10255 "CONNECT www.example.com:443 HTTP/1.1\r\n" |
10256 "Host: www.example.com\r\n" | 10256 "Host: www.example.com\r\n" |
10257 "Proxy-Connection: keep-alive\r\n\r\n"); | 10257 "Proxy-Connection: keep-alive\r\n\r\n"); |
10258 const MockWrite kConnectProxyAuth( | 10258 const MockWrite kConnectProxyAuth( |
10259 "CONNECT www.example.com:443 HTTP/1.1\r\n" | 10259 "CONNECT www.example.com:443 HTTP/1.1\r\n" |
10260 "Host: www.example.com\r\n" | 10260 "Host: www.example.com\r\n" |
10261 "Proxy-Connection: keep-alive\r\n" | 10261 "Proxy-Connection: keep-alive\r\n" |
10262 "Proxy-Authorization: auth_token\r\n\r\n"); | 10262 "Proxy-Authorization: mock auth_token,realm=proxy\r\n\r\n"); |
10263 | 10263 |
10264 const MockRead kSuccess( | 10264 const MockRead kSuccess( |
10265 "HTTP/1.1 200 OK\r\n" | 10265 "HTTP/1.1 200 OK\r\n" |
10266 "Content-Type: text/html; charset=iso-8859-1\r\n" | 10266 "Content-Type: text/html; charset=iso-8859-1\r\n" |
10267 "Content-Length: 3\r\n\r\n" | 10267 "Content-Length: 3\r\n\r\n" |
10268 "Yes"); | 10268 "Yes"); |
10269 const MockRead kFailure( | 10269 const MockRead kFailure( |
10270 "Should not be called."); | 10270 "Should not be called."); |
10271 const MockRead kServerChallenge( | 10271 const MockRead kServerChallenge( |
10272 "HTTP/1.1 401 Unauthorized\r\n" | 10272 "HTTP/1.1 401 Unauthorized\r\n" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10491 &kGet, &kServerChallenge), | 10491 &kGet, &kServerChallenge), |
10492 TestRound(kGetAuth, kSuccess, OK)}}, | 10492 TestRound(kGetAuth, kSuccess, OK)}}, |
10493 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, | 10493 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
10494 { TestRound(kConnect, kProxyChallenge, OK), | 10494 { TestRound(kConnect, kProxyChallenge, OK), |
10495 TestRound(kConnectProxyAuth, kProxyConnected, OK, | 10495 TestRound(kConnectProxyAuth, kProxyConnected, OK, |
10496 &kGet, &kServerChallenge), | 10496 &kGet, &kServerChallenge), |
10497 TestRound(kGetAuth, kFailure, kAuthErr)}}, | 10497 TestRound(kGetAuth, kFailure, kAuthErr)}}, |
10498 }; | 10498 }; |
10499 | 10499 |
10500 for (size_t i = 0; i < arraysize(test_configs); ++i) { | 10500 for (size_t i = 0; i < arraysize(test_configs); ++i) { |
| 10501 SCOPED_TRACE(::testing::Message() << "Test config " << i); |
10501 HttpAuthHandlerMock::Factory* auth_factory( | 10502 HttpAuthHandlerMock::Factory* auth_factory( |
10502 new HttpAuthHandlerMock::Factory()); | 10503 new HttpAuthHandlerMock::Factory()); |
10503 session_deps_.http_auth_handler_factory.reset(auth_factory); | 10504 session_deps_.http_auth_handler_factory.reset(auth_factory); |
10504 const TestConfig& test_config = test_configs[i]; | 10505 const TestConfig& test_config = test_configs[i]; |
10505 | 10506 |
10506 // Set up authentication handlers as necessary. | 10507 // Set up authentication handlers as necessary. |
10507 if (test_config.proxy_auth_timing != AUTH_NONE) { | 10508 if (test_config.proxy_auth_timing != AUTH_NONE) { |
10508 for (int n = 0; n < 2; n++) { | 10509 for (int n = 0; n < 2; n++) { |
10509 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); | 10510 scoped_ptr<HttpAuthHandlerMock> auth_handler(new HttpAuthHandlerMock()); |
10510 std::string auth_challenge = "Mock realm=proxy"; | |
10511 GURL origin(test_config.proxy_url); | |
10512 HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), | |
10513 auth_challenge.end()); | |
10514 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, | |
10515 origin, BoundNetLog()); | |
10516 auth_handler->SetGenerateExpectation( | 10511 auth_handler->SetGenerateExpectation( |
10517 test_config.proxy_auth_timing == AUTH_ASYNC, | 10512 test_config.proxy_auth_timing == AUTH_ASYNC, |
10518 test_config.proxy_auth_rv); | 10513 test_config.proxy_auth_rv); |
10519 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); | 10514 auth_factory->AddMockHandler( |
| 10515 auth_handler.Pass(), |
| 10516 n == 0 ? HttpAuthHandlerFactory::CREATE_CHALLENGE |
| 10517 : HttpAuthHandlerFactory::CREATE_PREEMPTIVE, |
| 10518 HttpAuth::AUTH_PROXY); |
10520 } | 10519 } |
10521 } | 10520 } |
10522 if (test_config.server_auth_timing != AUTH_NONE) { | 10521 if (test_config.server_auth_timing != AUTH_NONE) { |
10523 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); | 10522 scoped_ptr<HttpAuthHandlerMock> auth_handler(new HttpAuthHandlerMock()); |
10524 std::string auth_challenge = "Mock realm=server"; | |
10525 GURL origin(test_config.server_url); | |
10526 HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), | |
10527 auth_challenge.end()); | |
10528 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, | |
10529 origin, BoundNetLog()); | |
10530 auth_handler->SetGenerateExpectation( | 10523 auth_handler->SetGenerateExpectation( |
10531 test_config.server_auth_timing == AUTH_ASYNC, | 10524 test_config.server_auth_timing == AUTH_ASYNC, |
10532 test_config.server_auth_rv); | 10525 test_config.server_auth_rv); |
10533 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); | 10526 auth_factory->AddMockHandler(auth_handler.Pass(), |
| 10527 HttpAuthHandlerFactory::CREATE_CHALLENGE, |
| 10528 HttpAuth::AUTH_SERVER); |
10534 } | 10529 } |
10535 if (test_config.proxy_url) { | 10530 if (test_config.proxy_url) { |
10536 session_deps_.proxy_service = | 10531 session_deps_.proxy_service = |
10537 ProxyService::CreateFixed(test_config.proxy_url); | 10532 ProxyService::CreateFixed(test_config.proxy_url); |
10538 } else { | 10533 } else { |
10539 session_deps_.proxy_service = ProxyService::CreateDirect(); | 10534 session_deps_.proxy_service = ProxyService::CreateDirect(); |
10540 } | 10535 } |
10541 | 10536 |
10542 HttpRequestInfo request; | 10537 HttpRequestInfo request; |
10543 request.method = "GET"; | 10538 request.method = "GET"; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10582 ScopedVector<StaticSocketDataProvider> data_providers; | 10577 ScopedVector<StaticSocketDataProvider> data_providers; |
10583 for (size_t i = 0; i < mock_reads.size(); ++i) { | 10578 for (size_t i = 0; i < mock_reads.size(); ++i) { |
10584 data_providers.push_back(new StaticSocketDataProvider( | 10579 data_providers.push_back(new StaticSocketDataProvider( |
10585 vector_as_array(&mock_reads[i]), mock_reads[i].size(), | 10580 vector_as_array(&mock_reads[i]), mock_reads[i].size(), |
10586 vector_as_array(&mock_writes[i]), mock_writes[i].size())); | 10581 vector_as_array(&mock_writes[i]), mock_writes[i].size())); |
10587 session_deps_.socket_factory->AddSocketDataProvider( | 10582 session_deps_.socket_factory->AddSocketDataProvider( |
10588 data_providers.back()); | 10583 data_providers.back()); |
10589 } | 10584 } |
10590 | 10585 |
10591 for (int round = 0; round < test_config.num_auth_rounds; ++round) { | 10586 for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 10587 SCOPED_TRACE(::testing::Message() << "Test round " << round); |
10592 const TestRound& read_write_round = test_config.rounds[round]; | 10588 const TestRound& read_write_round = test_config.rounds[round]; |
10593 // Start or restart the transaction. | 10589 // Start or restart the transaction. |
10594 TestCompletionCallback callback; | 10590 TestCompletionCallback callback; |
10595 int rv; | 10591 int rv; |
10596 if (round == 0) { | 10592 if (round == 0) { |
10597 rv = trans.Start(&request, callback.callback(), BoundNetLog()); | 10593 rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
10598 } else { | 10594 } else { |
10599 rv = trans.RestartWithAuth( | 10595 rv = trans.RestartWithAuth( |
10600 AuthCredentials(kFoo, kBar), callback.callback()); | 10596 AuthCredentials(kFoo, kBar), callback.callback()); |
10601 } | 10597 } |
(...skipping 18 matching lines...) Expand all Loading... |
10620 | 10616 |
10621 TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { | 10617 TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
10622 // Do multi-round authentication and make sure it works correctly. | 10618 // Do multi-round authentication and make sure it works correctly. |
10623 HttpAuthHandlerMock::Factory* auth_factory( | 10619 HttpAuthHandlerMock::Factory* auth_factory( |
10624 new HttpAuthHandlerMock::Factory()); | 10620 new HttpAuthHandlerMock::Factory()); |
10625 session_deps_.http_auth_handler_factory.reset(auth_factory); | 10621 session_deps_.http_auth_handler_factory.reset(auth_factory); |
10626 session_deps_.proxy_service = ProxyService::CreateDirect(); | 10622 session_deps_.proxy_service = ProxyService::CreateDirect(); |
10627 session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); | 10623 session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
10628 session_deps_.host_resolver->set_synchronous_mode(true); | 10624 session_deps_.host_resolver->set_synchronous_mode(true); |
10629 | 10625 |
10630 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); | 10626 scoped_ptr<HttpAuthHandlerMock> auth_handler(new HttpAuthHandlerMock()); |
| 10627 auth_handler->SetGenerateExpectation(false, OK); |
10631 auth_handler->set_expect_multiple_challenges(true); | 10628 auth_handler->set_expect_multiple_challenges(true); |
10632 std::string auth_challenge = "Mock realm=server"; | 10629 auth_factory->AddMockHandler(auth_handler.Pass(), |
| 10630 HttpAuthHandlerFactory::CREATE_CHALLENGE, |
| 10631 HttpAuth::AUTH_SERVER); |
| 10632 |
10633 GURL origin("http://www.example.com"); | 10633 GURL origin("http://www.example.com"); |
10634 HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), | |
10635 auth_challenge.end()); | |
10636 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, | |
10637 origin, BoundNetLog()); | |
10638 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); | |
10639 | |
10640 int rv = OK; | 10634 int rv = OK; |
10641 const HttpResponseInfo* response = NULL; | 10635 const HttpResponseInfo* response = NULL; |
10642 HttpRequestInfo request; | 10636 HttpRequestInfo request; |
10643 request.method = "GET"; | 10637 request.method = "GET"; |
10644 request.url = origin; | 10638 request.url = origin; |
10645 request.load_flags = 0; | 10639 request.load_flags = 0; |
10646 | 10640 |
10647 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 10641 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
10648 | 10642 |
10649 // Use a TCP Socket Pool with only one connection per group. This is used | 10643 // Use a TCP Socket Pool with only one connection per group. This is used |
10650 // to validate that the TCP socket is not released to the pool between | 10644 // to validate that the TCP socket is not released to the pool between |
10651 // each round of multi-round authentication. | 10645 // each round of multi-round authentication. |
10652 HttpNetworkSessionPeer session_peer(session); | 10646 HttpNetworkSessionPeer session_peer(session); |
10653 TransportClientSocketPool* transport_pool = new TransportClientSocketPool( | 10647 TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
10654 50, // Max sockets for pool | 10648 50, // Max sockets for pool |
10655 1, // Max sockets per group | 10649 1, // Max sockets per group |
10656 session_deps_.host_resolver.get(), | 10650 session_deps_.host_resolver.get(), |
10657 session_deps_.socket_factory.get(), | 10651 session_deps_.socket_factory.get(), |
10658 session_deps_.net_log); | 10652 session_deps_.net_log); |
10659 scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( | 10653 scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
10660 new MockClientSocketPoolManager); | 10654 new MockClientSocketPoolManager); |
10661 mock_pool_manager->SetTransportSocketPool(transport_pool); | 10655 mock_pool_manager->SetTransportSocketPool(transport_pool); |
10662 session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); | 10656 session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
10663 | 10657 |
10664 scoped_ptr<HttpTransaction> trans( | 10658 scoped_ptr<HttpTransaction> trans( |
10665 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 10659 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
10666 TestCompletionCallback callback; | 10660 TestCompletionCallback callback; |
10667 | 10661 |
| 10662 // Initial request |
10668 const MockWrite kGet( | 10663 const MockWrite kGet( |
10669 "GET / HTTP/1.1\r\n" | 10664 "GET / HTTP/1.1\r\n" |
10670 "Host: www.example.com\r\n" | 10665 "Host: www.example.com\r\n" |
10671 "Connection: keep-alive\r\n\r\n"); | 10666 "Connection: keep-alive\r\n\r\n"); |
10672 const MockWrite kGetAuth( | |
10673 "GET / HTTP/1.1\r\n" | |
10674 "Host: www.example.com\r\n" | |
10675 "Connection: keep-alive\r\n" | |
10676 "Authorization: auth_token\r\n\r\n"); | |
10677 | 10667 |
| 10668 // Challenge / Response cycle. Repeats 3 times for primary request. Competing |
| 10669 // request never sees the server challenge. |
10678 const MockRead kServerChallenge( | 10670 const MockRead kServerChallenge( |
10679 "HTTP/1.1 401 Unauthorized\r\n" | 10671 "HTTP/1.1 401 Unauthorized\r\n" |
10680 "WWW-Authenticate: Mock realm=server\r\n" | 10672 "WWW-Authenticate: Mock realm=server\r\n" |
10681 "Content-Type: text/html; charset=iso-8859-1\r\n" | 10673 "Content-Type: text/html; charset=iso-8859-1\r\n" |
10682 "Content-Length: 14\r\n\r\n" | 10674 "Content-Length: 14\r\n\r\n" |
10683 "Unauthorized\r\n"); | 10675 "Unauthorized\r\n"); |
| 10676 const MockWrite kGetAuth( |
| 10677 "GET / HTTP/1.1\r\n" |
| 10678 "Host: www.example.com\r\n" |
| 10679 "Connection: keep-alive\r\n" |
| 10680 "Authorization: mock auth_token,realm=server\r\n\r\n"); |
| 10681 const MockWrite kGetAuthContinuation( |
| 10682 "GET / HTTP/1.1\r\n" |
| 10683 "Host: www.example.com\r\n" |
| 10684 "Connection: keep-alive\r\n" |
| 10685 "Authorization: mock continuation,realm=server\r\n\r\n"); |
| 10686 |
| 10687 // Final server response. |
10684 const MockRead kSuccess( | 10688 const MockRead kSuccess( |
10685 "HTTP/1.1 200 OK\r\n" | 10689 "HTTP/1.1 200 OK\r\n" |
10686 "Content-Type: text/html; charset=iso-8859-1\r\n" | 10690 "Content-Type: text/html; charset=iso-8859-1\r\n" |
10687 "Content-Length: 3\r\n\r\n" | 10691 "Content-Length: 3\r\n\r\n" |
10688 "Yes"); | 10692 "Yes"); |
10689 | 10693 |
10690 MockWrite writes[] = { | 10694 MockWrite writes[] = { |
10691 // First round | 10695 // First round |
10692 kGet, | 10696 kGet, |
10693 // Second round | 10697 // Second round |
10694 kGetAuth, | 10698 kGetAuth, |
10695 // Third round | 10699 // Third round |
10696 kGetAuth, | 10700 kGetAuthContinuation, |
10697 // Fourth round | 10701 // Fourth round |
10698 kGetAuth, | 10702 kGetAuthContinuation, |
10699 // Competing request | 10703 // Competing request |
10700 kGet, | 10704 kGet, |
10701 }; | 10705 }; |
10702 MockRead reads[] = { | 10706 MockRead reads[] = { |
10703 // First round | 10707 // First round |
10704 kServerChallenge, | 10708 kServerChallenge, |
10705 // Second round | 10709 // Second round |
10706 kServerChallenge, | 10710 kServerChallenge, |
10707 // Third round | 10711 // Third round |
10708 kServerChallenge, | 10712 kServerChallenge, |
10709 // Fourth round | 10713 // Fourth round |
10710 kSuccess, | 10714 kSuccess, |
10711 // Competing response | 10715 // Competing response |
10712 kSuccess, | 10716 kSuccess, |
10713 }; | 10717 }; |
10714 StaticSocketDataProvider data_provider(reads, arraysize(reads), | 10718 StaticSocketDataProvider data_provider(reads, arraysize(reads), |
10715 writes, arraysize(writes)); | 10719 writes, arraysize(writes)); |
10716 session_deps_.socket_factory->AddSocketDataProvider(&data_provider); | 10720 session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
10717 | 10721 |
10718 const char kSocketGroup[] = "www.example.com:80"; | 10722 const char kSocketGroup[] = "www.example.com:80"; |
10719 | 10723 |
10720 // First round of authentication. | 10724 // First round of authentication. |
10721 auth_handler->SetGenerateExpectation(false, OK); | |
10722 rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 10725 rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
10723 if (rv == ERR_IO_PENDING) | 10726 if (rv == ERR_IO_PENDING) |
10724 rv = callback.WaitForResult(); | 10727 rv = callback.WaitForResult(); |
10725 EXPECT_EQ(OK, rv); | 10728 EXPECT_EQ(OK, rv); |
10726 response = trans->GetResponseInfo(); | 10729 response = trans->GetResponseInfo(); |
10727 ASSERT_TRUE(response != NULL); | 10730 ASSERT_TRUE(response); |
10728 EXPECT_FALSE(response->auth_challenge.get() == NULL); | 10731 EXPECT_TRUE(response->auth_challenge.get()); |
10729 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); | 10732 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
10730 | 10733 |
10731 // In between rounds, another request comes in for the same domain. | 10734 // In between rounds, another request comes in for the same domain. |
10732 // It should not be able to grab the TCP socket that trans has already | 10735 // It should not be able to grab the TCP socket that trans has already |
10733 // claimed. | 10736 // claimed. |
10734 scoped_ptr<HttpTransaction> trans_compete( | 10737 scoped_ptr<HttpTransaction> trans_compete( |
10735 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 10738 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
10736 TestCompletionCallback callback_compete; | 10739 TestCompletionCallback callback_compete; |
10737 rv = trans_compete->Start( | 10740 rv = trans_compete->Start( |
10738 &request, callback_compete.callback(), BoundNetLog()); | 10741 &request, callback_compete.callback(), BoundNetLog()); |
10739 EXPECT_EQ(ERR_IO_PENDING, rv); | 10742 EXPECT_EQ(ERR_IO_PENDING, rv); |
10740 // callback_compete.WaitForResult at this point would stall forever, | 10743 // callback_compete.WaitForResult at this point would stall forever, |
10741 // since the HttpNetworkTransaction does not release the request back to | 10744 // since the HttpNetworkTransaction does not release the request back to |
10742 // the pool until after authentication completes. | 10745 // the pool until after authentication completes. |
10743 | 10746 |
10744 // Second round of authentication. | 10747 // Second round of authentication. |
10745 auth_handler->SetGenerateExpectation(false, OK); | |
10746 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); | 10748 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
10747 if (rv == ERR_IO_PENDING) | 10749 EXPECT_EQ(OK, callback.GetResult(rv)); |
10748 rv = callback.WaitForResult(); | |
10749 EXPECT_EQ(OK, rv); | |
10750 response = trans->GetResponseInfo(); | 10750 response = trans->GetResponseInfo(); |
10751 ASSERT_TRUE(response != NULL); | 10751 ASSERT_TRUE(response); |
10752 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 10752 EXPECT_FALSE(response->auth_challenge.get()); |
10753 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); | 10753 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
10754 | 10754 |
10755 // Third round of authentication. | 10755 // Third round of authentication. |
10756 auth_handler->SetGenerateExpectation(false, OK); | |
10757 rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); | 10756 rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
10758 if (rv == ERR_IO_PENDING) | 10757 EXPECT_EQ(OK, callback.GetResult(rv)); |
10759 rv = callback.WaitForResult(); | |
10760 EXPECT_EQ(OK, rv); | |
10761 response = trans->GetResponseInfo(); | 10758 response = trans->GetResponseInfo(); |
10762 ASSERT_TRUE(response != NULL); | 10759 ASSERT_TRUE(response); |
10763 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 10760 EXPECT_FALSE(response->auth_challenge.get()); |
10764 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); | 10761 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
10765 | 10762 |
10766 // Fourth round of authentication, which completes successfully. | 10763 // Fourth round of authentication, which completes successfully. |
10767 auth_handler->SetGenerateExpectation(false, OK); | |
10768 rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); | 10764 rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
10769 if (rv == ERR_IO_PENDING) | 10765 EXPECT_EQ(OK, callback.GetResult(rv)); |
10770 rv = callback.WaitForResult(); | |
10771 EXPECT_EQ(OK, rv); | |
10772 response = trans->GetResponseInfo(); | 10766 response = trans->GetResponseInfo(); |
10773 ASSERT_TRUE(response != NULL); | 10767 ASSERT_TRUE(response); |
10774 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 10768 EXPECT_FALSE(response->auth_challenge.get()); |
10775 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); | 10769 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
10776 | 10770 |
10777 // Read the body since the fourth round was successful. This will also | 10771 // Read the body since the fourth round was successful. This will also |
10778 // release the socket back to the pool. | 10772 // release the socket back to the pool. |
10779 scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); | 10773 scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
10780 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); | 10774 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
10781 if (rv == ERR_IO_PENDING) | 10775 EXPECT_EQ(3, callback.GetResult(rv)); |
10782 rv = callback.WaitForResult(); | |
10783 EXPECT_EQ(3, rv); | |
10784 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); | 10776 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
10785 EXPECT_EQ(0, rv); | 10777 EXPECT_EQ(0, rv); |
10786 // There are still 0 idle sockets, since the trans_compete transaction | 10778 // There are still 0 idle sockets, since the trans_compete transaction |
10787 // will be handed it immediately after trans releases it to the group. | 10779 // will be handed it immediately after trans releases it to the group. |
10788 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); | 10780 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
10789 | 10781 |
10790 // The competing request can now finish. Wait for the headers and then | 10782 // The competing request can now finish. Wait for the headers and then |
10791 // read the body. | 10783 // read the body. |
10792 rv = callback_compete.WaitForResult(); | 10784 rv = callback_compete.WaitForResult(); |
10793 EXPECT_EQ(OK, rv); | 10785 EXPECT_EQ(OK, rv); |
10794 rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); | 10786 rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
10795 if (rv == ERR_IO_PENDING) | 10787 EXPECT_EQ(3, callback.GetResult(rv)); |
10796 rv = callback.WaitForResult(); | |
10797 EXPECT_EQ(3, rv); | |
10798 rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); | 10788 rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
10799 EXPECT_EQ(0, rv); | 10789 EXPECT_EQ(0, rv); |
10800 | 10790 |
10801 // Finally, the socket is released to the group. | 10791 // Finally, the socket is released to the group. |
10802 EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); | 10792 EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
10803 } | 10793 } |
10804 | 10794 |
10805 // This tests the case that a request is issued via http instead of spdy after | 10795 // This tests the case that a request is issued via http instead of spdy after |
10806 // npn is negotiated. | 10796 // npn is negotiated. |
10807 TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { | 10797 TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10935 session_deps_.next_protos = SpdyNextProtos(); | 10925 session_deps_.next_protos = SpdyNextProtos(); |
10936 | 10926 |
10937 session_deps_.proxy_service = | 10927 session_deps_.proxy_service = |
10938 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); | 10928 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
10939 TestNetLog net_log; | 10929 TestNetLog net_log; |
10940 session_deps_.net_log = &net_log; | 10930 session_deps_.net_log = &net_log; |
10941 GURL request_url; | 10931 GURL request_url; |
10942 { | 10932 { |
10943 HttpAuthHandlerMock::Factory* auth_factory = | 10933 HttpAuthHandlerMock::Factory* auth_factory = |
10944 new HttpAuthHandlerMock::Factory(); | 10934 new HttpAuthHandlerMock::Factory(); |
10945 UrlRecordingHttpAuthHandlerMock* auth_handler = | 10935 scoped_ptr<UrlRecordingHttpAuthHandlerMock> auth_handler( |
10946 new UrlRecordingHttpAuthHandlerMock(&request_url); | 10936 new UrlRecordingHttpAuthHandlerMock(&request_url)); |
10947 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); | 10937 auth_factory->AddMockHandler(auth_handler.Pass(), |
10948 auth_factory->set_do_init_from_challenge(true); | 10938 HttpAuthHandlerFactory::CREATE_CHALLENGE, |
| 10939 HttpAuth::AUTH_PROXY); |
10949 session_deps_.http_auth_handler_factory.reset(auth_factory); | 10940 session_deps_.http_auth_handler_factory.reset(auth_factory); |
10950 } | 10941 } |
10951 | 10942 |
10952 HttpRequestInfo request; | 10943 HttpRequestInfo request; |
10953 request.method = "GET"; | 10944 request.method = "GET"; |
10954 request.url = GURL("http://www.example.org"); | 10945 request.url = GURL("http://www.example.org"); |
10955 request.load_flags = 0; | 10946 request.load_flags = 0; |
10956 | 10947 |
10957 // First round goes unauthenticated through the proxy. | 10948 // First round goes unauthenticated through the proxy. |
10958 MockWrite data_writes_1[] = { | 10949 MockWrite data_writes_1[] = { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11002 "CONNECT www.example.org:443 HTTP/1.1\r\n" | 10993 "CONNECT www.example.org:443 HTTP/1.1\r\n" |
11003 "Host: www.example.org\r\n" | 10994 "Host: www.example.org\r\n" |
11004 "Proxy-Connection: keep-alive\r\n" | 10995 "Proxy-Connection: keep-alive\r\n" |
11005 "\r\n"), | 10996 "\r\n"), |
11006 | 10997 |
11007 // Second connection attempt with Proxy-Authorization. | 10998 // Second connection attempt with Proxy-Authorization. |
11008 MockWrite(ASYNC, 2, | 10999 MockWrite(ASYNC, 2, |
11009 "CONNECT www.example.org:443 HTTP/1.1\r\n" | 11000 "CONNECT www.example.org:443 HTTP/1.1\r\n" |
11010 "Host: www.example.org\r\n" | 11001 "Host: www.example.org\r\n" |
11011 "Proxy-Connection: keep-alive\r\n" | 11002 "Proxy-Connection: keep-alive\r\n" |
11012 "Proxy-Authorization: auth_token\r\n" | 11003 "Proxy-Authorization: mock auth_token\r\n" |
11013 "\r\n"), | 11004 "\r\n"), |
11014 | 11005 |
11015 // SPDY request | 11006 // SPDY request |
11016 CreateMockWrite(*req, 4), | 11007 CreateMockWrite(*req, 4), |
11017 }; | 11008 }; |
11018 const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n" | 11009 const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n" |
11019 "Proxy-Authenticate: Mock\r\n" | 11010 "Proxy-Authenticate: Mock\r\n" |
11020 "Proxy-Connection: close\r\n" | 11011 "Proxy-Connection: close\r\n" |
11021 "\r\n"); | 11012 "\r\n"); |
11022 const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; | 11013 const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
(...skipping 3748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14771 std::string response_data; | 14762 std::string response_data; |
14772 EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 14763 EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
14773 | 14764 |
14774 EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), | 14765 EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
14775 trans->GetTotalSentBytes()); | 14766 trans->GetTotalSentBytes()); |
14776 EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), | 14767 EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
14777 trans->GetTotalReceivedBytes()); | 14768 trans->GetTotalReceivedBytes()); |
14778 } | 14769 } |
14779 | 14770 |
14780 } // namespace net | 14771 } // namespace net |
OLD | NEW |