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 26 matching lines...) Expand all Loading... |
37 #include "net/base/test_data_directory.h" | 37 #include "net/base/test_data_directory.h" |
38 #include "net/base/upload_bytes_element_reader.h" | 38 #include "net/base/upload_bytes_element_reader.h" |
39 #include "net/base/upload_file_element_reader.h" | 39 #include "net/base/upload_file_element_reader.h" |
40 #include "net/cert/mock_cert_verifier.h" | 40 #include "net/cert/mock_cert_verifier.h" |
41 #include "net/dns/host_cache.h" | 41 #include "net/dns/host_cache.h" |
42 #include "net/dns/mock_host_resolver.h" | 42 #include "net/dns/mock_host_resolver.h" |
43 #include "net/http/http_auth_challenge_tokenizer.h" | 43 #include "net/http/http_auth_challenge_tokenizer.h" |
44 #include "net/http/http_auth_handler_digest.h" | 44 #include "net/http/http_auth_handler_digest.h" |
45 #include "net/http/http_auth_handler_mock.h" | 45 #include "net/http/http_auth_handler_mock.h" |
46 #include "net/http/http_auth_handler_ntlm.h" | 46 #include "net/http/http_auth_handler_ntlm.h" |
| 47 #include "net/http/http_auth_scheme.h" |
47 #include "net/http/http_basic_state.h" | 48 #include "net/http/http_basic_state.h" |
48 #include "net/http/http_basic_stream.h" | 49 #include "net/http/http_basic_stream.h" |
49 #include "net/http/http_network_session.h" | 50 #include "net/http/http_network_session.h" |
50 #include "net/http/http_network_session_peer.h" | 51 #include "net/http/http_network_session_peer.h" |
51 #include "net/http/http_request_headers.h" | 52 #include "net/http/http_request_headers.h" |
52 #include "net/http/http_server_properties_impl.h" | 53 #include "net/http/http_server_properties_impl.h" |
53 #include "net/http/http_stream.h" | 54 #include "net/http/http_stream.h" |
54 #include "net/http/http_stream_factory.h" | 55 #include "net/http/http_stream_factory.h" |
55 #include "net/http/http_stream_parser.h" | 56 #include "net/http/http_stream_parser.h" |
56 #include "net/http/http_transaction_test_util.h" | 57 #include "net/http/http_transaction_test_util.h" |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 //----------------------------------------------------------------------------- | 661 //----------------------------------------------------------------------------- |
661 | 662 |
662 // Helper functions for validating that AuthChallengeInfo's are correctly | 663 // Helper functions for validating that AuthChallengeInfo's are correctly |
663 // configured for common cases. | 664 // configured for common cases. |
664 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { | 665 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
665 if (!auth_challenge) | 666 if (!auth_challenge) |
666 return false; | 667 return false; |
667 EXPECT_FALSE(auth_challenge->is_proxy); | 668 EXPECT_FALSE(auth_challenge->is_proxy); |
668 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); | 669 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
669 EXPECT_EQ("MyRealm1", auth_challenge->realm); | 670 EXPECT_EQ("MyRealm1", auth_challenge->realm); |
670 EXPECT_EQ("basic", auth_challenge->scheme); | 671 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
671 return true; | 672 return true; |
672 } | 673 } |
673 | 674 |
674 bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { | 675 bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
675 if (!auth_challenge) | 676 if (!auth_challenge) |
676 return false; | 677 return false; |
677 EXPECT_TRUE(auth_challenge->is_proxy); | 678 EXPECT_TRUE(auth_challenge->is_proxy); |
678 EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); | 679 EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
679 EXPECT_EQ("MyRealm1", auth_challenge->realm); | 680 EXPECT_EQ("MyRealm1", auth_challenge->realm); |
680 EXPECT_EQ("basic", auth_challenge->scheme); | 681 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
681 return true; | 682 return true; |
682 } | 683 } |
683 | 684 |
684 bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { | 685 bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
685 if (!auth_challenge) | 686 if (!auth_challenge) |
686 return false; | 687 return false; |
687 EXPECT_FALSE(auth_challenge->is_proxy); | 688 EXPECT_FALSE(auth_challenge->is_proxy); |
688 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); | 689 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
689 EXPECT_EQ("digestive", auth_challenge->realm); | 690 EXPECT_EQ("digestive", auth_challenge->realm); |
690 EXPECT_EQ("digest", auth_challenge->scheme); | 691 EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
691 return true; | 692 return true; |
692 } | 693 } |
693 | 694 |
694 #if defined(NTLM_PORTABLE) | 695 #if defined(NTLM_PORTABLE) |
695 bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { | 696 bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
696 if (!auth_challenge) | 697 if (!auth_challenge) |
697 return false; | 698 return false; |
698 EXPECT_FALSE(auth_challenge->is_proxy); | 699 EXPECT_FALSE(auth_challenge->is_proxy); |
699 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); | 700 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
700 EXPECT_EQ(std::string(), auth_challenge->realm); | 701 EXPECT_EQ(std::string(), auth_challenge->realm); |
701 EXPECT_EQ("ntlm", auth_challenge->scheme); | 702 EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
702 return true; | 703 return true; |
703 } | 704 } |
704 #endif // defined(NTLM_PORTABLE) | 705 #endif // defined(NTLM_PORTABLE) |
705 | 706 |
706 } // namespace | 707 } // namespace |
707 | 708 |
708 TEST_P(HttpNetworkTransactionTest, Basic) { | 709 TEST_P(HttpNetworkTransactionTest, Basic) { |
709 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 710 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
710 scoped_ptr<HttpTransaction> trans( | 711 scoped_ptr<HttpTransaction> trans( |
711 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 712 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
(...skipping 5804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6516 rv = callback1.WaitForResult(); | 6517 rv = callback1.WaitForResult(); |
6517 EXPECT_EQ(OK, rv); | 6518 EXPECT_EQ(OK, rv); |
6518 | 6519 |
6519 const HttpResponseInfo* response = trans->GetResponseInfo(); | 6520 const HttpResponseInfo* response = trans->GetResponseInfo(); |
6520 ASSERT_TRUE(response != NULL); | 6521 ASSERT_TRUE(response != NULL); |
6521 ASSERT_TRUE(response->auth_challenge.get()); | 6522 ASSERT_TRUE(response->auth_challenge.get()); |
6522 EXPECT_FALSE(response->auth_challenge->is_proxy); | 6523 EXPECT_FALSE(response->auth_challenge->is_proxy); |
6523 EXPECT_EQ("www.example.org:80", | 6524 EXPECT_EQ("www.example.org:80", |
6524 response->auth_challenge->challenger.ToString()); | 6525 response->auth_challenge->challenger.ToString()); |
6525 EXPECT_EQ("MyRealm2", response->auth_challenge->realm); | 6526 EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
6526 EXPECT_EQ("basic", response->auth_challenge->scheme); | 6527 EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
6527 | 6528 |
6528 TestCompletionCallback callback2; | 6529 TestCompletionCallback callback2; |
6529 | 6530 |
6530 rv = trans->RestartWithAuth( | 6531 rv = trans->RestartWithAuth( |
6531 AuthCredentials(kFoo2, kBar2), callback2.callback()); | 6532 AuthCredentials(kFoo2, kBar2), callback2.callback()); |
6532 EXPECT_EQ(ERR_IO_PENDING, rv); | 6533 EXPECT_EQ(ERR_IO_PENDING, rv); |
6533 | 6534 |
6534 rv = callback2.WaitForResult(); | 6535 rv = callback2.WaitForResult(); |
6535 EXPECT_EQ(OK, rv); | 6536 EXPECT_EQ(OK, rv); |
6536 | 6537 |
(...skipping 2809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9346 EXPECT_EQ(ERR_IO_PENDING, rv); | 9347 EXPECT_EQ(ERR_IO_PENDING, rv); |
9347 rv = callback1.WaitForResult(); | 9348 rv = callback1.WaitForResult(); |
9348 EXPECT_EQ(OK, rv); | 9349 EXPECT_EQ(OK, rv); |
9349 const HttpResponseInfo* response = trans->GetResponseInfo(); | 9350 const HttpResponseInfo* response = trans->GetResponseInfo(); |
9350 ASSERT_TRUE(response != NULL); | 9351 ASSERT_TRUE(response != NULL); |
9351 const AuthChallengeInfo* challenge = response->auth_challenge.get(); | 9352 const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
9352 ASSERT_FALSE(challenge == NULL); | 9353 ASSERT_FALSE(challenge == NULL); |
9353 EXPECT_FALSE(challenge->is_proxy); | 9354 EXPECT_FALSE(challenge->is_proxy); |
9354 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); | 9355 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
9355 EXPECT_EQ("first_realm", challenge->realm); | 9356 EXPECT_EQ("first_realm", challenge->realm); |
9356 EXPECT_EQ("basic", challenge->scheme); | 9357 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
9357 | 9358 |
9358 // Issue the second request with an incorrect password. There should be a | 9359 // Issue the second request with an incorrect password. There should be a |
9359 // password prompt for second_realm waiting to be filled in after the | 9360 // password prompt for second_realm waiting to be filled in after the |
9360 // transaction completes. | 9361 // transaction completes. |
9361 TestCompletionCallback callback2; | 9362 TestCompletionCallback callback2; |
9362 rv = trans->RestartWithAuth( | 9363 rv = trans->RestartWithAuth( |
9363 AuthCredentials(kFirst, kBaz), callback2.callback()); | 9364 AuthCredentials(kFirst, kBaz), callback2.callback()); |
9364 EXPECT_EQ(ERR_IO_PENDING, rv); | 9365 EXPECT_EQ(ERR_IO_PENDING, rv); |
9365 rv = callback2.WaitForResult(); | 9366 rv = callback2.WaitForResult(); |
9366 EXPECT_EQ(OK, rv); | 9367 EXPECT_EQ(OK, rv); |
9367 response = trans->GetResponseInfo(); | 9368 response = trans->GetResponseInfo(); |
9368 ASSERT_TRUE(response != NULL); | 9369 ASSERT_TRUE(response != NULL); |
9369 challenge = response->auth_challenge.get(); | 9370 challenge = response->auth_challenge.get(); |
9370 ASSERT_FALSE(challenge == NULL); | 9371 ASSERT_FALSE(challenge == NULL); |
9371 EXPECT_FALSE(challenge->is_proxy); | 9372 EXPECT_FALSE(challenge->is_proxy); |
9372 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); | 9373 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
9373 EXPECT_EQ("second_realm", challenge->realm); | 9374 EXPECT_EQ("second_realm", challenge->realm); |
9374 EXPECT_EQ("basic", challenge->scheme); | 9375 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
9375 | 9376 |
9376 // Issue the third request with another incorrect password. There should be | 9377 // Issue the third request with another incorrect password. There should be |
9377 // a password prompt for first_realm waiting to be filled in. If the password | 9378 // a password prompt for first_realm waiting to be filled in. If the password |
9378 // prompt is not present, it indicates that the HttpAuthCacheEntry for | 9379 // prompt is not present, it indicates that the HttpAuthCacheEntry for |
9379 // first_realm was not correctly removed. | 9380 // first_realm was not correctly removed. |
9380 TestCompletionCallback callback3; | 9381 TestCompletionCallback callback3; |
9381 rv = trans->RestartWithAuth( | 9382 rv = trans->RestartWithAuth( |
9382 AuthCredentials(kSecond, kFou), callback3.callback()); | 9383 AuthCredentials(kSecond, kFou), callback3.callback()); |
9383 EXPECT_EQ(ERR_IO_PENDING, rv); | 9384 EXPECT_EQ(ERR_IO_PENDING, rv); |
9384 rv = callback3.WaitForResult(); | 9385 rv = callback3.WaitForResult(); |
9385 EXPECT_EQ(OK, rv); | 9386 EXPECT_EQ(OK, rv); |
9386 response = trans->GetResponseInfo(); | 9387 response = trans->GetResponseInfo(); |
9387 ASSERT_TRUE(response != NULL); | 9388 ASSERT_TRUE(response != NULL); |
9388 challenge = response->auth_challenge.get(); | 9389 challenge = response->auth_challenge.get(); |
9389 ASSERT_FALSE(challenge == NULL); | 9390 ASSERT_FALSE(challenge == NULL); |
9390 EXPECT_FALSE(challenge->is_proxy); | 9391 EXPECT_FALSE(challenge->is_proxy); |
9391 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); | 9392 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
9392 EXPECT_EQ("first_realm", challenge->realm); | 9393 EXPECT_EQ("first_realm", challenge->realm); |
9393 EXPECT_EQ("basic", challenge->scheme); | 9394 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
9394 | 9395 |
9395 // Issue the fourth request with the correct password and username. | 9396 // Issue the fourth request with the correct password and username. |
9396 TestCompletionCallback callback4; | 9397 TestCompletionCallback callback4; |
9397 rv = trans->RestartWithAuth( | 9398 rv = trans->RestartWithAuth( |
9398 AuthCredentials(kFirst, kBar), callback4.callback()); | 9399 AuthCredentials(kFirst, kBar), callback4.callback()); |
9399 EXPECT_EQ(ERR_IO_PENDING, rv); | 9400 EXPECT_EQ(ERR_IO_PENDING, rv); |
9400 rv = callback4.WaitForResult(); | 9401 rv = callback4.WaitForResult(); |
9401 EXPECT_EQ(OK, rv); | 9402 EXPECT_EQ(OK, rv); |
9402 response = trans->GetResponseInfo(); | 9403 response = trans->GetResponseInfo(); |
9403 ASSERT_TRUE(response != NULL); | 9404 ASSERT_TRUE(response != NULL); |
(...skipping 6056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15460 std::string response_data; | 15461 std::string response_data; |
15461 EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 15462 EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
15462 | 15463 |
15463 EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), | 15464 EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
15464 trans->GetTotalSentBytes()); | 15465 trans->GetTotalSentBytes()); |
15465 EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), | 15466 EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
15466 trans->GetTotalReceivedBytes()); | 15467 trans->GetTotalReceivedBytes()); |
15467 } | 15468 } |
15468 | 15469 |
15469 } // namespace net | 15470 } // namespace net |
OLD | NEW |