| 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 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 } | 670 } |
| 671 | 671 |
| 672 //----------------------------------------------------------------------------- | 672 //----------------------------------------------------------------------------- |
| 673 | 673 |
| 674 // Helper functions for validating that AuthChallengeInfo's are correctly | 674 // Helper functions for validating that AuthChallengeInfo's are correctly |
| 675 // configured for common cases. | 675 // configured for common cases. |
| 676 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { | 676 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 677 if (!auth_challenge) | 677 if (!auth_challenge) |
| 678 return false; | 678 return false; |
| 679 EXPECT_FALSE(auth_challenge->is_proxy); | 679 EXPECT_FALSE(auth_challenge->is_proxy); |
| 680 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); | 680 EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
| 681 EXPECT_EQ("MyRealm1", auth_challenge->realm); | 681 EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 682 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); | 682 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 683 return true; | 683 return true; |
| 684 } | 684 } |
| 685 | 685 |
| 686 bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { | 686 bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 687 if (!auth_challenge) | 687 if (!auth_challenge) |
| 688 return false; | 688 return false; |
| 689 EXPECT_TRUE(auth_challenge->is_proxy); | 689 EXPECT_TRUE(auth_challenge->is_proxy); |
| 690 EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); | 690 EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 691 EXPECT_EQ("MyRealm1", auth_challenge->realm); | 691 EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 692 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); | 692 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 693 return true; | 693 return true; |
| 694 } |
| 695 |
| 696 bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 697 if (!auth_challenge) |
| 698 return false; |
| 699 EXPECT_TRUE(auth_challenge->is_proxy); |
| 700 EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
| 701 EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 702 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 703 return true; |
| 694 } | 704 } |
| 695 | 705 |
| 696 bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { | 706 bool CheckDigestServerAuth(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("www.example.org:80", auth_challenge->challenger.ToString()); | 710 EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
| 701 EXPECT_EQ("digestive", auth_challenge->realm); | 711 EXPECT_EQ("digestive", auth_challenge->realm); |
| 702 EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); | 712 EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
| 703 return true; | 713 return true; |
| 704 } | 714 } |
| 705 | 715 |
| 706 #if defined(NTLM_PORTABLE) | 716 #if defined(NTLM_PORTABLE) |
| 707 bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { | 717 bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 708 if (!auth_challenge) | 718 if (!auth_challenge) |
| 709 return false; | 719 return false; |
| 710 EXPECT_FALSE(auth_challenge->is_proxy); | 720 EXPECT_FALSE(auth_challenge->is_proxy); |
| 711 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); | 721 EXPECT_EQ("http://172.22.68.17", auth_challenge->challenger.Serialize()); |
| 712 EXPECT_EQ(std::string(), auth_challenge->realm); | 722 EXPECT_EQ(std::string(), auth_challenge->realm); |
| 713 EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); | 723 EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
| 714 return true; | 724 return true; |
| 715 } | 725 } |
| 716 #endif // defined(NTLM_PORTABLE) | 726 #endif // defined(NTLM_PORTABLE) |
| 717 | 727 |
| 718 } // namespace | 728 } // namespace |
| 719 | 729 |
| 720 TEST_P(HttpNetworkTransactionTest, Basic) { | 730 TEST_P(HttpNetworkTransactionTest, Basic) { |
| 721 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 731 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| (...skipping 3968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4690 | 4700 |
| 4691 rv = callback1.WaitForResult(); | 4701 rv = callback1.WaitForResult(); |
| 4692 EXPECT_EQ(OK, rv); | 4702 EXPECT_EQ(OK, rv); |
| 4693 | 4703 |
| 4694 const HttpResponseInfo* const response = trans->GetResponseInfo(); | 4704 const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 4695 | 4705 |
| 4696 ASSERT_TRUE(response); | 4706 ASSERT_TRUE(response); |
| 4697 ASSERT_TRUE(response->headers); | 4707 ASSERT_TRUE(response->headers); |
| 4698 EXPECT_EQ(407, response->headers->response_code()); | 4708 EXPECT_EQ(407, response->headers->response_code()); |
| 4699 EXPECT_TRUE(response->was_fetched_via_spdy); | 4709 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4700 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); | 4710 EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
| 4701 | 4711 |
| 4702 TestCompletionCallback callback2; | 4712 TestCompletionCallback callback2; |
| 4703 | 4713 |
| 4704 rv = trans->RestartWithAuth( | 4714 rv = trans->RestartWithAuth( |
| 4705 AuthCredentials(kFoo, kBar), callback2.callback()); | 4715 AuthCredentials(kFoo, kBar), callback2.callback()); |
| 4706 EXPECT_EQ(ERR_IO_PENDING, rv); | 4716 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4707 | 4717 |
| 4708 rv = callback2.WaitForResult(); | 4718 rv = callback2.WaitForResult(); |
| 4709 EXPECT_EQ(OK, rv); | 4719 EXPECT_EQ(OK, rv); |
| 4710 | 4720 |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5384 LoadTimingInfo load_timing_info; | 5394 LoadTimingInfo load_timing_info; |
| 5385 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | 5395 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5386 TestLoadTimingNotReused(load_timing_info, | 5396 TestLoadTimingNotReused(load_timing_info, |
| 5387 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); | 5397 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5388 | 5398 |
| 5389 const HttpResponseInfo* response = trans->GetResponseInfo(); | 5399 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5390 ASSERT_TRUE(response); | 5400 ASSERT_TRUE(response); |
| 5391 ASSERT_TRUE(response->headers); | 5401 ASSERT_TRUE(response->headers); |
| 5392 EXPECT_EQ(407, response->headers->response_code()); | 5402 EXPECT_EQ(407, response->headers->response_code()); |
| 5393 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | 5403 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5394 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); | 5404 EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
| 5395 | 5405 |
| 5396 TestCompletionCallback callback2; | 5406 TestCompletionCallback callback2; |
| 5397 | 5407 |
| 5398 rv = trans->RestartWithAuth( | 5408 rv = trans->RestartWithAuth( |
| 5399 AuthCredentials(kFoo, kBar), callback2.callback()); | 5409 AuthCredentials(kFoo, kBar), callback2.callback()); |
| 5400 EXPECT_EQ(ERR_IO_PENDING, rv); | 5410 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5401 | 5411 |
| 5402 rv = callback2.WaitForResult(); | 5412 rv = callback2.WaitForResult(); |
| 5403 EXPECT_EQ(OK, rv); | 5413 EXPECT_EQ(OK, rv); |
| 5404 | 5414 |
| (...skipping 1560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6965 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | 6975 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 6966 EXPECT_EQ(ERR_IO_PENDING, rv); | 6976 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6967 | 6977 |
| 6968 rv = callback1.WaitForResult(); | 6978 rv = callback1.WaitForResult(); |
| 6969 EXPECT_EQ(OK, rv); | 6979 EXPECT_EQ(OK, rv); |
| 6970 | 6980 |
| 6971 const HttpResponseInfo* response = trans->GetResponseInfo(); | 6981 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6972 ASSERT_TRUE(response); | 6982 ASSERT_TRUE(response); |
| 6973 ASSERT_TRUE(response->auth_challenge); | 6983 ASSERT_TRUE(response->auth_challenge); |
| 6974 EXPECT_FALSE(response->auth_challenge->is_proxy); | 6984 EXPECT_FALSE(response->auth_challenge->is_proxy); |
| 6975 EXPECT_EQ("www.example.org:80", | 6985 EXPECT_EQ("http://www.example.org", |
| 6976 response->auth_challenge->challenger.ToString()); | 6986 response->auth_challenge->challenger.Serialize()); |
| 6977 EXPECT_EQ("MyRealm2", response->auth_challenge->realm); | 6987 EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
| 6978 EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); | 6988 EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
| 6979 | 6989 |
| 6980 TestCompletionCallback callback2; | 6990 TestCompletionCallback callback2; |
| 6981 | 6991 |
| 6982 rv = trans->RestartWithAuth( | 6992 rv = trans->RestartWithAuth( |
| 6983 AuthCredentials(kFoo2, kBar2), callback2.callback()); | 6993 AuthCredentials(kFoo2, kBar2), callback2.callback()); |
| 6984 EXPECT_EQ(ERR_IO_PENDING, rv); | 6994 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6985 | 6995 |
| 6986 rv = callback2.WaitForResult(); | 6996 rv = callback2.WaitForResult(); |
| (...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7939 entries, pos, | 7949 entries, pos, |
| 7940 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, | 7950 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 7941 NetLog::PHASE_NONE); | 7951 NetLog::PHASE_NONE); |
| 7942 | 7952 |
| 7943 const HttpResponseInfo* response = trans->GetResponseInfo(); | 7953 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7944 ASSERT_TRUE(response); | 7954 ASSERT_TRUE(response); |
| 7945 ASSERT_TRUE(response->headers); | 7955 ASSERT_TRUE(response->headers); |
| 7946 EXPECT_EQ(407, response->headers->response_code()); | 7956 EXPECT_EQ(407, response->headers->response_code()); |
| 7947 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | 7957 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7948 EXPECT_TRUE(response->auth_challenge); | 7958 EXPECT_TRUE(response->auth_challenge); |
| 7949 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); | 7959 EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
| 7950 | 7960 |
| 7951 TestCompletionCallback callback2; | 7961 TestCompletionCallback callback2; |
| 7952 | 7962 |
| 7953 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), | 7963 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7954 callback2.callback()); | 7964 callback2.callback()); |
| 7955 EXPECT_EQ(ERR_IO_PENDING, rv); | 7965 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7956 | 7966 |
| 7957 rv = callback2.WaitForResult(); | 7967 rv = callback2.WaitForResult(); |
| 7958 EXPECT_EQ(OK, rv); | 7968 EXPECT_EQ(OK, rv); |
| 7959 | 7969 |
| (...skipping 1921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9881 // transaction completes. | 9891 // transaction completes. |
| 9882 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | 9892 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 9883 EXPECT_EQ(ERR_IO_PENDING, rv); | 9893 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9884 rv = callback1.WaitForResult(); | 9894 rv = callback1.WaitForResult(); |
| 9885 EXPECT_EQ(OK, rv); | 9895 EXPECT_EQ(OK, rv); |
| 9886 const HttpResponseInfo* response = trans->GetResponseInfo(); | 9896 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9887 ASSERT_TRUE(response); | 9897 ASSERT_TRUE(response); |
| 9888 const AuthChallengeInfo* challenge = response->auth_challenge.get(); | 9898 const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 9889 ASSERT_TRUE(challenge); | 9899 ASSERT_TRUE(challenge); |
| 9890 EXPECT_FALSE(challenge->is_proxy); | 9900 EXPECT_FALSE(challenge->is_proxy); |
| 9891 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); | 9901 EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
| 9892 EXPECT_EQ("first_realm", challenge->realm); | 9902 EXPECT_EQ("first_realm", challenge->realm); |
| 9893 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); | 9903 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
| 9894 | 9904 |
| 9895 // Issue the second request with an incorrect password. There should be a | 9905 // Issue the second request with an incorrect password. There should be a |
| 9896 // password prompt for second_realm waiting to be filled in after the | 9906 // password prompt for second_realm waiting to be filled in after the |
| 9897 // transaction completes. | 9907 // transaction completes. |
| 9898 TestCompletionCallback callback2; | 9908 TestCompletionCallback callback2; |
| 9899 rv = trans->RestartWithAuth( | 9909 rv = trans->RestartWithAuth( |
| 9900 AuthCredentials(kFirst, kBaz), callback2.callback()); | 9910 AuthCredentials(kFirst, kBaz), callback2.callback()); |
| 9901 EXPECT_EQ(ERR_IO_PENDING, rv); | 9911 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9902 rv = callback2.WaitForResult(); | 9912 rv = callback2.WaitForResult(); |
| 9903 EXPECT_EQ(OK, rv); | 9913 EXPECT_EQ(OK, rv); |
| 9904 response = trans->GetResponseInfo(); | 9914 response = trans->GetResponseInfo(); |
| 9905 ASSERT_TRUE(response); | 9915 ASSERT_TRUE(response); |
| 9906 challenge = response->auth_challenge.get(); | 9916 challenge = response->auth_challenge.get(); |
| 9907 ASSERT_TRUE(challenge); | 9917 ASSERT_TRUE(challenge); |
| 9908 EXPECT_FALSE(challenge->is_proxy); | 9918 EXPECT_FALSE(challenge->is_proxy); |
| 9909 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); | 9919 EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
| 9910 EXPECT_EQ("second_realm", challenge->realm); | 9920 EXPECT_EQ("second_realm", challenge->realm); |
| 9911 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); | 9921 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
| 9912 | 9922 |
| 9913 // Issue the third request with another incorrect password. There should be | 9923 // Issue the third request with another incorrect password. There should be |
| 9914 // a password prompt for first_realm waiting to be filled in. If the password | 9924 // a password prompt for first_realm waiting to be filled in. If the password |
| 9915 // prompt is not present, it indicates that the HttpAuthCacheEntry for | 9925 // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 9916 // first_realm was not correctly removed. | 9926 // first_realm was not correctly removed. |
| 9917 TestCompletionCallback callback3; | 9927 TestCompletionCallback callback3; |
| 9918 rv = trans->RestartWithAuth( | 9928 rv = trans->RestartWithAuth( |
| 9919 AuthCredentials(kSecond, kFou), callback3.callback()); | 9929 AuthCredentials(kSecond, kFou), callback3.callback()); |
| 9920 EXPECT_EQ(ERR_IO_PENDING, rv); | 9930 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9921 rv = callback3.WaitForResult(); | 9931 rv = callback3.WaitForResult(); |
| 9922 EXPECT_EQ(OK, rv); | 9932 EXPECT_EQ(OK, rv); |
| 9923 response = trans->GetResponseInfo(); | 9933 response = trans->GetResponseInfo(); |
| 9924 ASSERT_TRUE(response); | 9934 ASSERT_TRUE(response); |
| 9925 challenge = response->auth_challenge.get(); | 9935 challenge = response->auth_challenge.get(); |
| 9926 ASSERT_TRUE(challenge); | 9936 ASSERT_TRUE(challenge); |
| 9927 EXPECT_FALSE(challenge->is_proxy); | 9937 EXPECT_FALSE(challenge->is_proxy); |
| 9928 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); | 9938 EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
| 9929 EXPECT_EQ("first_realm", challenge->realm); | 9939 EXPECT_EQ("first_realm", challenge->realm); |
| 9930 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); | 9940 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
| 9931 | 9941 |
| 9932 // Issue the fourth request with the correct password and username. | 9942 // Issue the fourth request with the correct password and username. |
| 9933 TestCompletionCallback callback4; | 9943 TestCompletionCallback callback4; |
| 9934 rv = trans->RestartWithAuth( | 9944 rv = trans->RestartWithAuth( |
| 9935 AuthCredentials(kFirst, kBar), callback4.callback()); | 9945 AuthCredentials(kFirst, kBar), callback4.callback()); |
| 9936 EXPECT_EQ(ERR_IO_PENDING, rv); | 9946 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9937 rv = callback4.WaitForResult(); | 9947 rv = callback4.WaitForResult(); |
| 9938 EXPECT_EQ(OK, rv); | 9948 EXPECT_EQ(OK, rv); |
| (...skipping 6195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16134 base::RunLoop().RunUntilIdle(); | 16144 base::RunLoop().RunUntilIdle(); |
| 16135 | 16145 |
| 16136 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); | 16146 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 16137 HttpRequestHeaders headers; | 16147 HttpRequestHeaders headers; |
| 16138 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); | 16148 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 16139 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); | 16149 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 16140 } | 16150 } |
| 16141 #endif // !defined(OS_IOS) | 16151 #endif // !defined(OS_IOS) |
| 16142 | 16152 |
| 16143 } // namespace net | 16153 } // namespace net |
| OLD | NEW |