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 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 } | 659 } |
660 | 660 |
661 //----------------------------------------------------------------------------- | 661 //----------------------------------------------------------------------------- |
662 | 662 |
663 // Helper functions for validating that AuthChallengeInfo's are correctly | 663 // Helper functions for validating that AuthChallengeInfo's are correctly |
664 // configured for common cases. | 664 // configured for common cases. |
665 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { | 665 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
666 if (!auth_challenge) | 666 if (!auth_challenge) |
667 return false; | 667 return false; |
668 EXPECT_FALSE(auth_challenge->is_proxy); | 668 EXPECT_FALSE(auth_challenge->is_proxy); |
669 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); | 669 EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
670 EXPECT_EQ("MyRealm1", auth_challenge->realm); | 670 EXPECT_EQ("MyRealm1", auth_challenge->realm); |
671 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); | 671 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
672 return true; | 672 return true; |
673 } | 673 } |
674 | 674 |
675 bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { | 675 bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
676 if (!auth_challenge) | 676 if (!auth_challenge) |
677 return false; | 677 return false; |
678 EXPECT_TRUE(auth_challenge->is_proxy); | 678 EXPECT_TRUE(auth_challenge->is_proxy); |
679 EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); | 679 EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
680 EXPECT_EQ("MyRealm1", auth_challenge->realm); | 680 EXPECT_EQ("MyRealm1", auth_challenge->realm); |
681 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); | 681 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
682 return true; | 682 return true; |
| 683 } |
| 684 |
| 685 bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 686 if (!auth_challenge) |
| 687 return false; |
| 688 EXPECT_TRUE(auth_challenge->is_proxy); |
| 689 EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
| 690 EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 691 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 692 return true; |
683 } | 693 } |
684 | 694 |
685 bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { | 695 bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
686 if (!auth_challenge) | 696 if (!auth_challenge) |
687 return false; | 697 return false; |
688 EXPECT_FALSE(auth_challenge->is_proxy); | 698 EXPECT_FALSE(auth_challenge->is_proxy); |
689 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); | 699 EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
690 EXPECT_EQ("digestive", auth_challenge->realm); | 700 EXPECT_EQ("digestive", auth_challenge->realm); |
691 EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); | 701 EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
692 return true; | 702 return true; |
693 } | 703 } |
694 | 704 |
695 #if defined(NTLM_PORTABLE) | 705 #if defined(NTLM_PORTABLE) |
696 bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { | 706 bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
697 if (!auth_challenge) | 707 if (!auth_challenge) |
698 return false; | 708 return false; |
699 EXPECT_FALSE(auth_challenge->is_proxy); | 709 EXPECT_FALSE(auth_challenge->is_proxy); |
700 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); | 710 EXPECT_EQ("http://172.22.68.17", auth_challenge->challenger.Serialize()); |
701 EXPECT_EQ(std::string(), auth_challenge->realm); | 711 EXPECT_EQ(std::string(), auth_challenge->realm); |
702 EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); | 712 EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
703 return true; | 713 return true; |
704 } | 714 } |
705 #endif // defined(NTLM_PORTABLE) | 715 #endif // defined(NTLM_PORTABLE) |
706 | 716 |
707 } // namespace | 717 } // namespace |
708 | 718 |
709 TEST_P(HttpNetworkTransactionTest, Basic) { | 719 TEST_P(HttpNetworkTransactionTest, Basic) { |
710 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 720 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
(...skipping 3967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4678 | 4688 |
4679 rv = callback1.WaitForResult(); | 4689 rv = callback1.WaitForResult(); |
4680 EXPECT_EQ(OK, rv); | 4690 EXPECT_EQ(OK, rv); |
4681 | 4691 |
4682 const HttpResponseInfo* const response = trans->GetResponseInfo(); | 4692 const HttpResponseInfo* const response = trans->GetResponseInfo(); |
4683 | 4693 |
4684 ASSERT_TRUE(response); | 4694 ASSERT_TRUE(response); |
4685 ASSERT_TRUE(response->headers); | 4695 ASSERT_TRUE(response->headers); |
4686 EXPECT_EQ(407, response->headers->response_code()); | 4696 EXPECT_EQ(407, response->headers->response_code()); |
4687 EXPECT_TRUE(response->was_fetched_via_spdy); | 4697 EXPECT_TRUE(response->was_fetched_via_spdy); |
4688 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); | 4698 EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
4689 | 4699 |
4690 TestCompletionCallback callback2; | 4700 TestCompletionCallback callback2; |
4691 | 4701 |
4692 rv = trans->RestartWithAuth( | 4702 rv = trans->RestartWithAuth( |
4693 AuthCredentials(kFoo, kBar), callback2.callback()); | 4703 AuthCredentials(kFoo, kBar), callback2.callback()); |
4694 EXPECT_EQ(ERR_IO_PENDING, rv); | 4704 EXPECT_EQ(ERR_IO_PENDING, rv); |
4695 | 4705 |
4696 rv = callback2.WaitForResult(); | 4706 rv = callback2.WaitForResult(); |
4697 EXPECT_EQ(OK, rv); | 4707 EXPECT_EQ(OK, rv); |
4698 | 4708 |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5372 LoadTimingInfo load_timing_info; | 5382 LoadTimingInfo load_timing_info; |
5373 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | 5383 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
5374 TestLoadTimingNotReused(load_timing_info, | 5384 TestLoadTimingNotReused(load_timing_info, |
5375 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); | 5385 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
5376 | 5386 |
5377 const HttpResponseInfo* response = trans->GetResponseInfo(); | 5387 const HttpResponseInfo* response = trans->GetResponseInfo(); |
5378 ASSERT_TRUE(response); | 5388 ASSERT_TRUE(response); |
5379 ASSERT_TRUE(response->headers); | 5389 ASSERT_TRUE(response->headers); |
5380 EXPECT_EQ(407, response->headers->response_code()); | 5390 EXPECT_EQ(407, response->headers->response_code()); |
5381 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | 5391 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
5382 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); | 5392 EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
5383 | 5393 |
5384 TestCompletionCallback callback2; | 5394 TestCompletionCallback callback2; |
5385 | 5395 |
5386 rv = trans->RestartWithAuth( | 5396 rv = trans->RestartWithAuth( |
5387 AuthCredentials(kFoo, kBar), callback2.callback()); | 5397 AuthCredentials(kFoo, kBar), callback2.callback()); |
5388 EXPECT_EQ(ERR_IO_PENDING, rv); | 5398 EXPECT_EQ(ERR_IO_PENDING, rv); |
5389 | 5399 |
5390 rv = callback2.WaitForResult(); | 5400 rv = callback2.WaitForResult(); |
5391 EXPECT_EQ(OK, rv); | 5401 EXPECT_EQ(OK, rv); |
5392 | 5402 |
(...skipping 1560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6953 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | 6963 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
6954 EXPECT_EQ(ERR_IO_PENDING, rv); | 6964 EXPECT_EQ(ERR_IO_PENDING, rv); |
6955 | 6965 |
6956 rv = callback1.WaitForResult(); | 6966 rv = callback1.WaitForResult(); |
6957 EXPECT_EQ(OK, rv); | 6967 EXPECT_EQ(OK, rv); |
6958 | 6968 |
6959 const HttpResponseInfo* response = trans->GetResponseInfo(); | 6969 const HttpResponseInfo* response = trans->GetResponseInfo(); |
6960 ASSERT_TRUE(response); | 6970 ASSERT_TRUE(response); |
6961 ASSERT_TRUE(response->auth_challenge); | 6971 ASSERT_TRUE(response->auth_challenge); |
6962 EXPECT_FALSE(response->auth_challenge->is_proxy); | 6972 EXPECT_FALSE(response->auth_challenge->is_proxy); |
6963 EXPECT_EQ("www.example.org:80", | 6973 EXPECT_EQ("http://www.example.org", |
6964 response->auth_challenge->challenger.ToString()); | 6974 response->auth_challenge->challenger.Serialize()); |
6965 EXPECT_EQ("MyRealm2", response->auth_challenge->realm); | 6975 EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
6966 EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); | 6976 EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
6967 | 6977 |
6968 TestCompletionCallback callback2; | 6978 TestCompletionCallback callback2; |
6969 | 6979 |
6970 rv = trans->RestartWithAuth( | 6980 rv = trans->RestartWithAuth( |
6971 AuthCredentials(kFoo2, kBar2), callback2.callback()); | 6981 AuthCredentials(kFoo2, kBar2), callback2.callback()); |
6972 EXPECT_EQ(ERR_IO_PENDING, rv); | 6982 EXPECT_EQ(ERR_IO_PENDING, rv); |
6973 | 6983 |
6974 rv = callback2.WaitForResult(); | 6984 rv = callback2.WaitForResult(); |
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7927 entries, pos, | 7937 entries, pos, |
7928 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, | 7938 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
7929 NetLog::PHASE_NONE); | 7939 NetLog::PHASE_NONE); |
7930 | 7940 |
7931 const HttpResponseInfo* response = trans->GetResponseInfo(); | 7941 const HttpResponseInfo* response = trans->GetResponseInfo(); |
7932 ASSERT_TRUE(response); | 7942 ASSERT_TRUE(response); |
7933 ASSERT_TRUE(response->headers); | 7943 ASSERT_TRUE(response->headers); |
7934 EXPECT_EQ(407, response->headers->response_code()); | 7944 EXPECT_EQ(407, response->headers->response_code()); |
7935 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | 7945 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
7936 EXPECT_TRUE(response->auth_challenge); | 7946 EXPECT_TRUE(response->auth_challenge); |
7937 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); | 7947 EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
7938 | 7948 |
7939 TestCompletionCallback callback2; | 7949 TestCompletionCallback callback2; |
7940 | 7950 |
7941 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), | 7951 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
7942 callback2.callback()); | 7952 callback2.callback()); |
7943 EXPECT_EQ(ERR_IO_PENDING, rv); | 7953 EXPECT_EQ(ERR_IO_PENDING, rv); |
7944 | 7954 |
7945 rv = callback2.WaitForResult(); | 7955 rv = callback2.WaitForResult(); |
7946 EXPECT_EQ(OK, rv); | 7956 EXPECT_EQ(OK, rv); |
7947 | 7957 |
(...skipping 1921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9869 // transaction completes. | 9879 // transaction completes. |
9870 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | 9880 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
9871 EXPECT_EQ(ERR_IO_PENDING, rv); | 9881 EXPECT_EQ(ERR_IO_PENDING, rv); |
9872 rv = callback1.WaitForResult(); | 9882 rv = callback1.WaitForResult(); |
9873 EXPECT_EQ(OK, rv); | 9883 EXPECT_EQ(OK, rv); |
9874 const HttpResponseInfo* response = trans->GetResponseInfo(); | 9884 const HttpResponseInfo* response = trans->GetResponseInfo(); |
9875 ASSERT_TRUE(response); | 9885 ASSERT_TRUE(response); |
9876 const AuthChallengeInfo* challenge = response->auth_challenge.get(); | 9886 const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
9877 ASSERT_TRUE(challenge); | 9887 ASSERT_TRUE(challenge); |
9878 EXPECT_FALSE(challenge->is_proxy); | 9888 EXPECT_FALSE(challenge->is_proxy); |
9879 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); | 9889 EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
9880 EXPECT_EQ("first_realm", challenge->realm); | 9890 EXPECT_EQ("first_realm", challenge->realm); |
9881 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); | 9891 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
9882 | 9892 |
9883 // Issue the second request with an incorrect password. There should be a | 9893 // Issue the second request with an incorrect password. There should be a |
9884 // password prompt for second_realm waiting to be filled in after the | 9894 // password prompt for second_realm waiting to be filled in after the |
9885 // transaction completes. | 9895 // transaction completes. |
9886 TestCompletionCallback callback2; | 9896 TestCompletionCallback callback2; |
9887 rv = trans->RestartWithAuth( | 9897 rv = trans->RestartWithAuth( |
9888 AuthCredentials(kFirst, kBaz), callback2.callback()); | 9898 AuthCredentials(kFirst, kBaz), callback2.callback()); |
9889 EXPECT_EQ(ERR_IO_PENDING, rv); | 9899 EXPECT_EQ(ERR_IO_PENDING, rv); |
9890 rv = callback2.WaitForResult(); | 9900 rv = callback2.WaitForResult(); |
9891 EXPECT_EQ(OK, rv); | 9901 EXPECT_EQ(OK, rv); |
9892 response = trans->GetResponseInfo(); | 9902 response = trans->GetResponseInfo(); |
9893 ASSERT_TRUE(response); | 9903 ASSERT_TRUE(response); |
9894 challenge = response->auth_challenge.get(); | 9904 challenge = response->auth_challenge.get(); |
9895 ASSERT_TRUE(challenge); | 9905 ASSERT_TRUE(challenge); |
9896 EXPECT_FALSE(challenge->is_proxy); | 9906 EXPECT_FALSE(challenge->is_proxy); |
9897 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); | 9907 EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
9898 EXPECT_EQ("second_realm", challenge->realm); | 9908 EXPECT_EQ("second_realm", challenge->realm); |
9899 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); | 9909 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
9900 | 9910 |
9901 // Issue the third request with another incorrect password. There should be | 9911 // Issue the third request with another incorrect password. There should be |
9902 // a password prompt for first_realm waiting to be filled in. If the password | 9912 // a password prompt for first_realm waiting to be filled in. If the password |
9903 // prompt is not present, it indicates that the HttpAuthCacheEntry for | 9913 // prompt is not present, it indicates that the HttpAuthCacheEntry for |
9904 // first_realm was not correctly removed. | 9914 // first_realm was not correctly removed. |
9905 TestCompletionCallback callback3; | 9915 TestCompletionCallback callback3; |
9906 rv = trans->RestartWithAuth( | 9916 rv = trans->RestartWithAuth( |
9907 AuthCredentials(kSecond, kFou), callback3.callback()); | 9917 AuthCredentials(kSecond, kFou), callback3.callback()); |
9908 EXPECT_EQ(ERR_IO_PENDING, rv); | 9918 EXPECT_EQ(ERR_IO_PENDING, rv); |
9909 rv = callback3.WaitForResult(); | 9919 rv = callback3.WaitForResult(); |
9910 EXPECT_EQ(OK, rv); | 9920 EXPECT_EQ(OK, rv); |
9911 response = trans->GetResponseInfo(); | 9921 response = trans->GetResponseInfo(); |
9912 ASSERT_TRUE(response); | 9922 ASSERT_TRUE(response); |
9913 challenge = response->auth_challenge.get(); | 9923 challenge = response->auth_challenge.get(); |
9914 ASSERT_TRUE(challenge); | 9924 ASSERT_TRUE(challenge); |
9915 EXPECT_FALSE(challenge->is_proxy); | 9925 EXPECT_FALSE(challenge->is_proxy); |
9916 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); | 9926 EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
9917 EXPECT_EQ("first_realm", challenge->realm); | 9927 EXPECT_EQ("first_realm", challenge->realm); |
9918 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); | 9928 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
9919 | 9929 |
9920 // Issue the fourth request with the correct password and username. | 9930 // Issue the fourth request with the correct password and username. |
9921 TestCompletionCallback callback4; | 9931 TestCompletionCallback callback4; |
9922 rv = trans->RestartWithAuth( | 9932 rv = trans->RestartWithAuth( |
9923 AuthCredentials(kFirst, kBar), callback4.callback()); | 9933 AuthCredentials(kFirst, kBar), callback4.callback()); |
9924 EXPECT_EQ(ERR_IO_PENDING, rv); | 9934 EXPECT_EQ(ERR_IO_PENDING, rv); |
9925 rv = callback4.WaitForResult(); | 9935 rv = callback4.WaitForResult(); |
9926 EXPECT_EQ(OK, rv); | 9936 EXPECT_EQ(OK, rv); |
(...skipping 6187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16114 base::RunLoop().RunUntilIdle(); | 16124 base::RunLoop().RunUntilIdle(); |
16115 | 16125 |
16116 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); | 16126 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
16117 HttpRequestHeaders headers; | 16127 HttpRequestHeaders headers; |
16118 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); | 16128 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
16119 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); | 16129 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
16120 } | 16130 } |
16121 #endif // !defined(OS_IOS) | 16131 #endif // !defined(OS_IOS) |
16122 | 16132 |
16123 } // namespace net | 16133 } // namespace net |
OLD | NEW |