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 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 } | 663 } |
664 | 664 |
665 //----------------------------------------------------------------------------- | 665 //----------------------------------------------------------------------------- |
666 | 666 |
667 // Helper functions for validating that AuthChallengeInfo's are correctly | 667 // Helper functions for validating that AuthChallengeInfo's are correctly |
668 // configured for common cases. | 668 // configured for common cases. |
669 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { | 669 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
670 if (!auth_challenge) | 670 if (!auth_challenge) |
671 return false; | 671 return false; |
672 EXPECT_FALSE(auth_challenge->is_proxy); | 672 EXPECT_FALSE(auth_challenge->is_proxy); |
673 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); | 673 EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
674 EXPECT_EQ("MyRealm1", auth_challenge->realm); | 674 EXPECT_EQ("MyRealm1", auth_challenge->realm); |
675 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); | 675 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
676 return true; | 676 return true; |
677 } | 677 } |
678 | 678 |
679 bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { | 679 bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
680 if (!auth_challenge) | 680 if (!auth_challenge) |
681 return false; | 681 return false; |
682 EXPECT_TRUE(auth_challenge->is_proxy); | 682 EXPECT_TRUE(auth_challenge->is_proxy); |
683 EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); | 683 EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
684 EXPECT_EQ("MyRealm1", auth_challenge->realm); | 684 EXPECT_EQ("MyRealm1", auth_challenge->realm); |
685 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); | 685 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
686 return true; | 686 return true; |
| 687 } |
| 688 |
| 689 bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 690 if (!auth_challenge) |
| 691 return false; |
| 692 EXPECT_TRUE(auth_challenge->is_proxy); |
| 693 EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
| 694 EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 695 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 696 return true; |
687 } | 697 } |
688 | 698 |
689 bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { | 699 bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
690 if (!auth_challenge) | 700 if (!auth_challenge) |
691 return false; | 701 return false; |
692 EXPECT_FALSE(auth_challenge->is_proxy); | 702 EXPECT_FALSE(auth_challenge->is_proxy); |
693 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); | 703 EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
694 EXPECT_EQ("digestive", auth_challenge->realm); | 704 EXPECT_EQ("digestive", auth_challenge->realm); |
695 EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); | 705 EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
696 return true; | 706 return true; |
697 } | 707 } |
698 | 708 |
699 #if defined(NTLM_PORTABLE) | 709 #if defined(NTLM_PORTABLE) |
700 bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { | 710 bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
701 if (!auth_challenge) | 711 if (!auth_challenge) |
702 return false; | 712 return false; |
703 EXPECT_FALSE(auth_challenge->is_proxy); | 713 EXPECT_FALSE(auth_challenge->is_proxy); |
704 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); | 714 EXPECT_EQ("http://172.22.68.17", auth_challenge->challenger.Serialize()); |
705 EXPECT_EQ(std::string(), auth_challenge->realm); | 715 EXPECT_EQ(std::string(), auth_challenge->realm); |
706 EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); | 716 EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
707 return true; | 717 return true; |
708 } | 718 } |
709 #endif // defined(NTLM_PORTABLE) | 719 #endif // defined(NTLM_PORTABLE) |
710 | 720 |
711 } // namespace | 721 } // namespace |
712 | 722 |
713 TEST_P(HttpNetworkTransactionTest, Basic) { | 723 TEST_P(HttpNetworkTransactionTest, Basic) { |
714 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 724 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
(...skipping 3686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4401 | 4411 |
4402 rv = callback1.WaitForResult(); | 4412 rv = callback1.WaitForResult(); |
4403 EXPECT_EQ(OK, rv); | 4413 EXPECT_EQ(OK, rv); |
4404 | 4414 |
4405 const HttpResponseInfo* const response = trans->GetResponseInfo(); | 4415 const HttpResponseInfo* const response = trans->GetResponseInfo(); |
4406 | 4416 |
4407 ASSERT_TRUE(response != NULL); | 4417 ASSERT_TRUE(response != NULL); |
4408 ASSERT_TRUE(response->headers.get() != NULL); | 4418 ASSERT_TRUE(response->headers.get() != NULL); |
4409 EXPECT_EQ(407, response->headers->response_code()); | 4419 EXPECT_EQ(407, response->headers->response_code()); |
4410 EXPECT_TRUE(response->was_fetched_via_spdy); | 4420 EXPECT_TRUE(response->was_fetched_via_spdy); |
4411 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); | 4421 EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
4412 | 4422 |
4413 TestCompletionCallback callback2; | 4423 TestCompletionCallback callback2; |
4414 | 4424 |
4415 rv = trans->RestartWithAuth( | 4425 rv = trans->RestartWithAuth( |
4416 AuthCredentials(kFoo, kBar), callback2.callback()); | 4426 AuthCredentials(kFoo, kBar), callback2.callback()); |
4417 EXPECT_EQ(ERR_IO_PENDING, rv); | 4427 EXPECT_EQ(ERR_IO_PENDING, rv); |
4418 | 4428 |
4419 rv = callback2.WaitForResult(); | 4429 rv = callback2.WaitForResult(); |
4420 EXPECT_EQ(OK, rv); | 4430 EXPECT_EQ(OK, rv); |
4421 | 4431 |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5095 LoadTimingInfo load_timing_info; | 5105 LoadTimingInfo load_timing_info; |
5096 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | 5106 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
5097 TestLoadTimingNotReused(load_timing_info, | 5107 TestLoadTimingNotReused(load_timing_info, |
5098 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); | 5108 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
5099 | 5109 |
5100 const HttpResponseInfo* response = trans->GetResponseInfo(); | 5110 const HttpResponseInfo* response = trans->GetResponseInfo(); |
5101 ASSERT_TRUE(response != NULL); | 5111 ASSERT_TRUE(response != NULL); |
5102 ASSERT_FALSE(response->headers.get() == NULL); | 5112 ASSERT_FALSE(response->headers.get() == NULL); |
5103 EXPECT_EQ(407, response->headers->response_code()); | 5113 EXPECT_EQ(407, response->headers->response_code()); |
5104 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | 5114 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
5105 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); | 5115 EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
5106 | 5116 |
5107 TestCompletionCallback callback2; | 5117 TestCompletionCallback callback2; |
5108 | 5118 |
5109 rv = trans->RestartWithAuth( | 5119 rv = trans->RestartWithAuth( |
5110 AuthCredentials(kFoo, kBar), callback2.callback()); | 5120 AuthCredentials(kFoo, kBar), callback2.callback()); |
5111 EXPECT_EQ(ERR_IO_PENDING, rv); | 5121 EXPECT_EQ(ERR_IO_PENDING, rv); |
5112 | 5122 |
5113 rv = callback2.WaitForResult(); | 5123 rv = callback2.WaitForResult(); |
5114 EXPECT_EQ(OK, rv); | 5124 EXPECT_EQ(OK, rv); |
5115 | 5125 |
(...skipping 1560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6676 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | 6686 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
6677 EXPECT_EQ(ERR_IO_PENDING, rv); | 6687 EXPECT_EQ(ERR_IO_PENDING, rv); |
6678 | 6688 |
6679 rv = callback1.WaitForResult(); | 6689 rv = callback1.WaitForResult(); |
6680 EXPECT_EQ(OK, rv); | 6690 EXPECT_EQ(OK, rv); |
6681 | 6691 |
6682 const HttpResponseInfo* response = trans->GetResponseInfo(); | 6692 const HttpResponseInfo* response = trans->GetResponseInfo(); |
6683 ASSERT_TRUE(response != NULL); | 6693 ASSERT_TRUE(response != NULL); |
6684 ASSERT_TRUE(response->auth_challenge.get()); | 6694 ASSERT_TRUE(response->auth_challenge.get()); |
6685 EXPECT_FALSE(response->auth_challenge->is_proxy); | 6695 EXPECT_FALSE(response->auth_challenge->is_proxy); |
6686 EXPECT_EQ("www.example.org:80", | 6696 EXPECT_EQ("http://www.example.org", |
6687 response->auth_challenge->challenger.ToString()); | 6697 response->auth_challenge->challenger.Serialize()); |
6688 EXPECT_EQ("MyRealm2", response->auth_challenge->realm); | 6698 EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
6689 EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); | 6699 EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
6690 | 6700 |
6691 TestCompletionCallback callback2; | 6701 TestCompletionCallback callback2; |
6692 | 6702 |
6693 rv = trans->RestartWithAuth( | 6703 rv = trans->RestartWithAuth( |
6694 AuthCredentials(kFoo2, kBar2), callback2.callback()); | 6704 AuthCredentials(kFoo2, kBar2), callback2.callback()); |
6695 EXPECT_EQ(ERR_IO_PENDING, rv); | 6705 EXPECT_EQ(ERR_IO_PENDING, rv); |
6696 | 6706 |
6697 rv = callback2.WaitForResult(); | 6707 rv = callback2.WaitForResult(); |
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7650 entries, pos, | 7660 entries, pos, |
7651 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, | 7661 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
7652 NetLog::PHASE_NONE); | 7662 NetLog::PHASE_NONE); |
7653 | 7663 |
7654 const HttpResponseInfo* response = trans->GetResponseInfo(); | 7664 const HttpResponseInfo* response = trans->GetResponseInfo(); |
7655 ASSERT_TRUE(response != NULL); | 7665 ASSERT_TRUE(response != NULL); |
7656 ASSERT_FALSE(response->headers.get() == NULL); | 7666 ASSERT_FALSE(response->headers.get() == NULL); |
7657 EXPECT_EQ(407, response->headers->response_code()); | 7667 EXPECT_EQ(407, response->headers->response_code()); |
7658 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | 7668 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
7659 EXPECT_TRUE(response->auth_challenge.get() != NULL); | 7669 EXPECT_TRUE(response->auth_challenge.get() != NULL); |
7660 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); | 7670 EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
7661 | 7671 |
7662 TestCompletionCallback callback2; | 7672 TestCompletionCallback callback2; |
7663 | 7673 |
7664 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), | 7674 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
7665 callback2.callback()); | 7675 callback2.callback()); |
7666 EXPECT_EQ(ERR_IO_PENDING, rv); | 7676 EXPECT_EQ(ERR_IO_PENDING, rv); |
7667 | 7677 |
7668 rv = callback2.WaitForResult(); | 7678 rv = callback2.WaitForResult(); |
7669 EXPECT_EQ(OK, rv); | 7679 EXPECT_EQ(OK, rv); |
7670 | 7680 |
(...skipping 1924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9595 // transaction completes. | 9605 // transaction completes. |
9596 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | 9606 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
9597 EXPECT_EQ(ERR_IO_PENDING, rv); | 9607 EXPECT_EQ(ERR_IO_PENDING, rv); |
9598 rv = callback1.WaitForResult(); | 9608 rv = callback1.WaitForResult(); |
9599 EXPECT_EQ(OK, rv); | 9609 EXPECT_EQ(OK, rv); |
9600 const HttpResponseInfo* response = trans->GetResponseInfo(); | 9610 const HttpResponseInfo* response = trans->GetResponseInfo(); |
9601 ASSERT_TRUE(response != NULL); | 9611 ASSERT_TRUE(response != NULL); |
9602 const AuthChallengeInfo* challenge = response->auth_challenge.get(); | 9612 const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
9603 ASSERT_FALSE(challenge == NULL); | 9613 ASSERT_FALSE(challenge == NULL); |
9604 EXPECT_FALSE(challenge->is_proxy); | 9614 EXPECT_FALSE(challenge->is_proxy); |
9605 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); | 9615 EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
9606 EXPECT_EQ("first_realm", challenge->realm); | 9616 EXPECT_EQ("first_realm", challenge->realm); |
9607 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); | 9617 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
9608 | 9618 |
9609 // Issue the second request with an incorrect password. There should be a | 9619 // Issue the second request with an incorrect password. There should be a |
9610 // password prompt for second_realm waiting to be filled in after the | 9620 // password prompt for second_realm waiting to be filled in after the |
9611 // transaction completes. | 9621 // transaction completes. |
9612 TestCompletionCallback callback2; | 9622 TestCompletionCallback callback2; |
9613 rv = trans->RestartWithAuth( | 9623 rv = trans->RestartWithAuth( |
9614 AuthCredentials(kFirst, kBaz), callback2.callback()); | 9624 AuthCredentials(kFirst, kBaz), callback2.callback()); |
9615 EXPECT_EQ(ERR_IO_PENDING, rv); | 9625 EXPECT_EQ(ERR_IO_PENDING, rv); |
9616 rv = callback2.WaitForResult(); | 9626 rv = callback2.WaitForResult(); |
9617 EXPECT_EQ(OK, rv); | 9627 EXPECT_EQ(OK, rv); |
9618 response = trans->GetResponseInfo(); | 9628 response = trans->GetResponseInfo(); |
9619 ASSERT_TRUE(response != NULL); | 9629 ASSERT_TRUE(response != NULL); |
9620 challenge = response->auth_challenge.get(); | 9630 challenge = response->auth_challenge.get(); |
9621 ASSERT_FALSE(challenge == NULL); | 9631 ASSERT_FALSE(challenge == NULL); |
9622 EXPECT_FALSE(challenge->is_proxy); | 9632 EXPECT_FALSE(challenge->is_proxy); |
9623 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); | 9633 EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
9624 EXPECT_EQ("second_realm", challenge->realm); | 9634 EXPECT_EQ("second_realm", challenge->realm); |
9625 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); | 9635 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
9626 | 9636 |
9627 // Issue the third request with another incorrect password. There should be | 9637 // Issue the third request with another incorrect password. There should be |
9628 // a password prompt for first_realm waiting to be filled in. If the password | 9638 // a password prompt for first_realm waiting to be filled in. If the password |
9629 // prompt is not present, it indicates that the HttpAuthCacheEntry for | 9639 // prompt is not present, it indicates that the HttpAuthCacheEntry for |
9630 // first_realm was not correctly removed. | 9640 // first_realm was not correctly removed. |
9631 TestCompletionCallback callback3; | 9641 TestCompletionCallback callback3; |
9632 rv = trans->RestartWithAuth( | 9642 rv = trans->RestartWithAuth( |
9633 AuthCredentials(kSecond, kFou), callback3.callback()); | 9643 AuthCredentials(kSecond, kFou), callback3.callback()); |
9634 EXPECT_EQ(ERR_IO_PENDING, rv); | 9644 EXPECT_EQ(ERR_IO_PENDING, rv); |
9635 rv = callback3.WaitForResult(); | 9645 rv = callback3.WaitForResult(); |
9636 EXPECT_EQ(OK, rv); | 9646 EXPECT_EQ(OK, rv); |
9637 response = trans->GetResponseInfo(); | 9647 response = trans->GetResponseInfo(); |
9638 ASSERT_TRUE(response != NULL); | 9648 ASSERT_TRUE(response != NULL); |
9639 challenge = response->auth_challenge.get(); | 9649 challenge = response->auth_challenge.get(); |
9640 ASSERT_FALSE(challenge == NULL); | 9650 ASSERT_FALSE(challenge == NULL); |
9641 EXPECT_FALSE(challenge->is_proxy); | 9651 EXPECT_FALSE(challenge->is_proxy); |
9642 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); | 9652 EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
9643 EXPECT_EQ("first_realm", challenge->realm); | 9653 EXPECT_EQ("first_realm", challenge->realm); |
9644 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); | 9654 EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
9645 | 9655 |
9646 // Issue the fourth request with the correct password and username. | 9656 // Issue the fourth request with the correct password and username. |
9647 TestCompletionCallback callback4; | 9657 TestCompletionCallback callback4; |
9648 rv = trans->RestartWithAuth( | 9658 rv = trans->RestartWithAuth( |
9649 AuthCredentials(kFirst, kBar), callback4.callback()); | 9659 AuthCredentials(kFirst, kBar), callback4.callback()); |
9650 EXPECT_EQ(ERR_IO_PENDING, rv); | 9660 EXPECT_EQ(ERR_IO_PENDING, rv); |
9651 rv = callback4.WaitForResult(); | 9661 rv = callback4.WaitForResult(); |
9652 EXPECT_EQ(OK, rv); | 9662 EXPECT_EQ(OK, rv); |
(...skipping 6464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16117 base::MessageLoop::current()->RunUntilIdle(); | 16127 base::MessageLoop::current()->RunUntilIdle(); |
16118 | 16128 |
16119 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); | 16129 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
16120 HttpRequestHeaders headers; | 16130 HttpRequestHeaders headers; |
16121 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); | 16131 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
16122 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); | 16132 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
16123 } | 16133 } |
16124 #endif // !defined(OS_IOS) | 16134 #endif // !defined(OS_IOS) |
16125 | 16135 |
16126 } // namespace net | 16136 } // namespace net |
OLD | NEW |