OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 #endif | 10 #endif |
(...skipping 3895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3906 << " Parameter = \"" << test_file << "\""; | 3906 << " Parameter = \"" << test_file << "\""; |
3907 } else { | 3907 } else { |
3908 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); | 3908 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
3909 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, r->status().error()) | 3909 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, r->status().error()) |
3910 << " Parameter = \"" << test_file << "\""; | 3910 << " Parameter = \"" << test_file << "\""; |
3911 } | 3911 } |
3912 } | 3912 } |
3913 } | 3913 } |
3914 } | 3914 } |
3915 | 3915 |
3916 TEST_F(URLRequestTestHTTP, HTTPSToHTTPRedirectNoRefererTest) { | |
3917 ASSERT_TRUE(test_server_.Start()); | |
3918 | |
3919 SpawnedTestServer https_test_server( | |
3920 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, | |
3921 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | |
3922 ASSERT_TRUE(https_test_server.Start()); | |
3923 | |
3924 // An https server is sent a request with an https referer, | |
3925 // and responds with a redirect to an http url. The http | |
3926 // server should not be sent the referer. | |
3927 GURL http_destination = test_server_.GetURL(std::string()); | |
3928 TestDelegate d; | |
3929 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | |
3930 https_test_server.GetURL("server-redirect?" + http_destination.spec()), | |
3931 DEFAULT_PRIORITY, &d, NULL)); | |
3932 req->SetReferrer("https://www.referrer.com/"); | |
3933 req->Start(); | |
3934 base::RunLoop().Run(); | |
3935 | |
3936 EXPECT_EQ(1, d.response_started_count()); | |
3937 EXPECT_EQ(1, d.received_redirect_count()); | |
3938 EXPECT_EQ(http_destination, req->url()); | |
3939 EXPECT_EQ(std::string(), req->referrer()); | |
3940 } | |
3941 | |
3942 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { | 3916 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { |
3943 ASSERT_TRUE(test_server_.Start()); | 3917 ASSERT_TRUE(test_server_.Start()); |
3944 | 3918 |
3945 GURL destination_url = test_server_.GetURL(std::string()); | 3919 GURL destination_url = test_server_.GetURL(std::string()); |
3946 GURL original_url = | 3920 GURL original_url = |
3947 test_server_.GetURL("server-redirect?" + destination_url.spec()); | 3921 test_server_.GetURL("server-redirect?" + destination_url.spec()); |
3948 TestDelegate d; | 3922 TestDelegate d; |
3949 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 3923 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
3950 original_url, DEFAULT_PRIORITY, &d, NULL)); | 3924 original_url, DEFAULT_PRIORITY, &d, NULL)); |
3951 req->Start(); | 3925 req->Start(); |
(...skipping 2768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6720 EXPECT_EQ(200, req->response_headers()->response_code()); | 6694 EXPECT_EQ(200, req->response_headers()->response_code()); |
6721 EXPECT_EQ("hello", d.data_received()); | 6695 EXPECT_EQ("hello", d.data_received()); |
6722 EXPECT_EQ(1, d.response_started_count()); | 6696 EXPECT_EQ(1, d.response_started_count()); |
6723 EXPECT_EQ(0, d.received_redirect_count()); | 6697 EXPECT_EQ(0, d.received_redirect_count()); |
6724 | 6698 |
6725 EXPECT_EQ(1, default_network_delegate()->created_requests()); | 6699 EXPECT_EQ(1, default_network_delegate()->created_requests()); |
6726 EXPECT_EQ(2, default_network_delegate()->before_send_headers_count()); | 6700 EXPECT_EQ(2, default_network_delegate()->before_send_headers_count()); |
6727 EXPECT_EQ(2, default_network_delegate()->headers_received_count()); | 6701 EXPECT_EQ(2, default_network_delegate()->headers_received_count()); |
6728 } | 6702 } |
6729 | 6703 |
| 6704 class URLRequestTestReferrerPolicy : public URLRequestTest { |
| 6705 public: |
| 6706 URLRequestTestReferrerPolicy() {} |
| 6707 |
| 6708 void InstantiateSameOriginServers(SpawnedTestServer::Type origin_type) { |
| 6709 origin_server_.reset(new SpawnedTestServer( |
| 6710 origin_type, SpawnedTestServer::kLocalhost, |
| 6711 origin_type == SpawnedTestServer::TYPE_HTTPS |
| 6712 ? base::FilePath(FILE_PATH_LITERAL("net/data/ssl")) |
| 6713 : base::FilePath( |
| 6714 FILE_PATH_LITERAL("net/data/url_request_unittest")))); |
| 6715 ASSERT_TRUE(origin_server_->Start()); |
| 6716 } |
| 6717 |
| 6718 void InstantiateCrossOriginServers(SpawnedTestServer::Type origin_type, |
| 6719 SpawnedTestServer::Type destination_type) { |
| 6720 origin_server_.reset(new SpawnedTestServer( |
| 6721 origin_type, SpawnedTestServer::kLocalhost, |
| 6722 origin_type == SpawnedTestServer::TYPE_HTTPS |
| 6723 ? base::FilePath(FILE_PATH_LITERAL("net/data/ssl")) |
| 6724 : base::FilePath( |
| 6725 FILE_PATH_LITERAL("net/data/url_request_unittest")))); |
| 6726 ASSERT_TRUE(origin_server_->Start()); |
| 6727 |
| 6728 destination_server_.reset(new SpawnedTestServer( |
| 6729 destination_type, SpawnedTestServer::kLocalhost, |
| 6730 destination_type == SpawnedTestServer::TYPE_HTTPS |
| 6731 ? base::FilePath(FILE_PATH_LITERAL("net/data/ssl")) |
| 6732 : base::FilePath( |
| 6733 FILE_PATH_LITERAL("net/data/url_request_unittest")))); |
| 6734 ASSERT_TRUE(destination_server_->Start()); |
| 6735 } |
| 6736 |
| 6737 void VerifyReferrerAfterRedirect(URLRequest::ReferrerPolicy policy, |
| 6738 const GURL& referrer, |
| 6739 const GURL& expected) { |
| 6740 // Create and execute the request: we'll only have a |destination_server_| |
| 6741 // if the origins are meant to be distinct. Otherwise, we'll use the |
| 6742 // |origin_server_| for both endpoints. |
| 6743 GURL destination_url = |
| 6744 destination_server_ ? destination_server_->GetURL("echoheader?Referer") |
| 6745 : origin_server_->GetURL("echoheader?Referer"); |
| 6746 GURL origin_url = |
| 6747 origin_server_->GetURL("server-redirect?" + destination_url.spec()); |
| 6748 |
| 6749 TestDelegate d; |
| 6750 scoped_ptr<URLRequest> req( |
| 6751 default_context_.CreateRequest(origin_url, DEFAULT_PRIORITY, &d, NULL)); |
| 6752 req->set_referrer_policy(policy); |
| 6753 req->SetReferrer(referrer.spec()); |
| 6754 req->Start(); |
| 6755 base::RunLoop().Run(); |
| 6756 |
| 6757 EXPECT_EQ(1, d.response_started_count()); |
| 6758 EXPECT_EQ(1, d.received_redirect_count()); |
| 6759 EXPECT_EQ(destination_url, req->url()); |
| 6760 EXPECT_TRUE(req->status().is_success()); |
| 6761 EXPECT_EQ(200, req->response_headers()->response_code()); |
| 6762 |
| 6763 EXPECT_EQ(expected.spec(), req->referrer()); |
| 6764 if (expected.is_empty()) |
| 6765 EXPECT_EQ("None", d.data_received()); |
| 6766 else |
| 6767 EXPECT_EQ(expected.spec(), d.data_received()); |
| 6768 } |
| 6769 |
| 6770 SpawnedTestServer* origin_server() const { return origin_server_.get(); } |
| 6771 |
| 6772 private: |
| 6773 scoped_ptr<SpawnedTestServer> origin_server_; |
| 6774 scoped_ptr<SpawnedTestServer> destination_server_; |
| 6775 }; |
| 6776 |
| 6777 TEST_F(URLRequestTestReferrerPolicy, HTTPToSameOriginHTTP) { |
| 6778 InstantiateSameOriginServers(SpawnedTestServer::TYPE_HTTP); |
| 6779 |
| 6780 VerifyReferrerAfterRedirect( |
| 6781 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 6782 origin_server()->GetURL("path/to/file.html"), |
| 6783 origin_server()->GetURL("path/to/file.html")); |
| 6784 |
| 6785 VerifyReferrerAfterRedirect( |
| 6786 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, |
| 6787 origin_server()->GetURL("path/to/file.html"), |
| 6788 origin_server()->GetURL("path/to/file.html")); |
| 6789 |
| 6790 VerifyReferrerAfterRedirect( |
| 6791 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, |
| 6792 origin_server()->GetURL("path/to/file.html"), |
| 6793 origin_server()->GetURL("path/to/file.html")); |
| 6794 |
| 6795 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, |
| 6796 origin_server()->GetURL("path/to/file.html"), |
| 6797 origin_server()->GetURL("path/to/file.html")); |
| 6798 } |
| 6799 |
| 6800 TEST_F(URLRequestTestReferrerPolicy, HTTPToCrossOriginHTTP) { |
| 6801 InstantiateCrossOriginServers(SpawnedTestServer::TYPE_HTTP, |
| 6802 SpawnedTestServer::TYPE_HTTP); |
| 6803 |
| 6804 VerifyReferrerAfterRedirect( |
| 6805 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 6806 origin_server()->GetURL("path/to/file.html"), |
| 6807 origin_server()->GetURL("path/to/file.html")); |
| 6808 |
| 6809 VerifyReferrerAfterRedirect( |
| 6810 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, |
| 6811 origin_server()->GetURL("path/to/file.html"), |
| 6812 origin_server()->GetURL(std::string())); |
| 6813 |
| 6814 VerifyReferrerAfterRedirect( |
| 6815 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, |
| 6816 origin_server()->GetURL("path/to/file.html"), |
| 6817 origin_server()->GetURL(std::string())); |
| 6818 |
| 6819 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, |
| 6820 origin_server()->GetURL("path/to/file.html"), |
| 6821 origin_server()->GetURL("path/to/file.html")); |
| 6822 } |
| 6823 |
| 6824 TEST_F(URLRequestTestReferrerPolicy, HTTPSToSameOriginHTTPS) { |
| 6825 InstantiateSameOriginServers(SpawnedTestServer::TYPE_HTTPS); |
| 6826 |
| 6827 VerifyReferrerAfterRedirect( |
| 6828 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 6829 origin_server()->GetURL("path/to/file.html"), |
| 6830 origin_server()->GetURL("path/to/file.html")); |
| 6831 |
| 6832 VerifyReferrerAfterRedirect( |
| 6833 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, |
| 6834 origin_server()->GetURL("path/to/file.html"), |
| 6835 origin_server()->GetURL("path/to/file.html")); |
| 6836 |
| 6837 VerifyReferrerAfterRedirect( |
| 6838 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, |
| 6839 origin_server()->GetURL("path/to/file.html"), |
| 6840 origin_server()->GetURL("path/to/file.html")); |
| 6841 |
| 6842 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, |
| 6843 origin_server()->GetURL("path/to/file.html"), |
| 6844 origin_server()->GetURL("path/to/file.html")); |
| 6845 } |
| 6846 |
| 6847 TEST_F(URLRequestTestReferrerPolicy, HTTPSToCrossOriginHTTPS) { |
| 6848 InstantiateCrossOriginServers(SpawnedTestServer::TYPE_HTTPS, |
| 6849 SpawnedTestServer::TYPE_HTTPS); |
| 6850 |
| 6851 VerifyReferrerAfterRedirect( |
| 6852 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 6853 origin_server()->GetURL("path/to/file.html"), |
| 6854 origin_server()->GetURL("path/to/file.html")); |
| 6855 |
| 6856 VerifyReferrerAfterRedirect( |
| 6857 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, |
| 6858 origin_server()->GetURL("path/to/file.html"), |
| 6859 origin_server()->GetURL(std::string())); |
| 6860 |
| 6861 VerifyReferrerAfterRedirect( |
| 6862 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, |
| 6863 origin_server()->GetURL("path/to/file.html"), |
| 6864 origin_server()->GetURL(std::string())); |
| 6865 |
| 6866 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, |
| 6867 origin_server()->GetURL("path/to/file.html"), |
| 6868 origin_server()->GetURL("path/to/file.html")); |
| 6869 } |
| 6870 |
| 6871 TEST_F(URLRequestTestReferrerPolicy, HTTPToHTTPS) { |
| 6872 InstantiateCrossOriginServers(SpawnedTestServer::TYPE_HTTP, |
| 6873 SpawnedTestServer::TYPE_HTTPS); |
| 6874 |
| 6875 VerifyReferrerAfterRedirect( |
| 6876 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 6877 origin_server()->GetURL("path/to/file.html"), |
| 6878 origin_server()->GetURL("path/to/file.html")); |
| 6879 |
| 6880 VerifyReferrerAfterRedirect( |
| 6881 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, |
| 6882 origin_server()->GetURL("path/to/file.html"), |
| 6883 origin_server()->GetURL(std::string())); |
| 6884 |
| 6885 VerifyReferrerAfterRedirect( |
| 6886 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, |
| 6887 origin_server()->GetURL("path/to/file.html"), |
| 6888 origin_server()->GetURL(std::string())); |
| 6889 |
| 6890 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, |
| 6891 origin_server()->GetURL("path/to/file.html"), |
| 6892 origin_server()->GetURL("path/to/file.html")); |
| 6893 } |
| 6894 |
| 6895 TEST_F(URLRequestTestReferrerPolicy, HTTPSToHTTP) { |
| 6896 InstantiateCrossOriginServers(SpawnedTestServer::TYPE_HTTPS, |
| 6897 SpawnedTestServer::TYPE_HTTP); |
| 6898 |
| 6899 VerifyReferrerAfterRedirect( |
| 6900 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 6901 origin_server()->GetURL("path/to/file.html"), GURL()); |
| 6902 |
| 6903 VerifyReferrerAfterRedirect( |
| 6904 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, |
| 6905 origin_server()->GetURL("path/to/file.html"), GURL()); |
| 6906 |
| 6907 VerifyReferrerAfterRedirect( |
| 6908 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, |
| 6909 origin_server()->GetURL("path/to/file.html"), |
| 6910 origin_server()->GetURL(std::string())); |
| 6911 |
| 6912 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, |
| 6913 origin_server()->GetURL("path/to/file.html"), |
| 6914 origin_server()->GetURL("path/to/file.html")); |
| 6915 } |
| 6916 |
6730 class HTTPSRequestTest : public testing::Test { | 6917 class HTTPSRequestTest : public testing::Test { |
6731 public: | 6918 public: |
6732 HTTPSRequestTest() : default_context_(true) { | 6919 HTTPSRequestTest() : default_context_(true) { |
6733 default_context_.set_network_delegate(&default_network_delegate_); | 6920 default_context_.set_network_delegate(&default_network_delegate_); |
6734 default_context_.Init(); | 6921 default_context_.Init(); |
6735 } | 6922 } |
6736 ~HTTPSRequestTest() override {} | 6923 ~HTTPSRequestTest() override {} |
6737 | 6924 |
6738 protected: | 6925 protected: |
6739 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 6926 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7974 DoConnection(ssl_options, &cert_status); | 8161 DoConnection(ssl_options, &cert_status); |
7975 | 8162 |
7976 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS); | 8163 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS); |
7977 | 8164 |
7978 EXPECT_EQ(SystemUsesChromiumEVMetadata(), | 8165 EXPECT_EQ(SystemUsesChromiumEVMetadata(), |
7979 static_cast<bool>(cert_status & CERT_STATUS_IS_EV)); | 8166 static_cast<bool>(cert_status & CERT_STATUS_IS_EV)); |
7980 | 8167 |
7981 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); | 8168 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); |
7982 } | 8169 } |
7983 | 8170 |
7984 TEST_F(HTTPSOCSPTest, RevokedStapled) { | 8171 // Disabled on NSS ports. See https://crbug.com/431716. |
| 8172 #if defined(USE_NSS) |
| 8173 #define MAYBE_RevokedStapled DISABLED_RevokedStapled |
| 8174 #else |
| 8175 #define MAYBE_RevokedStapled RevokedStapled |
| 8176 #endif |
| 8177 TEST_F(HTTPSOCSPTest, MAYBE_RevokedStapled) { |
7985 if (!SystemSupportsOCSPStapling()) { | 8178 if (!SystemSupportsOCSPStapling()) { |
7986 LOG(WARNING) | 8179 LOG(WARNING) |
7987 << "Skipping test because system doesn't support OCSP stapling"; | 8180 << "Skipping test because system doesn't support OCSP stapling"; |
7988 return; | 8181 return; |
7989 } | 8182 } |
7990 | 8183 |
7991 SpawnedTestServer::SSLOptions ssl_options( | 8184 SpawnedTestServer::SSLOptions ssl_options( |
7992 SpawnedTestServer::SSLOptions::CERT_AUTO); | 8185 SpawnedTestServer::SSLOptions::CERT_AUTO); |
7993 ssl_options.ocsp_status = SpawnedTestServer::SSLOptions::OCSP_REVOKED; | 8186 ssl_options.ocsp_status = SpawnedTestServer::SSLOptions::OCSP_REVOKED; |
7994 ssl_options.staple_ocsp_response = true; | 8187 ssl_options.staple_ocsp_response = true; |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8622 | 8815 |
8623 EXPECT_FALSE(r->is_pending()); | 8816 EXPECT_FALSE(r->is_pending()); |
8624 EXPECT_EQ(1, d->response_started_count()); | 8817 EXPECT_EQ(1, d->response_started_count()); |
8625 EXPECT_FALSE(d->received_data_before_response()); | 8818 EXPECT_FALSE(d->received_data_before_response()); |
8626 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 8819 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
8627 } | 8820 } |
8628 } | 8821 } |
8629 #endif // !defined(DISABLE_FTP_SUPPORT) | 8822 #endif // !defined(DISABLE_FTP_SUPPORT) |
8630 | 8823 |
8631 } // namespace net | 8824 } // namespace net |
OLD | NEW |