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 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 //----------------------------------------------------------------------------- | 635 //----------------------------------------------------------------------------- |
635 | 636 |
636 // Helper functions for validating that AuthChallengeInfo's are correctly | 637 // Helper functions for validating that AuthChallengeInfo's are correctly |
637 // configured for common cases. | 638 // configured for common cases. |
638 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { | 639 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
639 if (!auth_challenge) | 640 if (!auth_challenge) |
640 return false; | 641 return false; |
641 EXPECT_FALSE(auth_challenge->is_proxy); | 642 EXPECT_FALSE(auth_challenge->is_proxy); |
642 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); | 643 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
643 EXPECT_EQ("MyRealm1", auth_challenge->realm); | 644 EXPECT_EQ("MyRealm1", auth_challenge->realm); |
644 EXPECT_EQ("basic", auth_challenge->scheme); | 645 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
645 return true; | 646 return true; |
646 } | 647 } |
647 | 648 |
648 bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { | 649 bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
649 if (!auth_challenge) | 650 if (!auth_challenge) |
650 return false; | 651 return false; |
651 EXPECT_TRUE(auth_challenge->is_proxy); | 652 EXPECT_TRUE(auth_challenge->is_proxy); |
652 EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); | 653 EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
653 EXPECT_EQ("MyRealm1", auth_challenge->realm); | 654 EXPECT_EQ("MyRealm1", auth_challenge->realm); |
654 EXPECT_EQ("basic", auth_challenge->scheme); | 655 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
655 return true; | 656 return true; |
656 } | 657 } |
657 | 658 |
658 bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { | 659 bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
659 if (!auth_challenge) | 660 if (!auth_challenge) |
660 return false; | 661 return false; |
661 EXPECT_FALSE(auth_challenge->is_proxy); | 662 EXPECT_FALSE(auth_challenge->is_proxy); |
662 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); | 663 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
663 EXPECT_EQ("digestive", auth_challenge->realm); | 664 EXPECT_EQ("digestive", auth_challenge->realm); |
664 EXPECT_EQ("digest", auth_challenge->scheme); | 665 EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
665 return true; | 666 return true; |
666 } | 667 } |
667 | 668 |
668 #if defined(NTLM_PORTABLE) | 669 #if defined(NTLM_PORTABLE) |
669 bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { | 670 bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
670 if (!auth_challenge) | 671 if (!auth_challenge) |
671 return false; | 672 return false; |
672 EXPECT_FALSE(auth_challenge->is_proxy); | 673 EXPECT_FALSE(auth_challenge->is_proxy); |
673 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); | 674 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
674 EXPECT_EQ(std::string(), auth_challenge->realm); | 675 EXPECT_EQ(std::string(), auth_challenge->realm); |
675 EXPECT_EQ("ntlm", auth_challenge->scheme); | 676 EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
676 return true; | 677 return true; |
677 } | 678 } |
678 #endif // defined(NTLM_PORTABLE) | 679 #endif // defined(NTLM_PORTABLE) |
679 | 680 |
680 } // namespace | 681 } // namespace |
681 | 682 |
682 TEST_P(HttpNetworkTransactionTest, Basic) { | 683 TEST_P(HttpNetworkTransactionTest, Basic) { |
683 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 684 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
684 scoped_ptr<HttpTransaction> trans( | 685 scoped_ptr<HttpTransaction> trans( |
685 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 686 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
(...skipping 5816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6502 rv = callback1.WaitForResult(); | 6503 rv = callback1.WaitForResult(); |
6503 EXPECT_EQ(OK, rv); | 6504 EXPECT_EQ(OK, rv); |
6504 | 6505 |
6505 const HttpResponseInfo* response = trans->GetResponseInfo(); | 6506 const HttpResponseInfo* response = trans->GetResponseInfo(); |
6506 ASSERT_TRUE(response != NULL); | 6507 ASSERT_TRUE(response != NULL); |
6507 ASSERT_TRUE(response->auth_challenge.get()); | 6508 ASSERT_TRUE(response->auth_challenge.get()); |
6508 EXPECT_FALSE(response->auth_challenge->is_proxy); | 6509 EXPECT_FALSE(response->auth_challenge->is_proxy); |
6509 EXPECT_EQ("www.example.org:80", | 6510 EXPECT_EQ("www.example.org:80", |
6510 response->auth_challenge->challenger.ToString()); | 6511 response->auth_challenge->challenger.ToString()); |
6511 EXPECT_EQ("MyRealm2", response->auth_challenge->realm); | 6512 EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
6512 EXPECT_EQ("basic", response->auth_challenge->scheme); | 6513 EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
6513 | 6514 |
6514 TestCompletionCallback callback2; | 6515 TestCompletionCallback callback2; |
6515 | 6516 |
6516 rv = trans->RestartWithAuth( | 6517 rv = trans->RestartWithAuth( |
6517 AuthCredentials(kFoo2, kBar2), callback2.callback()); | 6518 AuthCredentials(kFoo2, kBar2), callback2.callback()); |
6518 EXPECT_EQ(ERR_IO_PENDING, rv); | 6519 EXPECT_EQ(ERR_IO_PENDING, rv); |
6519 | 6520 |
6520 rv = callback2.WaitForResult(); | 6521 rv = callback2.WaitForResult(); |
6521 EXPECT_EQ(OK, rv); | 6522 EXPECT_EQ(OK, rv); |
6522 | 6523 |
(...skipping 2819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9342 EXPECT_EQ(ERR_IO_PENDING, rv); | 9343 EXPECT_EQ(ERR_IO_PENDING, rv); |
9343 rv = callback1.WaitForResult(); | 9344 rv = callback1.WaitForResult(); |
9344 EXPECT_EQ(OK, rv); | 9345 EXPECT_EQ(OK, rv); |
9345 const HttpResponseInfo* response = trans->GetResponseInfo(); | 9346 const HttpResponseInfo* response = trans->GetResponseInfo(); |
9346 ASSERT_TRUE(response != NULL); | 9347 ASSERT_TRUE(response != NULL); |
9347 const AuthChallengeInfo* challenge = response->auth_challenge.get(); | 9348 const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
9348 ASSERT_FALSE(challenge == NULL); | 9349 ASSERT_FALSE(challenge == NULL); |
9349 EXPECT_FALSE(challenge->is_proxy); | 9350 EXPECT_FALSE(challenge->is_proxy); |
9350 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); | 9351 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
9351 EXPECT_EQ("first_realm", challenge->realm); | 9352 EXPECT_EQ("first_realm", challenge->realm); |
9352 EXPECT_EQ("basic", challenge->scheme); | 9353 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
9353 | 9354 |
9354 // Issue the second request with an incorrect password. There should be a | 9355 // Issue the second request with an incorrect password. There should be a |
9355 // password prompt for second_realm waiting to be filled in after the | 9356 // password prompt for second_realm waiting to be filled in after the |
9356 // transaction completes. | 9357 // transaction completes. |
9357 TestCompletionCallback callback2; | 9358 TestCompletionCallback callback2; |
9358 rv = trans->RestartWithAuth( | 9359 rv = trans->RestartWithAuth( |
9359 AuthCredentials(kFirst, kBaz), callback2.callback()); | 9360 AuthCredentials(kFirst, kBaz), callback2.callback()); |
9360 EXPECT_EQ(ERR_IO_PENDING, rv); | 9361 EXPECT_EQ(ERR_IO_PENDING, rv); |
9361 rv = callback2.WaitForResult(); | 9362 rv = callback2.WaitForResult(); |
9362 EXPECT_EQ(OK, rv); | 9363 EXPECT_EQ(OK, rv); |
9363 response = trans->GetResponseInfo(); | 9364 response = trans->GetResponseInfo(); |
9364 ASSERT_TRUE(response != NULL); | 9365 ASSERT_TRUE(response != NULL); |
9365 challenge = response->auth_challenge.get(); | 9366 challenge = response->auth_challenge.get(); |
9366 ASSERT_FALSE(challenge == NULL); | 9367 ASSERT_FALSE(challenge == NULL); |
9367 EXPECT_FALSE(challenge->is_proxy); | 9368 EXPECT_FALSE(challenge->is_proxy); |
9368 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); | 9369 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
9369 EXPECT_EQ("second_realm", challenge->realm); | 9370 EXPECT_EQ("second_realm", challenge->realm); |
9370 EXPECT_EQ("basic", challenge->scheme); | 9371 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
9371 | 9372 |
9372 // Issue the third request with another incorrect password. There should be | 9373 // Issue the third request with another incorrect password. There should be |
9373 // a password prompt for first_realm waiting to be filled in. If the password | 9374 // a password prompt for first_realm waiting to be filled in. If the password |
9374 // prompt is not present, it indicates that the HttpAuthCacheEntry for | 9375 // prompt is not present, it indicates that the HttpAuthCacheEntry for |
9375 // first_realm was not correctly removed. | 9376 // first_realm was not correctly removed. |
9376 TestCompletionCallback callback3; | 9377 TestCompletionCallback callback3; |
9377 rv = trans->RestartWithAuth( | 9378 rv = trans->RestartWithAuth( |
9378 AuthCredentials(kSecond, kFou), callback3.callback()); | 9379 AuthCredentials(kSecond, kFou), callback3.callback()); |
9379 EXPECT_EQ(ERR_IO_PENDING, rv); | 9380 EXPECT_EQ(ERR_IO_PENDING, rv); |
9380 rv = callback3.WaitForResult(); | 9381 rv = callback3.WaitForResult(); |
9381 EXPECT_EQ(OK, rv); | 9382 EXPECT_EQ(OK, rv); |
9382 response = trans->GetResponseInfo(); | 9383 response = trans->GetResponseInfo(); |
9383 ASSERT_TRUE(response != NULL); | 9384 ASSERT_TRUE(response != NULL); |
9384 challenge = response->auth_challenge.get(); | 9385 challenge = response->auth_challenge.get(); |
9385 ASSERT_FALSE(challenge == NULL); | 9386 ASSERT_FALSE(challenge == NULL); |
9386 EXPECT_FALSE(challenge->is_proxy); | 9387 EXPECT_FALSE(challenge->is_proxy); |
9387 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); | 9388 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
9388 EXPECT_EQ("first_realm", challenge->realm); | 9389 EXPECT_EQ("first_realm", challenge->realm); |
9389 EXPECT_EQ("basic", challenge->scheme); | 9390 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
9390 | 9391 |
9391 // Issue the fourth request with the correct password and username. | 9392 // Issue the fourth request with the correct password and username. |
9392 TestCompletionCallback callback4; | 9393 TestCompletionCallback callback4; |
9393 rv = trans->RestartWithAuth( | 9394 rv = trans->RestartWithAuth( |
9394 AuthCredentials(kFirst, kBar), callback4.callback()); | 9395 AuthCredentials(kFirst, kBar), callback4.callback()); |
9395 EXPECT_EQ(ERR_IO_PENDING, rv); | 9396 EXPECT_EQ(ERR_IO_PENDING, rv); |
9396 rv = callback4.WaitForResult(); | 9397 rv = callback4.WaitForResult(); |
9397 EXPECT_EQ(OK, rv); | 9398 EXPECT_EQ(OK, rv); |
9398 response = trans->GetResponseInfo(); | 9399 response = trans->GetResponseInfo(); |
9399 ASSERT_TRUE(response != NULL); | 9400 ASSERT_TRUE(response != NULL); |
(...skipping 5967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15367 std::string response_data; | 15368 std::string response_data; |
15368 EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 15369 EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
15369 | 15370 |
15370 EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), | 15371 EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
15371 trans->GetTotalSentBytes()); | 15372 trans->GetTotalSentBytes()); |
15372 EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), | 15373 EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
15373 trans->GetTotalReceivedBytes()); | 15374 trans->GetTotalReceivedBytes()); |
15374 } | 15375 } |
15375 | 15376 |
15376 } // namespace net | 15377 } // namespace net |
OLD | NEW |